2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017-2018 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.service;
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.HashSet;
43 import java.util.List;
46 import java.util.stream.Collectors;
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpSession;
51 import org.hibernate.SessionFactory;
52 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
53 import org.onap.portalapp.portal.domain.EPUser;
54 import org.onap.portalapp.portal.exceptions.RoleFunctionException;
55 import org.onap.portalapp.portal.utils.EcompPortalUtils;
56 import org.onap.portalapp.util.EPUserUtils;
57 import org.onap.portalsdk.core.domain.RoleFunction;
58 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
59 import org.onap.portalsdk.core.service.DataAccessService;
60 import org.onap.portalsdk.core.util.SystemProperties;
61 import org.springframework.beans.factory.annotation.Autowired;
62 import org.springframework.transaction.annotation.Transactional;
66 public class EPRoleFunctionServiceCentralizedImpl implements EPRoleFunctionService{
68 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPRoleFunctionServiceCentralizedImpl.class);
71 private DataAccessService dataAccessService;
74 private SessionFactory sessionFactory;
77 private ExternalAccessRolesService externalAccessRolesService;
79 @SuppressWarnings("unchecked")
81 public List<RoleFunction> getRoleFunctions() {
82 List<CentralV2RoleFunction> getRoleFuncList = null;
83 List<RoleFunction> getRoleFuncListOfPortal = new ArrayList<>();
84 final Map<String, Long> params = new HashMap<>();
85 params.put("appId", (long) 1);
86 //Sync all functions from external system into ONAP portal DB
87 getRoleFuncList = dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null);
88 for(CentralV2RoleFunction roleFunction : getRoleFuncList)
90 RoleFunction roleFun = new RoleFunction();
91 String code = EcompPortalUtils.getFunctionCode(roleFunction.getCode());
92 roleFun.setCode(code);
93 roleFun.setName(roleFunction.getName());
94 getRoleFuncListOfPortal.add(roleFun);
96 return getRoleFuncListOfPortal;
99 @SuppressWarnings({ "unchecked", "rawtypes" })
101 public Set getRoleFunctions(HttpServletRequest request, EPUser user) throws RoleFunctionException {
102 HttpSession session = request.getSession();
103 String userId = user.getId().toString();
104 final Map<String, String> params = new HashMap<>();
105 params.put("userId", userId);
106 List getRoleFuncListOfPortal = dataAccessService.executeNamedQuery("getRoleFunctionsOfUser", params, null);
107 Set<String> getRoleFuncListOfPortalSet = new HashSet<>(getRoleFuncListOfPortal);
108 Set<String> roleFunSet = new HashSet<>();
109 roleFunSet = getRoleFuncListOfPortalSet.stream().filter(x -> x.contains("|")).collect(Collectors.toSet());
110 if (roleFunSet.size() > 0)
111 for (String roleFunction : roleFunSet) {
112 String roleFun = EcompPortalUtils.getFunctionCode(roleFunction);
113 getRoleFuncListOfPortalSet.remove(roleFunction);
114 getRoleFuncListOfPortalSet.add(roleFun);
117 Set<String> finalRoleFunctionSet = new HashSet<>();
118 for (String roleFn : getRoleFuncListOfPortalSet) {
119 finalRoleFunctionSet.add(EPUserUtils.decodeFunctionCode(roleFn));
121 session.setAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME),
122 finalRoleFunctionSet);
123 logger.debug(EELFLoggerDelegate.debugLogger,
124 "getRoleFunctions: RoleFunctions Of User" + finalRoleFunctionSet);
125 return finalRoleFunctionSet;