X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=portal-BE%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fportal%2Fdomain%2Fdb%2Ffn%2FFnUserRole.java;h=e2913e05daca94e36759b69414a6fdb7849f5a86;hb=ffd9af970318c1f5a0bad46d7aad5d4611414aae;hp=2eecd7417f88e51596cdc035e052d0465247e647;hpb=f71707238ebabd9911277af55673b1d42ac1495f;p=portal.git diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUserRole.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUserRole.java index 2eecd741..e2913e05 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUserRole.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUserRole.java @@ -40,8 +40,11 @@ package org.onap.portal.domain.db.fn; +import java.io.Serializable; import javax.persistence.CascadeType; import javax.persistence.Column; +import javax.persistence.ColumnResult; +import javax.persistence.ConstructorResult; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; @@ -52,16 +55,21 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.NamedNativeQueries; import javax.persistence.NamedNativeQuery; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.OneToOne; +import javax.persistence.SequenceGenerator; +import javax.persistence.SqlResultSetMapping; import javax.persistence.Table; import javax.persistence.UniqueConstraint; import javax.validation.Valid; import javax.validation.constraints.Digits; import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.onap.portal.domain.dto.ecomp.UserRole; /* CREATE TABLE `fn_user_role` ( @@ -80,52 +88,105 @@ CREATE TABLE `fn_user_role` ( */ @NamedNativeQueries({ - @NamedNativeQuery( - name = "FnUserRole.retrieveUserRoleOnUserIdAndRoleIdAndAppId", - query = "select * from FnUserRole where user_id= :userId" - + " and role_id= :roleId" - + " and app_id= :appId"), - @NamedNativeQuery( - name = "FnUserRole.retrieveCachedAppRolesForUser", - query = "select * from FnUserRole where user_id= :userId" - + " and user_id= :userId" - + " and app_id= :appId") + @NamedNativeQuery( + name = "FnUserRole.retrieveUserRoleOnUserIdAndRoleIdAndAppId", + query = "FROM FnUserRole where userId= :userId" + + " and role_id= :roleId" + + " and app_id= :appId"), + @NamedNativeQuery( + name = "FnUserRole.retrieveCachedAppRolesForUser", + query = "FROM FnUserRole where userId= :userId" + + " and userId= :userId" + + " and app_id= :appId"), + @NamedNativeQuery( + name = "FnUserRole.isSuperAdmin", + query = "SELECT" + + " userId.id as userId," + + " userId.org_user_id as orgUserId," + + " userrole.ROLE_ID as roleId," + + " userrole.APP_ID as appId" + + " FROM" + + " fn_user_role userrole" + + " INNER JOIN fn_user user ON user.USER_ID = userrole.USER_ID" + + " WHERE" + + " user.org_user_id = :orgUserId" + + " AND userrole.ROLE_ID =:roleId" + + " AND userrole.APP_ID =:appId", + resultSetMapping = "UserRole", + resultClass = UserRole.class + ) +}) + +@SqlResultSetMapping( + name = "UserRole", + classes = { + @ConstructorResult( + targetClass = UserRole.class, + columns = { + @ColumnResult(name = "userId", type = Long.class), + @ColumnResult(name = "orgUserId", type = String.class), + @ColumnResult(name = "roleId", type = Long.class), + @ColumnResult(name = "appId", type = Long.class) + } + ) + } +) + +@NamedQueries({ + @NamedQuery( + name = "FnUserRole.getAdminUserRoles", + query = "FROM FnUserRole " + + " WHERE userId.id = :userId " + + " AND roleId.id = :roleId " + + " AND fnAppId.id = :appId"), + @NamedQuery( + name = "FnUserRole.retrieveByAppIdAndUserId", + query = "from FnUserRole where fnAppId.id =:appId and userId.id =:userId" + ), + @NamedQuery( + name = "FnUserRole.retrieveByAppIdAndRoleId", + query = "from FnUserRole where fnAppId.id =:appId and roleId.id =:roleId" + ), + @NamedQuery( + name = "FnUserRole.retrieveByUserIdAndRoleId", + query = "from FnUserRole where userId.id =:userId and roleId.id =:roleId" + ) }) @Table( - name = "fn_user_role", - indexes = { - @Index(name = "fn_user_role_role_id", columnList = "role_id"), - @Index(name = "fn_user_role_user_id", columnList = "user_id"), - @Index(name = "fk_fn_user__ref_178_fn_app_idx", columnList = "app_id")}, - uniqueConstraints = { - @UniqueConstraint(name = "fn_user_role_id", columnNames = {"role_id", "user_id", "app_id"}) - }) + name = "fn_user_role", + indexes = { + @Index(name = "fn_user_role_role_id", columnList = "role_id"), + @Index(name = "fn_user_role_user_id", columnList = "user_id"), + @Index(name = "fk_fn_user__ref_178_fn_app_idx", columnList = "fn_App_Id")}, + uniqueConstraints = { + @UniqueConstraint(name = "fn_user_role_id", columnNames = {"role_id", "user_id", "fn_App_Id"}) + }) @NoArgsConstructor @AllArgsConstructor -@EqualsAndHashCode +@Builder @Getter @Setter @Entity -public class FnUserRole { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id", columnDefinition = "int(11) auto_increment") - private Long id; - @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) - @JoinColumn(name = "user_id") - @Valid - private FnUser userId; - @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) - @JoinColumn(name = "role_id") - @Valid - private FnRole roleId; - @Column(name = "priority", length = 4, columnDefinition = "decimal(4,0) DEFAULT NULL") - @Digits(integer = 4, fraction = 0) - private Long priority; - @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) - @JoinColumn(name = "app_Id") - @Valid - private FnApp appId; +public class FnUserRole implements Serializable { + @Id + @SequenceGenerator(name = "portal_generator", sequenceName = "portal_generator", initialValue = 1000) + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", columnDefinition = "int(11) auto_increment") + private Long id; + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE) + @JoinColumn(name = "user_id", columnDefinition = "bigint") + @Valid + private FnUser userId; + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE) + @JoinColumn(name = "role_id", columnDefinition = "bigint") + @Valid + private FnRole roleId; + @Column(name = "priority", length = 4, columnDefinition = "decimal(4,0) DEFAULT NULL") + @Digits(integer = 4, fraction = 0) + private Long priority; + @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) + @JoinColumn(name = "fn_App_Id", columnDefinition = "bigint") + @Valid + private FnApp fnAppId; } \ No newline at end of file