1 package org.openecomp.portalapp.portal.service;
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.HashSet;
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpSession;
13 import org.hibernate.SessionFactory;
14 import org.openecomp.portalapp.portal.domain.CentralRoleFunction;
15 import org.openecomp.portalapp.portal.domain.EPUser;
16 import org.openecomp.portalsdk.core.domain.RoleFunction;
17 import org.openecomp.portalsdk.core.service.DataAccessService;
18 import org.openecomp.portalsdk.core.util.SystemProperties;
19 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.transaction.annotation.Transactional;
24 public class EPRoleFunctionServiceCentralizedImpl implements EPRoleFunctionService{
28 private DataAccessService dataAccessService;
31 private SessionFactory sessionFactory;
33 @SuppressWarnings({ "unchecked"})
35 public List<RoleFunction> getRoleFunctions() {
36 List<CentralRoleFunction> getRoleFuncList = null;
37 List<RoleFunction> getRoleFuncListOfPortal = new ArrayList<>();
38 final Map<String, Long> params = new HashMap<>();
39 params.put("appId", (long) 1);
40 //Sync all functions from external system into Ecomp portal DB
41 getRoleFuncList = dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null);
42 for(CentralRoleFunction roleFunction : getRoleFuncList)
44 RoleFunction roleFun = new RoleFunction();
45 roleFun.setCode(roleFunction.getCode());
46 roleFun.setName(roleFunction.getName());
47 getRoleFuncListOfPortal.add(roleFun);
49 return getRoleFuncListOfPortal;
52 @SuppressWarnings("unchecked")
54 public Set getRoleFunctions(HttpServletRequest request, EPUser user) {
55 HttpSession session = request.getSession();
56 String userId = user.getId().toString();
57 final Map<String, String> params = new HashMap<>();
58 params.put("userId", userId);
59 @SuppressWarnings("unchecked")
60 List getRoleFuncListOfPortal = dataAccessService.executeNamedQuery("getRoleFunctionsOfUser", params, null);
61 Set<String> getRoleFuncListOfPortalSet = new HashSet<>(getRoleFuncListOfPortal);
62 session.setAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME),
63 getRoleFuncListOfPortalSet);
64 return getRoleFuncListOfPortalSet;