Skip to content

Commit

Permalink
MOSIP-37601 : Deactivate FTM Chip details
Browse files Browse the repository at this point in the history
Signed-off-by: sudeep <[email protected]>
  • Loading branch information
Sudeep7353 committed Nov 28, 2024
1 parent 2951a91 commit 5b0b40f
Showing 1 changed file with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,17 @@ public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(String ftmId) {
validateFtmChipDetail(ftmChipDetail);

FTPChipDetail ftm = ftmChipDetail.get();
Partner partnerDetails = getAssociatedPartner(partnerList, ftm, userId);
checkIfPartnerIsNotActive(partnerDetails);

boolean isAdmin = partnerHelper.isPartnerAdmin(authUserDetails().getAuthorities().toString());
if(!isAdmin){
validateFtmBelongsToUser(partnerList, ftm, userId);
}
Optional<Partner> partnerDetails = partnerRepository.findById(ftm.getFtpProviderId());
if (partnerDetails.isEmpty()){
throw new PartnerServiceException(ErrorCode.PARTNER_DOES_NOT_EXIST_EXCEPTION.getErrorCode(),
ErrorCode.PARTNER_DOES_NOT_EXIST_EXCEPTION.getErrorMessage());
}
checkIfPartnerIsNotActive(partnerDetails.get());
if (!ftm.getApprovalStatus().equals(APPROVED)) {
LOGGER.error("Unable to deactivate FTM with id {}", ftm.getFtpChipDetailId());
throw new PartnerServiceException(ErrorCode.FTM_NOT_APPROVED.getErrorCode(),
Expand Down Expand Up @@ -596,8 +605,17 @@ public ResponseWrapperV2<OriginalCertDownloadResponseDto> getOriginalFtmCertific
validateFtmChipDetail(ftmChipDetail);

FTPChipDetail ftm = ftmChipDetail.get();
Partner partnerDetails = getAssociatedPartner(partnerList, ftm, userId);
checkIfPartnerIsNotActive(partnerDetails);

boolean isAdmin = partnerHelper.isPartnerAdmin(authUserDetails().getAuthorities().toString());
if(!isAdmin){
validateFtmBelongsToUser(partnerList, ftm, userId);
}
Optional<Partner> partnerDetails = partnerRepository.findById(ftm.getFtpProviderId());
if (partnerDetails.isEmpty()){
throw new PartnerServiceException(ErrorCode.PARTNER_DOES_NOT_EXIST_EXCEPTION.getErrorCode(),
ErrorCode.PARTNER_DOES_NOT_EXIST_EXCEPTION.getErrorMessage());
}
checkIfPartnerIsNotActive(partnerDetails.get());

if (!(ftm.getApprovalStatus().equals(PENDING_APPROVAL) || ftm.getApprovalStatus().equals(APPROVED))) {
LOGGER.error("Unable to download original FTM certificate with id {}", ftm.getFtpChipDetailId());
Expand Down Expand Up @@ -655,16 +673,14 @@ public static void checkIfPartnerIsNotActive(Partner partner) {
}
}

public Partner getAssociatedPartner(List<Partner> partnerList, FTPChipDetail ftm, String userId) {
public void validateFtmBelongsToUser(List<Partner> partnerList, FTPChipDetail ftm, String userId) {
String ftmProviderId = ftm.getFtpProviderId();
boolean ftmProviderExist = false;
Partner partnerDetails = null;

for (Partner partner : partnerList) {
if (partner.getId().equals(ftmProviderId)) {
validatePartnerId(partner, userId);
ftmProviderExist = true;
partnerDetails = partner;
break;
}
}
Expand All @@ -674,8 +690,6 @@ public Partner getAssociatedPartner(List<Partner> partnerList, FTPChipDetail ftm
throw new PartnerServiceException(ErrorCode.FTM_NOT_ASSOCIATED_WITH_USER.getErrorCode(),
ErrorCode.FTM_NOT_ASSOCIATED_WITH_USER.getErrorMessage());
}

return partnerDetails;
}

public static void validatePartnerId(Partner partner, String userId) {
Expand Down

0 comments on commit 5b0b40f

Please sign in to comment.