summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserServiceCentalizedImpl.java
blob: 879b2a9a1944b9f9daeb522988980859e5c377b8 (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
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 {
		ObjectMapper mapper = new ObjectMapper();
		User user = new User();
		HashSet<RoleFunction> rolefun = null;
		String orgUserId = getUserByProfileId(id);
		String responseString = restApiRequestBuilder.getViaREST("/user/" + orgUserId, true, id);
		user = mapper.readValue(responseString, User.class);
		
		@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();

			Set<RoleFunction> roleFunctionList = role.getRoleFunctions();
			Set<RoleFunction> roleFunctionListNew = new HashSet<>();
			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();
			SortedSet<UserApp> UserAppSet = new TreeSet<>();
			UserAppSet.add(nextApp);
			user.setUserApps(UserAppSet);
		}
		
		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;
	}

}