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.portalapp.portal.utils.EPSystemProperties;
28 import org.openecomp.portalsdk.core.util.SystemProperties;
30 public class UserRoles implements Serializable {
31 private static final long serialVersionUID = 1L;
33 private static final HashMap<Long, String> rolesDictionary;
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");
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());
49 public void addRole(Long roleId) {
50 String normalizedRole = normalizeRole(roleId);
51 if (!getRoles().contains(normalizedRole)) {
52 this.roles.add(normalizedRole);
56 public static String normalizeRole(Long role) {
57 String roleTranslated = rolesDictionary.get(role);
58 return roleTranslated == null ? "user" : roleTranslated;
61 private String orgUserId;
63 private String firstName;
65 private String lastName;
67 private boolean guestSession;
69 // TODO: Make into set
70 private List<String> roles = new ArrayList<String>();
72 public String getFirstName() {
76 public void setFirstName(String firstName) {
77 this.firstName = firstName;
80 public String getLastName() {
84 public void setLastName(String lastName) {
85 this.lastName = lastName;
88 public String getOrgUserId() {
92 public void setOrgUserId(String orgUserId) {
93 this.orgUserId = orgUserId;
96 public List<String> getRoles() {
100 public void setRoles(List<String> roles) {
104 public void setGuestSession(boolean guestSession) {
105 this.guestSession = guestSession;
108 public boolean getGuestSession() {
109 return this.guestSession;