nexus site path corrected
[portal.git] / ecomp-portal-BE / src / main / java / org / openecomp / portalapp / portal / domain / EPRole.java
1 /*-
2  * ================================================================================
3  * eCOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 package org.openecomp.portalapp.portal.domain;
21
22 import java.util.Iterator;
23 import java.util.SortedSet;
24 import java.util.TreeSet;
25
26 import org.openecomp.portalsdk.core.domain.RoleFunction;
27 import org.openecomp.portalsdk.core.domain.support.DomainVo;
28
29 import com.fasterxml.jackson.annotation.JsonIgnore;
30
31 public class EPRole extends DomainVo {
32
33         private static final long serialVersionUID = 1L;
34         private String  name;
35     private boolean active;
36     private Integer priority;
37     
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
41
42     private SortedSet<RoleFunction>     roleFunctions = new TreeSet<RoleFunction>();
43     
44     private SortedSet<EPRole> childRoles = new TreeSet<EPRole>();
45     
46     @JsonIgnore
47     private SortedSet<EPRole> parentRoles = new TreeSet<EPRole>();
48
49     public EPRole() {}
50
51     public String getName() {
52         return name;
53     }
54
55     public boolean getActive() {
56         return active;
57     }
58
59     public SortedSet<RoleFunction> getRoleFunctions() {
60         return roleFunctions;
61     }
62
63     public Integer getPriority() {
64         return priority;
65     }
66
67     public SortedSet<EPRole> getChildRoles() {
68         return childRoles;
69     }
70
71     public SortedSet<EPRole> getParentRoles() {
72         return parentRoles;
73     }
74
75     public void setName(String name) {
76         this.name = name;
77     }
78
79     public void setActive(boolean active) {
80         this.active = active;
81     }
82
83     public void setRoleFunctions(SortedSet<RoleFunction> roleFunctions) {
84         this.roleFunctions = roleFunctions;
85     }
86
87     public void setPriority(Integer priority) {
88         this.priority = priority;
89     }
90
91     public void setChildRoles(SortedSet<EPRole> childRoles) {
92         this.childRoles = childRoles;
93     }
94
95     public void setParentRoles(SortedSet<EPRole> parentRoles) {
96         this.parentRoles = parentRoles;
97     }
98
99     public void addRoleFunction(RoleFunction roleFunction) {
100         this.roleFunctions.add(roleFunction);
101     }
102
103     public void addChildRole(EPRole role) {
104         this.childRoles.add(role);
105     }
106
107     public void addParentRole(EPRole role) {
108         this.parentRoles.add(role);
109     }
110
111     public String getEditUrl() {
112         return "/role.htm?role_id=" + getId();          
113     }
114     
115         public String getToggleActiveImage() {
116                 return "/static/fusion/images/" + (getActive() ? "active.png" : "inactive.png" );
117         }
118
119         public String getToggleActiveAltText() {
120                 return getActive() ? "Click to Deactivate Role" : "Click to Activate Role";
121         }
122     
123     public void removeChildRole(Long roleId) {
124       Iterator<EPRole> i = this.childRoles.iterator();
125
126       while (i.hasNext()) {
127         EPRole childRole = (EPRole)i.next();
128         if (childRole.getId().equals(roleId)) {
129           this.childRoles.remove(childRole);
130           break;
131         }
132       }
133     }
134
135     public void removeParentRole(Long roleId) {
136         Iterator<EPRole> i = this.parentRoles.iterator();
137
138         while (i.hasNext()) {
139           EPRole parentRole = (EPRole)i.next();
140           if (parentRole.getId().equals(roleId)) {
141             this.parentRoles.remove(parentRole);
142             break;
143           }
144         }
145       }
146
147     public void removeRoleFunction(String roleFunctionCd) {
148       Iterator<RoleFunction> i = this.roleFunctions.iterator();
149
150       while (i.hasNext()) {
151         RoleFunction roleFunction = (RoleFunction)i.next();
152         if (roleFunction.getCode().equals(roleFunctionCd)) {
153           this.roleFunctions.remove(roleFunction);
154           break;
155         }
156       }
157     }
158
159     public int compareTo(Object obj){
160         EPRole other = (EPRole)obj;
161
162         if(this.appId == null)
163                 if(other.getAppId() == null)
164                         return compareByName(other); //equal
165                 else
166                         return -1; 
167         else // this.appId != null
168                 if(other.getAppId() == null)
169                         return 1;  // appId != null, but others is null
170                 else{
171                         int appIdCompareResult = appId.compareTo(other.getAppId());
172                         return appIdCompareResult == 0? compareByName(other) : appIdCompareResult;
173                 }
174     }
175
176         private int compareByName(EPRole other) {
177                 String c1 = getName();
178         String c2 = other.getName();
179
180         return (c1 == null || c2 == null) ? 1 : c1.compareTo(c2);
181         }
182
183         public Long getAppId() {
184                 return appId;
185         }
186
187         public void setAppId(Long appId) {
188                 this.appId = appId;
189         }
190
191         public Long getAppRoleId() {
192                 return appRoleId;
193         }
194
195         public void setAppRoleId(Long appRoleId) {
196                 this.appRoleId = appRoleId;
197         }
198         
199         @Override
200         public String toString() {
201                 String str = "[id: "+getId()+", appId: "+appId+", appRoleId: "+appRoleId+"]";
202                 return str;
203         }
204 }