From 704b993fd8a952d0c8656ebd15dab4bc3d416cfc Mon Sep 17 00:00:00 2001 From: sudeep Date: Fri, 27 Sep 2024 18:30:55 +0530 Subject: [PATCH] MOSIP-35895,MOSIP-35655 - updated error messages. Signed-off-by: sudeep --- .../service/impl/DeviceDetailServiceImpl.java | 32 +++++----- .../SecureBiometricInterfaceServiceImpl.java | 61 ++++++++++--------- ...oundationalTrustProviderErrorMessages.java | 2 +- .../mosip/pms/partner/constant/ErrorCode.java | 6 +- 4 files changed, 55 insertions(+), 46 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 95bbd7c8b5..37546c337c 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 @@ -545,22 +545,26 @@ 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.getIsActive()){ + LOGGER.error("Unable to deactivate device with id {}", device.getId()); + throw new PartnerServiceException(ErrorCode.DEVICE_ALREADY_DEACTIVATED.getErrorCode(), + ErrorCode.DEVICE_ALREADY_DEACTIVATED.getErrorMessage()); + } + if (!device.getApprovalStatus().equals(APPROVED)){ 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_NOT_APPROVED.getErrorCode(), + ErrorCode.DEVICE_NOT_APPROVED.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/SecureBiometricInterfaceServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/SecureBiometricInterfaceServiceImpl.java index 1a73b981c4..d80bfd12b0 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.isActive()){ + LOGGER.error("Unable to deactivate sbi with id {}", sbi.getId()); + throw new PartnerServiceException(ErrorCode.SBI_ALREADY_DEACTIVATED.getErrorCode(), + ErrorCode.SBI_ALREADY_DEACTIVATED.getErrorMessage()); + } + 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()); + } + // 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/device/constant/FoundationalTrustProviderErrorMessages.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/constant/FoundationalTrustProviderErrorMessages.java index ad28608a7b..2dd4a9e9bd 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/constant/FoundationalTrustProviderErrorMessages.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/constant/FoundationalTrustProviderErrorMessages.java @@ -1,7 +1,7 @@ package io.mosip.pms.device.constant; public enum FoundationalTrustProviderErrorMessages { - FTP_PROVIDER_NOT_EXISTS("PMP_AUT_030","ftp provider not exists."), + FTP_PROVIDER_NOT_EXISTS("PMP_AUT_030","The FTP provider is either inactive or does not exist."), FTP_CHIP_ID_NOT_EXISTS("PMP_AUT_031","ftp chip id not exists."), FTP_PROVIDER_MAKE_MODEL_EXISTS("PMP_AUT_032","FTM Chip details already exists for the same make and model"), FTP_CERT_NOT_UPLOADED("PMP_AUT_033","Certificate is not uploaded."), 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 f627650076..4b9bcfef56 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,14 +115,16 @@ 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 selected device must be active and approved"), + DEVICE_ALREADY_DEACTIVATED("PMS_DEVICE_ERROR_014", "The selected device is 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", "The selected SBI must be active and approved"), + 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"), + DEVICE_NOT_APPROVED("PMS_DEVICE_ERROR_022", "The selected device must have an approved status in order to be deactivated."), + SBI_NOT_APPROVED("PMS_DEVICE_ERROR_023", "The selected SBI must have an approved status in order to be deactivated."), 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"),