X-Git-Url: https://gerrit.onap.org/r/gitweb?p=portal.git;a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fportalapp%2Fportal%2Fservice%2FUserRolesCommonServiceImpl.java;h=b0dd4a21e256d9912af848eccf248777f4c5d9da;hp=2eb7c948604b06f1856b197764270930c052aa2c;hb=47bcf09a62fb260a60b90d4f6c8406d956ab5a8a;hpb=15586620ec762ba42f2c6ec1b596ea6ea4425355 diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java index 2eb7c948..b0dd4a21 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java @@ -823,6 +823,72 @@ public class UserRolesCommonServiceImpl { return addRemoteUser; } + + private EPUser pushRemoteUser(List roleInAppForUserList, String userId, EPApp app, + ObjectMapper mapper, SearchService searchService, + ApplicationsRestClientService applicationsRestClientService) throws Exception { + EPUser addRemoteUser = null; + if (remoteUserShouldBeCreated(roleInAppForUserList)) { + pushUserOnRemoteApp(userId, app, applicationsRestClientService, searchService, mapper, + isAppUpgradeVersion(app), roleInAppForUserList); + } + return addRemoteUser; + } + + protected void pushUserOnRemoteApp(String userId, EPApp app, + ApplicationsRestClientService applicationsRestClientService, SearchService searchService, + ObjectMapper mapper, boolean postOpenSource, List roleInAppForUserList) throws Exception { + + EPUser client = searchService.searchUserByUserId(userId); + + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + if (client == null) { + String msg = "cannot create user " + userId + ", because he/she cannot be found in phonebook."; + logger.error(EELFLoggerDelegate.errorLogger, msg); + throw new Exception(msg); + } + + client.setLoginId(userId); + client.setActive(true); + roleInAppForUserList.removeIf(role -> role.isApplied.equals(false)); + Set userRolesInRemoteApp = constructUsersRemoteAppRoles(roleInAppForUserList); + SortedSet roles = new TreeSet<>(); + List getAppRoles = getAppRoles(app.getId()); + for (EcompRole epRole : userRolesInRemoteApp) { + Role role = new Role(); + EPRole appRole = getAppRoles.stream() + .filter(applicationRole -> epRole.getId().equals(applicationRole.getId())) + .findAny() + .orElse(null); + if(appRole != null) + role.setId(appRole.getAppRoleId()); + role.setName(epRole.getName()); + roles.add(role); + } + client.setRoles(roles); + String userInString = null; + userInString = mapper.writerFor(EPUser.class).writeValueAsString(client); + logger.debug(EELFLoggerDelegate.debugLogger, + "about to post a client to remote application, users json = " + userInString); + applicationsRestClientService.post(EPUser.class, app.getId(), userInString, String.format("/user/%s", userId)); + + } + + + public List getAppRoles(Long appId) throws Exception { + List applicationRoles = null; + final Map appParams = new HashMap<>(); + try { + appParams.put("appId", appId); + applicationRoles = dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getAppRoles: failed", e); + throw e; + } + return applicationRoles; + } + /** * It checks whether the remote user exists or not * if exits returns user object else null @@ -883,16 +949,12 @@ public class UserRolesCommonServiceImpl { // if centralized app if (app.getCentralAuth()) { if (!app.getId().equals(PortalConstants.PORTAL_APP_ID)) { - try { - addRemoteUser(roleInAppForUserList, userId, app, mapper, searchService, + pushRemoteUser(roleInAppForUserList, userId, app, mapper, searchService, applicationsRestClientService); - } catch (Exception e) { - String message=e.getMessage(); - logger.error(EELFLoggerDelegate.errorLogger, message, e); - } } - Set userRolesInLocalApp = postUsersRolesToLocalApp(roleInAppForUserList, mapper, + + Set userRolesInLocalApp = postUsersRolesToLocalApp(roleInAppForUserList, mapper, applicationsRestClientService, appId, userId); RolesInAppForUser rolesInAppForUser = constructRolesInAppForUserUpdate(userId, appId, userRolesInLocalApp);