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