diff options
Diffstat (limited to 'ecomp-portal-BE-common/src/main')
12 files changed, 244 insertions, 110 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AuditLogController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AuditLogController.java index e0232850..e8fb71a6 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AuditLogController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AuditLogController.java @@ -37,6 +37,10 @@ */ package org.onap.portalapp.portal.controller; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; + import javax.servlet.http.HttpServletRequest; import org.slf4j.MDC; @@ -45,6 +49,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; + +import com.att.eelf.configuration.Configuration; + import org.onap.portalapp.controller.EPRestrictedBaseController; import org.onap.portalapp.portal.domain.EPUser; import org.onap.portalapp.portal.logging.aop.EPEELFLoggerAdvice; @@ -56,6 +63,7 @@ import org.onap.portalapp.util.EPUserUtils; import org.onap.portalsdk.core.domain.AuditLog; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.service.AuditService; +import org.onap.portalsdk.core.util.SystemProperties; @RestController @RequestMapping("/portalApi/auditLog") @@ -103,19 +111,34 @@ public class AuditLogController extends EPRestrictedBaseController { AuditLog auditLog = new AuditLog(); auditLog.setActivityCode(cd_type); /* - * Check affectedAppId and comment and see if these two values are valid + * Check affectedAppId and comment and see if these two values + * are valid */ if (comment != null && !comment.equals("") && !comment.equals("undefined")) - auditLog.setComments(EcompPortalUtils.truncateString(comment, PortalConstants.AUDIT_LOG_COMMENT_SIZE)); + auditLog.setComments( + EcompPortalUtils.truncateString(comment, PortalConstants.AUDIT_LOG_COMMENT_SIZE)); if (affectedAppId != null && !affectedAppId.equals("") && !affectedAppId.equals("undefined")) auditLog.setAffectedRecordId(affectedAppId); long userId = EPUserUtils.getUserId(request); auditLog.setUserId(userId); - auditService.logActivity(auditLog, null); - - // Log file MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC()); + MDC.put(EPCommonSystemProperties.PARTNER_NAME, EPCommonSystemProperties.ECOMP_PORTAL_FE); + MDC.put(Configuration.MDC_SERVICE_NAME, EPCommonSystemProperties.ECOMP_PORTAL_BE); + if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null) { + String requestId = UUID.randomUUID().toString(); + MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId); + } + // Log file MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC()); + SimpleDateFormat ecompLogDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + String beginDateTime = MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP); + Date beginDate = ecompLogDateFormat.parse(beginDateTime); + auditService.logActivity(auditLog, null); + String endDateTime = MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP); + Date endDate = ecompLogDateFormat.parse(endDateTime); + String timeDifference = String.format("%d", endDate.getTime() - beginDate.getTime()); + MDC.put(SystemProperties.MDC_TIMER, timeDifference); + MDC.put(EPCommonSystemProperties.STATUS_CODE, "COMPLETE"); logger.info(EELFLoggerDelegate.auditLogger, EPLogUtil.formatAuditLogMessage( "AuditLogController.auditLog", cd_type, user.getOrgUserId(), affectedAppId, comment)); MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP); @@ -123,6 +146,13 @@ public class AuditLogController extends EPRestrictedBaseController { } } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "auditLog failed", e); + MDC.put(EPCommonSystemProperties.STATUS_CODE, "ERROR"); + } finally{ + MDC.remove(Configuration.MDC_SERVICE_NAME); + MDC.remove(EPCommonSystemProperties.PARTNER_NAME); + MDC.remove(SystemProperties.MDC_TIMER); + MDC.remove(Configuration.MDC_KEY_REQUEST_ID); + MDC.remove(EPCommonSystemProperties.STATUS_CODE); } } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java index 4b364995..964ccb5b 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java @@ -273,19 +273,26 @@ public class DashboardController extends EPRestrictedBaseController { auditLog.setUserId(user.getId()); auditLog.setActivityCode(EcompAuditLog.CD_ACTIVITY_SEARCH); auditLog.setComments(EcompPortalUtils.truncateString(searchString, PortalConstants.AUDIT_LOG_COMMENT_SIZE)); - MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,EPEELFLoggerAdvice.getCurrentDateTimeUTC()); + MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,EPEELFLoggerAdvice.getCurrentDateTimeUTC()); + MDC.put(EPCommonSystemProperties.PARTNER_NAME, EPCommonSystemProperties.ECOMP_PORTAL_FE); + MDC.put(com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME, EPCommonSystemProperties.ECOMP_PORTAL_BE); auditService.logActivity(auditLog, null); MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,EPEELFLoggerAdvice.getCurrentDateTimeUTC()); + + MDC.put(EPCommonSystemProperties.STATUS_CODE, "COMPLETE"); EcompPortalUtils.calculateDateTimeDifferenceForLog(MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP)); logger.info(EELFLoggerDelegate.auditLogger, EPLogUtil.formatAuditLogMessage("DashboardController.PortalRestResponse", EcompAuditLog.CD_ACTIVITY_SEARCH, user.getOrgUserId(), null, searchString)); MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP); MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP); MDC.remove(SystemProperties.MDC_TIMER); + MDC.remove(EPCommonSystemProperties.STATUS_CODE); return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results); } } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "searchPortal failed", e); + MDC.put(EPCommonSystemProperties.STATUS_CODE, "ERROR"); + MDC.remove(EPCommonSystemProperties.STATUS_CODE); return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage() + " - check logs.", new HashMap<String, List<SearchResultItem>>()); } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java index 1e955c8b..f846253f 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java @@ -209,10 +209,10 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl @ApiOperation(value = "Gets all role functions for an application for older version.", response = CentralRoleFunction.class, responseContainer="Json") @RequestMapping(value = { "/functions" }, method = RequestMethod.GET, produces = "application/json") - public List<RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response) + public List<CentralRoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response) throws Exception { List<CentralV2RoleFunction> answer = null; - List<RoleFunction> roleFuncList = null; + List<CentralRoleFunction> roleFuncList = null; logger.debug(EELFLoggerDelegate.debugLogger, "Request received for getRoleFunctionsList"); try { fieldsValidation(request); @@ -253,6 +253,7 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl logger.debug(EELFLoggerDelegate.debugLogger, "Request completed for getV2RoleFunctionsList"); return cenRoleFuncList; } + @ApiOperation(value = "Gets role information for an application.", response = CentralRole.class, responseContainer="Json") @RequestMapping(value = { @@ -572,16 +573,32 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl return new PortalRestResponse<String>(PortalRestStatusEnum.OK, SUCCESSFULLY_DELETED, "Success"); } - @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json") + @ApiOperation(value = "Gets active roles for an application.", response = CentralRole.class, responseContainer = "Json") @RequestMapping(value = { "/activeRoles" }, method = RequestMethod.GET, produces = "application/json") - public List<CentralV2Role> getActiveRoles(HttpServletRequest request, HttpServletResponse response) throws Exception { + public List<CentralRole> getActiveRoles(HttpServletRequest request, HttpServletResponse response) throws Exception { + List<CentralRole> roles = null; + try { + fieldsValidation(request); + List<CentralV2Role> cenRoles= externalAccessRolesService.getActiveRoles(request.getHeader(UEBKEY)); + roles = externalAccessRolesService.convertV2CentralRoleListToOldVerisonCentralRoleList(cenRoles); + } catch (Exception e) { + sendErrorResponse(response, e); + logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e); + } + return roles; + + } + + @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json") + @RequestMapping(value = { "/v1/activeRoles" }, method = RequestMethod.GET, produces = "application/json") + public List<CentralV2Role> getV2ActiveRoles(HttpServletRequest request, HttpServletResponse response) throws Exception { List<CentralV2Role> cenRole = null; try { fieldsValidation(request); cenRole = externalAccessRolesService.getActiveRoles(request.getHeader(UEBKEY)); } catch (Exception e) { sendErrorResponse(response, e); - logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e); + logger.error(EELFLoggerDelegate.errorLogger, "getV2ActiveRoles failed", e); } return cenRole; @@ -831,13 +848,12 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl @PathVariable("loginId") String loginId) throws Exception { EcompUser user = null; ObjectMapper mapper = new ObjectMapper(); - CentralUser answer = null; + String answer = null; try { fieldsValidation(request); - answer = externalAccessRolesService.getUserRoles(loginId, request.getHeader(UEBKEY)); + answer = externalAccessRolesService.getV2UserWithRoles(loginId, request.getHeader(UEBKEY)); if (answer != null) { - String res = mapper.writeValueAsString(answer); - User ecompUser = userservice.userMapper(res); + User ecompUser = userservice.userMapper(answer); user = UserUtils.convertToEcompUser(ecompUser); } } catch (Exception e) { diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java index 8f0558aa..dbea91f5 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java @@ -78,6 +78,7 @@ import org.onap.portalapp.portal.utils.PortalConstants; import org.onap.portalapp.util.EPUserUtils; import org.onap.portalsdk.core.domain.AuditLog; 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.service.AuditService; import org.onap.portalsdk.core.util.SystemProperties; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java index c1127758..30795c0e 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java @@ -38,6 +38,7 @@ package org.onap.portalapp.portal.logging.aop; import java.net.InetAddress; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.UUID; @@ -104,7 +105,7 @@ public class EPEELFLoggerAdvice { String className = ""; if (passOnArgs.length > 0 && passOnArgs[0] != null) className = passOnArgs[0].toString(); - String methodName = ""; + String methodName = EPCommonSystemProperties.ECOMP_PORTAL_BE; if (passOnArgs.length > 1 && passOnArgs[1] != null) methodName = passOnArgs[1].toString(); @@ -112,7 +113,7 @@ public class EPEELFLoggerAdvice { MDC.put(className + methodName + EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC()); MDC.put(EPCommonSystemProperties.TARGET_ENTITY, EPCommonSystemProperties.ECOMP_PORTAL_BE); MDC.put(EPCommonSystemProperties.TARGET_SERVICE_NAME, methodName); - if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null || MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){ + if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null||MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){ String requestId = UUID.randomUUID().toString(); MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId); } @@ -149,7 +150,7 @@ public class EPEELFLoggerAdvice { if (passOnArgs.length > 0 && passOnArgs[0] != null) className = passOnArgs[0].toString(); // Method Name - String methodName = ""; + String methodName = EPCommonSystemProperties.ECOMP_PORTAL_BE; if (passOnArgs.length > 1 && passOnArgs[1] != null) methodName = passOnArgs[1].toString(); @@ -160,6 +161,14 @@ public class EPEELFLoggerAdvice { if (MDC.get(EPCommonSystemProperties.TARGET_ENTITY) == null || MDC.get(EPCommonSystemProperties.TARGET_ENTITY) == "") MDC.put(EPCommonSystemProperties.TARGET_ENTITY, EPCommonSystemProperties.ECOMP_PORTAL_BE); + + if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null||MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){ + String requestId = UUID.randomUUID().toString(); + MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId); + } + MDC.put(EPCommonSystemProperties.PARTNER_NAME, "Unknown"); + MDC.put(Configuration.MDC_SERVICE_NAME, EPCommonSystemProperties.ECOMP_PORTAL_BE); + MDC.put(EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP, MDC.get(className + methodName + EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP)); @@ -173,7 +182,7 @@ public class EPEELFLoggerAdvice { if (securityEventType != null && args.length > 0 && args[0] != null && args[0] instanceof HttpServletRequest && securityEventType == SecurityEventTypeEnum.INCOMING_REST_MESSAGE && (MDC.get(EPCommonSystemProperties.FULL_URL) == null - || MDC.get(EPCommonSystemProperties.FULL_URL).isEmpty())) { + || MDC.get(EPCommonSystemProperties.FULL_URL).isEmpty())) { HttpServletRequest req = (HttpServletRequest) args[0]; this.setHttpRequestBasedDefaultsIntoGlobalLoggingContext(req, securityEventType, methodName); } @@ -308,13 +317,12 @@ public class EPEELFLoggerAdvice { MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId); // Load user agent into MDC context, if available. - String accessingClient = "Unknown"; - accessingClient = req.getHeader(SystemProperties.USERAGENT_NAME); + String accessingClient = req.getHeader(SystemProperties.USERAGENT_NAME); + accessingClient = (accessingClient == null || accessingClient.trim().length()==0)?"Unknown":accessingClient; if (accessingClient != null && accessingClient.trim().length()==0 && (accessingClient.contains("Mozilla") || accessingClient.contains("Chrome") || accessingClient.contains("Safari"))) { accessingClient = EPCommonSystemProperties.ECOMP_PORTAL_FE; - }else if(accessingClient==null || accessingClient.isEmpty()) - accessingClient = "Unknown"; + } MDC.put(EPCommonSystemProperties.PARTNER_NAME, accessingClient); // Load loginId into MDC context. @@ -333,7 +341,8 @@ public class EPEELFLoggerAdvice { MDC.put(EPCommonSystemProperties.FULL_URL, EPCommonSystemProperties.UNKNOWN); MDC.put(EPCommonSystemProperties.PROTOCOL, EPCommonSystemProperties.HTTP); restURL = UserUtils.getFullURL(req); - if (restURL != null && restURL != "") { + //if (restURL != null && restURL != "") { + if (restURL != null && restURL.trim().length()>0) { MDC.put(EPCommonSystemProperties.FULL_URL, restURL); if (restURL.toLowerCase().contains("https")) { MDC.put(EPCommonSystemProperties.PROTOCOL, EPCommonSystemProperties.HTTPS); @@ -341,9 +350,11 @@ public class EPEELFLoggerAdvice { } // Rest Path - MDC.put(Configuration.MDC_SERVICE_NAME, (restMethod==null || restMethod.isEmpty()) ? "Unknown" : restMethod); + MDC.put(Configuration.MDC_SERVICE_NAME, restMethod); String restPath = req.getServletPath(); - if (restPath != null && !restPath.isEmpty()) { + //if (restPath != null && restPath != "") { + if (restPath != null && restPath.trim().length()>0) { + MDC.put(Configuration.MDC_SERVICE_NAME, restPath); } @@ -360,7 +371,7 @@ public class EPEELFLoggerAdvice { MDC.put(EPCommonSystemProperties.TARGET_SERVICE_NAME, "search"); } } else { - MDC.put(Configuration.MDC_SERVICE_NAME, (restMethod==null || restMethod.isEmpty()) ? "Unknown" : restMethod); + MDC.put(Configuration.MDC_SERVICE_NAME, restMethod); MDC.put(EPCommonSystemProperties.PARTNER_NAME, EPCommonSystemProperties.ECOMP_PORTAL_FE); } @@ -398,4 +409,5 @@ public class EPEELFLoggerAdvice { public String getInternalResponseCode() { return MDC.get(EPCommonSystemProperties.RESPONSE_CODE); } + } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLdapServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLdapServiceImpl.java index 941acaf6..0e566a99 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLdapServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLdapServiceImpl.java @@ -193,7 +193,7 @@ public class EPLdapServiceImpl extends FusionService implements EPLdapService { for (NamingEnumeration e = resultAttributes.getAll(); e.hasMore();) { // why the nested loop? Attribute attribute = (Attribute) e.next(); for (NamingEnumeration ie = attribute.getAll(); ie.hasMore();) { - if (attribute.getID().equalsIgnoreCase("nickname")) { + if (attribute.getID().equalsIgnoreCase("givenName")) { user.setFirstName((String) ie.next()); } else if (attribute.getID().equalsIgnoreCase("initials")) { user.setMiddleInitial((String) ie.next()); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java index bcf806b2..2f72bab2 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java @@ -51,6 +51,7 @@ import org.onap.portalapp.portal.domain.EPUser; import org.onap.portalapp.portal.domain.ExternalRoleDetails; import org.onap.portalapp.portal.exceptions.InvalidUserException; import org.onap.portalapp.portal.transport.CentralRole; +import org.onap.portalapp.portal.transport.CentralRoleFunction; import org.onap.portalapp.portal.transport.CentralUser; import org.onap.portalapp.portal.transport.CentralV2Role; import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator; @@ -132,11 +133,11 @@ public interface ExternalAccessRolesService { CentralV2Role getRoleInfo(Long roleId, String uebkey) throws Exception; /** - * It returns the CentralRoleFunction object + * It returns the CentralV2RoleFunction object * * @param functionCode * @param uebkey - * @return CentralRoleFunction + * @return CentralV2RoleFunction * @throws Exception */ public CentralV2RoleFunction getRoleFunction(String functionCode, String uebkey) throws Exception; @@ -150,7 +151,7 @@ public interface ExternalAccessRolesService { * @throws Exception */ public boolean saveCentralRoleFunction(CentralV2RoleFunction domainCentralRoleFunction, EPApp requestedApp) throws Exception; - + /** * It deletes role function in the DB * @@ -335,11 +336,11 @@ public interface ExternalAccessRolesService { public List<EPRole> getGlobalRolesOfPortal(); /** - * It converts list of CentralRoleFunction objects to RoleFunction objects + * It converts list of CentralV2RoleFunction objects to older version of CentralRoleFunction objects * @param answer contains list of CentralRoleFunction objects - * @return List of RoleFunction objects + * @return List of CentralRoleFunction objects */ - public List<RoleFunction> convertCentralRoleFunctionToRoleFunctionObject(List<CentralV2RoleFunction> answer); + public List<CentralRoleFunction> convertCentralRoleFunctionToRoleFunctionObject(List<CentralV2RoleFunction> answer); /** * 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 39bd92d6..a2226944 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 @@ -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; @@ -1324,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; @@ -1504,7 +1507,12 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic return roleFunc; roleFunc = checkIfPipesExitsInFunctionCode(cenV2RoleFunction); } else { - roleFunc = getRoleFuncList.get(0); + // Check even if single record have pipes + if (!getRoleFuncList.isEmpty() && getRoleFuncList.get(0).getCode().contains(FUNCTION_PIPE)) { + roleFunc = checkIfPipesExitsInFunctionCode(getRoleFuncList.get(0)); + } else { + roleFunc = getRoleFuncList.get(0); + } } } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction: failed", e); @@ -3080,79 +3088,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; - } - } + 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; - 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(); - - 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; } @@ -3304,10 +3349,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); @@ -3324,6 +3369,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic sendUserRoles = convertV2UserRolesToOlderVersion(cenV2User); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "getUserRoles: failed", e); + throw e; } return sendUserRoles; } @@ -3393,8 +3439,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic @Override public List<CentralRole> convertV2CentralRoleListToOldVerisonCentralRoleList(List<CentralV2Role> v2CenRoleList) { List<CentralRole> cenRoleList = new ArrayList<>(); - SortedSet<CentralRoleFunction> cenRoleFuncList = new TreeSet<>(); for(CentralV2Role v2CenRole : v2CenRoleList){ + SortedSet<CentralRoleFunction> cenRoleFuncList = new TreeSet<>(); for(CentralV2RoleFunction v2CenRoleFunc: v2CenRole.getRoleFunctions()){ CentralRoleFunction roleFunc = new CentralRoleFunction(v2CenRoleFunc.getCode(), v2CenRoleFunc.getName()); cenRoleFuncList.add(roleFunc); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRole.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRole.java index dc1a78fe..7214f80a 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRole.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRole.java @@ -42,6 +42,8 @@ import java.util.Date; import java.util.SortedSet; import java.util.TreeSet; +import org.onap.portalsdk.core.domain.RoleFunction; + public class CentralRole implements Serializable { private static final long serialVersionUID = -9210905386086213882L; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java index 6cc474a1..6d982c27 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java @@ -248,4 +248,4 @@ public class CentralRoleFunction implements Serializable, Comparable { return true; } -} +}
\ No newline at end of file diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EcompUserRoles.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EcompUserRoles.java index 73409ede..a1d2ae30 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EcompUserRoles.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EcompUserRoles.java @@ -97,7 +97,27 @@ public class EcompUserRoles implements Serializable{ @Id @Column(name = "active_yn") private boolean active; + + @Id + @Column(name = "function_cd") + private String functionCode; + @Id + @Column(name = "function_name") + private String functionName; + + public String getFunctionCode() { + return functionCode; + } + public void setFunctionCode(String functionCode) { + this.functionCode = functionCode; + } + public String getFunctionName() { + return functionName; + } + public void setFunctionName(String functionName) { + this.functionName = functionName; + } public Long getOrgId() { return orgId; } diff --git a/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml b/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml index 5968b3ce..60174075 100644 --- a/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml +++ b/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml @@ -2101,17 +2101,16 @@ where fn_role.app_id = fn_app.app_id and fn_app.enabled='Y' and fn_role.active_y <sql-query name="ApplicationUserRoles"> <return alias="ApplicationUserRoles" class="org.onap.portalapp.portal.transport.EcompUserRoles" /> <![CDATA[ - select distinct fu.org_id, fu.manager_id, fu.first_name, fu.middle_name, fu.last_name, fu.phone, fu.email, fu.hrid, fu.org_user_id, fu.org_code, fu.org_manager_userid, fu.job_title, fu.login_id, - fu.active_yn , fr.app_role_id, fr.role_name - from fn_user fu, fn_role fr, fn_user_role fur - where fu.user_id = fur.user_id and fu.active_yn='Y' and fur.role_id = fr.role_id and fr.app_id =:appId and fr.active_yn='Y' - union - select distinct fu.org_id, fu.manager_id, fu.first_name, fu.middle_name, fu.last_name, fu.phone, - fu.email, fu.hrid, fu.org_user_id, fu.org_code, fu.org_manager_userid, fu.job_title, - fu.login_id, fu.active_yn , fr.role_id, fr.role_name - from fn_user_role a, fn_role fr, fn_user fu - where a.role_id in (select b.role_id from ep_app_role_function b where b.role_app_id = 1 and b.app_id =:appId) and a.user_id =fu.user_id and a.role_id = fr.role_id and fr.active_yn='Y' and fu.active_yn='Y' - ; + select distinct fu.org_id, fu.manager_id, fu.first_name, fu.middle_name, fu.last_name, fu.phone, fu.email, fu.hrid, fu.org_user_id, fu.org_code, fu.org_manager_userid, fu.job_title, fu.login_id, + fu.active_yn , fr.app_role_id, fr.role_name, epr.function_cd , epf.function_name + from fn_user fu, fn_role fr, fn_user_role fur, ep_app_role_function epr , ep_app_function epf + where fu.user_id = fur.user_id and fu.active_yn='Y' and fur.role_id = fr.role_id and fr.app_id =:appId and fr.active_yn='Y' and epr.function_cd= epf.function_cd and epf.app_id=epr.app_id and fur.role_id=epr.role_id + union + select distinct fu.org_id, fu.manager_id, fu.first_name, fu.middle_name, fu.last_name, fu.phone, fu.email, fu.hrid, fu.org_user_id, fu.org_code, fu.org_manager_userid, fu.job_title, + fu.login_id, fu.active_yn , fr.role_id, fr.role_name, earf.function_cd , eaf.function_name + from fn_user_role a, fn_role fr, fn_user fu , ep_app_role_function earf, ep_app_function eaf + where a.role_id in (select b.role_id from ep_app_role_function b where b.role_app_id = 1 and b.app_id =:appId) and a.user_id =fu.user_id and a.role_id = fr.role_id and fr.active_yn='Y' and fu.active_yn='Y' + and earf.role_id = a.role_id and earf.function_cd = eaf.function_cd and earf.app_id = eaf.app_id and earf.role_app_id = 1 and fr.active_yn='Y' and fu.active_yn='Y'; ]]> </sql-query> |