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;
28 import com.fasterxml.jackson.annotation.JsonIgnore;
30 public class EPRole extends DomainVo {
32 private static final long serialVersionUID = 1L;
34 private boolean active;
35 private Integer priority;
37 // ECOMP will identify the specific remote application role id by appID;appRoleId among all the application roles it persists.
38 private Long appId; // used by ECOMP only
39 private Long appRoleId; // used by ECOMP only
41 private SortedSet<RoleFunction> roleFunctions = new TreeSet<RoleFunction>();
43 private SortedSet<EPRole> childRoles = new TreeSet<EPRole>();
46 private SortedSet<EPRole> parentRoles = new TreeSet<EPRole>();
50 public String getName() {
54 public boolean getActive() {
58 public SortedSet<RoleFunction> getRoleFunctions() {
62 public Integer getPriority() {
66 public SortedSet<EPRole> getChildRoles() {
70 public SortedSet<EPRole> getParentRoles() {
74 public void setName(String name) {
78 public void setActive(boolean active) {
82 public void setRoleFunctions(SortedSet<RoleFunction> roleFunctions) {
83 this.roleFunctions = roleFunctions;
86 public void setPriority(Integer priority) {
87 this.priority = priority;
90 public void setChildRoles(SortedSet<EPRole> childRoles) {
91 this.childRoles = childRoles;
94 public void setParentRoles(SortedSet<EPRole> parentRoles) {
95 this.parentRoles = parentRoles;
98 public void addRoleFunction(RoleFunction roleFunction) {
99 this.roleFunctions.add(roleFunction);
102 public void addChildRole(EPRole role) {
103 this.childRoles.add(role);
106 public void addParentRole(EPRole role) {
107 this.parentRoles.add(role);
110 public String getEditUrl() {
111 return "/role.htm?role_id=" + getId();
114 public String getToggleActiveImage() {
115 return "/static/fusion/images/" + (getActive() ? "active.png" : "inactive.png" );
118 public String getToggleActiveAltText() {
119 return getActive() ? "Click to Deactivate Role" : "Click to Activate Role";
122 public void removeChildRole(Long roleId) {
123 Iterator<EPRole> i = this.childRoles.iterator();
125 while (i.hasNext()) {
126 EPRole childRole = (EPRole)i.next();
127 if (childRole.getId().equals(roleId)) {
128 this.childRoles.remove(childRole);
134 public void removeParentRole(Long roleId) {
135 Iterator<EPRole> i = this.parentRoles.iterator();
137 while (i.hasNext()) {
138 EPRole parentRole = (EPRole)i.next();
139 if (parentRole.getId().equals(roleId)) {
140 this.parentRoles.remove(parentRole);
146 public void removeRoleFunction(String roleFunctionCd) {
147 Iterator<RoleFunction> i = this.roleFunctions.iterator();
149 while (i.hasNext()) {
150 RoleFunction roleFunction = (RoleFunction)i.next();
151 if (roleFunction.getCode().equals(roleFunctionCd)) {
152 this.roleFunctions.remove(roleFunction);
158 public int compareTo(Object obj){
159 EPRole other = (EPRole)obj;
161 if(this.appId == null)
162 if(other.getAppId() == null)
163 return compareByName(other); //equal
166 else // this.appId != null
167 if(other.getAppId() == null)
168 return 1; // appId != null, but others is null
170 int appIdCompareResult = appId.compareTo(other.getAppId());
171 return appIdCompareResult == 0? compareByName(other) : appIdCompareResult;
175 private int compareByName(EPRole other) {
176 String c1 = getName();
177 String c2 = other.getName();
179 return (c1 == null || c2 == null) ? 1 : c1.compareTo(c2);
182 public Long getAppId() {
186 public void setAppId(Long appId) {
190 public Long getAppRoleId() {
194 public void setAppRoleId(Long appRoleId) {
195 this.appRoleId = appRoleId;
199 public String toString() {
200 return "[Id = " + id + ", name = " + name + "]";