package org.onap.portal.domain.db.fn;
-import java.util.ArrayList;
-import java.util.List;
+import java.io.Serializable;
+import java.time.LocalDateTime;
+import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
+import javax.persistence.NamedNativeQueries;
+import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.SafeHtml;
-import org.onap.portalapp.portal.domain.db.ep.EpAppRoleFunction;
-import org.onap.portalapp.portal.domain.db.ep.EpRoleNotification;
-import org.onap.portalapp.portal.domain.db.ep.EpUserRolesRequestDet;
-import org.onap.portalapp.portal.domain.db.ep.EpWidgetCatalogRole;
+import org.onap.portal.domain.db.DomainVo;
+import org.onap.portal.domain.db.ep.EpAppRoleFunction;
+import org.onap.portal.domain.db.ep.EpRoleNotification;
+import org.onap.portal.domain.db.ep.EpUserRolesRequestDet;
+import org.onap.portal.domain.db.ep.EpWidgetCatalogRole;
+import org.onap.portal.domain.dto.transport.Role;
/*
CREATE TABLE `fn_role` (
*/
@NamedQueries({
- @NamedQuery(
- name = "FnRole.retrieveAppRolesByRoleNameAndByAppId",
- query = "FROM FnRole where role_name =:roleName and app_id =:appId"),
- @NamedQuery(
- name = "FnRole.retrieveAppRolesByAppId",
- query = "FROM FnRole where app_id =:appId"),
- @NamedQuery(
- name = "FnRole.retrieveAppRolesWhereAppIdIsNull",
- query = "FROM FnRole where app_id is null"),
- @NamedQuery(
- name = "FnRole.retrieveAppRoleByRoleIdWhereAppIdIsNull",
- query = "FROM FnRole where role_id =:roleId and app_id is null"),
- @NamedQuery(
- name = "FnRole.retrieveAppRoleByAppRoleIdAndByAppId",
- query = "FROM FnRole where app_role_id =:appRoleId and app_id =:appId"),
- @NamedQuery(
- name = "FnRole.retrieveAppRoleByRoleIdAndAppId",
- query = "FROM FnRole where role_id =:roleId and app_id =:appId"),
- @NamedQuery(
- name = "FnRole.retrieveAppRolesByRoleNameAndWhereAppIdIsNull",
- query = "FROM FnRole where role_name =:roleName and app_id is null"),
- @NamedQuery(
- name = "FnRole.retrieveActiveRolesOfApplication",
- query = "from FnRole where active_yn = 'Y' and app_id=:appId"),
- @NamedQuery(name = "FnRole.retrieveRoleToUpdateInExternalAuthSystem",
- query = "FROM FnRole where role_name =:roleName and app_id =:appId")
+ @NamedQuery(
+ name = "FnRole.retrieveAppRolesByRoleNameAndByAppId",
+ query = "FROM FnRole where roleName =:roleName and appId =:appId"),
+ @NamedQuery(
+ name = "FnRole.retrieveAppRolesByAppId",
+ query = "FROM FnRole where appId =:appId"),
+ @NamedQuery(
+ name = "FnRole.retrieveAppRolesWhereAppIdIsNull",
+ query = "FROM FnRole where appId is null"),
+ @NamedQuery(
+ name = "FnRole.retrieveAppRoleByRoleIdWhereAppIdIsNull",
+ query = "FROM FnRole where id =:roleId and appId is null"),
+ @NamedQuery(
+ name = "FnRole.retrieveAppRoleByAppRoleIdAndByAppId",
+ query = "FROM FnRole where appRoleId =:appRoleId and appId =:appId"),
+ @NamedQuery(
+ name = "FnRole.retrieveAppRoleByRoleIdAndAppId",
+ query = "FROM FnRole where id =:roleId and appId =:appId"),
+ @NamedQuery(
+ name = "FnRole.retrieveAppRolesByRoleNameAndWhereAppIdIsNull",
+ query = "FROM FnRole where roleName =:roleName and appId is null"),
+ @NamedQuery(
+ name = "FnRole.retrieveActiveRolesOfApplication",
+ query = "from FnRole where activeYn = 'Y' and appId=:appId"),
+ @NamedQuery(
+ name = "FnRole.retrieveActiveRolesWhereAppIdIsNull",
+ query = "from FnRole where activeYn = 'Y' and appId is null"),
+ @NamedQuery(
+ name = "FnRole.getUserRoleOnUserIdAndAppId",
+ query = " FROM"
+ + " FnRole fr,\n"
+ + " FnUserRole fur\n"
+ + " WHERE\n"
+ + " fr.id = fur.roleId\n"
+ + " AND fur.userId = :userId"
+ + " AND fur.fnAppId.id = :appId\n"
+ + " AND fr.activeYn = 'y'"),
+ @NamedQuery(
+ name = "FnRole.getGlobalRolesOfPortal",
+ query = "from"
+ + " FnRole"
+ + " where"
+ + " roleName like 'global_%'"
+ + " and appId is null"
+ + " and activeYn = 'Y'"),
+ @NamedQuery(
+ name = "FnRole.getSysAdminRoleId",
+ query = "FROM FnRole WHERE roleName = 'System_Administrator' and activeYn = 'true' and priority = 1 and appId is null and appRoleId is null"
+ )
})
-@Table(name = "fn_role", indexes = {
- @Index(name = "fn_role_name_app_id_idx", columnList = "role_name, app_id", unique = true)
-})
+@NamedNativeQuery(
+ name = "FnRole.userAppGlobalRoles",
+ query = "select fr.role_id , fr.role_name ,fr.active_yn, fr.priority, fr.app_id, fr.app_role_id \n"
+ + " from fn_user_role a, fn_role fr, fn_user fu \n"
+ + " where a.role_id in (select b.role_id from ep_app_role_function b where b.role_app_id = 1 and b.app_id =:appId) and a.user_id =fu.user_id and a.role_id = fr.role_id and fr.active_yn='Y' and fu.active_yn='Y' and fu.user_id =:userId\n"
+)
+
+@Table(name = "fn_role")
@NoArgsConstructor
-@AllArgsConstructor
@Getter
@Setter
@Entity
-public class FnRole {
+public class FnRole extends Role {
+
+ @Column(name = "app_role_id", length = 11, columnDefinition = "int(11) default null")
+ @Digits(integer = 11, fraction = 0)
+ private Long appRoleId;
+ @ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
+ @JoinTable(
+ name = "fn_user_pseudo_role",
+ joinColumns = {@JoinColumn(name = "pseudo_role_Id", referencedColumnName = "id", columnDefinition = "bigint not null")},
+ inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id", columnDefinition = "bigint not null")},
+ indexes = {
+ @Index(name = "fk_pseudo_role_user_id", columnList = "user_id")
+ }
+ )
+ private Set<FnUser> fnUsers;
+ @ManyToMany(cascade = CascadeType.MERGE,
+ fetch = FetchType.LAZY, mappedBy = "role")
+ private Set<FnRoleFunction> roleFunctions;
+ @OneToMany(
+ targetEntity = EpRoleNotification.class,
+ mappedBy = "notificationId",
+ cascade = CascadeType.MERGE,
+ fetch = FetchType.LAZY
+ )
+ private Set<EpRoleNotification> epRoleNotifications;
+ @OneToMany(
+ targetEntity = FnMenuFunctionalRoles.class,
+ mappedBy = "roleId",
+ cascade = CascadeType.MERGE,
+ fetch = FetchType.LAZY
+ )
+ private Set<FnMenuFunctionalRoles> fnMenuFunctionalRoles;
+ @OneToMany(
+ targetEntity = EpWidgetCatalogRole.class,
+ mappedBy = "roleId",
+ cascade = CascadeType.MERGE,
+ fetch = FetchType.LAZY
+ )
+ private Set<EpWidgetCatalogRole> epWidgetCatalogRoles;
+ @OneToMany(
+ targetEntity = EpAppRoleFunction.class,
+ mappedBy = "fnRole",
+ cascade = CascadeType.MERGE,
+ fetch = FetchType.LAZY
+ )
+ private Set<EpAppRoleFunction> epAppRoleFunctions;
+ @OneToMany(
+ targetEntity = EpUserRolesRequestDet.class,
+ mappedBy = "requestedRoleId",
+ cascade = CascadeType.MERGE,
+ fetch = FetchType.LAZY
+ )
+ private Set<EpUserRolesRequestDet> epUserRolesRequestDets;
+ @OneToMany(
+ targetEntity = FnUserRole.class,
+ mappedBy = "roleId",
+ cascade = CascadeType.MERGE,
+ fetch = FetchType.LAZY
+ )
+ private Set<FnUserRole> fnUserRoles;
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- @Column(name = "role_id", length = 11, nullable = false)
- @Digits(integer = 11, fraction = 0)
- private Long roleId;
- @Column(name = "role_name", length = 300, nullable = false)
- @Size(max = 300)
- @NotNull
- @SafeHtml
- private String roleName;
- @Column(name = "active_yn", length = 1, columnDefinition = "character varying(1) default 'y'", nullable = false)
- @Pattern(regexp = "[YNyn]")
- @Size(max = 1)
- @NotNull
- @SafeHtml
- private String activeYn;
- @Column(name = "priority", length = 4, columnDefinition = "decimal(4,0) DEFAULT NULL")
- @Digits(integer = 4, fraction = 0)
- private Long priority;
- @Column(name = "app_Id", length = 11, columnDefinition = "int(11) default null")
- @Digits(integer = 11, fraction = 0)
- private Long appId;
- @Column(name = "app_role_id", length = 11, columnDefinition = "int(11) default null")
- @Digits(integer = 11, fraction = 0)
- private Long appRoleId;
- @OneToMany(
- targetEntity = FnRoleFunction.class,
- mappedBy = "roleId",
- cascade = CascadeType.ALL,
- fetch = FetchType.LAZY
- )
- private List<FnRoleFunction> fnRoleFunctions = new ArrayList<>();
- @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
- @JoinTable(
- name = "fn_user_pseudo_role",
- joinColumns = {@JoinColumn(name = "pseudo_role_Id", referencedColumnName = "role_id")},
- inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "user_id")},
- indexes = {
- @Index(name = "fk_pseudo_role_user_id", columnList = "user_id")
- }
- )
- private List<FnUser> fnUsers = new ArrayList<>();
- @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
- @JoinTable(
- name = "fn_role_composite",
- joinColumns = {@JoinColumn(name = "parent_role_id", referencedColumnName = "role_id")},
- inverseJoinColumns = {@JoinColumn(name = "child_role_id", referencedColumnName = "role_id")},
- indexes = {
- @Index(name = "fk_fn_role_composite_child", columnList = "child_role_id")
- }
- )
- private List<FnRole> fnRoles = new ArrayList<>();
- @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
- private List<FnRole> fnRoleList = new ArrayList<>();
- @OneToMany(
- targetEntity = EpRoleNotification.class,
- mappedBy = "notificationID",
- cascade = CascadeType.ALL,
- fetch = FetchType.LAZY
- )
- private List<EpRoleNotification> epRoleNotifications = new ArrayList<>();
- @OneToMany(
- targetEntity = FnMenuFunctionalRoles.class,
- mappedBy = "roleId",
- cascade = CascadeType.ALL,
- fetch = FetchType.LAZY
- )
- private List<FnMenuFunctionalRoles> fnMenuFunctionalRoles = new ArrayList<>();
- @OneToMany(
- targetEntity = EpWidgetCatalogRole.class,
- mappedBy = "roleId",
- cascade = CascadeType.ALL,
- fetch = FetchType.LAZY
- )
- private List<EpWidgetCatalogRole> epWidgetCatalogRoles = new ArrayList<>();
- @OneToMany(
- targetEntity = EpAppRoleFunction.class,
- mappedBy = "fnRole",
- cascade = CascadeType.ALL,
- fetch = FetchType.LAZY
- )
- private List<EpAppRoleFunction> epAppRoleFunctions = new ArrayList<>();
- @OneToMany(
- targetEntity = EpUserRolesRequestDet.class,
- mappedBy = "requestedRoleId",
- cascade = CascadeType.ALL,
- fetch = FetchType.LAZY
- )
- private List<EpUserRolesRequestDet> epUserRolesRequestDets = new ArrayList<>();
- @OneToMany(
- targetEntity = FnUserRole.class,
- mappedBy = "roleId",
- cascade = CascadeType.ALL,
- fetch = FetchType.LAZY
- )
- private List<FnUserRole> fnUserRoles = new ArrayList<>();
+ @Builder
+ public FnRole(@Digits(integer = 11, fraction = 0) Long id, LocalDateTime created,
+ LocalDateTime modified, Long rowNum, Serializable auditUserId,
+ DomainVo createdId, DomainVo modifiedId,
+ Set<DomainVo> fnUsersCreatedId,
+ Set<DomainVo> fnUsersModifiedId,
+ @Size(max = 300) @NotNull @SafeHtml String roleName,
+ @Digits(integer = 11, fraction = 0) Long appId, @NotNull Boolean activeYn,
+ @Digits(integer = 4, fraction = 0) Integer priority,
+ Set<FnRoleFunction> fnRoleFunctions, Set<FnRoleComposite> childRoles,
+ Set<FnRoleComposite> parentRoles,
+ @Digits(integer = 11, fraction = 0) Long appRoleId, Set<FnUser> fnUsers,
+ Set<FnRoleFunction> roleFunctions,
+ Set<EpRoleNotification> epRoleNotifications,
+ Set<FnMenuFunctionalRoles> fnMenuFunctionalRoles,
+ Set<EpWidgetCatalogRole> epWidgetCatalogRoles,
+ Set<EpAppRoleFunction> epAppRoleFunctions,
+ Set<EpUserRolesRequestDet> epUserRolesRequestDets,
+ Set<FnUserRole> fnUserRoles) {
+ super(id, created, modified, rowNum, auditUserId, createdId, modifiedId, fnUsersCreatedId, fnUsersModifiedId,
+ roleName, appId, activeYn, priority, fnRoleFunctions, childRoles, parentRoles);
+ this.appRoleId = appRoleId;
+ this.fnUsers = fnUsers;
+ this.roleFunctions = roleFunctions;
+ this.epRoleNotifications = epRoleNotifications;
+ this.fnMenuFunctionalRoles = fnMenuFunctionalRoles;
+ this.epWidgetCatalogRoles = epWidgetCatalogRoles;
+ this.epAppRoleFunctions = epAppRoleFunctions;
+ this.epUserRolesRequestDets = epUserRolesRequestDets;
+ this.fnUserRoles = fnUserRoles;
+ }
}