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