2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
20 package org.openecomp.portalapp.portal.domain;
22 import java.io.Serializable;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
27 import org.openecomp.portalsdk.core.util.SystemProperties;
28 import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
30 public class UserRoles implements Serializable {
31 private static final long serialVersionUID = 1L;
34 private static final HashMap<Long, String> rolesDictionary;
35 // remove hard coded roles
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");
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);
49 addRole(user.getRoleName());
52 public void addRole(String roleName) {
53 //String normalizedRole = normalizeRole(roleId);
54 if (!getRoles().contains(roleName)) {
55 this.roles.add(roleName);
60 public static String normalizeRole(Long role) {
61 String roleTranslated = rolesDictionary.get(role);
62 return roleTranslated == null ? "user" : roleTranslated;
66 private String orgUserId;
67 private String firstName;
68 private String lastName;
69 private boolean guestSession;
71 // TODO: Make into set
72 private List<String> roles = new ArrayList<String>();
74 public String getFirstName() {
78 public void setFirstName(String firstName) {
79 this.firstName = firstName;
82 public String getLastName() {
86 public void setLastName(String lastName) {
87 this.lastName = lastName;
90 public String getOrgUserId() {
94 public void setOrgUserId(String orgUserId) {
95 this.orgUserId = orgUserId;
98 public List<String> getRoles() {
102 public void setRoles(List<String> roles) {
106 public void setGuestSession(boolean guestSession) {
107 this.guestSession = guestSession;
110 public boolean getGuestSession() {
111 return this.guestSession;