From 7eac39752d48dadaff4442a71a445be68377bb93 Mon Sep 17 00:00:00 2001 From: sudeep Date: Wed, 9 Oct 2024 17:40:44 +0530 Subject: [PATCH] MOSIP:35655, MOSIP:36406 - bug fixes. Signed-off-by: sudeep --- .../service/impl/DeviceDetailServiceImpl.java | 33 +++++----- .../impl/FTPChipDetailServiceImpl.java | 31 +++++----- .../SecureBiometricInterfaceServiceImpl.java | 61 ++++++++++--------- .../mosip/pms/partner/constant/ErrorCode.java | 11 ++-- 4 files changed, 75 insertions(+), 61 deletions(-) diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/DeviceDetailServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/DeviceDetailServiceImpl.java index 9015d71681..796b68ab63 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/DeviceDetailServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/DeviceDetailServiceImpl.java @@ -553,22 +553,27 @@ public ResponseWrapperV2 deactivateDevice(String device throw new PartnerServiceException(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode(), ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage()); } - // Deactivate only if the device is approved status and is_active true. - if (device.getApprovalStatus().equals(APPROVED) && device.getIsActive()) { - DeviceDetailResponseDto deviceDetailResponseDto = new DeviceDetailResponseDto(); - - device.setIsActive(false); - DeviceDetail updatedDetail = deviceDetailRepository.save(device); - deviceDetailResponseDto.setDeviceId(updatedDetail.getId()); - deviceDetailResponseDto.setStatus(updatedDetail.getApprovalStatus()); - deviceDetailResponseDto.setActive(updatedDetail.getIsActive()); - - responseWrapper.setResponse(deviceDetailResponseDto); - } else { + if (!device.getApprovalStatus().equals(APPROVED)) { + LOGGER.error("Unable to deactivate device with id {}", device.getId()); + throw new PartnerServiceException(ErrorCode.DEVICE_NOT_APPROVED.getErrorCode(), + ErrorCode.DEVICE_NOT_APPROVED.getErrorMessage()); + } + if (device.getApprovalStatus().equals(APPROVED) && !device.getIsActive()) { LOGGER.error("Unable to deactivate device with id {}", device.getId()); - throw new PartnerServiceException(ErrorCode.UNABLE_TO_DEACTIVATE_DEVICE.getErrorCode(), - ErrorCode.UNABLE_TO_DEACTIVATE_DEVICE.getErrorMessage()); + throw new PartnerServiceException(ErrorCode.DEVICE_ALREADY_DEACTIVATED.getErrorCode(), + ErrorCode.DEVICE_ALREADY_DEACTIVATED.getErrorMessage()); } + + DeviceDetailResponseDto deviceDetailResponseDto = new DeviceDetailResponseDto(); + + device.setIsActive(false); + DeviceDetail updatedDetail = deviceDetailRepository.save(device); + deviceDetailResponseDto.setDeviceId(updatedDetail.getId()); + deviceDetailResponseDto.setStatus(updatedDetail.getApprovalStatus()); + deviceDetailResponseDto.setActive(updatedDetail.getIsActive()); + + responseWrapper.setResponse(deviceDetailResponseDto); + } catch (PartnerServiceException ex) { LOGGER.info("sessionId", "idType", "id", "In deactivateDevice method of DeviceDetailServiceImpl - " + ex.getMessage()); responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/FTPChipDetailServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/FTPChipDetailServiceImpl.java index 711cb82460..add4d070d4 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/FTPChipDetailServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/FTPChipDetailServiceImpl.java @@ -535,22 +535,25 @@ public ResponseWrapperV2 deactivateFtm(String ftmId) { FTPChipDetail ftm = ftmChipDetail.get(); Partner partnerDetails = getAssociatedPartner(partnerList, ftm, userId); checkIfPartnerIsNotActive(partnerDetails); - // Deactivate only if the FTM is approved status and is_active true. - if (ftm.getApprovalStatus().equals(APPROVED) && ftm.isActive()) { - FtmDetailResponseDto ftmDetailResponseDto = new FtmDetailResponseDto(); - - ftm.setActive(false); - FTPChipDetail updatedDetail = ftpChipDetailRepository.save(ftm); - ftmDetailResponseDto.setFtmId(updatedDetail.getFtpChipDetailId()); - ftmDetailResponseDto.setStatus(updatedDetail.getApprovalStatus()); - ftmDetailResponseDto.setActive(updatedDetail.isActive()); - - responseWrapper.setResponse(ftmDetailResponseDto); - } else { + if (!ftm.getApprovalStatus().equals(APPROVED)) { LOGGER.error("Unable to deactivate FTM with id {}", ftm.getFtpChipDetailId()); - throw new PartnerServiceException(ErrorCode.UNABLE_TO_DEACTIVATE_FTM.getErrorCode(), - ErrorCode.UNABLE_TO_DEACTIVATE_FTM.getErrorMessage()); + throw new PartnerServiceException(ErrorCode.FTM_NOT_APPROVED.getErrorCode(), + ErrorCode.FTM_NOT_APPROVED.getErrorMessage()); } + if (ftm.getApprovalStatus().equals(APPROVED) && !ftm.isActive()) { + LOGGER.error("Unable to deactivate FTM with id {}", ftm.getFtpChipDetailId()); + throw new PartnerServiceException(ErrorCode.FTM_ALREADY_DEACTIVATED.getErrorCode(), + ErrorCode.FTM_ALREADY_DEACTIVATED.getErrorMessage()); + } + FtmDetailResponseDto ftmDetailResponseDto = new FtmDetailResponseDto(); + + ftm.setActive(false); + FTPChipDetail updatedDetail = ftpChipDetailRepository.save(ftm); + ftmDetailResponseDto.setFtmId(updatedDetail.getFtpChipDetailId()); + ftmDetailResponseDto.setStatus(updatedDetail.getApprovalStatus()); + ftmDetailResponseDto.setActive(updatedDetail.isActive()); + + responseWrapper.setResponse(ftmDetailResponseDto); } catch (PartnerServiceException ex) { LOGGER.info("sessionId", "idType", "id", "In deactivateFtm method of FTPChipDetailServiceImpl - " + ex.getMessage()); responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/SecureBiometricInterfaceServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/SecureBiometricInterfaceServiceImpl.java index 1a73b981c4..339805adee 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/SecureBiometricInterfaceServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/SecureBiometricInterfaceServiceImpl.java @@ -777,39 +777,42 @@ public ResponseWrapperV2 deactivateSbi(String sbiId) { throw new PartnerServiceException(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode(), ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage()); } - // Deactivate only if the SBI is approved and is_active true. - if (sbi.getApprovalStatus().equals(APPROVED) && sbi.isActive()) { - // Deactivate approved devices - List approvedDevices = deviceDetailRepository.findApprovedDevicesBySbiId(sbiId); - if (!approvedDevices.isEmpty()) { - for (DeviceDetail deviceDetail: approvedDevices) { - deviceDetail.setIsActive(false); - deviceDetailRepository.save(deviceDetail); - } + if (!sbi.getApprovalStatus().equals(APPROVED)) { + LOGGER.error("Unable to deactivate sbi with id {}", sbi.getId()); + throw new PartnerServiceException(ErrorCode.SBI_NOT_APPROVED.getErrorCode(), + ErrorCode.SBI_NOT_APPROVED.getErrorMessage()); + } + if (sbi.getApprovalStatus().equals(APPROVED) && !sbi.isActive()) { + LOGGER.error("Unable to deactivate sbi with id {}", sbi.getId()); + throw new PartnerServiceException(ErrorCode.SBI_ALREADY_DEACTIVATED.getErrorCode(), + ErrorCode.SBI_ALREADY_DEACTIVATED.getErrorMessage()); + } + // Deactivate approved devices + List approvedDevices = deviceDetailRepository.findApprovedDevicesBySbiId(sbiId); + if (!approvedDevices.isEmpty()) { + for (DeviceDetail deviceDetail : approvedDevices) { + deviceDetail.setIsActive(false); + deviceDetailRepository.save(deviceDetail); } - // Reject pending_approval devices - List pendingApprovalDevices = deviceDetailRepository.findPendingApprovalDevicesBySbiId(sbiId); - if (!pendingApprovalDevices.isEmpty()) { - for (DeviceDetail deviceDetail: pendingApprovalDevices) { - deviceDetail.setApprovalStatus(REJECTED); - deviceDetailRepository.save(deviceDetail); - } + } + // Reject pending_approval devices + List pendingApprovalDevices = deviceDetailRepository.findPendingApprovalDevicesBySbiId(sbiId); + if (!pendingApprovalDevices.isEmpty()) { + for (DeviceDetail deviceDetail : pendingApprovalDevices) { + deviceDetail.setApprovalStatus(REJECTED); + deviceDetailRepository.save(deviceDetail); } - sbi.setActive(false); - SecureBiometricInterface updatedSbi = sbiRepository.save(sbi); - SbiDetailsResponseDto sbiDetailsResponseDto = new SbiDetailsResponseDto(); + } + sbi.setActive(false); + SecureBiometricInterface updatedSbi = sbiRepository.save(sbi); + SbiDetailsResponseDto sbiDetailsResponseDto = new SbiDetailsResponseDto(); - sbiDetailsResponseDto.setSbiId(updatedSbi.getId()); - sbiDetailsResponseDto.setSbiVersion(updatedSbi.getSwVersion()); - sbiDetailsResponseDto.setStatus(updatedSbi.getApprovalStatus()); - sbiDetailsResponseDto.setActive(updatedSbi.isActive()); + sbiDetailsResponseDto.setSbiId(updatedSbi.getId()); + sbiDetailsResponseDto.setSbiVersion(updatedSbi.getSwVersion()); + sbiDetailsResponseDto.setStatus(updatedSbi.getApprovalStatus()); + sbiDetailsResponseDto.setActive(updatedSbi.isActive()); - responseWrapper.setResponse(sbiDetailsResponseDto); - } else { - LOGGER.error("Unable to deactivate sbi with id {}", sbi.getId()); - throw new PartnerServiceException(ErrorCode.UNABLE_TO_DEACTIVATE_SBI.getErrorCode(), - ErrorCode.UNABLE_TO_DEACTIVATE_SBI.getErrorMessage()); - } + responseWrapper.setResponse(sbiDetailsResponseDto); } catch (PartnerServiceException ex) { LOGGER.info("sessionId", "idType", "id", "In deactivateSbi method of SecureBiometricInterfaceServiceImpl - " + ex.getMessage()); responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); 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 10f80c2102..7514eeb3df 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 @@ -115,23 +115,26 @@ public enum ErrorCode { APPROVE_OR_REJECT_DEVICE_WITH_SBI_MAPPING_ERROR("PMS_DEVICE_ERROR_011", "Error while approving or rejecting device for Sbi Mapping."), SBI_DEVICE_MAPPING_NOT_EXISTS("PMS_DEVICE_ERROR_012","SBI and Device mapping does not exists."), INVALID_DEVICE_ID("PMS_DEVICE_ERROR_013", "Device Id is invalid"), - UNABLE_TO_DEACTIVATE_DEVICE("PMS_DEVICE_ERROR_014", "The device can only be deactivated if it is approved and has not been previously deactivated."), + DEVICE_ALREADY_DEACTIVATED("PMS_DEVICE_ERROR_014", "The selected device has been already deactivated."), DEACTIVATE_DEVICE_ERROR("PMS_DEVICE_ERROR_015", "Error while deactivating the device"), DEVICE_NOT_ASSOCIATED_WITH_USER("PMS_DEVICE_ERROR_016", "Device is not associated with user."), INVALID_SBI_ID("PMS_DEVICE_ERROR_017", "SBI Id is invalid"), DEACTIVATE_SBI_ERROR("PMS_DEVICE_ERROR_018", "Error while deactivating the SBI"), SBI_NOT_ASSOCIATED_WITH_USER("PMS_DEVICE_ERROR_019", "SBI is not associated with user."), - UNABLE_TO_DEACTIVATE_SBI("PMS_DEVICE_ERROR_020", "SBI can only be deactivated if it is approved and has not been previously deactivated."), + SBI_ALREADY_DEACTIVATED("PMS_DEVICE_ERROR_020", "The selected SBI is already deactivated."), SBI_EXPIRED("PMS_DEVICE_ERROR_021", "SBI for which device is being added is expired"), + SBI_NOT_APPROVED("PMS_DEVICE_ERROR_022", "The selected SBI is not in an approved status."), + DEVICE_NOT_APPROVED("PMS_DEVICE_ERROR_023", "The selected Device is not in an approved status."), FTM_CHIP_DETAILS_LIST_FETCH_ERROR("PMS_FTM_ERROR_001", "Error while fetching the FTM chip details"), APPROVED_FTM_PROVIDER_IDS_FETCH_ERROR("PMS_FTM_ERROR_002", "Unable to fetch approved FTM provider Ids."), DEACTIVATE_FTM_ERROR("PMS_FTM_ERROR_003", "Error while deactivating the FTM"), INVALID_FTM_ID("PMS_FTM_ERROR_004", "FTM Id is invalid"), FTM_NOT_EXISTS("PMS_FTM_ERROR_005", "FTM Details do not exists."), FTM_NOT_ASSOCIATED_WITH_USER("PMS_FTM_ERROR_006", "FTM is not associated with user."), - UNABLE_TO_DEACTIVATE_FTM("PMS_FTM_ERROR_007", "The selected FTM must be active and approved"), + FTM_ALREADY_DEACTIVATED("PMS_FTM_ERROR_007", "The selected FTM is already deactivated."), DOWNLOAD_ORIGINAL_FTM_CERTIFICATE_ERROR("PMS_FTM_ERROR_008", "The selected FTM must be pending_approval or approved"), - UNABLE_TO_DOWNLOAD_ORIGINAL_FTM_CERTIFICATE("PMS_FTM_ERROR_009", "Unable to download original FTM certificate"); + UNABLE_TO_DOWNLOAD_ORIGINAL_FTM_CERTIFICATE("PMS_FTM_ERROR_009", "Unable to download original FTM certificate"), + FTM_NOT_APPROVED("PMS_FTM_ERROR_010", "The selected FTM is not in an approved status."); /** * The error code. */