nexus site path corrected
[portal.git] / ecomp-portal-BE / src / main / java / org / openecomp / portalapp / portal / domain / UserRoles.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.io.Serializable;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26
27 import org.openecomp.portalapp.portal.utils.EPSystemProperties;
28 import org.openecomp.portalsdk.core.util.SystemProperties;
29
30 public class UserRoles implements Serializable {
31         private static final long serialVersionUID = 1L;
32
33         private static final HashMap<Long, String> rolesDictionary;
34
35         static {
36                 rolesDictionary = new HashMap<Long, String>();
37                 rolesDictionary.put(Long.valueOf(SystemProperties.getProperty(SystemProperties.SYS_ADMIN_ROLE_ID)).longValue(), "superAdmin");
38                 rolesDictionary.put(Long.valueOf(SystemProperties.getProperty(EPSystemProperties.ACCOUNT_ADMIN_ROLE_ID)).longValue(), "admin");
39         }
40
41         public UserRoles(UserRole user) {
42                 setOrgUserId(user.getOrgUserId());
43                 setFirstName(user.getFirstName());
44                 setLastName(user.getLastName());
45                 setGuestSession(user.getUser_Id()==-1 ? true : false);
46                 addRole(user.getRoleId());
47         }
48
49         public void addRole(Long roleId) {
50                 String normalizedRole = normalizeRole(roleId);
51                 if (!getRoles().contains(normalizedRole)) {
52                         this.roles.add(normalizedRole);
53                 }
54         }
55
56         public static String normalizeRole(Long role) {
57                 String roleTranslated = rolesDictionary.get(role);
58                 return roleTranslated == null ? "user" : roleTranslated;
59         }
60
61         private String orgUserId;
62
63         private String firstName;
64
65         private String lastName;
66         
67         private boolean guestSession;
68
69         // TODO: Make into set
70         private List<String> roles = new ArrayList<String>();
71
72         public String getFirstName() {
73                 return firstName;
74         }
75
76         public void setFirstName(String firstName) {
77                 this.firstName = firstName;
78         }
79
80         public String getLastName() {
81                 return lastName;
82         }
83
84         public void setLastName(String lastName) {
85                 this.lastName = lastName;
86         }
87
88         public String getOrgUserId() {
89                 return orgUserId;
90         }
91
92         public void setOrgUserId(String orgUserId) {
93                 this.orgUserId = orgUserId;
94         }
95
96         public List<String> getRoles() {
97                 return roles;
98         }
99
100         public void setRoles(List<String> roles) {
101                 this.roles = roles;
102         }
103         
104         public void setGuestSession(boolean guestSession) {
105                 this.guestSession = guestSession;
106         }
107         
108         public boolean getGuestSession() {
109                 return this.guestSession;
110         }
111 }