1 package org.openecomp.portalsdk.core.service;
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Iterator;
9 import java.util.SortedSet;
10 import java.util.TreeSet;
12 import org.openecomp.portalsdk.core.domain.Role;
13 import org.openecomp.portalsdk.core.domain.RoleFunction;
14 import org.openecomp.portalsdk.core.domain.User;
15 import org.openecomp.portalsdk.core.domain.UserApp;
16 import org.springframework.beans.factory.annotation.Autowired;
17 import org.springframework.transaction.annotation.Transactional;
19 import com.fasterxml.jackson.databind.ObjectMapper;
22 public class UserServiceCentalizedImpl implements UserService {
25 AppService appService;
28 RestApiRequestBuilder restApiRequestBuilder;
31 LoginService loginService;
34 private DataAccessService dataAccessService;
36 public DataAccessService getDataAccessService() {
37 return dataAccessService;
40 public void setDataAccessService(DataAccessService dataAccessService) {
41 this.dataAccessService = dataAccessService;
46 public User getUser(String id) throws Exception {
48 String orgUserId = getUserByProfileId(id);
49 String responseString = restApiRequestBuilder.getViaREST("/user/" + orgUserId, true, id);
50 user = userMapper(responseString);
54 public String getUserByProfileId(String id) {
55 Map<String, Long> params = new HashMap<String, Long>();
56 params.put("user_id", new Long(id));
57 @SuppressWarnings("rawtypes")
58 List list = getDataAccessService().executeNamedQuery("getUserByProfileId", params, null);
59 String orgUserId = "";
60 if (list != null && !list.isEmpty())
61 orgUserId = (String) list.get(0);
66 public User userMapper(String res) throws Exception
68 User user= new User();
69 ObjectMapper mapper = new ObjectMapper();
70 HashSet<RoleFunction> rolefun = null;
71 user = mapper.readValue(res, User.class);
72 Set<RoleFunction> roleFunctionListNew = new HashSet<>();
73 Set<RoleFunction> roleFunctionList = new HashSet<>();
74 SortedSet<UserApp> UserAppSet = new TreeSet<>();
75 @SuppressWarnings("unchecked")
76 Set<UserApp> setAppsObj = user.getUserApps();
77 Iterator<UserApp> it = setAppsObj.iterator();
78 while (it.hasNext()) {
79 Object next = it.next();
81 UserApp nextApp = mapper.convertValue(next, UserApp.class);
82 rolefun = new HashSet<>();
83 Role role = nextApp.getRole();
84 roleFunctionList = role.getRoleFunctions();
85 Iterator<RoleFunction> itetaror = roleFunctionList.iterator();
86 while (itetaror.hasNext()) {
87 Object nextValue = itetaror.next();
88 RoleFunction roleFunction = mapper.convertValue(nextValue, RoleFunction.class);
89 roleFunctionListNew.add(roleFunction);
91 role.setRoleFunctions(roleFunctionListNew);
92 nextApp.setRole(role);
93 nextApp.getRole().getRoleFunctions();
95 UserAppSet.add(nextApp);
96 user.setUserApps(UserAppSet);