From 59c9748fb2dbd4f5db555c76a8aff6a08169eb2e Mon Sep 17 00:00:00 2001 From: Sudeep7353 <103890430+Sudeep7353@users.noreply.github.com> Date: Fri, 25 Oct 2024 18:40:01 +0530 Subject: [PATCH] MOSIP:36804 - Filter related changes in API GET /partners/v3 (#953) * MOSIP:36804 - Filter related changes in API GET /partners/v3 Signed-off-by: sudeep * MOSIP:36804 - Filter related changes in API GET /partners/v3 Signed-off-by: sudeep --------- Signed-off-by: sudeep --- .../mosip/pms/partner/constant/ErrorCode.java | 4 +- .../PartnerManagementController.java | 33 ++++++++++--- .../impl/PartnerManagementServiceImpl.java | 17 +------ .../mosip/pms/partner/util/PartnerHelper.java | 46 +++++++++++++++++++ .../repository/PartnerSummaryRepository.java | 10 ++-- 5 files changed, 82 insertions(+), 28 deletions(-) diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/constant/ErrorCode.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/constant/ErrorCode.java index 6ac9f58c51..54332433ed 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/constant/ErrorCode.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/constant/ErrorCode.java @@ -15,7 +15,9 @@ public enum ErrorCode { INVALID_PAGINATION("PMS_PRT_356", "Pagination cannot be null"), INVALID_SORT_TYPE("PMS_PRT_358", "Sort type %s is not supported"), ERROR_OCCURED_WHILE_SORTING("PMS_PRT_359", "Error occured while sorting"), - INVALID_SORT_FIELD("PMS_PRT_357", "Invalid sort field %s"), + INVALID_SORT_FIELD("PMS_PRT_357", "Invalid sort field %s"), + INVALID_PAGE_NO("PMS_PRT_360", "Invalid Page No"), + INVALID_PAGE_SIZE("PMS_PRT_361", "Invalid page size"), INVALID_VALUE("KER_PRT_390", "Invalid filter value"), PARTNER_ALREADY_REGISTERED_EXCEPTION("PMS_PRT_001", "A Partner is already registered with the same Name"), PARTNER_ALREADY_REGISTERED_WITH_ID_EXCEPTION("PMS_PRT_051", "A Partner is already registered with the same Id"), diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/controller/PartnerManagementController.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/controller/PartnerManagementController.java index eeeba14f86..9da29c8978 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/controller/PartnerManagementController.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/controller/PartnerManagementController.java @@ -8,6 +8,7 @@ import io.mosip.pms.common.dto.PageResponseV2Dto; import io.mosip.pms.common.response.dto.ResponseWrapperV2; import io.mosip.pms.partner.manager.dto.*; +import io.mosip.pms.partner.util.PartnerHelper; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -59,6 +60,9 @@ public class PartnerManagementController { @Autowired AuditUtil auditUtil; + + @Autowired + PartnerHelper partnerHelper; String msg = "mosip.partnermanagement.partners.retrieve"; String version = "1.0"; @@ -278,14 +282,29 @@ public ResponseWrapperV2> getAllPartners( @RequestParam(value = "certificateUploadStatus", required = false) String certificateUploadStatus, @RequestParam(value = "policyGroupName", required = false) String policyGroupName ) { + partnerHelper.validateGetAllPartnersRequestParameters(sortFieldName, sortType, pageNo, pageSize); FilterDto filterDto = new FilterDto(); - filterDto.setPartnerId(partnerId); - filterDto.setPartnerTypeCode(partnerType); - filterDto.setOrganizationName(orgName); - filterDto.setPolicyGroupName(policyGroupName); - filterDto.setCertificateUploadStatus(certificateUploadStatus); - filterDto.setEmailAddress(emailAddress); - filterDto.setIsActive(isActive); + if (partnerId != null) { + filterDto.setPartnerId(partnerId.toLowerCase()); + } + if (partnerType != null) { + filterDto.setPartnerTypeCode(partnerType.toLowerCase()); + } + if (orgName != null) { + filterDto.setOrganizationName(orgName.toLowerCase()); + } + if (policyGroupName != null) { + filterDto.setPolicyGroupName(policyGroupName.toLowerCase()); + } + if (certificateUploadStatus != null) { + filterDto.setCertificateUploadStatus(certificateUploadStatus); + } + if (emailAddress != null) { + filterDto.setEmailAddress(emailAddress.toLowerCase()); + } + if (isActive != null) { + filterDto.setIsActive(isActive); + } return partnerManagementService.getAllPartners(sortFieldName, sortType, pageNo, pageSize, filterDto); } diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/service/impl/PartnerManagementServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/service/impl/PartnerManagementServiceImpl.java index 6f395559ec..563f2df415 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/service/impl/PartnerManagementServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/manager/service/impl/PartnerManagementServiceImpl.java @@ -75,19 +75,6 @@ public class PartnerManagementServiceImpl implements PartnerManagerService { public static final String DEVICE_PROVIDER = "Device_Provider"; public static final String FTM_PROVIDER = "FTM_Provider"; - private final Map aliasToColumnMap = new HashMap<>() {{ - put("partnerId", "id"); - put("partnerType", "partnerTypeCode"); - put("orgName", "name"); - put("policyGroupId", "policyGroupId"); - put("policyGroupName", "pg.name"); - put("emailAddress", "emailId"); - put("certificateUploadStatus", "certificateAlias"); - put("status", "approvalStatus"); - put("isActive", "isActive"); - put("createdDateTime", "crDtimes"); - }}; - @Value("${mosip.pms.api.id.all.partners.get}") private String getAllPartnersId; @@ -854,7 +841,7 @@ public ResponseWrapperV2> getAllPartners(St } Page page = partnerSummaryRepository. - getSummaryOfAllPartners(filterDto.getPartnerId(),filterDto.getPartnerTypeCode(), + getSummaryOfAllPartners(filterDto.getPartnerId(), filterDto.getPartnerTypeCode(), filterDto.getOrganizationName(), filterDto.getPolicyGroupName(), filterDto.getCertificateUploadStatus(), filterDto.getEmailAddress(), filterDto.getIsActive(), pageable); @@ -883,7 +870,7 @@ public ResponseWrapperV2> getAllPartners(St } public String getSortColumn(String alias) { - return aliasToColumnMap.getOrDefault(alias, alias); // Return alias if no match found + return partnerHelper.aliasToColumnMap.getOrDefault(alias, alias); // Return alias if no match found } private AuthUserDetails authUserDetails() { diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/util/PartnerHelper.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/util/PartnerHelper.java index 9342a493d2..bc828656c0 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/util/PartnerHelper.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/util/PartnerHelper.java @@ -38,6 +38,20 @@ public class PartnerHelper { public static final String APPROVED = "approved"; public static final String PENDING_APPROVAL = "pending_approval"; + public final Map aliasToColumnMap = new HashMap<>(); + { + aliasToColumnMap.put("partnerId", "id"); + aliasToColumnMap.put("partnerType", "partnerTypeCode"); + aliasToColumnMap.put("orgName", "name"); + aliasToColumnMap.put("policyGroupId", "policyGroupId"); + aliasToColumnMap.put("policyGroupName", "pg.name"); + aliasToColumnMap.put("emailAddress", "emailId"); + aliasToColumnMap.put("certificateUploadStatus", "certificateAlias"); + aliasToColumnMap.put("status", "approvalStatus"); + aliasToColumnMap.put("isActive", "isActive"); + aliasToColumnMap.put("createdDateTime", "crDtimes"); + } + @Autowired SecureBiometricInterfaceRepository secureBiometricInterfaceRepository; @@ -167,4 +181,36 @@ public boolean isPartnerAdmin(String roles) { } return false; } + + public void validateGetAllPartnersRequestParameters(String sortFieldName, String sortType, int pageNo, int pageSize) { + // Validate sortFieldName + if (sortFieldName != null && !aliasToColumnMap.containsKey(sortFieldName)) { + LOGGER.error("Invalid sort field name: " + sortFieldName); + throw new PartnerServiceException(ErrorCode.INVALID_SORT_FIELD.getErrorCode(), + String.format(ErrorCode.INVALID_SORT_FIELD.getErrorMessage(), sortFieldName)); + } + + // Validate sortType + if (sortType != null && + !sortType.equalsIgnoreCase(PartnerConstants.ASC) && + !sortType.equalsIgnoreCase(PartnerConstants.DESC)) { + LOGGER.error("Invalid sort type: " + sortType); + throw new PartnerServiceException(ErrorCode.INVALID_SORT_TYPE.getErrorCode(), + String.format(ErrorCode.INVALID_SORT_TYPE.getErrorMessage(), sortType)); + } + + // Validate pageNo + if (pageNo < 0) { + LOGGER.error("Invalid page no: " + pageNo); + throw new PartnerServiceException(ErrorCode.INVALID_PAGE_NO.getErrorCode(), + ErrorCode.INVALID_PAGE_NO.getErrorMessage()); + } + + // Validate pageSize + if (pageSize <= 0) { + LOGGER.error("Invalid page size: " + pageSize); + throw new PartnerServiceException(ErrorCode.INVALID_PAGE_SIZE.getErrorCode(), + ErrorCode.INVALID_PAGE_SIZE.getErrorMessage()); + } + } } diff --git a/partner/pms-common/src/main/java/io/mosip/pms/common/repository/PartnerSummaryRepository.java b/partner/pms-common/src/main/java/io/mosip/pms/common/repository/PartnerSummaryRepository.java index 68e5875c9a..2903efc1df 100644 --- a/partner/pms-common/src/main/java/io/mosip/pms/common/repository/PartnerSummaryRepository.java +++ b/partner/pms-common/src/main/java/io/mosip/pms/common/repository/PartnerSummaryRepository.java @@ -17,14 +17,14 @@ public interface PartnerSummaryRepository extends BaseRepository getSummaryOfAllPartners(