From 8d99c88af55041ff06e6b9372b6b1f66220bed38 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Mon, 10 Apr 2017 16:08:58 +0000
Subject: [PATCH] #3529 feature - Added applications to user profile and upgrade to angular4

---
 securis/src/main/java/net/curisit/securis/db/User.java |   64 +++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 1 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/db/User.java b/securis/src/main/java/net/curisit/securis/db/User.java
index e1e7396..d5b0f45 100644
--- a/securis/src/main/java/net/curisit/securis/db/User.java
+++ b/securis/src/main/java/net/curisit/securis/db/User.java
@@ -2,10 +2,12 @@
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -76,6 +78,14 @@
 			inverseJoinColumns = { @JoinColumn(name = "organization_id", referencedColumnName = "id") } //
 	)
 	private Set<Organization> organizations;
+
+	@JsonIgnore
+	@ManyToMany
+	@JoinTable(name = "user_application", //
+			joinColumns = { @JoinColumn(name = "username", referencedColumnName = "username") }, //
+			inverseJoinColumns = { @JoinColumn(name = "application_id", referencedColumnName = "id") } //
+	)
+	private Set<Application> applications;
 
 	public String getUsername() {
 		return username;
@@ -182,6 +192,14 @@
 		this.organizations = organizations;
 	}
 
+	public Set<Application> getApplications() {
+		return applications;
+	}
+
+	public void setApplications(Set<Application> applications) {
+		this.applications = applications;
+	}
+
 	@JsonProperty("organizations_ids")
 	public void setOrgsIds(List<Integer> orgsIds) {
 		organizations = new HashSet<>();
@@ -204,6 +222,28 @@
 		return ids;
 	}
 
+	@JsonProperty("applications_ids")
+	public void setAppsIds(Collection<Integer> appIds) {
+		applications = new HashSet<>();
+		for (Integer appid : appIds) {
+			Application a = new Application();
+			a.setId(appid);
+			applications.add(a);
+		}
+	}
+
+	@JsonProperty("applications_ids")
+	public Set<Integer> getAppsIds() {
+		if (applications == null) {
+			return null;
+		}
+		Set<Integer> ids = new HashSet<>();
+		for (Application app : applications) {
+			ids.add(app.getId());
+		}
+		return ids;
+	}
+
 	@JsonIgnore
 	public Set<Integer> getAllOrgsIds() {
 		if (organizations == null) {
@@ -214,6 +254,22 @@
 		return ids;
 	}
 
+	@JsonIgnore
+	public Set<Integer> getAllAppsIds() {
+		if (applications == null) {
+			return null;
+		}
+		Set<Integer> ids = this.applications.parallelStream().map(app -> app.getId()).collect(Collectors.toSet());
+
+		return ids;
+	}
+
+	/**
+	 * Walk into the organization hierarchy to include all descendants
+	 * 
+	 * @param list
+	 * @param orgIds
+	 */
 	private void includeAllOrgs(Set<Organization> list, Set<Integer> orgIds) {
 		for (Organization org : list) {
 			orgIds.add(org.getId());
@@ -229,10 +285,16 @@
 		this.email = email;
 	}
 
+	/**
+	 * Numeric rol mask. Be aware to use different bit position for each role
+	 * 
+	 * @author rob
+	 */
 	public static class Rol {
 		public static final int ADVANCE = 0x01;
 		public static final int ADMIN = 0x02;
-		public static final int[] ALL = new int[] { ADVANCE, ADMIN };
+		public static final int BASIC = 0x04;
+		public static final int[] ALL = new int[] { ADVANCE, ADMIN, BASIC };
 	}
 
 }

--
Gitblit v1.3.2