2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
20 package org.openecomp.portalapp.portal.domain;
\r
22 import java.util.Iterator;
\r
23 import java.util.SortedSet;
\r
24 import java.util.TreeSet;
\r
26 import org.openecomp.portalsdk.core.domain.RoleFunction;
\r
27 import org.openecomp.portalsdk.core.domain.support.DomainVo;
\r
28 import com.fasterxml.jackson.annotation.JsonIgnore;
\r
30 public class EPRole extends DomainVo {
\r
32 private static final long serialVersionUID = 1L;
\r
33 private String name;
\r
34 private boolean active;
\r
35 private Integer priority;
\r
37 // ECOMP will identify the specific remote application role id by appID;appRoleId among all the application roles it persists.
\r
38 private Long appId; // used by ECOMP only
\r
39 private Long appRoleId; // used by ECOMP only
\r
41 private SortedSet<RoleFunction> roleFunctions = new TreeSet<RoleFunction>();
\r
43 private SortedSet<EPRole> childRoles = new TreeSet<EPRole>();
\r
46 private SortedSet<EPRole> parentRoles = new TreeSet<EPRole>();
\r
50 public String getName() {
\r
54 public boolean getActive() {
\r
58 public SortedSet<RoleFunction> getRoleFunctions() {
\r
59 return roleFunctions;
\r
62 public Integer getPriority() {
\r
66 public SortedSet<EPRole> getChildRoles() {
\r
70 public SortedSet<EPRole> getParentRoles() {
\r
74 public void setName(String name) {
\r
78 public void setActive(boolean active) {
\r
79 this.active = active;
\r
82 public void setRoleFunctions(SortedSet<RoleFunction> roleFunctions) {
\r
83 this.roleFunctions = roleFunctions;
\r
86 public void setPriority(Integer priority) {
\r
87 this.priority = priority;
\r
90 public void setChildRoles(SortedSet<EPRole> childRoles) {
\r
91 this.childRoles = childRoles;
\r
94 public void setParentRoles(SortedSet<EPRole> parentRoles) {
\r
95 this.parentRoles = parentRoles;
\r
98 public void addRoleFunction(RoleFunction roleFunction) {
\r
99 this.roleFunctions.add(roleFunction);
\r
102 public void addChildRole(EPRole role) {
\r
103 this.childRoles.add(role);
\r
106 public void addParentRole(EPRole role) {
\r
107 this.parentRoles.add(role);
\r
110 public String getEditUrl() {
\r
111 return "/role.htm?role_id=" + getId();
\r
114 public String getToggleActiveImage() {
\r
115 return "/static/fusion/images/" + (getActive() ? "active.png" : "inactive.png" );
\r
118 public String getToggleActiveAltText() {
\r
119 return getActive() ? "Click to Deactivate Role" : "Click to Activate Role";
\r
122 public void removeChildRole(Long roleId) {
\r
123 Iterator<EPRole> i = this.childRoles.iterator();
\r
125 while (i.hasNext()) {
\r
126 EPRole childRole = (EPRole)i.next();
\r
127 if (childRole.getId().equals(roleId)) {
\r
128 this.childRoles.remove(childRole);
\r
134 public void removeParentRole(Long roleId) {
\r
135 Iterator<EPRole> i = this.parentRoles.iterator();
\r
137 while (i.hasNext()) {
\r
138 EPRole parentRole = (EPRole)i.next();
\r
139 if (parentRole.getId().equals(roleId)) {
\r
140 this.parentRoles.remove(parentRole);
\r
146 public void removeRoleFunction(String roleFunctionCd) {
\r
147 Iterator<RoleFunction> i = this.roleFunctions.iterator();
\r
149 while (i.hasNext()) {
\r
150 RoleFunction roleFunction = (RoleFunction)i.next();
\r
151 if (roleFunction.getCode().equals(roleFunctionCd)) {
\r
152 this.roleFunctions.remove(roleFunction);
\r
158 public int compareTo(Object obj){
\r
159 EPRole other = (EPRole)obj;
\r
161 if(this.appId == null)
\r
162 if(other.getAppId() == null)
\r
163 return compareByName(other); //equal
\r
166 else // this.appId != null
\r
167 if(other.getAppId() == null)
\r
168 return 1; // appId != null, but others is null
\r
170 int appIdCompareResult = appId.compareTo(other.getAppId());
\r
171 return appIdCompareResult == 0? compareByName(other) : appIdCompareResult;
\r
175 private int compareByName(EPRole other) {
\r
176 String c1 = getName();
\r
177 String c2 = other.getName();
\r
179 return (c1 == null || c2 == null) ? 1 : c1.compareTo(c2);
\r
182 public Long getAppId() {
\r
186 public void setAppId(Long appId) {
\r
187 this.appId = appId;
\r
190 public Long getAppRoleId() {
\r
194 public void setAppRoleId(Long appRoleId) {
\r
195 this.appRoleId = appRoleId;
\r
199 public String toString() {
\r
200 return "[Id = " + id + ", name = " + name + "]";
\r