2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.portal.domain;
40 import java.io.Serializable;
41 import java.util.ArrayList;
42 import java.util.HashMap;
43 import java.util.List;
45 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
46 import org.onap.portalsdk.core.util.SystemProperties;
48 public class UserRoles implements Serializable {
49 private static final long serialVersionUID = 1L;
52 private static final HashMap<Long, String> rolesDictionary;
53 // remove hard coded roles
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");
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);
67 addRole(user.getRoleName());
70 public void addRole(String roleName) {
71 //String normalizedRole = normalizeRole(roleId);
72 if (!getRoles().contains(roleName)) {
73 this.roles.add(roleName);
78 public static String normalizeRole(Long role) {
79 String roleTranslated = rolesDictionary.get(role);
80 return roleTranslated == null ? "user" : roleTranslated;
84 private String orgUserId;
85 private String firstName;
86 private String lastName;
87 private boolean guestSession;
89 // TODO: Make into set
90 private List<String> roles = new ArrayList<String>();
92 public String getFirstName() {
96 public void setFirstName(String firstName) {
97 this.firstName = firstName;
100 public String getLastName() {
104 public void setLastName(String lastName) {
105 this.lastName = lastName;
108 public String getOrgUserId() {
112 public void setOrgUserId(String orgUserId) {
113 this.orgUserId = orgUserId;
116 public List<String> getRoles() {
120 public void setRoles(List<String> roles) {
124 public void setGuestSession(boolean guestSession) {
125 this.guestSession = guestSession;
128 public boolean getGuestSession() {
129 return this.guestSession;