Docker changes and Music Integration
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / service / ExternalAccessRolesServiceImpl.java
index b1804d8..678672b 100644 (file)
@@ -107,6 +107,7 @@ import org.onap.portalsdk.core.domain.Role;
 import org.onap.portalsdk.core.domain.RoleFunction;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 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.DataAccessService;
 import org.onap.portalsdk.core.util.SystemProperties;
@@ -513,8 +514,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                String action = "";
                if (roleFunc.getCode().contains(FUNCTION_PIPE)) {
                        code = EcompPortalUtils.getFunctionCode(roleFunc.getCode());
-                       type = getFunctionType(roleFunc.getCode());
-                       action = getFunctionAction(roleFunc.getCode());
+                       type = getFunctionCodeType(roleFunc.getCode());
+                       action = getFunctionCodeAction(roleFunc.getCode());
                } else {
                        code = roleFunc.getCode();
                        type = roleFunc.getCode().contains("menu") ? "menu" : "url";
@@ -663,8 +664,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                                String action = "";
                                if (addFunction.getCode().contains(FUNCTION_PIPE)) {
                                        code = EcompPortalUtils.getFunctionCode(addFunction.getCode());
-                                       type = getFunctionType(addFunction.getCode());
-                                       action = getFunctionAction(addFunction.getCode());
+                                       type = getFunctionCodeType(addFunction.getCode());
+                                       action = getFunctionCodeAction(addFunction.getCode());
                                } else {
                                        code = addFunction.getCode();
                                        type = addFunction.getCode().contains("menu") ? "menu" : "url";
@@ -720,8 +721,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                        String action = "";
                        if (roleFunc.getCode().contains(FUNCTION_PIPE)) {
                                code = EcompPortalUtils.getFunctionCode(roleFunc.getCode());
-                               type = getFunctionType(roleFunc.getCode());
-                               action = getFunctionAction(roleFunc.getCode());
+                               type = getFunctionCodeType(roleFunc.getCode());
+                               action = getFunctionCodeAction(roleFunc.getCode());
                        } else {
                                code = roleFunc.getCode();
                                type = roleFunc.getCode().contains("menu") ? "menu" : "url";
@@ -1191,8 +1192,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                List<CentralV2RoleFunction> getRoleFuncList = dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null);
                for (CentralV2RoleFunction roleFuncItem : getRoleFuncList) {
                        String code = EcompPortalUtils.getFunctionCode(roleFuncItem.getCode());
-                       String type = getFunctionType(roleFuncItem.getCode());
-                       String action = getFunctionAction(roleFuncItem.getCode());
+                       String type = getFunctionCodeType(roleFuncItem.getCode());
+                       String action = getFunctionCodeAction(roleFuncItem.getCode());
                        roleFuncItem.setCode(EPUserUtils.decodeFunctionCode(code));
                        roleFuncItem.setType(type);
                        roleFuncItem.setAction(action);
@@ -1202,26 +1203,14 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
        }
 
 
-       /**
-        * It return function action
-        * 
-        * @param roleFuncItem
-        * @return String action
-        */
-       private String getFunctionAction(String roleFuncItem) {
+       @Override
+       public String getFunctionCodeAction(String roleFuncItem) {
                return (!roleFuncItem.contains(FUNCTION_PIPE)) ? "*"
                                : EcompPortalUtils.getFunctionAction(roleFuncItem);
        }
 
-       /**
-        * 
-        * It check function code has any pipes, if found return function type
-        * 
-        * @param roleFuncItem
-        * @param type
-        * @return function type
-        */
-       private String getFunctionType(String roleFuncItem) {
+       @Override
+       public String getFunctionCodeType(String roleFuncItem) {
                String type = null;
                if ((roleFuncItem.contains(FUNCTION_PIPE) && roleFuncItem.contains("menu"))
                                || (!roleFuncItem.contains(FUNCTION_PIPE) && roleFuncItem.contains("menu"))) {
@@ -1336,8 +1325,10 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                                                SortedSet<CentralV2RoleFunction> roleFunctionSet = new TreeSet<>();
                                                for (CentralV2RoleFunction roleFunc : appRoleFunctionList) {
                                                        String functionCode = EcompPortalUtils.getFunctionCode(roleFunc.getCode());
+                                                       String type = getFunctionCodeType(roleFunc.getCode());
+                                                       String action = getFunctionCodeAction(roleFunc.getCode());
                                                        CentralV2RoleFunction cenRoleFunc = new CentralV2RoleFunction(roleFunc.getId(),
-                                                                       functionCode, roleFunc.getName(), null, null);
+                                                                       functionCode, roleFunc.getName(), null, type, action, null);
                                                        roleFunctionSet.add(cenRoleFunc);
                                                }
                                                Long userRoleId = null;
@@ -1467,8 +1458,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                        for (CentralV2RoleFunction roleFunc : cenRoleFuncList) {
                                String functionCode = EcompPortalUtils.getFunctionCode(roleFunc.getCode());
                                functionCode = EPUserUtils.decodeFunctionCode(functionCode);
-                               String type = getFunctionType(roleFunc.getCode());
-                               String action = getFunctionAction(roleFunc.getCode());
+                               String type = getFunctionCodeType(roleFunc.getCode());
+                               String action = getFunctionCodeAction(roleFunc.getCode());
                                CentralV2RoleFunction cenRoleFunc = new CentralV2RoleFunction(role.getId(), functionCode,
                                                roleFunc.getName(), null, type, action, null);
                                roleFunctionSet.add(cenRoleFunc);
@@ -1509,15 +1500,14 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                                if (getRoleFuncList.isEmpty()) {
                                        return roleFunc;
                                }
+                       }
+                       if (getRoleFuncList.size() > 1) {
+                               CentralV2RoleFunction cenV2RoleFunction = appFunctionListFilter(encodedCode, getRoleFuncList);
+                               if (cenV2RoleFunction == null)
+                                       return roleFunc;
+                               roleFunc = checkIfPipesExitsInFunctionCode(cenV2RoleFunction);
                        } else {
-                               if (getRoleFuncList.size() > 1) {
-                                       CentralV2RoleFunction cenV2RoleFunction = appFunctionListFilter(encodedCode, getRoleFuncList);
-                                       if (cenV2RoleFunction == null)
-                                               return roleFunc;
-                                       roleFunc = checkIfPipesExitsInFunctionCode(cenV2RoleFunction);
-                               } else {
-                                       roleFunc = checkIfPipesExitsInFunctionCode(getRoleFuncList.get(0));
-                               }
+                               roleFunc = getRoleFuncList.get(0);
                        }
                } catch (Exception e) {
                        logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction: failed", e);
@@ -1693,8 +1683,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                        ObjectMapper mapper = new ObjectMapper();
                        ExternalAccessPerms extPerms = new ExternalAccessPerms();
                        String instanceValue = EcompPortalUtils.getFunctionCode(domainCentralRoleFunction.getCode());
-                       String checkType = getFunctionType(domainCentralRoleFunction.getCode());
-                       String actionValue = getFunctionAction(domainCentralRoleFunction.getCode());
+                       String checkType = getFunctionCodeType(domainCentralRoleFunction.getCode());
+                       String actionValue = getFunctionCodeAction(domainCentralRoleFunction.getCode());
                        HttpHeaders headers = EcompPortalUtils.base64encodeKeyForAAFBasicAuth();
                        extPerms.setAction(actionValue);
                        extPerms.setInstance(instanceValue);
@@ -3093,79 +3083,116 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
        @Override
        public List<String> getMenuFunctionsList(String uebkey) throws Exception {
                List<String> appMenuFunctionsList = null;
+               List<String> appMenuFunctionsFinalList = new ArrayList<>();
                try {
                        EPApp app = getApp(uebkey).get(0);
                        final Map<String, Long> appParams = new HashMap<>();
                        appParams.put(APP_ID, app.getId());
                        appMenuFunctionsList = dataAccessService.executeNamedQuery("getMenuFunctions", appParams, null);
+                       for(String appMenuFunction : appMenuFunctionsList) {
+                               if(appMenuFunction.contains(FUNCTION_PIPE)) {
+                                       appMenuFunctionsFinalList.add(EcompPortalUtils.getFunctionCode(appMenuFunction));
+                               } else {
+                                       appMenuFunctionsFinalList.add(appMenuFunction);
+                               }
+                       }
                } catch (Exception e) {
                        logger.error(EELFLoggerDelegate.errorLogger, "getMenuFunctionsList: Failed", e);
-                       return appMenuFunctionsList;
+                       return appMenuFunctionsFinalList;
                }
-               return appMenuFunctionsList;
+               return appMenuFunctionsFinalList;
        }
 
        @SuppressWarnings({ "unchecked"})
        @Override
        public List<EcompUser> getAllAppUsers(String uebkey) throws Exception {
                List<String> usersList = new ArrayList<>();
-               List<EcompUser> usersfinalList = new ArrayList<>();
-               try {
-                       EPApp app = getApp(uebkey).get(0);
-                       final Map<String, Long> appParams = new HashMap<>();
-                       appParams.put("appId", app.getId());
-                       List<EcompUserRoles> userList = (List<EcompUserRoles>) dataAccessService
-                                       .executeNamedQuery("ApplicationUserRoles", appParams, null);
-                       for (EcompUserRoles ecompUserRole : userList) {
-                               boolean found = false;
-                               Set<EcompRole> roles = null;
-                               for (EcompUser user : usersfinalList) {
-                                       if (user.getOrgUserId().equals(ecompUserRole.getOrgUserId())) {
-                                               EcompRole ecompRole = new EcompRole();
-                                               ecompRole.setId(ecompUserRole.getRoleId());
-                                               ecompRole.setName(ecompUserRole.getRoleName());
-                                               roles = user.getRoles();
-                                               roles.add(ecompRole);
-                                               user.setRoles(roles);
-                                               found = true;
-                                               break;
-                                       }
-                               }
-
-                               if (!found) {
-                                       EcompUser epUser = new EcompUser();
-                                       epUser.setOrgId(ecompUserRole.getOrgId());
-                                       epUser.setManagerId(ecompUserRole.getManagerId());
-                                       epUser.setFirstName(ecompUserRole.getFirstName());
-                                       epUser.setLastName(ecompUserRole.getLastName());
-                                       epUser.setPhone(ecompUserRole.getPhone());
-                                       epUser.setEmail(ecompUserRole.getEmail());
-                                       epUser.setOrgUserId(ecompUserRole.getOrgUserId());
-                                       epUser.setOrgCode(ecompUserRole.getOrgCode());
-                                       epUser.setOrgManagerUserId(ecompUserRole.getOrgManagerUserId());
-                                       epUser.setJobTitle(ecompUserRole.getJobTitle());
-                                       epUser.setLoginId(ecompUserRole.getLoginId());
-                                       epUser.setActive(true);
-                                       roles = new HashSet<>();
-                                       EcompRole ecompRole = new EcompRole();
-                                       ecompRole.setId(ecompUserRole.getRoleId());
-                                       ecompRole.setName(ecompUserRole.getRoleName());
-                                       roles.add(ecompRole);
-                                       epUser.setRoles(roles);
-                                       usersfinalList.add(epUser);
-                               }
-                       }
-                       ObjectMapper mapper = new ObjectMapper();
+        List<EcompUser> usersfinalList = new ArrayList<>();
+        try {
+               EPApp app = getApp(uebkey).get(0);
+               final Map<String, Long> appParams = new HashMap<>();
+               appParams.put("appId", app.getId());
+               List<EcompUserRoles> userList = (List<EcompUserRoles>) dataAccessService
+                            .executeNamedQuery("ApplicationUserRoles", appParams, null);
+               for (EcompUserRoles ecompUserRole : userList) {
+                     boolean found = false;
+                     Set<EcompRole> roles = null;
+                     for (EcompUser user : usersfinalList) {
+                            if (user.getOrgUserId().equals(ecompUserRole.getOrgUserId())) {
+                                   EcompRole ecompRole = new EcompRole();
+                                   ecompRole.setId(ecompUserRole.getRoleId());
+                                   ecompRole.setName(ecompUserRole.getRoleName());
+                                   roles = user.getRoles();
+                                   EcompRole role = roles.stream().filter(x -> x.getName().equals(ecompUserRole.getRoleName())).findAny()
+                                                 .orElse(null);
+                                   SortedSet<EcompRoleFunction> roleFunctionSet = new TreeSet<>();
+                                   if(role != null)
+                                   {
+                                          roleFunctionSet = (SortedSet<EcompRoleFunction>) role.getRoleFunctions();
+                                   }
+                                          
+                             String functionCode = EcompPortalUtils.getFunctionCode(ecompUserRole.getFunctionCode());
+                            functionCode = EPUserUtils.decodeFunctionCode(functionCode);
+                            EcompRoleFunction epRoleFunction = new EcompRoleFunction();
+                            epRoleFunction.setName(ecompUserRole.getFunctionName());
+                            epRoleFunction.setCode(EPUserUtils.decodeFunctionCode(functionCode));
+                            epRoleFunction.setType(getFunctionCodeType(ecompUserRole.getFunctionCode()));
+                            epRoleFunction.setAction(getFunctionCodeAction(ecompUserRole.getFunctionCode()));
+                            roleFunctionSet.add(epRoleFunction);
+                        ecompRole.setRoleFunctions(roleFunctionSet);
+                                   roles.add(ecompRole);
+                                   user.setRoles(roles);
+                                   found = true;
+                                   break;
+                            }
+                     }
+
+                     if (!found) {
+                            EcompUser epUser = new EcompUser();
+                            epUser.setOrgId(ecompUserRole.getOrgId());
+                            epUser.setManagerId(ecompUserRole.getManagerId());
+                            epUser.setFirstName(ecompUserRole.getFirstName());
+                            epUser.setLastName(ecompUserRole.getLastName());
+                            epUser.setPhone(ecompUserRole.getPhone());
+                            epUser.setEmail(ecompUserRole.getEmail());
+                            epUser.setOrgUserId(ecompUserRole.getOrgUserId());
+                            epUser.setOrgCode(ecompUserRole.getOrgCode());
+                            epUser.setOrgManagerUserId(ecompUserRole.getOrgManagerUserId());
+                            epUser.setJobTitle(ecompUserRole.getJobTitle());
+                            epUser.setLoginId(ecompUserRole.getLoginId());
+                            epUser.setActive(true);
+                            roles = new HashSet<>();
+                            EcompRole ecompRole = new EcompRole();
+                            ecompRole.setId(ecompUserRole.getRoleId());
+                            ecompRole.setName(ecompUserRole.getRoleName());
+              SortedSet<EcompRoleFunction> roleFunctionSet = new TreeSet<>();
+              
+                            String functionCode = EcompPortalUtils.getFunctionCode(ecompUserRole.getFunctionCode());
+              functionCode = EPUserUtils.decodeFunctionCode(functionCode);
+              EcompRoleFunction epRoleFunction = new EcompRoleFunction();
+              epRoleFunction.setName(ecompUserRole.getFunctionName());
+              epRoleFunction.setCode(EPUserUtils.decodeFunctionCode(functionCode));
+              epRoleFunction.setType(getFunctionCodeType(ecompUserRole.getFunctionCode()));
+              epRoleFunction.setAction(getFunctionCodeAction(ecompUserRole.getFunctionCode()));
+              roleFunctionSet.add(epRoleFunction);
+              ecompRole.setRoleFunctions(roleFunctionSet);
+                            roles.add(ecompRole);
+                            epUser.setRoles(roles);
+                            usersfinalList.add(epUser);
+                     }
+               }
+               ObjectMapper mapper = new ObjectMapper();
+
+               for (EcompUser u1 : usersfinalList) {
+                     String str = mapper.writeValueAsString(u1);
+                     usersList.add(str);
+               }
+        } catch (Exception e) {
+               logger.error(EELFLoggerDelegate.errorLogger, "getAllUsers failed", e);
+               throw e;
+        }
+        return usersfinalList;
 
-                       for (EcompUser u1 : usersfinalList) {
-                               String str = mapper.writeValueAsString(u1);
-                               usersList.add(str);
-                       }
-               } catch (Exception e) {
-                       logger.error(EELFLoggerDelegate.errorLogger, "getAllUsers failed", e);
-                       throw e;
-               }
-               return usersfinalList;
        }
        
 
@@ -3290,8 +3317,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                        action = EcompPortalUtils.getFunctionAction(role.getFunctionCd());
                        cenRoleFun = new CentralV2RoleFunction(null, instance, role.getFunctionName(), null, type, action, null);
                } else{
-                       type = getFunctionType(role.getFunctionCd());
-                       action = getFunctionAction(role.getFunctionCd());
+                       type = getFunctionCodeType(role.getFunctionCd());
+                       action = getFunctionCodeAction(role.getFunctionCd());
                        cenRoleFun = new CentralV2RoleFunction(null, role.getFunctionCd(), role.getFunctionName(), null, type, action, null);
                }
                return cenRoleFun;
@@ -3317,10 +3344,10 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
        }
        
        @Override
-       public List<RoleFunction> convertCentralRoleFunctionToRoleFunctionObject(List<CentralV2RoleFunction> answer) {
-               List<RoleFunction> addRoleFuncList = new ArrayList<>();
+       public List<CentralRoleFunction> convertCentralRoleFunctionToRoleFunctionObject(List<CentralV2RoleFunction> answer) {
+               List<CentralRoleFunction> addRoleFuncList = new ArrayList<>();
                for(CentralV2RoleFunction cenRoleFunc : answer){
-                       RoleFunction setRoleFunc = new RoleFunction();
+                       CentralRoleFunction setRoleFunc = new CentralRoleFunction();
                        setRoleFunc.setCode(cenRoleFunc.getCode());
                        setRoleFunc.setName(cenRoleFunc.getName());
                        addRoleFuncList.add(setRoleFunc);
@@ -3337,6 +3364,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
                        sendUserRoles = convertV2UserRolesToOlderVersion(cenV2User);
                } catch (Exception e) {
                        logger.error(EELFLoggerDelegate.errorLogger, "getUserRoles: failed", e);
+                       throw e;
                }
                return sendUserRoles;
        }