Deliver centralized role management feature
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / service / EPRoleFunctionServiceCentralizedImpl.java
1 package org.openecomp.portalapp.portal.service;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.HashSet;
6 import java.util.List;
7 import java.util.Map;
8 import java.util.Set;
9
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpSession;
12
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;
21
22
23 @Transactional
24 public class EPRoleFunctionServiceCentralizedImpl implements EPRoleFunctionService{
25
26         
27         @Autowired
28         private DataAccessService dataAccessService;
29         
30         @Autowired
31         private  SessionFactory sessionFactory;
32         
33         @SuppressWarnings({ "unchecked"})
34         @Override
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)
43                 {
44                         RoleFunction roleFun = new RoleFunction();
45                         roleFun.setCode(roleFunction.getCode());
46                         roleFun.setName(roleFunction.getName());
47                         getRoleFuncListOfPortal.add(roleFun);
48                 }
49                 return getRoleFuncListOfPortal;
50         }
51
52         @SuppressWarnings("unchecked")
53         @Override
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;
65                                 
66         }
67
68         
69         
70 }