Update license; improve coverage; add docs dir
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / domain / UserRoles.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright © 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.openecomp.portalapp.portal.domain;
39
40 import java.io.Serializable;
41 import java.util.ArrayList;
42 import java.util.HashMap;
43 import java.util.List;
44
45 import org.openecomp.portalsdk.core.util.SystemProperties;
46 import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
47
48 public class UserRoles implements Serializable {
49         private static final long serialVersionUID = 1L;
50
51         /* 
52         private static final HashMap<Long, String> rolesDictionary;
53         // remove hard coded roles
54         static {
55                 rolesDictionary = new HashMap<Long, String>();
56                 rolesDictionary.put(Long.valueOf(SystemProperties.getProperty(SystemProperties.SYS_ADMIN_ROLE_ID)).longValue(), "superAdmin");
57                 rolesDictionary.put(Long.valueOf(SystemProperties.getProperty(EPCommonSystemProperties.ACCOUNT_ADMIN_ROLE_ID)).longValue(), "admin");
58         }
59         */
60
61         public UserRoles(UserRole user) {
62                 setOrgUserId(user.getOrgUserId());
63                 setFirstName(user.getFirstName());
64                 setLastName(user.getLastName());
65                 setGuestSession(user.getUser_Id()==-1 ? true : false);
66
67                 addRole(user.getRoleName());
68         }
69
70         public void addRole(String roleName) {
71                 //String normalizedRole = normalizeRole(roleId);
72                 if (!getRoles().contains(roleName)) {
73                         this.roles.add(roleName);
74                 }
75         }
76
77         /*
78         public static String normalizeRole(Long role) {
79                 String roleTranslated = rolesDictionary.get(role);
80                 return roleTranslated == null ? "user" : roleTranslated;
81         }
82         */
83
84         private String orgUserId;
85         private String firstName;
86         private String lastName;
87         private boolean guestSession;
88
89         // TODO: Make into set
90         private List<String> roles = new ArrayList<String>();
91
92         public String getFirstName() {
93                 return firstName;
94         }
95
96         public void setFirstName(String firstName) {
97                 this.firstName = firstName;
98         }
99
100         public String getLastName() {
101                 return lastName;
102         }
103
104         public void setLastName(String lastName) {
105                 this.lastName = lastName;
106         }
107
108         public String getOrgUserId() {
109                 return orgUserId;
110         }
111
112         public void setOrgUserId(String orgUserId) {
113                 this.orgUserId = orgUserId;
114         }
115
116         public List<String> getRoles() {
117                 return roles;
118         }
119
120         public void setRoles(List<String> roles) {
121                 this.roles = roles;
122         }
123
124         public void setGuestSession(boolean guestSession) {
125                 this.guestSession = guestSession;
126         }
127
128         public boolean getGuestSession() {
129                 return this.guestSession;
130         }
131 }