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=b1804d8ca097133a8483f7b1a355c54bd64d8526;hb=1376951553a11ed93a9fde45b7f26b51c0b31e9c;hp=af5b50015b2867c5af103b95d3a286b1677fac5e;hpb=2036d5039c90736c54484e539f37dfb8f661e4f1;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 af5b5001..b1804d8c 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 @@ -1285,7 +1285,15 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic final Map params = new HashMap<>(); CentralV2User userAppList = new CentralV2User(); CentralV2User user1 = null; + final Map params1 = new HashMap<>(); + List globalRoleList = new ArrayList<>(); + try { + if (app.getId() != PortalConstants.PORTAL_APP_ID) { + params1.put("userId", userInfo.getId()); + params1.put("appId", app.getId()); + globalRoleList = dataAccessService.executeNamedQuery("userAppGlobalRoles", params1, null); + } userAppList.setUserApps(new TreeSet()); for (EPUserApp userApp : userAppSet) { if (userApp.getRole().getActive()) { @@ -1306,41 +1314,46 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic epApp.getThumbnail(), epApp.getUsername(), epApp.getUebKey(), epApp.getUebSecret(), epApp.getUebTopicName()); cua.setApp(cenApp); + Long appId = null; + if (globalRole.toLowerCase().startsWith("global_") + && epApp.getId().equals(PortalConstants.PORTAL_APP_ID) + && !epApp.getId().equals(app.getId())) { + appId = app.getId(); + EPRole result = null; + if (globalRoleList.size() > 0) + result = globalRoleList.stream() + .filter(x -> userApp.getRole().getId().equals(x.getId())).findAny() + .orElse(null); + if (result == null) + continue; + } else { + appId = userApp.getApp().getId(); + } params.put("roleId", userApp.getRole().getId()); - params.put(APP_ID, userApp.getApp().getId()); - CentralV2Role centralRole; - List globalRoleList; - globalRoleList = getGlobalRolesOfPortal(); - EPRole result = globalRoleList.stream().filter(x -> userApp.getRole().getId().equals(x.getId())) - .findAny().orElse(null); - if (result != null && userApp.getApp().getId() != app.getId()) { - userApp.getRole().setId(result.getId()); - centralRole = getGlobalRoleForRequestedApp(app.getId(), userApp.getRole().getId()); - cua.setRole(centralRole); + params.put(APP_ID, appId); + List appRoleFunctionList = dataAccessService + .executeNamedQuery("getAppRoleFunctionList", params, null); + SortedSet roleFunctionSet = new TreeSet<>(); + for (CentralV2RoleFunction roleFunc : appRoleFunctionList) { + String functionCode = EcompPortalUtils.getFunctionCode(roleFunc.getCode()); + CentralV2RoleFunction cenRoleFunc = new CentralV2RoleFunction(roleFunc.getId(), + functionCode, roleFunc.getName(), null, null); + roleFunctionSet.add(cenRoleFunc); + } + Long userRoleId = null; + if (globalRole.toLowerCase().startsWith("global_") + || epApp.getId().equals(PortalConstants.PORTAL_APP_ID)) { + userRoleId = userApp.getRole().getId(); } else { - List appRoleFunctionList = dataAccessService - .executeNamedQuery("getAppRoleFunctionList", params, null); - SortedSet roleFunctionSet = new TreeSet<>(); - for (CentralV2RoleFunction roleFunc : appRoleFunctionList) { - String functionCode = EcompPortalUtils.getFunctionCode(roleFunc.getCode()); - CentralV2RoleFunction cenRoleFunc = new CentralV2RoleFunction(roleFunc.getId(), - functionCode, roleFunc.getName(), null, null); - roleFunctionSet.add(cenRoleFunc); - } - Long userRoleId = null; - if (globalRole.toLowerCase().startsWith("global_") - && epApp.getId().equals(PortalConstants.PORTAL_APP_ID)) { - userRoleId = userApp.getRole().getId(); - } 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); - cua.setRole(cenRole); + 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); + cua.setRole(cenRole); + userAppList.getUserApps().add(cua); } } @@ -1480,9 +1493,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic @SuppressWarnings("unchecked") @Override public CentralV2RoleFunction getRoleFunction(String functionCode, String uebkey) throws Exception { - if (functionCode.contains("|")) - functionCode = EcompPortalUtils.getFunctionCode(functionCode); - functionCode = encodeFunctionCode(functionCode); + String code = EcompPortalUtils.getFunctionCode(functionCode); + String encodedCode = encodeFunctionCode(code); CentralV2RoleFunction roleFunc = null; EPApp app = getApp(uebkey).get(0); List getRoleFuncList = null; @@ -1492,11 +1504,15 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic params.put(APP_ID, String.valueOf(app.getId())); getRoleFuncList = dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, params, null); if (getRoleFuncList.isEmpty()) { - return roleFunc; + params.put(FUNCTION_CODE_PARAMS, encodedCode); + getRoleFuncList = dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, params, null); + if (getRoleFuncList.isEmpty()) { + return roleFunc; + } } else { if (getRoleFuncList.size() > 1) { - CentralV2RoleFunction cenV2RoleFunction = appFunctionListFilter(functionCode, getRoleFuncList); - if(cenV2RoleFunction == null) + CentralV2RoleFunction cenV2RoleFunction = appFunctionListFilter(encodedCode, getRoleFuncList); + if (cenV2RoleFunction == null) return roleFunc; roleFunc = checkIfPipesExitsInFunctionCode(cenV2RoleFunction); } else { @@ -1528,7 +1544,6 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic return roleFunc; } - @SuppressWarnings("unchecked") @Override public boolean saveCentralRoleFunction(CentralV2RoleFunction domainCentralRoleFunction, EPApp app) throws Exception { boolean saveOrUpdateFunction = false; @@ -1536,41 +1551,15 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic domainCentralRoleFunction.setCode(encodeFunctionCode(domainCentralRoleFunction.getCode())); final Map functionParams = new HashMap<>(); functionParams.put("appId", String.valueOf(app.getId())); - List appRoleFuncWithPipe = new ArrayList<>(); - // If request coming from portal application we use type, instance/code and action to fetch record - if(domainCentralRoleFunction.getType()!=null && domainCentralRoleFunction.getAction()!=null){ - functionParams.put(FUNCTION_CODE_PARAMS, domainCentralRoleFunction.getType()+FUNCTION_PIPE - +domainCentralRoleFunction.getCode()+FUNCTION_PIPE+domainCentralRoleFunction.getAction()); - appRoleFuncWithPipe = dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, functionParams, null); - if(appRoleFuncWithPipe.isEmpty()){ - functionParams.put(FUNCTION_CODE_PARAMS, domainCentralRoleFunction.getCode()); - appRoleFuncWithPipe = dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, functionParams, null); - } - } - // If request coming from SDK applications we use just function code to fetch record - else{ - functionParams.put(FUNCTION_CODE_PARAMS, domainCentralRoleFunction.getCode()); - } - CentralV2RoleFunction appFunctionCode = null; - if(!appRoleFuncWithPipe.isEmpty()){ - // Make sure we extract correct record if similar records are found as query uses like condition - appFunctionCode = appFunctionListFilter(domainCentralRoleFunction.getCode(), appRoleFuncWithPipe); - if(appFunctionCode == null){ - appFunctionCode = domainCentralRoleFunction; - } - } else{ - appFunctionCode = domainCentralRoleFunction; - } - appFunctionCode.setName(domainCentralRoleFunction.getName()); if(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()) { - addRoleFunctionInExternalSystem(appFunctionCode, app); + addRoleFunctionInExternalSystem(domainCentralRoleFunction, app); } if(domainCentralRoleFunction.getType() != null && domainCentralRoleFunction.getAction() != null){ - appFunctionCode.setCode(domainCentralRoleFunction.getType()+ + domainCentralRoleFunction.setCode(domainCentralRoleFunction.getType()+ FUNCTION_PIPE+domainCentralRoleFunction.getCode()+FUNCTION_PIPE+domainCentralRoleFunction.getAction()); } - appFunctionCode.setAppId(app.getId()); - dataAccessService.saveDomainObject(appFunctionCode, null); + domainCentralRoleFunction.setAppId(app.getId()); + dataAccessService.saveDomainObject(domainCentralRoleFunction, null); saveOrUpdateFunction = true; } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "saveCentralRoleFunction: failed", e);