getAppRolesForUser() method up in UserRolesController
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / ep / EpAppFunction.java
index cae3b3b..5cccdcb 100644 (file)
@@ -41,8 +41,7 @@
 package org.onap.portal.domain.db.ep;
 
 import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Set;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -52,6 +51,8 @@ import javax.persistence.IdClass;
 import javax.persistence.Index;
 import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
 import javax.persistence.OneToMany;
 import javax.persistence.Table;
 import javax.validation.Valid;
@@ -65,6 +66,7 @@ import lombok.Setter;
 import org.hibernate.validator.constraints.SafeHtml;
 import org.onap.portal.domain.db.ep.EpAppFunction.EpAppFunctionId;
 import org.onap.portal.domain.db.fn.FnApp;
+import org.onap.portal.domain.dto.DomainVo;
 
 /*
 CREATE TABLE `ep_app_function` (
@@ -77,51 +79,86 @@ CREATE TABLE `ep_app_function` (
         )
 */
 
+@NamedQueries({
+    @NamedQuery(
+        name = "EpAppFunction.getAppRoleFunctionList",
+        query = "from\n"
+            + "  EpAppRoleFunction rf,\n"
+            + "  EpAppFunction f\n"
+            + " where\n"
+            + "  rf.fnRole.roleId = :roleId\n"
+            + "  and rf.appId.appId = :appId\n"
+            + "  and rf.appId.appId = f.appId.appId\n"
+            + "  and rf.epAppFunction.functionCd = f.functionCd"
+    )
+})
+
 @Table(name = "ep_app_function", indexes = {@Index(name = "fk_ep_app_function_app_id", columnList = "app_id")})
-@EqualsAndHashCode
+
 @Getter
 @Setter
 @Entity
 @IdClass(EpAppFunctionId.class)
 @NoArgsConstructor
 @AllArgsConstructor
-public class EpAppFunction {
-       @Id
-       @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
-       @JoinColumn(name = "app_id")
-       @Valid
-       private FnApp appId;
-       @Id
-       @Column(name = "function_cd", length = 250, nullable = false)
-       @Size(max = 250)
-       @NotNull
-       @SafeHtml
-       private String functionCd;
-       @Column(name = "function_name", length = 250, nullable = false)
-       @Size(max = 250)
-       @NotNull
-       @SafeHtml
-       private String functionName;
-       @OneToMany(
-               targetEntity = EpAppRoleFunction.class,
-               mappedBy = "epAppFunction",
-               cascade = CascadeType.ALL,
-               fetch = FetchType.LAZY
-       )
-       private List<EpAppRoleFunction> epAppRoleFunctions = new ArrayList<>();
+public class EpAppFunction extends DomainVo implements Serializable {
+
+  @Id
+  @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+  @JoinColumn(name = "app_id")
+  @Valid
+  private FnApp appId;
+  @Id
+  @Column(name = "function_cd", length = 250, nullable = false)
+  @Size(max = 250)
+  @NotNull
+  @SafeHtml
+  private String functionCd;
+  @Column(name = "function_name", length = 250, nullable = false)
+  @Size(max = 250)
+  @NotNull
+  @SafeHtml
+  private String functionName;
+
+  private Long roleId;
+  private String type;
+  @SafeHtml
+  private String action;
+  @SafeHtml
+  private String editUrl;
+
+  @OneToMany(
+      targetEntity = EpAppRoleFunction.class,
+      mappedBy = "epAppFunction",
+      cascade = CascadeType.ALL,
+      fetch = FetchType.LAZY
+  )
+  private Set<EpAppRoleFunction> epAppRoleFunctions;
+
+  public EpAppFunction(Long id, String code, String name, FnApp appId, String type, String action, String editUrl) {
+    super();
+    this.id = id;
+    this.functionCd = code;
+    this.functionName = name;
+    this.appId = appId;
+    this.type = type;
+    this.action = action;
+    this.editUrl = editUrl;
+  }
+
+  @Getter
+  @Setter
+  @EqualsAndHashCode
+  @NoArgsConstructor
+  @AllArgsConstructor
+  public static class EpAppFunctionId implements Serializable {
 
-       @Getter
-       @Setter
-       @EqualsAndHashCode
-       @NoArgsConstructor
-       @AllArgsConstructor
-       public static class EpAppFunctionId implements Serializable {
-              @Valid
-              private FnApp appId;
-              @Size(max = 250)
-              @NotNull
-              @SafeHtml
-              private String functionCd;
-       }
+    @Valid
+    private FnApp appId;
+    @Size(max = 250)
+    @NotNull
+    @SafeHtml
+    private String functionCd;
+  }
 }