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 org.onap.portalsdk.core.domain.RoleFunction;
45 import org.onap.portalsdk.core.domain.support.DomainVo;
46 import com.fasterxml.jackson.annotation.JsonIgnore;
48 public class EPRole extends DomainVo {
50 private static final long serialVersionUID = 1L;
52 private boolean active;
53 private Integer priority;
55 // ONAP will identify the specific remote application role id by appID;appRoleId among all the application roles it persists.
56 private Long appId; // used by ONAP only
57 private Long appRoleId; // used by ONAP only
59 private SortedSet<RoleFunction> roleFunctions = new TreeSet<RoleFunction>();
61 private SortedSet<EPRole> childRoles = new TreeSet<EPRole>();
64 private SortedSet<EPRole> parentRoles = new TreeSet<EPRole>();
68 public String getName() {
72 public boolean getActive() {
76 public SortedSet<RoleFunction> getRoleFunctions() {
80 public Integer getPriority() {
84 public SortedSet<EPRole> getChildRoles() {
88 public SortedSet<EPRole> getParentRoles() {
92 public void setName(String name) {
96 public void setActive(boolean active) {
100 public void setRoleFunctions(SortedSet<RoleFunction> roleFunctions) {
101 this.roleFunctions = roleFunctions;
104 public void setPriority(Integer priority) {
105 this.priority = priority;
108 public void setChildRoles(SortedSet<EPRole> childRoles) {
109 this.childRoles = childRoles;
112 public void setParentRoles(SortedSet<EPRole> parentRoles) {
113 this.parentRoles = parentRoles;
116 public void addRoleFunction(RoleFunction roleFunction) {
117 this.roleFunctions.add(roleFunction);
120 public void addChildRole(EPRole role) {
121 this.childRoles.add(role);
124 public void addParentRole(EPRole role) {
125 this.parentRoles.add(role);
128 public String getEditUrl() {
129 return "/role.htm?role_id=" + getId();
132 public String getToggleActiveImage() {
133 return "/static/fusion/images/" + (getActive() ? "active.png" : "inactive.png" );
136 public String getToggleActiveAltText() {
137 return getActive() ? "Click to Deactivate Role" : "Click to Activate Role";
140 public void removeChildRole(Long roleId) {
141 Iterator<EPRole> i = this.childRoles.iterator();
143 while (i.hasNext()) {
144 EPRole childRole = (EPRole)i.next();
145 if (childRole.getId().equals(roleId)) {
146 this.childRoles.remove(childRole);
152 public void removeParentRole(Long roleId) {
153 Iterator<EPRole> i = this.parentRoles.iterator();
155 while (i.hasNext()) {
156 EPRole parentRole = (EPRole)i.next();
157 if (parentRole.getId().equals(roleId)) {
158 this.parentRoles.remove(parentRole);
164 public void removeRoleFunction(String roleFunctionCd) {
165 Iterator<RoleFunction> i = this.roleFunctions.iterator();
167 while (i.hasNext()) {
168 RoleFunction roleFunction = (RoleFunction)i.next();
169 if (roleFunction.getCode().equals(roleFunctionCd)) {
170 this.roleFunctions.remove(roleFunction);
176 public int compareTo(Object obj){
177 EPRole other = (EPRole)obj;
179 if(this.appId == null)
180 if(other.getAppId() == null)
181 return compareByName(other); //equal
184 else // this.appId != null
185 if(other.getAppId() == null)
186 return 1; // appId != null, but others is null
188 int appIdCompareResult = appId.compareTo(other.getAppId());
189 return appIdCompareResult == 0? compareByName(other) : appIdCompareResult;
193 private int compareByName(EPRole other) {
194 String c1 = getName();
195 String c2 = other.getName();
197 return (c1 == null || c2 == null) ? 1 : c1.compareTo(c2);
200 public Long getAppId() {
204 public void setAppId(Long appId) {
208 public Long getAppRoleId() {
212 public void setAppRoleId(Long appRoleId) {
213 this.appRoleId = appRoleId;
217 public String toString() {
218 return "[Id = " + id + ", name = " + name + "]";