+ logger.debug(EELFLoggerDelegate.debugLogger, "getRolesForApp: Finished!");
+ return roleList.stream().distinct().collect(Collectors.toList());
+ }
+
+ private CentralV2Role convertRoleToCentralV2Role(FnRole role) {
+ return CentralV2Role.builder().id(role.getId()).created(role.getCreated())
+ .modified(role.getModified())
+ .rowNum(role.getRowNum()).name(role.getRoleName()).active(role.getActiveYn())
+ .priority(role.getPriority()).roleFunctions(new TreeSet<>()).childRoles(new TreeSet<>())
+ .parentRoles(new TreeSet<>()).build();
+ }
+
+ private List<CentralV2Role> getGlobalRolesOfApplication(Long appId) {
+ List<GlobalRoleWithApplicationRoleFunction> globalRoles = new ArrayList<>();
+ try {
+ List<Tuple> tuples = entityManager.createQuery(GET_GLOBAL_ROLE_WITH_APPLICATION_ROLE_FUNCTIONS, Tuple.class)
+ .setParameter("appId", appId)
+ .getResultList();
+ globalRoles = tuples.stream().map(this::tupleToGlobalRoleWithApplicationRoleFunction).collect(Collectors.toList());
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getCentralizedAppsOfUser failed", e);
+ }
+ List<CentralV2Role> roleList = new ArrayList<>();
+ if (globalRoles.size() > 0) {
+ roleList = finalListOfCentralRoles(globalRoles);
+ }
+ return roleList;
+ }
+
+ private GlobalRoleWithApplicationRoleFunction tupleToGlobalRoleWithApplicationRoleFunction(Tuple tuple) {
+ return GlobalRoleWithApplicationRoleFunction.builder().roleId((Long) tuple.get("roleId"))
+ .roleName((String) tuple.get("roleName"))
+ .functionCd((String) tuple.get("functionCd")).functionName((String) tuple.get("functionName"))
+ .active((Boolean) tuple.get("active")).priority((Integer) tuple.get("priority"))
+ .appId((Long) tuple.get("appId")).roleAppId((Long) tuple.get("roleAppId")).build();
+ }
+
+ private List<CentralV2Role> finalListOfCentralRoles(List<GlobalRoleWithApplicationRoleFunction> globalRoles) {
+ List<CentralV2Role> rolesfinalList = new ArrayList<>();
+ for (GlobalRoleWithApplicationRoleFunction role : globalRoles) {
+ boolean found = false;
+ for (CentralV2Role cenRole : rolesfinalList) {
+ if (role.getRoleId().equals(cenRole.getId())) {
+ SortedSet<FnRoleFunction> roleFunctions = cenRole.getRoleFunctions();
+ FnRoleFunction cenRoleFun = createCentralRoleFunctionForGlobalRole(role);
+ roleFunctions.add(cenRoleFun);
+ cenRole.setRoleFunctions(roleFunctions);
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ CentralV2Role cenrole = new CentralV2Role();
+ cenrole.setName(role.getRoleName());
+ cenrole.setId(role.getRoleId());
+ cenrole.setActive(role.getActive());
+ cenrole.setPriority(role.getPriority());
+ SortedSet<FnRoleFunction> roleFunctions = new TreeSet<>();
+ FnRoleFunction cenRoleFun = createCentralRoleFunctionForGlobalRole(role);
+ roleFunctions.add(cenRoleFun);
+ cenrole.setRoleFunctions(roleFunctions);
+ rolesfinalList.add(cenrole);
+ }
+ }
+ return rolesfinalList;
+ }
+
+ private FnRoleFunction createCentralRoleFunctionForGlobalRole(GlobalRoleWithApplicationRoleFunction role) {
+ String instance;
+ String type;
+ String action;
+ FnRoleFunction cenRoleFun = null;
+ if (role.getFunctionCd().contains(FUNCTION_PIPE)) {
+ instance = EcompPortalUtils.getFunctionCode(role.getFunctionCd());
+ type = EcompPortalUtils.getFunctionType(role.getFunctionCd());
+ action = EcompPortalUtils.getFunctionAction(role.getFunctionCd());
+ cenRoleFun = FnRoleFunction.builder().build();
+ FnRole fnRole = new FnRole();
+ FnFunction fnFunction = FnFunction.builder().functionCd(instance).name(role.getFunctionName()).type(type).action(action).build();
+ cenRoleFun.setRole(fnRole);
+ cenRoleFun.setFunctionCd(fnFunction);
+ } else {
+ type = getFunctionCodeType(role.getFunctionCd());
+ action = getFunctionCodeAction(role.getFunctionCd());
+ FnFunction fnFunction = FnFunction.builder().functionCd(role.getFunctionCd()).name(role.getFunctionName()).type(type).action(action).build();
+ cenRoleFun.setRole(new FnRole());
+ cenRoleFun.setFunctionCd(fnFunction);
+ }
+ return cenRoleFun;