summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java')
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java81
1 files changed, 72 insertions, 9 deletions
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
index 966eb8f2..139f69a2 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
@@ -38,6 +38,7 @@
package org.onap.portalapp.service;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -45,12 +46,14 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
+import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import org.onap.portalsdk.core.auth.LoginStrategy;
import org.onap.portalsdk.core.domain.App;
import org.onap.portalsdk.core.domain.Role;
+import org.onap.portalsdk.core.domain.RoleFunction;
import org.onap.portalsdk.core.domain.User;
import org.onap.portalsdk.core.domain.UserApp;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
@@ -64,6 +67,7 @@ import org.onap.portalsdk.core.onboarding.util.CipherUtil;
import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
import org.onap.portalsdk.core.restful.domain.EcompRole;
+import org.onap.portalsdk.core.restful.domain.EcompRoleFunction;
import org.onap.portalsdk.core.restful.domain.EcompUser;
import org.onap.portalsdk.core.service.AppService;
import org.onap.portalsdk.core.service.RestApiRequestBuilder;
@@ -77,6 +81,7 @@ import org.onap.portalsdk.core.web.support.UserUtils;
import org.slf4j.MDC;
import org.springframework.context.ApplicationContext;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
@@ -120,12 +125,14 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
// initialize the base class definition for Admin Auth Extension
adminAuthExtensionServiceImpl = appContext.getBean(IAdminAuthExtension.class);
userService = appContext.getBean(UserService.class);
- if(isCentralized.equals(isAccessCentralized)){
- restApiRequestBuilder = appContext.getBean(RestApiRequestBuilder.class);
appServiceImpl = appContext.getBean(AppService.class);
+
+ if(isCentralized.equals(isAccessCentralized)){
+ restApiRequestBuilder = appContext.getBean(RestApiRequestBuilder.class);
}
}
+ @SuppressWarnings("unchecked")
private void setCurrentAttributes(User user, EcompUser userJson) {
user.setEmail(userJson.getEmail());
@@ -141,12 +148,11 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
user.setPhone(userJson.getPhone());
user.setOrgUserId(userJson.getOrgUserId());
user.setActive(userJson.isActive());
- // user.setRoles(new TreeSet(userJson.getRoles()));
+// user.setRoles(new TreeSet(userJson.getRoles()));
}
@Override
public void pushUser(EcompUser userJson) throws PortalAPIException {
-
if (logger.isDebugEnabled())
logger.debug(EELFLoggerDelegate.debugLogger, "pushUser was invoked: {}", userJson);
User user = new User();
@@ -157,10 +163,28 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
user.setRoles(new TreeSet<Role>());
user.setUserApps(new TreeSet<UserApp>());
user.setPseudoRoles(new TreeSet<Role>());
- userProfileService.saveUser(user);
+
+ User domainUser = userProfileService.getUserByLoginId(user.getLoginId());
+ if (domainUser != null) {
+ JSONUtil.mapToDomainUser(domainUser, user);
+ userProfileService.saveUser(domainUser);
+ } else {
+ userProfileService.saveUser(user);
+ }
logger.debug(EELFLoggerDelegate.debugLogger, "push user success.");
// After successful creation, call admin auth extension
+
+ Set<EcompRole> ecompRoles = userJson.getRoles();
+ SortedSet<Role> roles = new TreeSet<>();
+ Iterator<EcompRole> roleIter = ecompRoles.iterator();
+ ObjectMapper mapper = new ObjectMapper();
+ while (roleIter.hasNext()) {
+ Object nextValue = roleIter.next();
+ EcompRole epRole = mapper.convertValue(nextValue, EcompRole.class);
+ roles.add(convertToRole(epRole));
+ }
+ user.setRoles(roles);
if (adminAuthExtensionServiceImpl != null) {
try {
adminAuthExtensionServiceImpl.saveUserExtension(user);
@@ -168,7 +192,6 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
logger.error("pushUser: saveUserExtension failed", ex);
}
}
-
response = "push user success.";
response = JSONUtil.convertResponseToJSON(response);
} catch (Exception e) {
@@ -179,6 +202,35 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
MDC.remove(SystemProperties.MDC_TIMER);
}
}
+
+ public Role convertToRole(EcompRole epRole) {
+ Role role = new Role();
+ role.setId(epRole.getId());
+ role.setName(epRole.getName());
+ role.setActive(true);
+ Set<RoleFunction> ecompRolefunctions = new TreeSet<>();
+ @SuppressWarnings("unchecked")
+ Set<EcompRoleFunction> rolefunctions = epRole.getRoleFunctions();
+ ObjectMapper mapper = new ObjectMapper();
+ Iterator<EcompRoleFunction> roleFnIter = rolefunctions.iterator();
+ while (roleFnIter.hasNext()) {
+ Object nextValue = roleFnIter.next();
+ EcompRoleFunction epRoleFunction = mapper.convertValue(nextValue, EcompRoleFunction.class);
+ ecompRolefunctions.add(convertToRoleFunction(epRoleFunction));
+ }
+ role.setRoleFunctions(ecompRolefunctions);
+ return role;
+ }
+
+ public RoleFunction convertToRoleFunction(EcompRoleFunction rolefun) {
+ RoleFunction roleFunction = new RoleFunction();
+ roleFunction.setName(rolefun.getName());
+ roleFunction.setCode(rolefun.getCode());
+ roleFunction.setType(rolefun.getType());
+ roleFunction.setAction(rolefun.getAction());
+ return roleFunction;
+ }
+
@Override
public void editUser(String loginId, EcompUser userJson) throws PortalAPIException {
@@ -200,7 +252,19 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
domainUser = editUser;
userProfileService.saveUser(domainUser);
logger.debug(EELFLoggerDelegate.debugLogger, "edit user success.");
-
+
+
+ Set<EcompRole> ecompRoles = userJson.getRoles();
+ SortedSet<Role> roles = new TreeSet<>();
+ Iterator<EcompRole> roleIter = ecompRoles.iterator();
+ ObjectMapper mapper = new ObjectMapper();
+ while (roleIter.hasNext()) {
+ Object nextValue = roleIter.next();
+ EcompRole epRole = mapper.convertValue(nextValue, EcompRole.class);
+ roles.add(convertToRole(epRole));
+ }
+ domainUser.setRoles(roles);
+
// After successful edit, call the admin auth extension
if (adminAuthExtensionServiceImpl != null) {
try {
@@ -482,5 +546,4 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
return getAppCredentials();
}
-
-}
+} \ No newline at end of file