blob: 979d6658c7dbfb3972eec76867149742384a796c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
package org.openecomp.portalsdk.core.service;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.openecomp.portalsdk.core.domain.Role;
import org.openecomp.portalsdk.core.domain.RoleFunction;
import org.openecomp.portalsdk.core.domain.User;
import org.openecomp.portalsdk.core.domain.UserApp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.fasterxml.jackson.databind.ObjectMapper;
@Transactional
public class UserServiceCentalizedImpl implements UserService {
@Autowired
AppService appService;
@Autowired
RestApiRequestBuilder restApiRequestBuilder;
@Autowired
LoginService loginService;
@Autowired
private DataAccessService dataAccessService;
public DataAccessService getDataAccessService() {
return dataAccessService;
}
public void setDataAccessService(DataAccessService dataAccessService) {
this.dataAccessService = dataAccessService;
}
@Override
public User getUser(String id) throws Exception {
User user = null;
String orgUserId = getUserByProfileId(id);
String responseString = restApiRequestBuilder.getViaREST("/user/" + orgUserId, true, id);
user = userMapper(responseString);
return user;
}
public String getUserByProfileId(String id) {
Map<String, Long> params = new HashMap<String, Long>();
params.put("user_id", new Long(id));
@SuppressWarnings("rawtypes")
List list = getDataAccessService().executeNamedQuery("getUserByProfileId", params, null);
String orgUserId = "";
if (list != null && !list.isEmpty())
orgUserId = (String) list.get(0);
return orgUserId;
}
@Override
public User userMapper(String res) throws Exception
{
User user= new User();
ObjectMapper mapper = new ObjectMapper();
HashSet<RoleFunction> rolefun = null;
user = mapper.readValue(res, User.class);
Set<RoleFunction> roleFunctionListNew = new HashSet<>();
Set<RoleFunction> roleFunctionList = new HashSet<>();
SortedSet<UserApp> UserAppSet = new TreeSet<>();
@SuppressWarnings("unchecked")
Set<UserApp> setAppsObj = user.getUserApps();
Iterator<UserApp> it = setAppsObj.iterator();
while (it.hasNext()) {
Object next = it.next();
UserApp nextApp = mapper.convertValue(next, UserApp.class);
rolefun = new HashSet<>();
Role role = nextApp.getRole();
roleFunctionList = role.getRoleFunctions();
Iterator<RoleFunction> itetaror = roleFunctionList.iterator();
while (itetaror.hasNext()) {
Object nextValue = itetaror.next();
RoleFunction roleFunction = mapper.convertValue(nextValue, RoleFunction.class);
roleFunctionListNew.add(roleFunction);
}
role.setRoleFunctions(roleFunctionListNew);
nextApp.setRole(role);
nextApp.getRole().getRoleFunctions();
UserAppSet.add(nextApp);
user.setUserApps(UserAppSet);
}
return user;
}
}
|