X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=portal-BE%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fportal%2Fservice%2Ffn%2FFnUserRoleService.java;h=fac4b14a54ca3f4ff8386341a60f292d7a177474;hb=ffd9af970318c1f5a0bad46d7aad5d4611414aae;hp=7772c8f0d90683030c90c7a4c2022214a8ed174c;hpb=dd4c51e4349b596766f2fda555a7a0d3ba46e9fa;p=portal.git diff --git a/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserRoleService.java b/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserRoleService.java index 7772c8f0..fac4b14a 100644 --- a/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserRoleService.java +++ b/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserRoleService.java @@ -47,24 +47,17 @@ import java.io.IOException; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.SortedSet; import java.util.stream.Collectors; import javax.persistence.EntityManager; -import javax.persistence.Query; import javax.persistence.Tuple; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.lang.StringUtils; import org.apache.cxf.transport.http.HTTPException; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.Transaction; import org.onap.portal.dao.fn.FnUserRoleDao; import org.onap.portal.domain.db.ep.EpUserRolesRequest; import org.onap.portal.domain.db.ep.EpUserRolesRequestDet; @@ -75,21 +68,17 @@ import org.onap.portal.domain.db.fn.FnUserRole; import org.onap.portal.domain.dto.ecomp.EPUserAppCatalogRoles; import org.onap.portal.domain.dto.ecomp.ExternalSystemAccess; import org.onap.portal.domain.dto.transport.AppWithRolesForUser; -import org.onap.portal.domain.dto.transport.ExternalAccessUserRoleDetail; import org.onap.portal.domain.dto.transport.FieldsValidator; import org.onap.portal.domain.dto.transport.RemoteRole; import org.onap.portal.domain.dto.transport.RemoteUserWithRoles; +import org.onap.portal.domain.dto.transport.Role; import org.onap.portal.domain.dto.transport.RoleInAppForUser; import org.onap.portal.domain.dto.transport.UserApplicationRoles; -import org.onap.portal.exception.SyncUserRolesException; -import org.onap.portal.logging.format.EPAppMessagesEnum; -import org.onap.portal.logging.logic.EPLogUtil; import org.onap.portal.service.ApplicationsRestClientService; -import org.onap.portal.service.ExternalAccessRolesService; +import org.onap.portal.service.ep.EpAppFunctionService; import org.onap.portal.service.ep.EpUserRolesRequestDetService; import org.onap.portal.service.ep.EpUserRolesRequestService; import org.onap.portal.utils.EPCommonSystemProperties; -import org.onap.portal.utils.EcompPortalUtils; import org.onap.portal.utils.PortalConstants; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.restful.domain.EcompRole; @@ -97,7 +86,6 @@ import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.client.RestTemplate; @Service @Transactional @@ -132,25 +120,25 @@ public class FnUserRoleService { private static final String USER_APP_CATALOG_ROLES = "select\n" + " A.reqId as reqId,\n" - + " B.requestedRoleId.roleId as requestedRoleId,\n" + + " B.requestedRoleId.id as requestedRoleId,\n" + " A.requestStatus as requestStatus,\n" - + " A.appId.appId as appId,\n" + + " A.appId.id as appId,\n" + " (\n" + " select\n" + " roleName\n" + " from\n" + " FnRole\n" + " where\n" - + " roleId = B.requestedRoleId.roleId\n" + + " id = B.requestedRoleId.id\n" + " ) as roleName\n" + "from\n" + " EpUserRolesRequest A\n" + " left join EpUserRolesRequestDet B on A.reqId = B.reqId.reqId\n" + "where\n" - + " A.userId.userId = :userid\n" + + " A.userId.id = :userid\n" + " and A.appId IN (\n" + " select\n" - + " appId\n" + + " id\n" + " from\n" + " FnApp\n" + " where\n" @@ -158,7 +146,7 @@ public class FnUserRoleService { + " )\n" + " and A.requestStatus = 'P'\n"; - private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnUserRoleService.class); + private final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnUserRoleService.class); private final FnUserRoleDao fnUserRoleDao; private final FnAppService fnAppService; @@ -193,14 +181,18 @@ public class FnUserRoleService { return fnUserRoleDao.getAdminUserRoles(userId, roleId, appId).orElse(new ArrayList<>()); } - public boolean isSuperAdmin(final String orgUserId, final Long roleId, final Long appId) { + public boolean isSuperAdmin(final String loginId, final Long roleId, final Long appId) { List roles = getUserRolesForRoleIdAndAppId(roleId, appId).stream() - .filter(role -> role.getUserId().getOrgUserId().equals(orgUserId)).collect(Collectors.toList()); + .filter(role -> role.getUserId().getOrgUserId().equals(loginId)).collect(Collectors.toList()); return !roles.isEmpty(); } - private List getUserRolesForRoleIdAndAppId(final Long roleId, final Long appId) { - return Optional.of(fnUserRoleDao.getUserRolesForRoleIdAndAppId(roleId, appId)).orElse(new ArrayList<>()); + public List getUserRolesForRoleIdAndAppId(final Long roleId, final Long appId) { + return Optional.of(fnUserRoleDao.retrieveByAppIdAndRoleId(appId, roleId)).orElse(new ArrayList<>()); + } + + public List retrieveByUserIdAndRoleId(final Long userId, final Long roleId){ + return Optional.of(fnUserRoleDao.retrieveByUserIdAndRoleId(userId, roleId)).orElse(new ArrayList<>()); } public FnUserRole saveOne(final FnUserRole fnUserRole) { @@ -221,7 +213,7 @@ public class FnUserRoleService { public List getUserAppCatalogRoles(FnUser userid, String appName) { List tuples = entityManager.createQuery(USER_APP_CATALOG_ROLES, Tuple.class) - .setParameter("userid", userid.getUserId()) + .setParameter("userid", userid.getId()) .setParameter("appName", appName) .getResultList(); return Optional.of(tuples.stream().map(this::tupleToEPUserAppCatalogRoles).collect(Collectors.toList())) @@ -480,4 +472,68 @@ public class FnUserRoleService { public void deleteById(final Long id) { fnUserRoleDao.deleteById(id); } + + public List constructRolesInAppForUserGet(List appRoles, FnRole[] userAppRoles, + Boolean extRequestValue) { + List rolesInAppForUser = new ArrayList<>(); + + Set userAppRolesMap = new HashSet<>(); + if (userAppRoles != null) { + for (FnRole ecompRole : userAppRoles) { + userAppRolesMap.add(ecompRole.getAppId()); + } + logger.debug(EELFLoggerDelegate.debugLogger, "In constructRolesInAppForUserGet() - userAppRolesMap = {}", + userAppRolesMap); + + } else { + logger.error(EELFLoggerDelegate.errorLogger, + "constructRolesInAppForUserGet has received userAppRoles list empty."); + } + + if (appRoles != null) { + for (Role ecompRole : appRoles) { + logger.debug(EELFLoggerDelegate.debugLogger, "In constructRolesInAppForUserGet() - appRoles not null = {}", + ecompRole); + + if (ecompRole.getId().equals(PortalConstants.ACCOUNT_ADMIN_ROLE_ID) && !extRequestValue) { + continue; + } + RoleInAppForUser roleForUser = new RoleInAppForUser(ecompRole.getId(), ecompRole.getRoleName()); + roleForUser.setIsApplied(userAppRolesMap.contains(ecompRole.getId())); + rolesInAppForUser.add(roleForUser); + logger.debug(EELFLoggerDelegate.debugLogger, "In constructRolesInAppForUserGet() - rolesInAppForUser = {}", + rolesInAppForUser); + + } + } else { + logger.error(EELFLoggerDelegate.errorLogger, + "constructRolesInAppForUser has received appRoles list empty."); + } + return rolesInAppForUser; + } + + public List constructRolesInAppForUserGet(EcompRole[] appRoles, EcompRole[] userAppRoles) { + List rolesInAppForUser = new ArrayList<>(); + + Set userAppRolesMap = new HashSet<>(); + if (userAppRoles != null) { + for (EcompRole ecompRole : userAppRoles) { + userAppRolesMap.add(ecompRole.getId()); + } + } else { + logger.error(EELFLoggerDelegate.errorLogger, + "constructRolesInAppForUserGet has received userAppRoles list empty"); + } + + if (appRoles != null) { + for (EcompRole ecompRole : appRoles) { + RoleInAppForUser roleForUser = new RoleInAppForUser(ecompRole.getId(), ecompRole.getName()); + roleForUser.setIsApplied(userAppRolesMap.contains(ecompRole.getId())); + rolesInAppForUser.add(roleForUser); + } + } else { + logger.error(EELFLoggerDelegate.errorLogger, "constructRolesInAppForUser has received appRoles list empty"); + } + return rolesInAppForUser; + } }