X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fportalapp%2Fportal%2Fservice%2FExternalAccessRolesServiceImpl.java;h=ad06dd96bdd4a76da9da20ab7e934788640bb6db;hb=230c71614b1d2fb71a8fb482c749ff5a6dad65d8;hp=3778a00ff48c36d0f937fe7f7e1135440f567809;hpb=d13dacf060ff58d36f7d8995d185d78085bfd669;p=portal.git diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java index 3778a00f..ad06dd96 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java @@ -311,8 +311,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic boolean isRoleNameChanged = false; if (!desc.equals(updateExtRole.getName())) { isRoleNameChanged = true; + addRole(updateExtRole, app.getUebKey()); //interchange 314 -315 deleteRoleInExtSystem(mapper, name); - addRole(updateExtRole, app.getUebKey()); // add partner functions to the global role in External // Auth System if (!list.isEmpty() && isGlobalRole) { @@ -348,7 +348,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic roleFunc.getCode(), roleFunc.getAction()); extAddRolePerms = new ExternalAccessRolePerms(extAddPerms, app.getNameSpace() + "." + updateExtRole.getName().replaceAll( - EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_")); + EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_")); response = addRoleFuncExtSysRestAPI(mapper, extAddRolePerms, headers); } } @@ -1183,13 +1183,13 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic .setModified(epApp.getModified()).setCreatedId(epApp.getCreatedId()) .setModifiedId(epApp.getModifiedId()).setRowNum(epApp.getRowNum()) .setName(epApp.getName()).setImageUrl(epApp.getImageUrl()) - .setDescription(epApp.getDescription()).setNotes(epApp.getNotes()) - .setUrl(epApp.getUrl()).setAlternateUrl(epApp.getAlternateUrl()) + .setDescription(epApp.getAppDescription()).setNotes(epApp.getAppNotes()) + .setUrl(epApp.getLandingPage()).setAlternateUrl(epApp.getLandingPage()) .setRestEndpoint(epApp.getAppRestEndpoint()).setMlAppName(epApp.getMlAppName()) .setMlAppAdminId(epApp.getMlAppAdminId()).setMotsId(String.valueOf(epApp.getMotsId())) - .setAppPassword(epApp.getAppPassword()).setOpen(String.valueOf(epApp.getOpen())) + .setAppPassword(epApp.getAppBasicAuthPassword()).setOpen(String.valueOf(epApp.getOpen())) .setEnabled(String.valueOf(epApp.getEnabled())).setThumbnail(epApp.getThumbnail()) - .setUsername(epApp.getUsername()).setUebKey(epApp.getUebKey()) + .setUsername(epApp.getAppBasicAuthUsername()).setUebKey(epApp.getUebKey()) .setUebSecret(epApp.getUebSecret()).setUebTopicName(epApp.getUebTopicName()) .createCentralApp(); cenApp.setAppPassword(EPCommonSystemProperties.APP_DISPLAY_PASSWORD); @@ -1229,11 +1229,14 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic } else { userRoleId = userApp.getRole().getAppRoleId(); } - CentralV2Role cenRole = new CentralV2Role(userRoleId, userApp.getRole().getCreated(), - userApp.getRole().getModified(), userApp.getRole().getCreatedId(), - userApp.getRole().getModifiedId(), userApp.getRole().getRowNum(), - userApp.getRole().getName(), userApp.getRole().getActive(), - userApp.getRole().getPriority(), roleFunctionSet, null, null); + CentralV2Role cenRole = new CentralV2Role.CentralV2RoleBuilder().setId(userRoleId) + .setCreated(userApp.getRole().getCreated()).setModified(userApp.getRole().getModified()) + .setCreatedId(userApp.getRole().getCreatedId()) + .setModifiedId(userApp.getRole().getModifiedId()) + .setRowNum(userApp.getRole().getRowNum()).setName(userApp.getRole().getName()) + .setActive(userApp.getRole().getActive()).setPriority(userApp.getRole().getPriority()) + .setRoleFunctions(roleFunctionSet).setChildRoles(null).setParentRoles(null) + .createCentralV2Role(); cua.setRole(cenRole); userAppList.getUserApps().add(cua); } @@ -1276,7 +1279,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic public CentralV2Role getRoleInfo(Long roleId, String uebkey) throws Exception { final Map params = new HashMap<>(); List roleList = new ArrayList<>(); - CentralV2Role cenRole = new CentralV2Role(); + CentralV2Role cenRole = new CentralV2Role.CentralV2RoleBuilder().createCentralV2Role(); List roleInfo = null; List app = null; try { @@ -1368,15 +1371,19 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic SortedSet childRoles = new TreeSet<>(); SortedSet parentRoles = new TreeSet<>(); CentralV2Role cenRole = null; - if (role.getAppRoleId() == null) { - cenRole = new CentralV2Role(role.getId(), role.getCreated(), role.getModified(), role.getCreatedId(), - role.getModifiedId(), role.getRowNum(), role.getName(), role.getActive(), role.getPriority(), - roleFunctionSet, childRoles, parentRoles); - } else { - cenRole = new CentralV2Role(role.getAppRoleId(), role.getCreated(), role.getModified(), - role.getCreatedId(), role.getModifiedId(), role.getRowNum(), role.getName(), role.getActive(), - role.getPriority(), roleFunctionSet, childRoles, parentRoles); - } + if (role.getAppRoleId() == null) { + cenRole = new CentralV2Role.CentralV2RoleBuilder().setId(role.getId()).setCreated(role.getCreated()) + .setModified(role.getModified()).setCreatedId(role.getCreatedId()) + .setModifiedId(role.getModifiedId()).setRowNum(role.getRowNum()).setName(role.getName()) + .setActive(role.getActive()).setPriority(role.getPriority()).setRoleFunctions(roleFunctionSet) + .setChildRoles(childRoles).setParentRoles(parentRoles).createCentralV2Role(); + } else { + cenRole = new CentralV2Role.CentralV2RoleBuilder().setId(role.getAppRoleId()) + .setCreated(role.getCreated()).setModified(role.getModified()).setCreatedId(role.getCreatedId()) + .setModifiedId(role.getModifiedId()).setRowNum(role.getRowNum()).setName(role.getName()) + .setActive(role.getActive()).setPriority(role.getPriority()).setRoleFunctions(roleFunctionSet) + .setChildRoles(childRoles).setParentRoles(parentRoles).createCentralV2Role(); + } roleList.add(cenRole); } return roleList; @@ -1966,14 +1973,29 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic .containsKey(extAuthrole.substring(app.getNameSpace().length() + 1))) { EPRole localAddFuntionRole = currentRolesInDB .get(extAuthrole.substring(app.getNameSpace().length() + 1)); + + String key = extAuthrole.substring(app.getNameSpace().length() + 1); + Boolean isaddAppRoleFuncRequired = true; + if(localAddFuntionRole == null && key.contains("-")) { + key = key.replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"); + localAddFuntionRole = currentRolesInDB.get(key); + if(localAddFuntionRole !=null) { + isaddAppRoleFuncRequired = false; + } + } + + logger.info("key >>>>>"+key); + logger.info("localAddFuntionRole >>>>>"+localAddFuntionRole); if (localAddFuntionRole == null) { checkAndAddRoleInDB(app, currentRolesInDB, roleFunctionList, extAuthrole); } else { - EPAppRoleFunction addAppRoleFunc = new EPAppRoleFunction(); - addAppRoleFunc.setAppId(app.getId()); - addAppRoleFunc.setCode(roleFunctionList.get(0).getCode()); - addAppRoleFunc.setRoleId(localAddFuntionRole.getId()); - dataAccessService.saveDomainObject(addAppRoleFunc, null); + if(isaddAppRoleFuncRequired) { + EPAppRoleFunction addAppRoleFunc = new EPAppRoleFunction(); + addAppRoleFunc.setAppId(app.getId()); + addAppRoleFunc.setCode(roleFunctionList.get(0).getCode()); + addAppRoleFunc.setRoleId(localAddFuntionRole.getId()); + dataAccessService.saveDomainObject(addAppRoleFunc, null); + } } } // This block is to save global role function if exists @@ -2677,11 +2699,11 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic applicationRolesList = getAppRoles(app.getId()); List applicationRoleIdList = new ArrayList<>(); for (EPRole applicationRole : applicationRolesList) { - applicationRoleIdList.add(applicationRole.getName()); + applicationRoleIdList.add(applicationRole.getName().trim()); } List roleListToBeAddInEcompDB = new ArrayList<>(); for (EPRole aafRole : finalRoleList) { - if (!applicationRoleIdList.contains(aafRole.getName())) { + if (!applicationRoleIdList.contains(aafRole.getName().trim())) { roleListToBeAddInEcompDB.add(aafRole); } } @@ -2815,7 +2837,12 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic String name = extRole.getJSONObject(i).getString(ROLE_NAME); String actualRoleName = name.substring(app.getNameSpace().length() + 1); if (extRole.getJSONObject(i).has(EXTERNAL_AUTH_ROLE_DESCRIPTION)) { - actualRoleName = extRole.getJSONObject(i).getString(EXTERNAL_AUTH_ROLE_DESCRIPTION); + String description = extRole.getJSONObject(i).getString(EXTERNAL_AUTH_ROLE_DESCRIPTION); + + if(actualRoleName.replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS_EXCLUDE_HYPHEN,"_") + .equalsIgnoreCase(description.replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS_EXCLUDE_HYPHEN,"_"))){ + actualRoleName = description; + } } SortedSet externalAccessPermsOfRole = new TreeSet<>(); if (extRole.getJSONObject(i).has(EXTERNAL_AUTH_PERMS)) { @@ -2886,7 +2913,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic roleFunction = dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appFuncsParams, null); } - if (!roleFunction.isEmpty()) { + if (!roleFunction.isEmpty() && roleId != null) { EPAppRoleFunction apRoleFunction = new EPAppRoleFunction(); apRoleFunction.setAppId(app.getId()); apRoleFunction.setRoleId(roleId); @@ -2978,7 +3005,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic params.put("uebKey", app.getUebKey()); List userRolesList = null; Integer userRolesAdded = 0; - if (app.getCentralAuth()) { + if (app.getRolesInAAF()) { userRolesList = dataAccessService.executeNamedQuery("getBulkUserRoles", params, null); for (BulkUploadUserRoles userRolesUpload : userRolesList) { if (!userRolesUpload.getOrgUserId().equals("su1234")) { @@ -3289,7 +3316,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic } } if (!found) { - CentralV2Role cenrole = new CentralV2Role(); + CentralV2Role cenrole = new CentralV2Role.CentralV2RoleBuilder().createCentralV2Role(); cenrole.setName(role.getRoleName()); cenrole.setId(role.getRoleId()); cenrole.setActive(role.isActive()); @@ -3336,9 +3363,11 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic } private CentralV2Role convertRoleToCentralV2Role(EPRole role) { - return new CentralV2Role(role.getId(), role.getCreated(), role.getModified(), role.getCreatedId(), - role.getModifiedId(), role.getRowNum(), role.getName(), role.getActive(), role.getPriority(), - new TreeSet<>(), new TreeSet<>(), new TreeSet<>()); + return new CentralV2Role.CentralV2RoleBuilder().setId(role.getId()).setCreated(role.getCreated()) + .setModified(role.getModified()).setCreatedId(role.getCreatedId()).setModifiedId(role.getModifiedId()) + .setRowNum(role.getRowNum()).setName(role.getName()).setActive(role.getActive()) + .setPriority(role.getPriority()).setRoleFunctions(new TreeSet<>()).setChildRoles(new TreeSet<>()) + .setParentRoles(new TreeSet<>()).createCentralV2Role(); } @Override @@ -3573,7 +3602,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic params.put("roleId", String.valueOf(roleId)); List userRolesList = null; Integer userRolesAdded = 0; - if (app.getCentralAuth()) { + if (app.getRolesInAAF()) { userRolesList = dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null); for (BulkUploadUserRoles userRolesUpload : userRolesList) { userRolesUpload.setRoleName(modifiedRoleName);