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 {
47 ObjectMapper mapper = new ObjectMapper();
48 User user = new User();
49 HashSet<RoleFunction> rolefun = null;
50 String orgUserId = getUserByProfileId(id);
51 String responseString = restApiRequestBuilder.getViaREST("/user/" + orgUserId, true, id);
52 user = mapper.readValue(responseString, User.class);
54 @SuppressWarnings("unchecked")
55 Set<UserApp> setAppsObj = user.getUserApps();
57 Iterator<UserApp> it = setAppsObj.iterator();
58 while (it.hasNext()) {
59 Object next = it.next();
61 UserApp nextApp = mapper.convertValue(next, UserApp.class);
62 rolefun = new HashSet<>();
63 Role role = nextApp.getRole();
65 Set<RoleFunction> roleFunctionList = role.getRoleFunctions();
66 Set<RoleFunction> roleFunctionListNew = new HashSet<>();
67 Iterator<RoleFunction> itetaror = roleFunctionList.iterator();
68 while (itetaror.hasNext()) {
69 Object nextValue = itetaror.next();
70 RoleFunction roleFunction = mapper.convertValue(nextValue, RoleFunction.class);
71 roleFunctionListNew.add(roleFunction);
74 role.setRoleFunctions(roleFunctionListNew);
75 nextApp.setRole(role);
76 nextApp.getRole().getRoleFunctions();
77 SortedSet<UserApp> UserAppSet = new TreeSet<>();
78 UserAppSet.add(nextApp);
79 user.setUserApps(UserAppSet);
85 public String getUserByProfileId(String id) {
86 Map<String, Long> params = new HashMap<String, Long>();
87 params.put("user_id", new Long(id));
88 @SuppressWarnings("rawtypes")
89 List list = getDataAccessService().executeNamedQuery("getUserByProfileId", params, null);
90 String orgUserId = "";
91 if (list != null && !list.isEmpty())
92 orgUserId = (String) list.get(0);