UserRolesController methods up
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / fn / FnUser.java
index 315f911..dc01f38 100644 (file)
@@ -63,7 +63,6 @@ import javax.persistence.ManyToOne;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
 import javax.persistence.OneToMany;
-import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
 import javax.persistence.UniqueConstraint;
 import javax.validation.constraints.Digits;
@@ -85,6 +84,9 @@ 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.domain.App;
+import org.onap.portalsdk.core.domain.Role;
+import org.onap.portalsdk.core.domain.UserApp;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.authority.SimpleGrantedAuthority;
@@ -155,31 +157,31 @@ CREATE TABLE `fn_user` (
 */
 
 @NamedQueries({
-        @NamedQuery(
-                name = "FnUser.getUserWithOrgUserId",
-                query = "FROM FnUser WHERE orgUserId = :orgId"),
-        @NamedQuery(
-                name = "FnUser.getActiveUsers",
-                query = "FROM FnUser WHERE activeYn = 'Y'"),
-        @NamedQuery(
-                name = "FnUser.getUsersByOrgIds",
-                query = "FROM FnUser WHERE orgUserId IN :orgIds"
-        )
+    @NamedQuery(
+        name = "FnUser.getUserWithOrgUserId",
+        query = "FROM FnUser WHERE orgUserId = :orgId"),
+    @NamedQuery(
+        name = "FnUser.getActiveUsers",
+        query = "FROM FnUser WHERE activeYn = 'Y'"),
+    @NamedQuery(
+        name = "FnUser.getUsersByOrgIds",
+        query = "FROM FnUser WHERE orgUserId IN :orgIds"
+    )
 })
 @Table(name = "fn_user", indexes = {
-        @Index(name = "fn_user_address_id", columnList = "address_id"),
-        @Index(name = "fn_user_alert_method_cd", columnList = "alert_method_cd"),
-        @Index(name = "fn_user_org_id", columnList = "org_id"),
-        @Index(name = "fk_fn_user_ref_197_fn_user", columnList = "manager_id"),
-        @Index(name = "fk_fn_user_ref_198_fn_user", columnList = "created_id"),
-        @Index(name = "fk_fn_user_ref_199_fn_user", columnList = "modified_id"),
-        @Index(name = "fk_timezone", columnList = "timezone")
+    @Index(name = "fn_user_address_id", columnList = "address_id"),
+    @Index(name = "fn_user_alert_method_cd", columnList = "alert_method_cd"),
+    @Index(name = "fn_user_org_id", columnList = "org_id"),
+    @Index(name = "fk_fn_user_ref_197_fn_user", columnList = "manager_id"),
+    @Index(name = "fk_fn_user_ref_198_fn_user", columnList = "created_id"),
+    @Index(name = "fk_fn_user_ref_199_fn_user", columnList = "modified_id"),
+    @Index(name = "fk_timezone", columnList = "timezone")
 },
-        uniqueConstraints = {
-                @UniqueConstraint(name = "fn_user_hrid", columnNames = "hrid"),
-                @UniqueConstraint(name = "fn_user_login_id", columnNames = "login_id")
+    uniqueConstraints = {
+        @UniqueConstraint(name = "fn_user_hrid", columnNames = "hrid"),
+        @UniqueConstraint(name = "fn_user_login_id", columnNames = "login_id")
 
-        })
+    })
 
 @Getter
 @Setter
@@ -190,334 +192,361 @@ CREATE TABLE `fn_user` (
 @DynamicUpdate
 public class FnUser extends DomainVo implements UserDetails, Serializable {
 
-       private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnUser.class);
+  private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnUser.class);
+
+  @Id
+  @GeneratedValue(strategy = GenerationType.IDENTITY)
+  @Column(name = "user_id", nullable = false)
+  private Long userId;
+  @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+  @JoinColumn(name = "org_id")
+  private FnOrg orgId;
+  @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+  @JoinColumn(name = "manager_id")
+  private FnUser managerId;
+  @Column(name = "first_name", length = 50)
+  @Size(max = 50)
+  @SafeHtml
+  private String firstName;
+  @Column(name = "middle_name", length = 50)
+  @Size(max = 50)
+  @SafeHtml
+  private String middleName;
+  @Column(name = "last_name", length = 50)
+  @Size(max = 50)
+  @SafeHtml
+  private String lastName;
+  @Column(name = "phone", length = 25)
+  @Size(max = 25)
+  @SafeHtml
+  private String phone;
+  @Column(name = "fax", length = 25)
+  @Size(max = 25)
+  @SafeHtml
+  private String fax;
+  @Column(name = "cellular", length = 25)
+  @Size(max = 25)
+  @SafeHtml
+  private String cellular;
+  @Column(name = "email", length = 50)
+  @Size(max = 50)
+  @Email
+  @SafeHtml
+  private String email;
+  @Column(name = "address_id")
+  @Digits(integer = 11, fraction = 0)
+  private Long addressId;
+  @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+  @JoinColumn(name = "alert_method_cd")
+  private FnLuAlertMethod alertMethodCd;
+  @Column(name = "hrid", length = 20)
+  @Size(max = 20)
+  @SafeHtml
+  private String hrid;
+  @Column(name = "org_user_id", length = 20)
+  @Size(max = 20)
+  @SafeHtml
+  private String orgUserId;
+  @Column(name = "org_code", length = 30)
+  @Size(max = 30)
+  @SafeHtml
+  private String org_code;
+  @Column(name = "login_id", length = 25)
+  @Size(max = 25)
+  @SafeHtml
+  private String loginId;
+  @Column(name = "login_pwd", length = 100)
+  @Size(max = 100)
+  @SafeHtml
+  private String loginPwd;
+  @Column(name = "last_login_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
+  @PastOrPresent
+  protected LocalDateTime lastLoginDate;
+  @Column(name = "active_yn", nullable = false)
+  private Boolean activeYn;
+  @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+  @JoinColumn(name = "created_id")
+  private FnUser createdId;
+  @Column(name = "created_date", columnDefinition = "datetime DEFAULT current_timestamp()", nullable = false)
+  @PastOrPresent
+  protected LocalDateTime createdDate;
+  @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+  @JoinColumn(name = "modified_id")
+  private FnUser modifiedId;
+  @Column(name = "modified_date", nullable = false, columnDefinition = "datetime default now()")
+  @PastOrPresent
+  protected LocalDateTime modifiedDate;
+  @Column(name = "is_internal_yn", nullable = false, columnDefinition = "bit DEFAULT 0")
+  private Boolean isInternalYn;
+  @Column(name = "is_system_user", nullable = false, columnDefinition = "bit DEFAULT 0")
+  private Boolean isSystemUser;
+  @Column(name = "address_line_1", length = 100)
+  @Size(max = 100)
+  @SafeHtml
+  private String addressLine1;
+  @Column(name = "address_line_2", length = 100)
+  @Size(max = 100)
+  @SafeHtml
+  private String addressLine2;
+  @Column(name = "city", length = 50)
+  @Size(max = 50)
+  @SafeHtml
+  private String city;
+  @Column(name = "state_cd", length = 3)
+  @Size(max = 3)
+  @SafeHtml
+  private String stateCd;
+  @Column(name = "zip_code", length = 11)
+  @Size(max = 11)
+  @SafeHtml
+  private String zipCode;
+  @Column(name = "country_cd", length = 3)
+  @Size(max = 3)
+  @SafeHtml
+  private String countryCd;
+  @Column(name = "location_clli", length = 8)
+  @Size(max = 8)
+  @SafeHtml
+  private String locationClli;
+  @Column(name = "org_manager_userid", length = 20)
+  @Size(max = 20)
+  @SafeHtml
+  private String orgManagerUserId;
+  @Column(name = "company", length = 100)
+  @Size(max = 100)
+  @SafeHtml
+  private String company;
+  @Column(name = "department_name", length = 200)
+  @Size(max = 200)
+  @SafeHtml
+  private String departmentName;
+  @Column(name = "job_title", length = 100)
+  @Size(max = 100)
+  @SafeHtml
+  private String jobTitle;
+  @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+  @JoinColumn(name = "timezone")
+  private FnLuTimezone timezone;
+  @Column(name = "department", length = 25)
+  @Size(max = 25)
+  @SafeHtml
+  private String department;
+  @Column(name = "business_unit", length = 25)
+  @Size(max = 25)
+  @SafeHtml
+  private String businessUnit;
+  @Column(name = "business_unit_name", length = 100)
+  @Size(max = 100)
+  @SafeHtml
+  private String businessUnitName;
+  @Column(name = "cost_center", length = 25)
+  @Size(max = 25)
+  @SafeHtml
+  private String cost_center;
+  @Column(name = "fin_loc_code", length = 10)
+  @Size(max = 10)
+  @SafeHtml
+  private String finLocCode;
+  @Column(name = "silo_status", length = 10)
+  @Size(max = 10)
+  @SafeHtml
+  private String siloStatus;
+  @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+  @JoinColumn(name = "language_id", nullable = false, columnDefinition = "bigint DEFAULT 1")
+  @NotNull(message = "languageId must not be null")
+  private FnLanguage languageId;
+  @Column(name = "is_guest", nullable = false, columnDefinition = "bit DEFAULT 0")
+  @NotNull(message = "guest must not be null")
+  private Boolean guest;
+  @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList")
+  private Set<CrReportFileHistory> crReportFileHistorie;
+  @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+  private Set<FnRole> fnRoles;
+  @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+  private Set<FnMenuFunctional> fnRoleList;
+  @OneToMany(
+      targetEntity = FnAuditLog.class,
+      mappedBy = "userId",
+      cascade = CascadeType.ALL,
+      fetch = FetchType.LAZY
+  )
+  private Set<FnAuditLog> fnAuditLogs;
+  @OneToMany(
+      targetEntity = FnUser.class,
+      mappedBy = "createdId",
+      cascade = CascadeType.ALL,
+      fetch = FetchType.LAZY
+  )
+  private Set<FnUser> fnUsersCreatedId;
+  @OneToMany(
+      targetEntity = FnUser.class,
+      mappedBy = "managerId",
+      cascade = CascadeType.ALL,
+      fetch = FetchType.LAZY
+  )
+  private Set<FnUser> fnUsersManagerId;
+  @OneToMany(
+      targetEntity = FnUser.class,
+      mappedBy = "modifiedId",
+      cascade = CascadeType.ALL,
+      fetch = FetchType.LAZY
+  )
+  private Set<FnUser> fnUsersModifiedId;
+  @OneToMany(
+      targetEntity = EpUserRolesRequest.class,
+      mappedBy = "userId",
+      cascade = CascadeType.ALL,
+      fetch = FetchType.LAZY
+  )
+  private Set<EpUserRolesRequest> epUserRolesRequests;
+  @OneToMany(
+      targetEntity = FnPersUserAppSel.class,
+      mappedBy = "userId",
+      cascade = CascadeType.ALL,
+      fetch = FetchType.LAZY
+  )
+  private Set<FnPersUserAppSel> persUserAppSels;
+  @OneToMany(
+      targetEntity = EpWidgetCatalogParameter.class,
+      mappedBy = "userId",
+      cascade = CascadeType.ALL,
+      fetch = FetchType.LAZY
+  )
+  private Set<EpWidgetCatalogParameter> epWidgetCatalogParameters;
+  @OneToMany(
+      targetEntity = EpPersUserWidgetPlacement.class,
+      mappedBy = "userId",
+      cascade = CascadeType.ALL,
+      fetch = FetchType.LAZY
+  )
+  private Set<EpPersUserWidgetPlacement> epPersUserWidgetPlacements;
+  @OneToMany(
+      targetEntity = EpPersUserWidgetSel.class,
+      mappedBy = "userId",
+      cascade = CascadeType.ALL,
+      fetch = FetchType.LAZY
+  )
+  private Set<EpPersUserWidgetSel> epPersUserWidgetSels;
+  @OneToMany(
+      targetEntity = FnUserRole.class,
+      mappedBy = "userId",
+      cascade = CascadeType.ALL,
+      fetch = FetchType.LAZY
+  )
+  private Set<FnUserRole> userApps;
+  @OneToMany(
+      targetEntity = EpUserNotification.class,
+      mappedBy = "userId",
+      cascade = CascadeType.ALL,
+      fetch = FetchType.LAZY
+  )
+  private Set<EpUserNotification> epUserNotifications;
+
+  @Override
+  public Collection<? extends GrantedAuthority> getAuthorities() {
+    return fnRoles
+        .stream()
+        .map(fnRole -> new SimpleGrantedAuthority("ROLE_" + fnRole.getRoleName()))
+        .collect(Collectors.toList());
+  }
+
+  @Override
+  public String getPassword() {
+    return this.getLoginPwd();
+  }
+
+  @Override
+  public String getUsername() {
+    return this.getLoginId();
+  }
 
-       @Id
-       @GeneratedValue(strategy = GenerationType.IDENTITY)
-       @Column(name = "user_id", nullable = false)
-       private Long userId;
-       @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
-       @JoinColumn(name = "org_id")
-       private FnOrg orgId;
-       @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
-       @JoinColumn(name = "manager_id")
-       private FnUser managerId;
-       @Column(name = "first_name", length = 50)
-       @Size(max = 50)
-       @SafeHtml
-       private String firstName;
-       @Column(name = "middle_name", length = 50)
-       @Size(max = 50)
-       @SafeHtml
-       private String middleName;
-       @Column(name = "last_name", length = 50)
-       @Size(max = 50)
-       @SafeHtml
-       private String lastName;
-       @Column(name = "phone", length = 25)
-       @Size(max = 25)
-       @SafeHtml
-       private String phone;
-       @Column(name = "fax", length = 25)
-       @Size(max = 25)
-       @SafeHtml
-       private String fax;
-       @Column(name = "cellular", length = 25)
-       @Size(max = 25)
-       @SafeHtml
-       private String cellular;
-       @Column(name = "email", length = 50)
-       @Size(max = 50)
-       @Email
-       @SafeHtml
-       private String email;
-       @Column(name = "address_id")
-       @Digits(integer = 11, fraction = 0)
-       private Long addressId;
-       @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
-       @JoinColumn(name = "alert_method_cd")
-       private FnLuAlertMethod alertMethodCd;
-       @Column(name = "hrid", length = 20)
-       @Size(max = 20)
-       @SafeHtml
-       private String hrid;
-       @Column(name = "org_user_id", length = 20)
-       @Size(max = 20)
-       @SafeHtml
-       private String orgUserId;
-       @Column(name = "org_code", length = 30)
-       @Size(max = 30)
-       @SafeHtml
-       private String org_code;
-       @Column(name = "login_id", length = 25)
-       @Size(max = 25)
-       @SafeHtml
-       private String loginId;
-       @Column(name = "login_pwd", length = 100)
-       @Size(max = 100)
-       @SafeHtml
-       private String loginPwd;
-       @Column(name = "last_login_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
-       @PastOrPresent
-       protected LocalDateTime lastLoginDate;
-       @Column(name = "active_yn", nullable = false)
-       private Boolean activeYn;
-       @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
-       @JoinColumn(name = "created_id")
-       private FnUser createdId;
-       @Column(name = "created_date", columnDefinition = "datetime DEFAULT current_timestamp()", nullable = false)
-       @PastOrPresent
-       protected LocalDateTime createdDate;
-       @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
-       @JoinColumn(name = "modified_id")
-       private FnUser modifiedId;
-       @Column(name = "modified_date", nullable = false, columnDefinition = "datetime default now()")
-       @PastOrPresent
-       protected LocalDateTime modifiedDate;
-       @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
-       private String addressLine1;
-       @Column(name = "address_line_2", length = 100)
-       @Size(max = 100)
-       @SafeHtml
-       private String addressLine2;
-       @Column(name = "city", length = 50)
-       @Size(max = 50)
-       @SafeHtml
-       private String city;
-       @Column(name = "state_cd", length = 3)
-       @Size(max = 3)
-       @SafeHtml
-       private String stateCd;
-       @Column(name = "zip_code", length = 11)
-       @Size(max = 11)
-       @SafeHtml
-       private String zipCode;
-       @Column(name = "country_cd", length = 3)
-       @Size(max = 3)
-       @SafeHtml
-       private String countryCd;
-       @Column(name = "location_clli", length = 8)
-       @Size(max = 8)
-       @SafeHtml
-       private String locationClli;
-       @Column(name = "org_manager_userid", length = 20)
-       @Size(max = 20)
-       @SafeHtml
-       private String orgManagerUserId;
-       @Column(name = "company", length = 100)
-       @Size(max = 100)
-       @SafeHtml
-       private String company;
-       @Column(name = "department_name", length = 200)
-       @Size(max = 200)
-       @SafeHtml
-       private String departmentName;
-       @Column(name = "job_title", length = 100)
-       @Size(max = 100)
-       @SafeHtml
-       private String jobTitle;
-       @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
-       @JoinColumn(name = "timezone")
-       private FnLuTimezone timezone;
-       @Column(name = "department", length = 25)
-       @Size(max = 25)
-       @SafeHtml
-       private String department;
-       @Column(name = "business_unit", length = 25)
-       @Size(max = 25)
-       @SafeHtml
-       private String businessUnit;
-       @Column(name = "business_unit_name", length = 100)
-       @Size(max = 100)
-       @SafeHtml
-       private String businessUnitName;
-       @Column(name = "cost_center", length = 25)
-       @Size(max = 25)
-       @SafeHtml
-       private String cost_center;
-       @Column(name = "fin_loc_code", length = 10)
-       @Size(max = 10)
-       @SafeHtml
-       private String finLocCode;
-       @Column(name = "silo_status", length = 10)
-       @Size(max = 10)
-       @SafeHtml
-       private String siloStatus;
-       @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
-       @JoinColumn(name = "language_id", nullable = false, columnDefinition = "bigint DEFAULT 1")
-       @NotNull(message = "languageId must not be null")
-       private FnLanguage languageId;
-       @Column(name = "is_guest", nullable = false, columnDefinition = "bit DEFAULT 0")
-       @NotNull(message = "guest must not be null")
-       private Boolean guest;
-       @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList")
-       private Set<CrReportFileHistory> crReportFileHistorie;
-       @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
-       private Set<FnRole> fnRoles;
-       @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
-       private Set<FnMenuFunctional> fnRoleList;
-       @OneToMany(
-               targetEntity = FnAuditLog.class,
-               mappedBy = "userId",
-               cascade = CascadeType.ALL,
-               fetch = FetchType.LAZY
-       )
-       private Set<FnAuditLog> fnAuditLogs;
-       @OneToMany(
-               targetEntity = FnUser.class,
-               mappedBy = "createdId",
-               cascade = CascadeType.ALL,
-               fetch = FetchType.LAZY
-       )
-       private Set<FnUser> fnUsersCreatedId;
-       @OneToMany(
-               targetEntity = FnUser.class,
-               mappedBy = "managerId",
-               cascade = CascadeType.ALL,
-               fetch = FetchType.LAZY
-       )
-       private Set<FnUser> fnUsersManagerId;
-       @OneToMany(
-               targetEntity = FnUser.class,
-               mappedBy = "modifiedId",
-               cascade = CascadeType.ALL,
-               fetch = FetchType.LAZY
-       )
-       private Set<FnUser> fnUsersModifiedId;
-       @OneToMany(
-               targetEntity = EpUserRolesRequest.class,
-               mappedBy = "userId",
-               cascade = CascadeType.ALL,
-               fetch = FetchType.LAZY
-       )
-       private Set<EpUserRolesRequest> epUserRolesRequests;
-       @OneToMany(
-               targetEntity = FnPersUserAppSel.class,
-               mappedBy = "userId",
-               cascade = CascadeType.ALL,
-               fetch = FetchType.LAZY
-       )
-       private Set<FnPersUserAppSel> persUserAppSels;
-       @OneToMany(
-               targetEntity = EpWidgetCatalogParameter.class,
-               mappedBy = "userId",
-               cascade = CascadeType.ALL,
-               fetch = FetchType.LAZY
-       )
-       private Set<EpWidgetCatalogParameter> epWidgetCatalogParameters;
-       @OneToMany(
-               targetEntity = EpPersUserWidgetPlacement.class,
-               mappedBy = "userId",
-               cascade = CascadeType.ALL,
-               fetch = FetchType.LAZY
-       )
-       private Set<EpPersUserWidgetPlacement> epPersUserWidgetPlacements;
-       @OneToMany(
-               targetEntity = EpPersUserWidgetSel.class,
-               mappedBy = "userId",
-               cascade = CascadeType.ALL,
-               fetch = FetchType.LAZY
-       )
-       private Set<EpPersUserWidgetSel> epPersUserWidgetSels;
-       @OneToMany(
-               targetEntity = FnUserRole.class,
-               mappedBy = "userId",
-               cascade = CascadeType.ALL,
-               fetch = FetchType.LAZY
-       )
-       private Set<FnUserRole> fnUserRoles;
-       @OneToMany(
-               targetEntity = EpUserNotification.class,
-               mappedBy = "userId",
-               cascade = CascadeType.ALL,
-               fetch = FetchType.LAZY
-       )
-       private Set<EpUserNotification> epUserNotifications;
+  @Override
+  public boolean isAccountNonExpired() {
+    return true;
+  }
 
-       @Override
-       public Collection<? extends GrantedAuthority> getAuthorities() {
-              return fnRoles
-                      .stream()
-                      .map(fnRole -> new SimpleGrantedAuthority("ROLE_" + fnRole.getRoleName()))
-                      .collect(Collectors.toList());
-       }
+  @Override
+  public boolean isAccountNonLocked() {
+    return true;
+  }
 
-       @Override
-       public String getPassword() {
-              return this.getLoginPwd();
-       }
+  @Override
+  public boolean isCredentialsNonExpired() {
+    return true;
+  }
 
-       @Override
-       public String getUsername() {
-              return this.getLoginId();
-       }
+  @Override
+  public boolean isEnabled() {
+    return true;
+  }
 
-       @Override
-       public boolean isAccountNonExpired() {
-              return true;
-       }
+  public String getFullName() {
+    return this.firstName + " " + this.lastName;
+  }
 
-       @Override
-       public boolean isAccountNonLocked() {
-              return true;
-       }
+  public SortedSet<FnRole> getAppEPRoles(FnApp app) {
 
-       @Override
-       public boolean isCredentialsNonExpired() {
-              return true;
-       }
+    logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - app = {}", app.getAppName());
 
-       @Override
-       public boolean isEnabled() {
-              return true;
-       }
+    SortedSet<FnRole> roles = new TreeSet<>();
+    Set<FnUserRole> userAppRoles = getUserApps();
 
-       public String getFullName() {
-              return this.firstName + " " + this.lastName;
-       }
+    logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - userApps = {} ", userAppRoles.size());
 
-       public SortedSet<FnRole> getAppEPRoles(FnApp app) {
+    Iterator<FnUserRole> userAppRolesIterator = userAppRoles.iterator();
 
-                     logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - app = {}", app.getAppName());
+    FnUserRole userAppRole;
+    // getting default app
+    while (userAppRolesIterator.hasNext()) {
+      FnUserRole tempUserApp = userAppRolesIterator.next();
+      if (tempUserApp.getAppId().getId().equals(app.getId())) {
 
-                     SortedSet<FnRole> roles = new TreeSet<>();
-                     Set<FnUserRole> userAppRoles = getFnUserRoles();
+        logger.debug(EELFLoggerDelegate.debugLogger,
+            "In EPUser.getAppEPRoles() - for user {}, found application {}", this.getFullName(),
+            app.getAppName());
 
-                     logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - userApps = {} ", userAppRoles.size());
+        userAppRole = tempUserApp;
 
-                     Iterator<FnUserRole> userAppRolesIterator = userAppRoles.iterator();
+        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());
 
-              FnUserRole userAppRole;
-                     // getting default app
-                     while (userAppRolesIterator.hasNext()) {
-                            FnUserRole tempUserApp = userAppRolesIterator.next();
-                            if (tempUserApp.getAppId().getId().equals(app.getId())) {
+    return roles;
+  }
 
-                                   logger.debug(EELFLoggerDelegate.debugLogger,
-                                           "In EPUser.getAppEPRoles() - for user {}, found application {}", this.getFullName(),
-                                           app.getAppName());
+  public void setRoles(Set<FnRole> roles) {
+    FnApp app = new FnApp();
+    app.setId(1L);
+    app.setAppName("Default");
+    this.addAppRoles(app, roles);
+  }
 
-                                   userAppRole = tempUserApp;
+  private void addAppRoles(FnApp app, Set<FnRole> roles) {
+    if (roles != null) {
+      Set<FnUserRole> newUserApps = new HashSet<>();
+      for (FnRole role : roles) {
+        FnUserRole userApp = new FnUserRole();
+        userApp.setUserId(this);
+        userApp.setAppId(app);
+        userApp.setRoleId(role);
+        newUserApps.add(userApp);
+      }
 
-                                   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());
+      this.setUserApps(newUserApps);
+    } else {
+      this.userApps.clear();
+    }
 
-                     return roles;
-              }
+  }
 }