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============================================
 
  36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 
  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.regex.Pattern;
 
  47 import java.util.stream.Collectors;
 
  49 import javax.servlet.http.HttpServletRequest;
 
  50 import javax.servlet.http.HttpSession;
 
  52 import org.apache.commons.codec.DecoderException;
 
  53 import org.apache.commons.codec.binary.Hex;
 
  54 import org.hibernate.SessionFactory;
 
  55 import org.onap.portalapp.portal.controller.RoleManageController;
 
  56 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
 
  57 import org.onap.portalapp.portal.domain.EPRole;
 
  58 import org.onap.portalapp.portal.domain.EPUser;
 
  59 import org.onap.portalapp.portal.exceptions.RoleFunctionException;
 
  60 import org.onap.portalapp.portal.utils.EcompPortalUtils;
 
  61 import org.onap.portalapp.util.EPUserUtils;
 
  62 import org.onap.portalsdk.core.domain.RoleFunction;
 
  63 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 
  64 import org.onap.portalsdk.core.service.DataAccessService;
 
  65 import org.onap.portalsdk.core.util.SystemProperties;
 
  66 import org.springframework.beans.factory.annotation.Autowired;
 
  67 import org.springframework.transaction.annotation.Transactional;
 
  71 public class EPRoleFunctionServiceCentralizedImpl implements EPRoleFunctionService{
 
  73         private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPRoleFunctionServiceCentralizedImpl.class);
 
  76         private DataAccessService dataAccessService;
 
  79         private  SessionFactory sessionFactory;
 
  82         private  ExternalAccessRolesService externalAccessRolesService;
 
  84         @SuppressWarnings("unchecked")
 
  86         public List<RoleFunction> getRoleFunctions() {
 
  87                 List<CentralV2RoleFunction> getRoleFuncList = null;
 
  88                 List<RoleFunction> getRoleFuncListOfPortal = new ArrayList<>();
 
  89                 final Map<String, Long> params = new HashMap<>();
 
  90                 params.put("appId", (long) 1);
 
  91                 //Sync all functions from external system into Ecomp portal DB
 
  92                 getRoleFuncList = dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null);
 
  93                 for(CentralV2RoleFunction roleFunction : getRoleFuncList)
 
  95                         RoleFunction roleFun = new RoleFunction();
 
  96                         String code = EcompPortalUtils.getFunctionCode(roleFunction.getCode());
 
  97                         roleFun.setCode(code);
 
  98                         roleFun.setName(roleFunction.getName());
 
  99                         getRoleFuncListOfPortal.add(roleFun);
 
 101                 return getRoleFuncListOfPortal;
 
 104         @SuppressWarnings({ "unchecked", "rawtypes" })
 
 106         public Set getRoleFunctions(HttpServletRequest request, EPUser user) throws RoleFunctionException {
 
 107                 HttpSession session = request.getSession();
 
 108                 String userId = user.getId().toString();
 
 109                 final Map<String, String> params = new HashMap<>();
 
 110                 params.put("userId", userId);
 
 111                 List getRoleFuncListOfPortal = dataAccessService.executeNamedQuery("getRoleFunctionsOfUser", params, null);
 
 112                 Set<String> getRoleFuncListOfPortalSet = new HashSet<>(getRoleFuncListOfPortal);
 
 113                 Set<String> roleFunSet = new HashSet<>();
 
 114                 roleFunSet = getRoleFuncListOfPortalSet.stream().filter(x -> x.contains("|")).collect(Collectors.toSet());
 
 115                 if (roleFunSet.size() > 0)
 
 116                         for (String roleFunction : roleFunSet) {
 
 117                                 String roleFun = EcompPortalUtils.getFunctionCode(roleFunction);
 
 118                                 getRoleFuncListOfPortalSet.remove(roleFunction);
 
 119                                 getRoleFuncListOfPortalSet.add(roleFun);
 
 122                 Set<String> finalRoleFunctionSet = new HashSet<>();
 
 123                 for (String roleFn : getRoleFuncListOfPortalSet) {
 
 124                         finalRoleFunctionSet.add(EPUserUtils.decodeFunctionCode(roleFn));
 
 126                 session.setAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME),
 
 127                                 finalRoleFunctionSet);
 
 128                 logger.debug(EELFLoggerDelegate.debugLogger,
 
 129                                 "getRoleFunctions: RoleFunctions Of User" + finalRoleFunctionSet);
 
 130                 return finalRoleFunctionSet;