2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.portal.domain;
40 import java.util.Iterator;
41 import java.util.SortedSet;
42 import java.util.TreeSet;
44 import javax.validation.Valid;
45 import org.hibernate.validator.constraints.SafeHtml;
46 import org.onap.portalsdk.core.domain.RoleFunction;
47 import org.onap.portalsdk.core.domain.support.DomainVo;
48 import com.fasterxml.jackson.annotation.JsonIgnore;
50 public class EPRole extends DomainVo {
52 private static final long serialVersionUID = 1L;
55 private boolean active;
56 private Integer priority;
58 // ONAP will identify the specific remote application role id by appID;appRoleId among all the application roles it persists.
59 private Long appId; // used by ONAP only
60 private Long appRoleId; // used by ONAP only
62 private SortedSet<RoleFunction> roleFunctions = new TreeSet<RoleFunction>();
64 private SortedSet<EPRole> childRoles = new TreeSet<EPRole>();
67 private SortedSet<EPRole> parentRoles = new TreeSet<EPRole>();
71 public String getName() {
75 public boolean getActive() {
79 public SortedSet<RoleFunction> getRoleFunctions() {
83 public Integer getPriority() {
87 public SortedSet<EPRole> getChildRoles() {
91 public SortedSet<EPRole> getParentRoles() {
95 public void setName(String name) {
99 public void setActive(boolean active) {
100 this.active = active;
103 public void setRoleFunctions(SortedSet<RoleFunction> roleFunctions) {
104 this.roleFunctions = roleFunctions;
107 public void setPriority(Integer priority) {
108 this.priority = priority;
111 public void setChildRoles(SortedSet<EPRole> childRoles) {
112 this.childRoles = childRoles;
115 public void setParentRoles(SortedSet<EPRole> parentRoles) {
116 this.parentRoles = parentRoles;
119 public void addRoleFunction(RoleFunction roleFunction) {
120 this.roleFunctions.add(roleFunction);
123 public void addChildRole(EPRole role) {
124 this.childRoles.add(role);
127 public void addParentRole(EPRole role) {
128 this.parentRoles.add(role);
131 public String getEditUrl() {
132 return "/role.htm?role_id=" + getId();
135 public String getToggleActiveImage() {
136 return "/static/fusion/images/" + (getActive() ? "active.png" : "inactive.png" );
139 public String getToggleActiveAltText() {
140 return getActive() ? "Click to Deactivate Role" : "Click to Activate Role";
143 public void removeChildRole(Long roleId) {
144 Iterator<EPRole> i = this.childRoles.iterator();
146 while (i.hasNext()) {
147 EPRole childRole = (EPRole)i.next();
148 if (childRole.getId().equals(roleId)) {
149 this.childRoles.remove(childRole);
155 public void removeParentRole(Long roleId) {
156 Iterator<EPRole> i = this.parentRoles.iterator();
158 while (i.hasNext()) {
159 EPRole parentRole = (EPRole)i.next();
160 if (parentRole.getId().equals(roleId)) {
161 this.parentRoles.remove(parentRole);
167 public void removeRoleFunction(String roleFunctionCd) {
168 Iterator<RoleFunction> i = this.roleFunctions.iterator();
170 while (i.hasNext()) {
171 RoleFunction roleFunction = (RoleFunction)i.next();
172 if (roleFunction.getCode().equals(roleFunctionCd)) {
173 this.roleFunctions.remove(roleFunction);
179 public int compareTo(Object obj){
180 EPRole other = (EPRole)obj;
182 if(this.appId == null)
183 if(other.getAppId() == null)
184 return compareByName(other); //equal
187 else // this.appId != null
188 if(other.getAppId() == null)
189 return 1; // appId != null, but others is null
191 int appIdCompareResult = appId.compareTo(other.getAppId());
192 return appIdCompareResult == 0? compareByName(other) : appIdCompareResult;
196 private int compareByName(EPRole other) {
197 String c1 = getName();
198 String c2 = other.getName();
200 return (c1 == null || c2 == null) ? 1 : c1.compareTo(c2);
203 public Long getAppId() {
207 public void setAppId(Long appId) {
211 public Long getAppRoleId() {
215 public void setAppRoleId(Long appRoleId) {
216 this.appRoleId = appRoleId;
220 public String toString() {
221 return "[Id = " + id + ", name = " + name + "]";