fixes for supporting non-gui application access provisioning
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / service / ExternalAccessRolesServiceImpl.java
index 4e83b92..ad06dd9 100644 (file)
@@ -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);
@@ -1973,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
@@ -2684,11 +2699,11 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                        applicationRolesList = getAppRoles(app.getId());
                        List<String> applicationRoleIdList = new ArrayList<>();
                        for (EPRole applicationRole : applicationRolesList) {
-                               applicationRoleIdList.add(applicationRole.getName());
+                               applicationRoleIdList.add(applicationRole.getName().trim());
                        }
                        List<EPRole> roleListToBeAddInEcompDB = new ArrayList<>();
                        for (EPRole aafRole : finalRoleList) {
-                               if (!applicationRoleIdList.contains(aafRole.getName())) {
+                               if (!applicationRoleIdList.contains(aafRole.getName().trim())) {
                                        roleListToBeAddInEcompDB.add(aafRole);
                                }
                        }
@@ -2822,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<ExternalAccessPerms> externalAccessPermsOfRole = new TreeSet<>();
                        if (extRole.getJSONObject(i).has(EXTERNAL_AUTH_PERMS)) {
@@ -2985,7 +3005,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                params.put("uebKey", app.getUebKey());
                List<BulkUploadUserRoles> 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")) {
@@ -3582,7 +3602,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                params.put("roleId", String.valueOf(roleId));
                List<BulkUploadUserRoles> userRolesList = null;
                Integer userRolesAdded = 0;
-               if (app.getCentralAuth()) {
+               if (app.getRolesInAAF()) {
                        userRolesList = dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null);
                        for (BulkUploadUserRoles userRolesUpload : userRolesList) {
                                userRolesUpload.setRoleName(modifiedRoleName);