Skip to content

Commit

Permalink
MOSIP:36804 - Filter related changes in API GET /partners/v3 (#953)
Browse files Browse the repository at this point in the history
* MOSIP:36804 - Filter related changes in API GET /partners/v3

Signed-off-by: sudeep <[email protected]>

* MOSIP:36804 - Filter related changes in API GET /partners/v3

Signed-off-by: sudeep <[email protected]>

---------

Signed-off-by: sudeep <[email protected]>
  • Loading branch information
Sudeep7353 authored Oct 25, 2024
1 parent 8050095 commit 59c9748
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +60,9 @@ public class PartnerManagementController {

@Autowired
AuditUtil auditUtil;

@Autowired
PartnerHelper partnerHelper;

String msg = "mosip.partnermanagement.partners.retrieve";
String version = "1.0";
Expand Down Expand Up @@ -278,14 +282,29 @@ public ResponseWrapperV2<PageResponseV2Dto<PartnerSummaryDto>> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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;

Expand Down Expand Up @@ -854,7 +841,7 @@ public ResponseWrapperV2<PageResponseV2Dto<PartnerSummaryDto>> getAllPartners(St
}

Page<PartnerSummaryEntity> page = partnerSummaryRepository.
getSummaryOfAllPartners(filterDto.getPartnerId(),filterDto.getPartnerTypeCode(),
getSummaryOfAllPartners(filterDto.getPartnerId(), filterDto.getPartnerTypeCode(),
filterDto.getOrganizationName(), filterDto.getPolicyGroupName(),
filterDto.getCertificateUploadStatus(), filterDto.getEmailAddress(),
filterDto.getIsActive(), pageable);
Expand Down Expand Up @@ -883,7 +870,7 @@ public ResponseWrapperV2<PageResponseV2Dto<PartnerSummaryDto>> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ public class PartnerHelper {
public static final String APPROVED = "approved";
public static final String PENDING_APPROVAL = "pending_approval";

public final Map<String, String> 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;

Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public interface PartnerSummaryRepository extends BaseRepository<PartnerSummaryE
"p.approvalStatus, p.isActive, p.crDtimes) " +
"FROM PartnerV3 p " +
"LEFT JOIN p.policyGroup pg " +
"WHERE (:partnerId IS NULL OR p.id LIKE %:partnerId%) " +
"AND (:partnerTypeCode IS NULL OR p.partnerTypeCode LIKE %:partnerTypeCode%) " +
"AND (:organizationName IS NULL OR p.name LIKE %:organizationName%) " +
"AND (:policyGroupName IS NULL OR pg.name LIKE %:policyGroupName%) " +
"WHERE (:partnerId IS NULL OR lower(p.id) LIKE %:partnerId%) " +
"AND (:partnerTypeCode IS NULL OR lower(p.partnerTypeCode) LIKE %:partnerTypeCode%) " +
"AND (:organizationName IS NULL OR lower(p.name) LIKE %:organizationName%) " +
"AND (:policyGroupName IS NULL OR lower(pg.name) LIKE %:policyGroupName%) " +
"AND (:certificateUploadStatus IS NULL OR " +
"(:certificateUploadStatus = 'not_uploaded' AND p.certificateAlias IS NULL) " +
"OR (:certificateUploadStatus = 'uploaded' AND p.certificateAlias IS NOT NULL)) " +
"AND (:emailAddress IS NULL OR p.emailId LIKE %:emailAddress%) " +
"AND (:emailAddress IS NULL OR lower(p.emailId) LIKE %:emailAddress%) " +
"AND (:isActive IS NULL OR p.isActive = :isActive)"
)
Page<PartnerSummaryEntity> getSummaryOfAllPartners(
Expand Down

0 comments on commit 59c9748

Please sign in to comment.