UserRolesController methods up
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / fn / FnUser.java
index afd70b0..315f911 100644 (file)
@@ -43,7 +43,11 @@ package org.onap.portal.domain.db.fn;
 import java.io.Serializable;
 import java.time.LocalDateTime;
 import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
 import java.util.stream.Collectors;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
@@ -68,6 +72,7 @@ import javax.validation.constraints.NotNull;
 import javax.validation.constraints.PastOrPresent;
 import javax.validation.constraints.Size;
 import lombok.AllArgsConstructor;
+import lombok.Builder;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 import lombok.Setter;
@@ -80,6 +85,7 @@ import org.onap.portal.domain.db.ep.EpUserNotification;
 import org.onap.portal.domain.db.ep.EpUserRolesRequest;
 import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter;
 import org.onap.portal.domain.dto.DomainVo;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.userdetails.UserDetails;
@@ -178,16 +184,17 @@ CREATE TABLE `fn_user` (
 @Getter
 @Setter
 @Entity
+@Builder
 @NoArgsConstructor
 @AllArgsConstructor
 @DynamicUpdate
-@SequenceGenerator(name = "seq", initialValue = 1000, allocationSize = 100000)
 public class FnUser extends DomainVo implements UserDetails, Serializable {
 
+       private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnUser.class);
+
        @Id
-       @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
-       @Column(name = "user_id", length = 11, nullable = false)
-       @Digits(integer = 11, fraction = 0)
+       @GeneratedValue(strategy = GenerationType.IDENTITY)
+       @Column(name = "user_id", nullable = false)
        private Long userId;
        @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
        @JoinColumn(name = "org_id")
@@ -253,11 +260,8 @@ public class FnUser extends DomainVo implements UserDetails, Serializable {
        @Column(name = "last_login_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
        @PastOrPresent
        protected LocalDateTime lastLoginDate;
-       @Column(name = "active_yn", length = 1, nullable = false)
-       @Size(max = 1)
-       @SafeHtml
-       @NotNull(message = "activeYn must not be null")
-       private String activeYn;
+       @Column(name = "active_yn", nullable = false)
+       private Boolean activeYn;
        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
        @JoinColumn(name = "created_id")
        private FnUser createdId;
@@ -270,11 +274,8 @@ public class FnUser extends DomainVo implements UserDetails, Serializable {
        @Column(name = "modified_date", nullable = false, columnDefinition = "datetime default now()")
        @PastOrPresent
        protected LocalDateTime modifiedDate;
-       @Column(name = "is_internal_yn", length = 1, columnDefinition = "character varying(1) default 'n'", nullable = false)
-       @Size(max = 1)
-       @SafeHtml
-       @NotNull(message = "isInternalYn must not be null")
-       private String isInternalYn;
+       @Column(name = "is_internal_yn", nullable = false, columnDefinition = "bit DEFAULT 0")
+       private Boolean isInternalYn;
        @Column(name = "address_line_1", length = 100)
        @Size(max = 100)
        @SafeHtml
@@ -347,12 +348,12 @@ public class FnUser extends DomainVo implements UserDetails, Serializable {
        @SafeHtml
        private String siloStatus;
        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
-       @JoinColumn(name = "language_id", nullable = false, columnDefinition = "int(11) DEFAULT 1")
+       @JoinColumn(name = "language_id", nullable = false, columnDefinition = "bigint DEFAULT 1")
        @NotNull(message = "languageId must not be null")
        private FnLanguage languageId;
-       @Column(name = "is_guest", columnDefinition = "boolean default 0", nullable = false)
+       @Column(name = "is_guest", nullable = false, columnDefinition = "bit DEFAULT 0")
        @NotNull(message = "guest must not be null")
-       private boolean guest;
+       private Boolean guest;
        @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList")
        private Set<CrReportFileHistory> crReportFileHistorie;
        @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@@ -479,4 +480,44 @@ public class FnUser extends DomainVo implements UserDetails, Serializable {
               return this.firstName + " " + this.lastName;
        }
 
+       public SortedSet<FnRole> getAppEPRoles(FnApp app) {
+
+                     logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - app = {}", app.getAppName());
+
+                     SortedSet<FnRole> roles = new TreeSet<>();
+                     Set<FnUserRole> userAppRoles = getFnUserRoles();
+
+                     logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - userApps = {} ", userAppRoles.size());
+
+                     Iterator<FnUserRole> userAppRolesIterator = userAppRoles.iterator();
+
+              FnUserRole userAppRole;
+                     // getting default app
+                     while (userAppRolesIterator.hasNext()) {
+                            FnUserRole tempUserApp = userAppRolesIterator.next();
+                            if (tempUserApp.getAppId().getId().equals(app.getId())) {
+
+                                   logger.debug(EELFLoggerDelegate.debugLogger,
+                                           "In EPUser.getAppEPRoles() - for user {}, found application {}", this.getFullName(),
+                                           app.getAppName());
+
+                                   userAppRole = tempUserApp;
+
+                                   FnRole role = userAppRole.getRoleId();
+                                   if (role.getActiveYn()) {
+                                          logger.debug(EELFLoggerDelegate.debugLogger,
+                                                  "In EPUser.getAppEPRoles() - Role {} is active - adding for user {} and app {}",
+                                                  role.getRoleName(), this.getFullName(), app.getAppName());
+                                          roles.add(role);
+                                   } else {
+                                          logger.debug(EELFLoggerDelegate.debugLogger,
+                                                  "In EPUser.getAppEPRoles() - Role {} is NOT active - NOT adding for user {} and app {}",
+                                                  role.getRoleName(), this.getFullName(), app.getAppName());
+                                   }
+                            }
+                     }
+                     logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - roles = {}", roles.size());
+
+                     return roles;
+              }
 }