2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
41 package org.onap.portal.domain.dto.transport;
43 import com.fasterxml.jackson.annotation.JsonIgnore;
44 import java.io.Serializable;
45 import java.time.LocalDateTime;
47 import javax.persistence.CascadeType;
48 import javax.persistence.Column;
49 import javax.persistence.Entity;
50 import javax.persistence.FetchType;
51 import javax.persistence.Index;
52 import javax.persistence.Inheritance;
53 import javax.persistence.InheritanceType;
54 import javax.persistence.OneToMany;
55 import javax.persistence.Table;
56 import javax.validation.constraints.Digits;
57 import javax.validation.constraints.NotNull;
58 import javax.validation.constraints.Size;
59 import lombok.AllArgsConstructor;
60 import lombok.Builder;
62 import lombok.NoArgsConstructor;
64 import org.hibernate.validator.constraints.SafeHtml;
65 import org.onap.portal.domain.db.fn.FnRoleComposite;
66 import org.onap.portal.domain.db.fn.FnRoleFunction;
67 import org.onap.portal.domain.db.DomainVo;
68 import org.onap.portalsdk.core.domain.RoleFunction;
70 @Table(name = "role", indexes = {
71 @Index(name = "fn_role_name_app_id_idx", columnList = "role_name, app_id", unique = true)
77 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
78 public class Role extends DomainVo {
80 private static final long serialVersionUID = 1L;
82 @Column(name = "role_name", length = 300, nullable = false)
86 private String roleName;
87 @Column(name = "app_Id", length = 11, columnDefinition = "int(11) default null")
88 @Digits(integer = 11, fraction = 0)
90 @Column(name = "active_yn", length = 1, columnDefinition = "boolean default true", nullable = false)
92 private Boolean activeYn = true;
93 @Column(name = "priority", length = 4, columnDefinition = "decimal(4,0) DEFAULT NULL")
94 @Digits(integer = 4, fraction = 0)
95 private Integer priority;
97 targetEntity = FnRoleFunction.class,
99 cascade = CascadeType.MERGE,
100 fetch = FetchType.LAZY
102 private Set<FnRoleFunction> fnRoleFunctions;
104 targetEntity = FnRoleComposite.class,
105 mappedBy = "childRoles",
106 cascade = CascadeType.MERGE,
107 fetch = FetchType.LAZY
109 private Set<FnRoleComposite> childRoles;
112 targetEntity = FnRoleComposite.class,
113 mappedBy = "parentRoles",
114 cascade = CascadeType.MERGE,
115 fetch = FetchType.LAZY
117 private Set<FnRoleComposite> parentRoles;
119 public String getEditUrl() {
120 return "/role.htm?role_id=" + this.getId();
123 public String getToggleActiveImage() {
124 return "/static/fusion/images/" + (this.activeYn ? "active.png" : "inactive.png");
127 public String getToggleActiveAltText() {
128 return this.activeYn ? "Click to Deactivate Role" : "Click to Activate Role";
131 public void removeChildRole(Long roleId) {
133 for (FnRoleComposite role : this.childRoles) {
134 Role childRole = role.getChildRoles();
135 if (childRole.getId().equals(roleId)) {
136 this.childRoles.remove(childRole);
143 public void removeParentRole(Long roleId) {
145 for (Object role : this.parentRoles) {
146 org.onap.portalsdk.core.domain.Role parentRole = (org.onap.portalsdk.core.domain.Role) role;
147 if (parentRole.getId().equals(roleId)) {
148 this.parentRoles.remove(parentRole);
155 public void removeRoleFunction(String roleFunctionCd) {
157 for (Object function : this.fnRoleFunctions) {
158 RoleFunction roleFunction = (RoleFunction) function;
159 if (roleFunction.getCode().equals(roleFunctionCd)) {
160 this.fnRoleFunctions.remove(roleFunction);
167 public int compareTo(Object obj) {
168 String c1 = this.getRoleName();
169 String c2 = ((org.onap.portalsdk.core.domain.Role) obj).getName();
170 return c1 != null && c2 != null ? c1.compareTo(c2) : 1;
173 public Role( Long id, LocalDateTime created,
174 LocalDateTime modified, Long rowNum, Serializable auditUserId,
175 DomainVo createdId, DomainVo modifiedId, Set<DomainVo> fnUsersCreatedId,
176 Set<DomainVo> fnUsersModifiedId, String roleName, Long appId, Boolean activeYn, Integer priority,
177 Set<FnRoleFunction> fnRoleFunctions, Set<FnRoleComposite> childRoles,
178 Set<FnRoleComposite> parentRoles) {
179 super(id, created, modified, rowNum, auditUserId, createdId, modifiedId, fnUsersCreatedId, fnUsersModifiedId);
180 this.roleName = roleName;
182 this.activeYn = activeYn;
183 this.priority = priority;
184 this.fnRoleFunctions = fnRoleFunctions;
185 this.childRoles = childRoles;
186 this.parentRoles = parentRoles;