2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalapp.portal.domain;
22 import java.util.Iterator;
23 import java.util.SortedSet;
24 import java.util.TreeSet;
26 import org.openecomp.portalsdk.core.domain.RoleFunction;
27 import org.openecomp.portalsdk.core.domain.support.DomainVo;
29 import com.fasterxml.jackson.annotation.JsonIgnore;
31 public class EPRole extends DomainVo {
33 private static final long serialVersionUID = 1L;
35 private boolean active;
36 private Integer priority;
38 // ECOMP will identify the specific remote application role id by appID;appRoleId among all the application roles it persists.
39 private Long appId; // used by ECOMP only
40 private Long appRoleId; // used by ECOMP only
42 private SortedSet<RoleFunction> roleFunctions = new TreeSet<RoleFunction>();
44 private SortedSet<EPRole> childRoles = new TreeSet<EPRole>();
47 private SortedSet<EPRole> parentRoles = new TreeSet<EPRole>();
51 public String getName() {
55 public boolean getActive() {
59 public SortedSet<RoleFunction> getRoleFunctions() {
63 public Integer getPriority() {
67 public SortedSet<EPRole> getChildRoles() {
71 public SortedSet<EPRole> getParentRoles() {
75 public void setName(String name) {
79 public void setActive(boolean active) {
83 public void setRoleFunctions(SortedSet<RoleFunction> roleFunctions) {
84 this.roleFunctions = roleFunctions;
87 public void setPriority(Integer priority) {
88 this.priority = priority;
91 public void setChildRoles(SortedSet<EPRole> childRoles) {
92 this.childRoles = childRoles;
95 public void setParentRoles(SortedSet<EPRole> parentRoles) {
96 this.parentRoles = parentRoles;
99 public void addRoleFunction(RoleFunction roleFunction) {
100 this.roleFunctions.add(roleFunction);
103 public void addChildRole(EPRole role) {
104 this.childRoles.add(role);
107 public void addParentRole(EPRole role) {
108 this.parentRoles.add(role);
111 public String getEditUrl() {
112 return "/role.htm?role_id=" + getId();
115 public String getToggleActiveImage() {
116 return "/static/fusion/images/" + (getActive() ? "active.png" : "inactive.png" );
119 public String getToggleActiveAltText() {
120 return getActive() ? "Click to Deactivate Role" : "Click to Activate Role";
123 public void removeChildRole(Long roleId) {
124 Iterator<EPRole> i = this.childRoles.iterator();
126 while (i.hasNext()) {
127 EPRole childRole = (EPRole)i.next();
128 if (childRole.getId().equals(roleId)) {
129 this.childRoles.remove(childRole);
135 public void removeParentRole(Long roleId) {
136 Iterator<EPRole> i = this.parentRoles.iterator();
138 while (i.hasNext()) {
139 EPRole parentRole = (EPRole)i.next();
140 if (parentRole.getId().equals(roleId)) {
141 this.parentRoles.remove(parentRole);
147 public void removeRoleFunction(String roleFunctionCd) {
148 Iterator<RoleFunction> i = this.roleFunctions.iterator();
150 while (i.hasNext()) {
151 RoleFunction roleFunction = (RoleFunction)i.next();
152 if (roleFunction.getCode().equals(roleFunctionCd)) {
153 this.roleFunctions.remove(roleFunction);
159 public int compareTo(Object obj){
160 EPRole other = (EPRole)obj;
162 if(this.appId == null)
163 if(other.getAppId() == null)
164 return compareByName(other); //equal
167 else // this.appId != null
168 if(other.getAppId() == null)
169 return 1; // appId != null, but others is null
171 int appIdCompareResult = appId.compareTo(other.getAppId());
172 return appIdCompareResult == 0? compareByName(other) : appIdCompareResult;
176 private int compareByName(EPRole other) {
177 String c1 = getName();
178 String c2 = other.getName();
180 return (c1 == null || c2 == null) ? 1 : c1.compareTo(c2);
183 public Long getAppId() {
187 public void setAppId(Long appId) {
191 public Long getAppRoleId() {
195 public void setAppRoleId(Long appRoleId) {
196 this.appRoleId = appRoleId;
200 public String toString() {
201 String str = "[id: "+getId()+", appId: "+appId+", appRoleId: "+appRoleId+"]";