From 1bc24c748b53847d919a70a6b50a0d25c7b5612c Mon Sep 17 00:00:00 2001 From: Sudeep7353 <103890430+Sudeep7353@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:36:35 +0530 Subject: [PATCH] MOSIP-37899: API Review Comments (#1045) * MOSIP:37899 - APi review comment changes Signed-off-by: sudeep * MOSIP:37899 - APi review comment changes Signed-off-by: sudeep * MOSIP:37899 - APi review comment changes Signed-off-by: sudeep * MOSIP:37899 - APi review comment changes Signed-off-by: sudeep * MOSIP:37899 - APi review comment changes Signed-off-by: sudeep * MOSIP:37899 - APi review comment changes Signed-off-by: sudeep * MOSIP:37899 - APi review comment changes Signed-off-by: sudeep * MOSIP:37899 - APi review comment changes Signed-off-by: sudeep * MOSIP:37899 - APi review comment changes Signed-off-by: sudeep * MOSIP:37899 - APi review comment changes Signed-off-by: sudeep --------- Signed-off-by: sudeep --- .../service/DeviceDetailService.java | 2 + .../service/FtpChipDetailService.java | 6 +- .../SecureBiometricInterfaceService.java | 3 + .../service/impl/DeviceDetailServiceImpl.java | 75 ++- .../impl/FTPChipDetailServiceImpl.java | 83 ++- .../SecureBiometricInterfaceServiceImpl.java | 98 +++- .../controller/DeviceDetailController.java | 29 +- .../controller/FTPChipDetailController.java | 36 +- .../SecureBiometricInterfaceController.java | 31 +- .../dto/FtmChipDetailsDto.java | 2 +- .../dto/SbiDetailsDto.java | 6 +- .../dto/DeactivateDeviceRequestDto.java | 11 - .../request/dto/DeactivateFtmRequestDto.java | 11 - .../request/dto/DeactivateSbiRequestDto.java | 11 - .../pms/oauth/client/dto/OauthClientDto.java | 2 - .../impl/ClientManagementServiceImpl.java | 1 - .../MultiPartnerAdminServiceController.java | 76 --- .../MultiPartnerServiceController.java | 55 +- .../controller/PartnerServiceController.java | 43 +- .../pms/partner/dto/AuthorizedRolesDto.java | 8 +- .../pms/partner/dto/DeviceDetailDto.java | 2 +- .../io/mosip/pms/partner/dto/PolicyDto.java | 2 +- .../dto/SbiAndDeviceMappingRequestDto.java | 3 + .../service/MultiPartnerAdminService.java | 9 - .../partner/service/MultiPartnerService.java | 11 +- .../pms/partner/service/PartnerService.java | 11 +- .../impl/MultiPartnerAdminServiceImpl.java | 114 ----- .../service/impl/MultiPartnerServiceImpl.java | 471 +---------------- .../service/impl/PartnerServiceImpl.java | 224 +++++++- .../mosip/pms/partner/util/PartnerHelper.java | 70 +++ .../pms/user/controller/UserController.java | 11 +- .../src/main/resources/bootstrap.properties | 16 +- .../DeviceDetailControllerTest.java | 36 +- .../FTPChipDetailControllerTest.java | 31 +- ...ecureBiometricInterfaceControllerTest.java | 32 +- .../service/impl/DeviceDetailServiceTest.java | 106 ++++ .../impl/FTPChipDetailServiceTest.java | 51 +- .../device/service/impl/SBIServiceTest.java | 46 ++ ...MultiPartnerAdminServiceContollerTest.java | 113 ----- .../MultiPartnerServiceControllerTest.java | 79 +-- .../PartnerServiceControllerTest.java | 66 ++- .../controller/UserControllerTest.java | 2 +- .../MultiPartnerAdminServiceImplTest.java | 162 ------ .../impl/MultiPartnerServiceImplTest.java | 479 ------------------ .../service/impl/PartnerServiceImplTest.java | 402 ++++++++++++++- .../src/test/resources/application.properties | 14 +- .../mosip/pms/policy/dto/PolicyGroupDto.java | 1 - .../service/PolicyManagementService.java | 1 - 48 files changed, 1421 insertions(+), 1733 deletions(-) rename partner/partner-management-service/src/main/java/io/mosip/pms/{partner => device}/dto/FtmChipDetailsDto.java (98%) rename partner/partner-management-service/src/main/java/io/mosip/pms/{partner => device}/dto/SbiDetailsDto.java (92%) delete mode 100644 partner/partner-management-service/src/main/java/io/mosip/pms/device/request/dto/DeactivateDeviceRequestDto.java delete mode 100644 partner/partner-management-service/src/main/java/io/mosip/pms/device/request/dto/DeactivateFtmRequestDto.java delete mode 100644 partner/partner-management-service/src/main/java/io/mosip/pms/device/request/dto/DeactivateSbiRequestDto.java delete mode 100644 partner/partner-management-service/src/main/java/io/mosip/pms/partner/controller/MultiPartnerAdminServiceController.java delete mode 100644 partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/MultiPartnerAdminService.java delete mode 100644 partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/MultiPartnerAdminServiceImpl.java delete mode 100644 partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/MultiPartnerAdminServiceContollerTest.java delete mode 100644 partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/MultiPartnerAdminServiceImplTest.java diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/DeviceDetailService.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/DeviceDetailService.java index 9b92635932..8d8d736601 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/DeviceDetailService.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/DeviceDetailService.java @@ -97,4 +97,6 @@ public interface DeviceDetailService { public ResponseWrapperV2 deactivateDevice(String deviceDetailId); ResponseWrapperV2> getAllDeviceDetails(String sortFieldName, String sortType, int pageNo, int pageSize, DeviceDetailFilterDto filterDto); + + public ResponseWrapperV2 approveOrRejectMappingDeviceToSbi(String deviceId, SbiAndDeviceMappingRequestDto requestDto); } diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/FtpChipDetailService.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/FtpChipDetailService.java index 9af2e3a211..16cd3400fc 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/FtpChipDetailService.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/FtpChipDetailService.java @@ -1,9 +1,11 @@ package io.mosip.pms.device.authdevice.service; import java.io.IOException; +import java.util.List; import io.mosip.pms.common.dto.PageResponseV2Dto; import io.mosip.pms.common.response.dto.ResponseWrapperV2; +import io.mosip.pms.device.dto.FtmChipDetailsDto; import io.mosip.pms.device.dto.FtmChipFilterDto; import io.mosip.pms.device.response.dto.*; import io.mosip.pms.partner.response.dto.FtmCertificateDownloadResponseDto; @@ -88,8 +90,10 @@ public interface FtpChipDetailService { public ResponseWrapperV2 deactivateFtm(String ftmId); - public ResponseWrapperV2 getOriginalFtmCertificate(String ftmId); + public ResponseWrapperV2 getFtmCertificateData(String ftmId); public ResponseWrapperV2> getPartnersFtmChipDetails(String sortFieldName, String sortType, int pageNo, int pageSize, FtmChipFilterDto filterDto); + public ResponseWrapperV2> ftmChipDetail(); + } diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/SecureBiometricInterfaceService.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/SecureBiometricInterfaceService.java index 850e421fb4..5b5a341066 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/SecureBiometricInterfaceService.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/SecureBiometricInterfaceService.java @@ -7,6 +7,7 @@ import io.mosip.pms.device.response.dto.SbiSummaryDto; import io.mosip.pms.device.dto.SbiFilterDto; +import io.mosip.pms.device.dto.SbiDetailsDto; import org.springframework.stereotype.Service; import io.mosip.pms.common.dto.FilterValueDto; @@ -42,6 +43,8 @@ public interface SecureBiometricInterfaceService { public FilterResponseCodeDto filterValues(FilterValueDto filterValueDto); + public ResponseWrapperV2> getSbiDetails(); + public ResponseWrapperV2> getAllDevicesForSbi(String sbiId); public ResponseWrapperV2 deactivateSbi(String id); 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 6e4592e8e1..42c698ba5d 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 @@ -8,6 +8,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Map; +import java.util.Set; import io.mosip.kernel.core.authmanager.authadapter.model.AuthUserDetails; import io.mosip.kernel.core.logger.spi.Logger; @@ -87,12 +88,15 @@ public class DeviceDetailServiceImpl implements DeviceDetailService { @Value("${mosip.pms.api.id.add.inactive.mapping.device.to.sbi.id.post}") private String postInactiveMappingDeviceToSbiId; - @Value("${mosip.pms.api.id.deactivate.device.post}") - private String postDeactivateDevice; + @Value("${mosip.pms.api.id.deactivate.device.patch}") + private String patchDeactivateDevice; @Value("${mosip.pms.api.id.get.all.device.details.get}") private String getAllDeviceDetailsId; + @Value("${mosip.pms.api.id.mapping.device.to.sbi.post:mosip.pms.mapping.device.to.sbi.post}") + private String postMappingDeviceToSbiId; + @Autowired DeviceDetailSbiRepository deviceDetailSbiRepository; @@ -585,7 +589,72 @@ public ResponseWrapperV2 deactivateDevice(String device String errorMessage = ErrorCode.DEACTIVATE_DEVICE_ERROR.getErrorMessage(); responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); } - responseWrapper.setId(postDeactivateDevice); + responseWrapper.setId(patchDeactivateDevice); + responseWrapper.setVersion(VERSION); + return responseWrapper; + } + + @Override + public ResponseWrapperV2 approveOrRejectMappingDeviceToSbi(String deviceId, SbiAndDeviceMappingRequestDto requestDto) { + ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); + try { + String partnerId = requestDto.getPartnerId(); + String sbiId = requestDto.getSbiId(); + String status = requestDto.getStatus(); + if (Objects.isNull(partnerId) || Objects.isNull(deviceId) || Objects.isNull(status)) { + LOGGER.info("sessionId", "idType", "id", "Partner/Device id does not exist."); + throw new PartnerServiceException(ErrorCode.INVALID_REQUEST_PARAM.getErrorCode(), + ErrorCode.INVALID_REQUEST_PARAM.getErrorMessage()); + } + if (!Set.of(DeviceConstant.APPROVE, DeviceConstant.REJECT).contains(status)) { + throw new PartnerServiceException(ErrorCode.NO_SBI_FOUND_FOR_APPROVE.getErrorCode(), + ErrorCode.NO_SBI_FOUND_FOR_APPROVE.getErrorMessage()); + } + if (Objects.isNull(sbiId)) { + LOGGER.info("sessionId", "idType", "id", "SBI id is null."); + if (status.equals(DeviceConstant.APPROVE)) { + throw new PartnerServiceException(ErrorCode.NO_SBI_FOUND_FOR_APPROVE.getErrorCode(), + ErrorCode.NO_SBI_FOUND_FOR_APPROVE.getErrorMessage()); + } else { + throw new PartnerServiceException(ErrorCode.NO_SBI_FOUND_FOR_REJECT.getErrorCode(), + ErrorCode.NO_SBI_FOUND_FOR_REJECT.getErrorMessage()); + } + } + // validate sbi and device mapping + partnerHelper.validateSbiDeviceMapping(partnerId, sbiId, deviceId); + + DeviceDetailSBI deviceDetailSBI = deviceDetailSbiRepository.findByDeviceProviderIdAndSbiIdAndDeviceDetailId(partnerId, sbiId, deviceId); + if (Objects.isNull(deviceDetailSBI)) { + LOGGER.info("sessionId", "idType", "id", "SBI and Device mapping already exists in DB."); + throw new PartnerServiceException(ErrorCode.SBI_DEVICE_MAPPING_NOT_EXISTS.getErrorCode(), + ErrorCode.SBI_DEVICE_MAPPING_NOT_EXISTS.getErrorMessage()); + } + + UpdateDeviceDetailStatusDto deviceDetails = new UpdateDeviceDetailStatusDto(); + deviceDetails.setId(deviceId); + if (status.equals(DeviceConstant.REJECT)) { + deviceDetails.setApprovalStatus(DeviceConstant.REJECT); + } else { + deviceDetails.setApprovalStatus(DeviceConstant.APPROVE); + } + updateDeviceDetailStatus(deviceDetails); + + deviceDetailSBI.setIsActive(true); + deviceDetailSbiRepository.save(deviceDetailSBI); + LOGGER.info("sessionId", "idType", "id", "updated device mapping to sbi successfully in Db."); + responseWrapper.setResponse(true); + } catch (PartnerServiceException ex) { + LOGGER.info("sessionId", "idType", "id", "In approveOrRejectMappingDeviceToSbi method of DeviceDetailServiceImpl - " + ex.getMessage()); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); + } catch (Exception ex) { + LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace()); + LOGGER.error("sessionId", "idType", "id", + "In approveOrRejectMappingDeviceToSbi method of DeviceDetailServiceImplN - " + ex.getMessage()); + String errorCode = ErrorCode.APPROVE_OR_REJECT_DEVICE_WITH_SBI_MAPPING_ERROR.getErrorCode(); + String errorMessage = ErrorCode.APPROVE_OR_REJECT_DEVICE_WITH_SBI_MAPPING_ERROR.getErrorMessage(); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); + } + responseWrapper.setId(postMappingDeviceToSbiId); responseWrapper.setVersion(VERSION); return responseWrapper; } 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 023ea8e8df..4c3bf45ecf 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 @@ -5,7 +5,9 @@ import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.*; import io.mosip.kernel.core.authmanager.authadapter.model.AuthUserDetails; @@ -13,6 +15,7 @@ import io.mosip.pms.common.response.dto.ResponseWrapperV2; import io.mosip.pms.device.authdevice.entity.FtmDetailSummaryEntity; import io.mosip.pms.device.authdevice.repository.FtmDetailsSummaryRepository; +import io.mosip.pms.device.dto.FtmChipDetailsDto; import io.mosip.pms.device.dto.FtmChipFilterDto; import io.mosip.pms.device.response.dto.*; import io.mosip.pms.partner.constant.PartnerConstants; @@ -138,15 +141,18 @@ public class FTPChipDetailServiceImpl implements FtpChipDetailService { @Value("${pms.certs.datashare.policyId}") private String policyId; - @Value("${mosip.pms.api.id.deactivate.ftm.post}") - private String postDeactivateFtm; + @Value("${mosip.pms.api.id.deactivate.ftm.patch}") + private String patchDeactivateFtm; @Value("${mosip.pms.api.id.original.ftm.certificate.get}") private String getOriginalFtmCertificateId; @Value("${mosip.pms.api.id.partners.ftm.chip.details.get}") private String getPartnersFtmChipDetailsId; - + + @Value("${mosip.pms.api.id.ftm.chip.details.get}") + private String getFtmChipDetailsId; + @Autowired private WebSubPublisher webSubPublisher; @@ -595,13 +601,13 @@ public ResponseWrapperV2 deactivateFtm(String ftmId) { String errorMessage = ErrorCode.DEACTIVATE_FTM_ERROR.getErrorMessage(); responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); } - responseWrapper.setId(postDeactivateFtm); + responseWrapper.setId(patchDeactivateFtm); responseWrapper.setVersion(VERSION); return responseWrapper; } @Override - public ResponseWrapperV2 getOriginalFtmCertificate(String ftmId) { + public ResponseWrapperV2 getFtmCertificateData(String ftmId) { ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); try { String userId = getUserId(); @@ -715,6 +721,73 @@ private Page getFtmChipDetails(String sortFieldName, Str filterDto.getMake(), filterDto.getModel(), filterDto.getStatus(), pageable); } + @Override + public ResponseWrapperV2> ftmChipDetail() { + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + try { + String userId = getUserId(); + List partnerList = partnerRepository.findByUserId(userId); + List ftmChipDetailsDtoList = new ArrayList<>(); + if (!partnerList.isEmpty()) { + for (Partner partner : partnerList) { + if (partnerHelper.checkIfPartnerIsFtmPartner(partner)) { + partnerHelper.validatePartnerId(partner, userId); + List ftpChipDetailList = ftpChipDetailRepository.findByProviderId(partner.getId()); + if(!ftpChipDetailList.isEmpty()) { + for(FTPChipDetail ftpChipDetail: ftpChipDetailList) { + FtmChipDetailsDto ftmChipDetailsDto = new FtmChipDetailsDto(); + // Get certificate data if available + if (ftpChipDetail.getCertificateAlias() != null) { + ftmChipDetailsDto.setIsCertificateAvailable(true); + FtpChipCertDownloadRequestDto requestDto = new FtpChipCertDownloadRequestDto(); + requestDto.setFtpChipDetailId(ftpChipDetail.getFtpChipDetailId()); + FtpCertDownloadResponeDto ftpCertDownloadResponeDto = getCertificate(requestDto); + X509Certificate cert = MultiPartnerUtil.decodeCertificateData(ftpCertDownloadResponeDto.getCertificateData()); + + ftmChipDetailsDto.setCertificateUploadDateTime(cert.getNotBefore()); + ftmChipDetailsDto.setCertificateExpiryDateTime(cert.getNotAfter()); + + // Check the certificate expiration status + LocalDateTime currentDateTime = LocalDateTime.now(ZoneId.of("UTC")); + LocalDateTime certExpiryDate = cert.getNotAfter().toInstant().atZone(ZoneId.of("UTC")).toLocalDateTime(); + ftmChipDetailsDto.setIsCertificateExpired(certExpiryDate.isBefore(currentDateTime)); + } else { + ftmChipDetailsDto.setIsCertificateAvailable(false); + ftmChipDetailsDto.setIsCertificateExpired(false); + } + ftmChipDetailsDto.setFtmId(ftpChipDetail.getFtpChipDetailId()); + ftmChipDetailsDto.setPartnerId(ftpChipDetail.getFtpProviderId()); + ftmChipDetailsDto.setMake(ftpChipDetail.getMake()); + ftmChipDetailsDto.setModel(ftpChipDetail.getModel()); + ftmChipDetailsDto.setStatus(ftpChipDetail.getApprovalStatus()); + ftmChipDetailsDto.setIsActive(ftpChipDetail.isActive()); + ftmChipDetailsDto.setCreatedDateTime(ftpChipDetail.getCrDtimes()); + ftmChipDetailsDtoList.add(ftmChipDetailsDto); + } + } + } + } + } + responseWrapper.setResponse(ftmChipDetailsDtoList); + } catch (ApiAccessibleException ex) { + LOGGER.info("sessionId", "idType", "id", "In ftmChipDetails method of FTPChipDetailServiceImpl - " + ex.getMessage()); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); + } catch (PartnerServiceException ex) { + LOGGER.info("sessionId", "idType", "id", "In ftmChipDetail method of FTPChipDetailServiceImpl - " + ex.getMessage()); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); + } catch (Exception ex) { + LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace()); + LOGGER.error("sessionId", "idType", "id", + "In ftmChipDetail method of FTPChipDetailServiceImpl - " + ex.getMessage()); + String errorCode = ErrorCode.FTM_CHIP_DETAILS_LIST_FETCH_ERROR.getErrorCode(); + String errorMessage = ErrorCode.FTM_CHIP_DETAILS_LIST_FETCH_ERROR.getErrorMessage(); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); + } + responseWrapper.setId(getFtmChipDetailsId); + responseWrapper.setVersion(VERSION); + return responseWrapper; + } + public String getSortColumn(Map aliasToColumnMap, String alias) { return aliasToColumnMap.getOrDefault(alias, alias); // Return alias if no match found } 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 dfcce47274..f9be62e98f 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 @@ -4,7 +4,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; -import java.time.ZoneOffset; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -22,13 +21,14 @@ import io.mosip.pms.device.authdevice.repository.SbiSummaryRepository; import io.mosip.pms.device.dto.SbiFilterDto; import io.mosip.pms.partner.constant.ErrorCode; -import io.mosip.pms.partner.constant.PartnerConstants; import io.mosip.pms.partner.dto.DeviceDetailDto; +import io.mosip.pms.device.dto.SbiDetailsDto; import io.mosip.pms.partner.exception.PartnerServiceException; import io.mosip.pms.device.response.dto.SbiDetailsResponseDto; import io.mosip.pms.partner.util.MultiPartnerUtil; import io.mosip.pms.partner.util.PartnerHelper; import io.mosip.pms.partner.util.PartnerUtil; +import io.swagger.models.auth.In; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; @@ -91,16 +91,20 @@ public class SecureBiometricInterfaceServiceImpl implements SecureBiometricInter public static final String DEVICE_PROVIDER = "Device_Provider"; public static final String APPROVED = "approved"; public static final String REJECTED = "rejected"; + public static final String PENDING_APPROVAL = "pending_approval"; @Value("${mosip.pms.api.id.sbi.devices.get}") private String getSbiDevicesId; - @Value("${mosip.pms.api.id.deactivate.sbi.post}") - private String postDeactivateSbi; + @Value("${mosip.pms.api.id.deactivate.sbi.patch}") + private String patchDeactivateSbi; @Value("${mosip.pms.api.id.all.sbi.details.get}") private String getAllSbiDetails; + @Value("${mosip.pms.api.id.sbi.details.get}") + private String getSbiDetailsId; + @Autowired DeviceDetailRepository deviceDetailRepository; @@ -465,6 +469,88 @@ private void validateDates(LocalDateTime fromDate, LocalDateTime toDate) { } } + @Override + public ResponseWrapperV2> getSbiDetails() { + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + try { + String userId = getUserId(); + List partnerList = partnerRepository.findByUserId(userId); + if (partnerList.isEmpty()) { + LOGGER.info("sessionId", "idType", "id", "User id does not exists."); + throw new PartnerServiceException(ErrorCode.USER_ID_NOT_EXISTS.getErrorCode(), + ErrorCode.USER_ID_NOT_EXISTS.getErrorMessage()); + } + List sbiDetailsDtoList = new ArrayList<>(); + for (Partner partner : partnerList) { + validatePartnerId(partner, userId); + if (partnerHelper.checkIfPartnerIsDevicePartner(partner)) { + List secureBiometricInterfaceList = sbiRepository.findByProviderId(partner.getId()); + if (!secureBiometricInterfaceList.isEmpty()) { + for (SecureBiometricInterface secureBiometricInterface : secureBiometricInterfaceList) { + SbiDetailsDto sbiDetailsDto = new SbiDetailsDto(); + List deviceDetailSBIList = deviceDetailSbiRepository.findByDeviceProviderIdAndSbiId(partner.getId(), secureBiometricInterface.getId()); + sbiDetailsDto.setSbiId(secureBiometricInterface.getId()); + sbiDetailsDto.setPartnerId(partner.getId()); + sbiDetailsDto.setSbiVersion(secureBiometricInterface.getSwVersion()); + sbiDetailsDto.setStatus(secureBiometricInterface.getApprovalStatus()); + sbiDetailsDto.setSbiActive(secureBiometricInterface.isActive()); + sbiDetailsDto.setSbiExpired(checkIfSbiExpired(secureBiometricInterface)); + sbiDetailsDto.setCountOfApprovedDevices(countDevices(deviceDetailSBIList, APPROVED)); + sbiDetailsDto.setCountOfPendingDevices(countDevices(deviceDetailSBIList, PENDING_APPROVAL)); + sbiDetailsDto.setSbiCreatedDateTime(secureBiometricInterface.getSwCreateDateTime()); + sbiDetailsDto.setSbiExpiryDateTime(secureBiometricInterface.getSwExpiryDateTime()); + sbiDetailsDto.setCreatedDateTime(secureBiometricInterface.getCrDtimes()); + + sbiDetailsDtoList.add(sbiDetailsDto); + } + } + } + } + responseWrapper.setResponse(sbiDetailsDtoList); + } catch (PartnerServiceException ex) { + LOGGER.info("sessionId", "idType", "id", "In getSbiDetails method of SecureBiometricInterfaceServiceImpl - " + ex.getMessage()); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); + } catch (Exception ex) { + LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace()); + LOGGER.error("sessionId", "idType", "id", + "In getSbiDetails method of SecureBiometricInterfaceServiceImpl - " + ex.getMessage()); + String errorCode = ErrorCode.SBI_DETAILS_LIST_FETCH_ERROR.getErrorCode(); + String errorMessage = ErrorCode.SBI_DETAILS_LIST_FETCH_ERROR.getErrorMessage(); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); + } + responseWrapper.setId(getSbiDetailsId); + responseWrapper.setVersion(VERSION); + return responseWrapper; + } + + private boolean checkIfSbiExpired(SecureBiometricInterface secureBiometricInterface) { + return secureBiometricInterface.getSwExpiryDateTime().toLocalDate().isBefore(LocalDate.now()); + } + + private Integer countDevices(List deviceDetailSBIList, String status) { + Integer count = 0; + if (deviceDetailSBIList.isEmpty()) { + return count; + } + for (DeviceDetailSBI deviceDetailSBI : deviceDetailSBIList) { + Optional deviceDetail = deviceDetailRepository. + findByIdAndDeviceProviderId(deviceDetailSBI.getId().getDeviceDetailId(), deviceDetailSBI.getProviderId()); + if (deviceDetail.isPresent()) { + if (status.equals(APPROVED)) { + if (deviceDetail.get().getApprovalStatus().equals(status) && deviceDetail.get().getIsActive()) { + count++; + } + } + if (status.equals(PENDING_APPROVAL)) { + if (deviceDetail.get().getApprovalStatus().equals(status)) { + count++; + } + } + } + } + return count; + } + @Override public String mapDeviceDetailAndSbi(DeviceDetailSBIMappingDto input) { DeviceDetailSBI deviceDetailFromDb = deviceDetailSbiRepository.findByDeviceDetailAndSbi(input.getDeviceDetailId(), input.getSbiId()); @@ -704,7 +790,7 @@ public ResponseWrapperV2> getAllDevicesForSbi(String sbiId if (optionalDeviceDetail.isPresent()) { DeviceDetail deviceDetail = optionalDeviceDetail.get(); DeviceDetailDto deviceDetailDto = new DeviceDetailDto(); - deviceDetailDto.setId(deviceDetail.getId()); + deviceDetailDto.setDeviceId(deviceDetail.getId()); deviceDetailDto.setDeviceTypeCode(deviceDetail.getDeviceTypeCode()); deviceDetailDto.setDeviceSubTypeCode(deviceDetail.getDeviceSubTypeCode()); deviceDetailDto.setDeviceProviderId(deviceDetail.getDeviceProviderId()); @@ -830,7 +916,7 @@ public ResponseWrapperV2 deactivateSbi(String sbiId) { String errorMessage = ErrorCode.DEACTIVATE_SBI_ERROR.getErrorMessage(); responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); } - responseWrapper.setId(postDeactivateSbi); + responseWrapper.setId(patchDeactivateSbi); responseWrapper.setVersion(VERSION); return responseWrapper; } diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/controller/DeviceDetailController.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/controller/DeviceDetailController.java index f4b8754c31..25392a927b 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/controller/DeviceDetailController.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/controller/DeviceDetailController.java @@ -1,13 +1,13 @@ package io.mosip.pms.device.controller; import javax.validation.Valid; +import javax.validation.constraints.NotBlank; import io.mosip.pms.common.dto.PageResponseV2Dto; import io.mosip.pms.common.request.dto.RequestWrapperV2; import io.mosip.pms.common.response.dto.ResponseWrapperV2; import io.mosip.pms.device.dto.DeviceDetailFilterDto; import io.mosip.pms.device.dto.DeviceDetailSummaryDto; -import io.mosip.pms.device.request.dto.DeactivateDeviceRequestDto; import io.mosip.pms.partner.request.dto.SbiAndDeviceMappingRequestDto; import io.mosip.pms.device.response.dto.DeviceDetailResponseDto; import io.mosip.pms.partner.util.PartnerHelper; @@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.PathVariable; import io.mosip.kernel.core.http.ResponseFilter; import io.mosip.pms.common.dto.DeviceFilterValueDto; @@ -62,8 +63,8 @@ public class DeviceDetailController { @Value("${mosip.pms.api.id.add.inactive.mapping.device.to.sbi.id.post}") private String postInactiveMappingDeviceToSbiId; - @Value("${mosip.pms.api.id.deactivate.device.post}") - private String postDeactivateDeviceId; + @Value("${mosip.pms.api.id.mapping.device.to.sbi.post:mosip.pms.mapping.device.to.sbi.post}") + private String postMappingDeviceToSbiId; @Autowired AuditUtil auditUtil; @@ -248,20 +249,32 @@ public ResponseWrapperV2 inactiveMappingDeviceToSbi(@RequestBody @Valid return deviceDetaillService.inactiveMappingDeviceToSbi(requestWrapper.getRequest()); } - @PreAuthorize("hasAnyRole(@authorizedRoles.getPostdeactivatedevice())") - @PostMapping(value = "/deactivate-device") + @PreAuthorize("hasAnyRole(@authorizedRoles.getPatchdeactivatedevice())") + @PatchMapping(value = "/{deviceId}") @Operation(summary = "Deactivate device details", description = "Deactivate device details") @io.swagger.v3.oas.annotations.responses.ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "OK"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))) }) - public ResponseWrapperV2 deactivateDevice(@RequestBody @Valid RequestWrapperV2 requestWrapper) { - Optional> validationResponse = requestValidator.validate(postDeactivateDeviceId, requestWrapper); + public ResponseWrapperV2 deactivateDevice(@PathVariable("deviceId") @NotBlank String deviceId) { + return deviceDetaillService.deactivateDevice(deviceId); + } + + @PreAuthorize("hasAnyRole(@authorizedRoles.getPostdevicewithsbimapping())") + @PostMapping(value = "/{id}/approval") + @Operation(summary = "Approve or Reject device and activate device mapping to sbi.", description = "Approve or Reject device and activate device mapping to sbi.") + @io.swagger.v3.oas.annotations.responses.ApiResponses(value = { + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "OK"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))) + }) + public ResponseWrapperV2 approveOrRejectMappingDeviceToSbi(@PathVariable("id") String deviceId, @RequestBody @Valid RequestWrapperV2 requestWrapper) { + Optional> validationResponse = requestValidator.validate(postMappingDeviceToSbiId, requestWrapper); if (validationResponse.isPresent()) { return validationResponse.get(); } - return deviceDetaillService.deactivateDevice(requestWrapper.getRequest().getDeviceId()); + return deviceDetaillService.approveOrRejectMappingDeviceToSbi(deviceId, requestWrapper.getRequest()); } @PreAuthorize("hasAnyRole(@authorizedRoles.getGetalldevicedetails())") diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/controller/FTPChipDetailController.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/controller/FTPChipDetailController.java index db900e1b25..49e76bea42 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/controller/FTPChipDetailController.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/controller/FTPChipDetailController.java @@ -2,14 +2,15 @@ import java.io.IOException; import java.security.cert.CertificateException; -import java.util.Optional; +import java.util.List; import javax.validation.Valid; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import io.mosip.pms.common.dto.PageResponseV2Dto; -import io.mosip.pms.common.request.dto.RequestWrapperV2; import io.mosip.pms.common.response.dto.ResponseWrapperV2; +import io.mosip.pms.device.dto.FtmChipDetailsDto; import io.mosip.pms.device.dto.FtmChipFilterDto; import io.mosip.pms.device.request.dto.*; import io.mosip.pms.device.response.dto.*; @@ -67,9 +68,6 @@ public class FTPChipDetailController { @Autowired PartnerHelper partnerHelper; - @Value("${mosip.pms.api.id.deactivate.ftm.post}") - private String postDeactivateFtmId; - @Autowired RequestValidator requestValidator; @@ -248,31 +246,27 @@ public ResponseWrapper> searchFtpChipDetai return responseWrapper; } - @PreAuthorize("hasAnyRole(@authorizedRoles.getPostdeactivateftm())") - @PostMapping(value = "/deactivate-ftm") + @PreAuthorize("hasAnyRole(@authorizedRoles.getPatchdeactivateftm())") + @PatchMapping(value = "/{ftmId}") @Operation(summary = "Deactivate FTM details", description = "This endpoint will deactivate FTM Chip details based on the FTM Id sent in the Request Body.") @io.swagger.v3.oas.annotations.responses.ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "OK"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))) }) - public ResponseWrapperV2 deactivateFtm(@RequestBody @Valid RequestWrapperV2 requestWrapper) { - Optional> validationResponse = requestValidator.validate(postDeactivateFtmId, requestWrapper); - if (validationResponse.isPresent()) { - return validationResponse.get(); - } - return ftpChipDetaillService.deactivateFtm(requestWrapper.getRequest().getFtmId()); + public ResponseWrapperV2 deactivateFtm(@PathVariable("ftmId") @NotBlank String ftmId) { + return ftpChipDetaillService.deactivateFtm(ftmId); } @PreAuthorize("hasAnyRole(@authorizedRoles.getGetoriginalftmcertificate())") - @RequestMapping(value = "/{ftmId}/original-ftm-certificate", method = RequestMethod.GET) + @RequestMapping(value = "/{ftmId}/certificate-data", method = RequestMethod.GET) @Operation(summary = "Service to get original FTM certificate", description = "This endpoint will fetch both the CA signed certifacte uploaded by the FTM Chip Provider and the MOSIP signed certificate, which is generated by PMS after the CA signed certificate is uploaded by the FTM Chip Provider.") @io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "OK"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) - public ResponseWrapperV2 getOriginalFtmCertificate( + public ResponseWrapperV2 getFtmCertificateData( @ApiParam("To download original FTM certificate.") @PathVariable("ftmId") @NotNull String ftmId) throws JsonParseException, JsonMappingException, JsonProcessingException, IOException, CertificateException { - return ftpChipDetaillService.getOriginalFtmCertificate(ftmId); + return ftpChipDetaillService.getFtmCertificateData(ftmId); } @PreAuthorize("hasAnyRole(@authorizedRoles.getGetpartnersftmchipdetails())") @@ -318,4 +312,14 @@ ResponseWrapperV2> getPartnersFtmChipDeta } return ftpChipDetaillService.getPartnersFtmChipDetails(sortFieldName, sortType, pageNo, pageSize, filterDto); } + + @PreAuthorize("hasAnyRole(@authorizedRoles.getGetftmchipdetails())") + @GetMapping + @Operation(summary = "Get list of all the FTM Chip details", description = "This endpoint will fetch the list of all the FTM Chip details created by all the partner Id's associated with the logged in user") + @io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "OK"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) + public ResponseWrapperV2> ftmChipDetail() { + return ftpChipDetaillService.ftmChipDetail(); + } } diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/controller/SecureBiometricInterfaceController.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/controller/SecureBiometricInterfaceController.java index fe4f5e855f..04807ce633 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/controller/SecureBiometricInterfaceController.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/controller/SecureBiometricInterfaceController.java @@ -1,14 +1,15 @@ package io.mosip.pms.device.controller; import javax.validation.Valid; +import javax.validation.constraints.NotBlank; import io.mosip.pms.common.dto.PageResponseV2Dto; import io.mosip.pms.common.request.dto.RequestWrapperV2; import io.mosip.pms.common.response.dto.ResponseWrapperV2; import io.mosip.pms.device.dto.SbiFilterDto; import io.mosip.pms.partner.dto.DeviceDetailDto; -import io.mosip.pms.device.request.dto.DeactivateSbiRequestDto; import io.mosip.pms.device.response.dto.SbiDetailsResponseDto; +import io.mosip.pms.device.dto.SbiDetailsDto; import io.mosip.pms.partner.util.PartnerHelper; import io.mosip.pms.partner.util.RequestValidator; import io.swagger.v3.oas.annotations.Parameter; @@ -26,7 +27,6 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import io.mosip.kernel.core.http.ResponseFilter; @@ -63,9 +63,6 @@ @Api(tags = { "SecureBiometricInterface" }) public class SecureBiometricInterfaceController { - @Value("${mosip.pms.api.id.deactivate.sbi.post}") - private String postDeactivateSbiId; - @Autowired SecureBiometricInterfaceService secureBiometricInterface; @@ -217,7 +214,7 @@ public ResponseWrapper filterValues( } @PreAuthorize("hasAnyRole(@authorizedRoles.getGetsbidetails())") - @GetMapping(value = "/sbi-devices/{sbiId}") + @GetMapping(value = "/{sbiId}/devices") @Operation(summary = "Get all device list mapped with SBI.", description = "Get all device list mapped with SBI.") @io.swagger.v3.oas.annotations.responses.ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "OK"), @@ -228,20 +225,26 @@ public ResponseWrapperV2> getAllDevicesForSbi(@PathVariabl return secureBiometricInterface.getAllDevicesForSbi(sbiId); } - @PreAuthorize("hasAnyRole(@authorizedRoles.getPostdeactivatesbi())") - @PostMapping(value = "/deactivate-sbi") + @PreAuthorize("hasAnyRole(@authorizedRoles.getGetsbidetails())") + @GetMapping + @Operation(summary = "get all SBI details list.", description = "get all SBI details list associated with partner.") + @io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "OK"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) + public ResponseWrapperV2> getSbiDetails() { + return secureBiometricInterface.getSbiDetails(); + } + + @PreAuthorize("hasAnyRole(@authorizedRoles.getPatchdeactivatesbi())") + @PatchMapping(value = "/{sbiId}") @Operation(summary = "Deactivate SBI along with associated devices", description = "Deactivate SBI along with associated devices") @io.swagger.v3.oas.annotations.responses.ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "OK"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))) }) - public ResponseWrapperV2 deactivateSbi(@RequestBody @Valid RequestWrapperV2 requestWrapper) { - Optional> validationResponse = requestValidator.validate(postDeactivateSbiId, requestWrapper); - if (validationResponse.isPresent()) { - return validationResponse.get(); - } - return secureBiometricInterface.deactivateSbi(requestWrapper.getRequest().getSbiId()); + public ResponseWrapperV2 deactivateSbi(@PathVariable("sbiId") @NotBlank String sbiId) { + return secureBiometricInterface.deactivateSbi(sbiId); } @PreAuthorize("hasAnyRole(@authorizedRoles.getGetallsbidetails())") diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/FtmChipDetailsDto.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/dto/FtmChipDetailsDto.java similarity index 98% rename from partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/FtmChipDetailsDto.java rename to partner/partner-management-service/src/main/java/io/mosip/pms/device/dto/FtmChipDetailsDto.java index 8f399cf2e6..ff90b62509 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/FtmChipDetailsDto.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/dto/FtmChipDetailsDto.java @@ -1,4 +1,4 @@ -package io.mosip.pms.partner.dto; +package io.mosip.pms.device.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/SbiDetailsDto.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/dto/SbiDetailsDto.java similarity index 92% rename from partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/SbiDetailsDto.java rename to partner/partner-management-service/src/main/java/io/mosip/pms/device/dto/SbiDetailsDto.java index c9d2b9aa59..44929b5572 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/SbiDetailsDto.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/dto/SbiDetailsDto.java @@ -1,4 +1,4 @@ -package io.mosip.pms.partner.dto; +package io.mosip.pms.device.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -30,10 +30,10 @@ public class SbiDetailsDto { private boolean isSbiExpired; @Schema(description = "Number of approved devices associated with the SBI", example = "29") - private String countOfApprovedDevices; + private Integer countOfApprovedDevices; @Schema(description = "Number of pending devices associated with the SBI", example = "10") - private String countOfPendingDevices; + private Integer countOfPendingDevices; @Schema(description = "Date and time when the SBI was created", example = "2024-07-15T10:00:00Z") private LocalDateTime sbiCreatedDateTime; diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/request/dto/DeactivateDeviceRequestDto.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/request/dto/DeactivateDeviceRequestDto.java deleted file mode 100644 index 71ef87551c..0000000000 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/request/dto/DeactivateDeviceRequestDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.mosip.pms.device.request.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Data -public class DeactivateDeviceRequestDto { - - @Schema(description = "Unique identifier for the device details", example = "device789") - private String deviceId; -} diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/request/dto/DeactivateFtmRequestDto.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/request/dto/DeactivateFtmRequestDto.java deleted file mode 100644 index a47f056cc7..0000000000 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/request/dto/DeactivateFtmRequestDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.mosip.pms.device.request.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Data -public class DeactivateFtmRequestDto { - - @Schema(description = "Unique identifier for the FTM", example = "ftm456") - private String ftmId; -} diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/request/dto/DeactivateSbiRequestDto.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/request/dto/DeactivateSbiRequestDto.java deleted file mode 100644 index 978cd184cd..0000000000 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/request/dto/DeactivateSbiRequestDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.mosip.pms.device.request.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Data -public class DeactivateSbiRequestDto { - - @Schema(description = "Unique identifier for the SBI", example = "sbi456") - private String sbiId; -} diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/oauth/client/dto/OauthClientDto.java b/partner/partner-management-service/src/main/java/io/mosip/pms/oauth/client/dto/OauthClientDto.java index e28a213e53..20d03a7132 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/oauth/client/dto/OauthClientDto.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/oauth/client/dto/OauthClientDto.java @@ -8,8 +8,6 @@ @Data public class OauthClientDto { - @Schema(description = "Unique identifier for the user", example = "user789") - private String userId; @Schema(description = "Unique identifier for the partner", example = "partner123") private String partnerId; diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/oauth/client/service/impl/ClientManagementServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/oauth/client/service/impl/ClientManagementServiceImpl.java index 8aad018b07..b48378ec1b 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/oauth/client/service/impl/ClientManagementServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/oauth/client/service/impl/ClientManagementServiceImpl.java @@ -773,7 +773,6 @@ public ResponseWrapperV2> getClients() { } OauthClientDto oauthClientDto = new OauthClientDto(); oauthClientDto.setPartnerId(partnerId); - oauthClientDto.setUserId(userId); oauthClientDto.setClientId(clientDetail.getId()); oauthClientDto.setClientName(clientDetail.getName()); oauthClientDto.setPolicyGroupId(policyGroup.getId()); diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/controller/MultiPartnerAdminServiceController.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/controller/MultiPartnerAdminServiceController.java deleted file mode 100644 index f9c7b598f3..0000000000 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/controller/MultiPartnerAdminServiceController.java +++ /dev/null @@ -1,76 +0,0 @@ -package io.mosip.pms.partner.controller; - -import io.mosip.pms.common.request.dto.RequestWrapperV2; -import io.mosip.pms.common.response.dto.ResponseWrapperV2; -import io.mosip.pms.partner.request.dto.SbiAndDeviceMappingRequestDto; -import io.mosip.pms.partner.service.MultiPartnerAdminService; -import io.mosip.pms.partner.util.RequestValidator; -import io.swagger.annotations.Api; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.validation.Valid; -import java.util.Objects; -import java.util.Optional; - -@RestController -@RequestMapping(value = "/admin") -@Api(tags = {"Multi Partner Admin Service Controller"}) -public class MultiPartnerAdminServiceController { - - public static final String VERSION = "1.0"; - - @Value("${mosip.pms.api.id.approve.mapping.device.to.sbi.post:mosip.pms.approve.mapping.device.to.sbi.post}") - private String postApproveMappingDeviceToSbiId; - - @Value("${mosip.pms.api.id.reject.mapping.device.to.sbi.post:mosip.pms.reject.mapping.device.to.sbi.post}") - private String postRejectMappingDeviceToSbiId; - - @Autowired - MultiPartnerAdminService multiPartnerAdminService; - - @Autowired - RequestValidator requestValidator; - - @PreAuthorize("hasAnyRole(@authorizedRoles.getPostapproveorrejectdevicewithsbimapping())") - @PostMapping(value = "/approve-mapping-device-to-sbi") - @Operation(summary = "Approve device and activate device mapping to sbi.", description = "Approve device and activate device mapping to sbi.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))) - }) - public ResponseWrapperV2 approveMappingDeviceToSbi(@RequestBody @Valid RequestWrapperV2 requestWrapper) { - Optional> validationResponse = requestValidator.validate(postApproveMappingDeviceToSbiId, requestWrapper); - if (validationResponse.isPresent()) { - return validationResponse.get(); - } - return multiPartnerAdminService.approveOrRejectMappingDeviceToSbi(requestWrapper.getRequest(), false); - } - - @PreAuthorize("hasAnyRole(@authorizedRoles.getPostapproveorrejectdevicewithsbimapping())") - @PostMapping(value = "/reject-mapping-device-to-sbi") - @Operation(summary = "Reject device and activate device mapping to sbi.", description = "Reject device and activate device mapping to sbi.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))) - }) - public ResponseWrapperV2 rejectMappingDeviceToSbi(@RequestBody @Valid RequestWrapperV2 requestWrapper) { - Optional> validationResponse = requestValidator.validate(postRejectMappingDeviceToSbiId, requestWrapper); - if (validationResponse.isPresent()) { - return validationResponse.get(); - } - return multiPartnerAdminService.approveOrRejectMappingDeviceToSbi(requestWrapper.getRequest(), true); - } -} diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/controller/MultiPartnerServiceController.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/controller/MultiPartnerServiceController.java index d379637e8f..93900e6e78 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/controller/MultiPartnerServiceController.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/controller/MultiPartnerServiceController.java @@ -1,6 +1,7 @@ package io.mosip.pms.partner.controller; import io.mosip.pms.common.response.dto.ResponseWrapperV2; +import io.mosip.pms.device.dto.FtmChipDetailsDto; import io.mosip.pms.partner.dto.*; import io.mosip.pms.partner.service.MultiPartnerService; import io.mosip.pms.partner.util.RequestValidator; @@ -12,9 +13,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.*; @@ -29,26 +28,6 @@ public class MultiPartnerServiceController { @Autowired RequestValidator requestValidator; - @PreAuthorize("hasAnyRole(@authorizedRoles.getGetpartnercertificates())") - @GetMapping(value = "/partner-certificates") - @Operation(summary = "Get partner certificates", description = "fetch partner certificates") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) - public ResponseWrapperV2> getPartnerCertificates() { - return multiPartnerService.getPartnerCertificates(); - } - - @PreAuthorize("hasAnyRole(@authorizedRoles.getGetpolicyrequests())") - @GetMapping(value = "/policy-requests") - @Operation(summary = "Get all policies", description = "fetch all policies") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) - public ResponseWrapperV2> getPolicyRequests() { - return multiPartnerService.getPolicyRequests(); - } - @PreAuthorize("hasAnyRole(@authorizedRoles.getGetauthpartnerspolicies())") @GetMapping(value = "/auth-partners-policies") @Operation(summary = "Get all approved auth partner policies", description = "fetch all approved auth partner policies") @@ -69,26 +48,6 @@ public ResponseWrapperV2> getApprovedPartnerIdsWithPolicyGr return multiPartnerService.getApprovedPartnerIdsWithPolicyGroups(); } - @PreAuthorize("hasAnyRole(@authorizedRoles.getGetapikeysforauthpartners())") - @GetMapping(value = "/api-keys-for-auth-partners") - @Operation(summary = "Get all api keys for auth partners", description = "fetch all api keys for auth partners") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) - public ResponseWrapperV2> getApiKeysForAuthPartners() { - return multiPartnerService.getApiKeysForAuthPartners(); - } - - @PreAuthorize("hasAnyRole(@authorizedRoles.getGetsbidetails())") - @GetMapping(value = "/sbi-details") - @Operation(summary = "get all SBI details list.", description = "get all SBI details list associated with partner.") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) - public ResponseWrapperV2> sbiDetails() { - return multiPartnerService.sbiDetails(); - } - @PreAuthorize("hasAnyRole(@authorizedRoles.getGetapproveddeviceproviderids())") @GetMapping(value = "/approved-device-provider-ids") @Operation(summary = "get all approved device providers id.", description = "get all approved device providers id.") @@ -99,16 +58,6 @@ public ResponseWrapperV2> approvedDeviceProviderIds() { return multiPartnerService.approvedDeviceProviderIds(); } - @PreAuthorize("hasAnyRole(@authorizedRoles.getGetftmchipdetails())") - @GetMapping(value = "/ftm-chip-details") - @Operation(summary = "Get list of all the FTM Chip details", description = "This endpoint will fetch the list of all the FTM Chip details created by all the partner Id's associated with the logged in user") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) - public ResponseWrapperV2> ftmChipDetails() { - return multiPartnerService.ftmChipDetails(); - } - @PreAuthorize("hasAnyRole(@authorizedRoles.getGetapprovedftmproviderids())") @GetMapping(value = "/approved-ftm-provider-ids") @Operation(summary = "Get all approved FTM providers ids.", description = "This endpoint will fetch list of all the approved FTM provider ID's mapped to the logged in user.") diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/controller/PartnerServiceController.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/controller/PartnerServiceController.java index 6486f852ea..8711c8903e 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/controller/PartnerServiceController.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/controller/PartnerServiceController.java @@ -10,6 +10,9 @@ import javax.validation.constraints.NotNull; import io.mosip.pms.common.response.dto.ResponseWrapperV2; +import io.mosip.pms.partner.dto.ApiKeyResponseDto; +import io.mosip.pms.partner.dto.CertificateDto; +import io.mosip.pms.partner.dto.PolicyDto; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -357,18 +360,48 @@ public ResponseWrapper getPartnerCertificate( } @PreAuthorize("hasAnyRole(@authorizedRoles.getGetpartnerscertificate())") - @RequestMapping(value = "/{partnerId}/original-partner-certificate", method = RequestMethod.GET) - @Operation(summary = "Service to get original partner certificate", description = "Service to get original partner certificate") + @GetMapping(value = "/{partnerId}/certificate-data") + @Operation(summary = "Service to get original partner certificate data", description = "Service to get original partner certificate data") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) - public ResponseWrapperV2 getOriginalPartnerCertificate( + public ResponseWrapperV2 getPartnerCertificateData( @ApiParam("To download original partner certificate.") @PathVariable("partnerId") @NotNull String partnerId) throws JsonParseException, JsonMappingException, JsonProcessingException, IOException, CertificateException { PartnerCertDownloadRequestDto requestDto = new PartnerCertDownloadRequestDto(); requestDto.setPartnerId(partnerId); - return partnerService.getOriginalPartnerCertificate(requestDto); + return partnerService.getPartnerCertificateData(requestDto); } - + + @PreAuthorize("hasAnyRole(@authorizedRoles.getGetpolicyrequests())") + @GetMapping(value = "/policy-requests") + @Operation(summary = "Get all policies", description = "fetch all policies") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), + @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) + public ResponseWrapperV2> getPolicyRequests() { + return partnerService.getPolicyRequests(); + } + + @PreAuthorize("hasAnyRole(@authorizedRoles.getGetpartnercertificates())") + @GetMapping(value = "/partner-certificates-details") + @Operation(summary = "Get partner certificates", description = "fetch partner certificates") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), + @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) + public ResponseWrapperV2> getPartnerCertificatesDetails() { + return partnerService.getPartnerCertificatesDetails(); + } + + @PreAuthorize("hasAnyRole(@authorizedRoles.getGetapikeysforauthpartners())") + @GetMapping(value = "/auth-partner-api-keys") + @Operation(summary = "Get all api keys for auth partners", description = "fetch all api keys for auth partners") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), + @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) + public ResponseWrapperV2> getAuthPartnerApiKeys() { + return partnerService.getAuthPartnerApiKeys(); + } + @ResponseFilter @PostMapping("/search") @PreAuthorize("hasAnyRole(@authorizedRoles.getPostpartnerssearch())") diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/AuthorizedRolesDto.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/AuthorizedRolesDto.java index 6c53e5cf49..8e9a122a58 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/AuthorizedRolesDto.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/AuthorizedRolesDto.java @@ -173,17 +173,17 @@ public class AuthorizedRolesDto { private List postinactivemappingdevicetosbi; - private List postapproveorrejectdevicewithsbimapping; + private List postdevicewithsbimapping; - private List postdeactivatedevice; + private List patchdeactivatedevice; - private List postdeactivatesbi; + private List patchdeactivatesbi; private List getftmchipdetails; private List getapprovedftmproviderids; - private List postdeactivateftm; + private List patchdeactivateftm; private List getoriginalftmcertificate; diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/DeviceDetailDto.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/DeviceDetailDto.java index 0e00c4a363..549be61ab0 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/DeviceDetailDto.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/DeviceDetailDto.java @@ -14,7 +14,7 @@ public class DeviceDetailDto { @Schema(description = "Code representing the id of the device. The id can either be provided by the user as a unique ID or left as null. If it's provided, that unique ID will be used as the device_detail_id. If it's null, the service will automatically generate a unique ID for the device_detail_id.", example = "12345") - private String id; + private String deviceId; @Schema(description = "Code representing the type of device", example = "DT001") private String deviceTypeCode; diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/PolicyDto.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/PolicyDto.java index 1a5fc97440..662cd45716 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/PolicyDto.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/dto/PolicyDto.java @@ -42,7 +42,7 @@ public class PolicyDto { private String policyDescription; @Schema(description = "Comments or notes from the partner about the policy", example = "Requires annual review.") - private String partnerComments; + private String partnerComment; @Schema(description = "Date and time when the policy was last updated", example = "2024-08-01T14:30:00Z") private LocalDateTime updatedDateTime; diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/request/dto/SbiAndDeviceMappingRequestDto.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/request/dto/SbiAndDeviceMappingRequestDto.java index f8a41ecea0..b4f0f12e1e 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/request/dto/SbiAndDeviceMappingRequestDto.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/request/dto/SbiAndDeviceMappingRequestDto.java @@ -13,4 +13,7 @@ public class SbiAndDeviceMappingRequestDto { @Schema(description = "Unique identifier for the device details", example = "device789") private String deviceDetailId; + + @Schema(description = "status of the SBI and Device mapping request", example = "approved") + private String status; } diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/MultiPartnerAdminService.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/MultiPartnerAdminService.java deleted file mode 100644 index cf6c71b1ca..0000000000 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/MultiPartnerAdminService.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.mosip.pms.partner.service; - -import io.mosip.pms.common.response.dto.ResponseWrapperV2; -import io.mosip.pms.partner.request.dto.SbiAndDeviceMappingRequestDto; - -public interface MultiPartnerAdminService { - - public ResponseWrapperV2 approveOrRejectMappingDeviceToSbi(SbiAndDeviceMappingRequestDto requestDto, boolean rejectFlag); -} diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/MultiPartnerService.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/MultiPartnerService.java index beeb8d8a75..0f72c38528 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/MultiPartnerService.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/MultiPartnerService.java @@ -1,27 +1,18 @@ package io.mosip.pms.partner.service; import io.mosip.pms.common.response.dto.ResponseWrapperV2; +import io.mosip.pms.device.dto.FtmChipDetailsDto; import io.mosip.pms.partner.dto.*; import java.util.List; public interface MultiPartnerService { - public ResponseWrapperV2> getPartnerCertificates(); - - public ResponseWrapperV2> getPolicyRequests(); - public ResponseWrapperV2> getAuthPartnersPolicies(); public ResponseWrapperV2> getApprovedPartnerIdsWithPolicyGroups(); - public ResponseWrapperV2> getApiKeysForAuthPartners(); - - public ResponseWrapperV2> sbiDetails(); - public ResponseWrapperV2> approvedDeviceProviderIds(); - public ResponseWrapperV2> ftmChipDetails(); - public ResponseWrapperV2> approvedFTMProviderIds(); } diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/PartnerService.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/PartnerService.java index b5f93d7bae..7118e77b61 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/PartnerService.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/PartnerService.java @@ -14,11 +14,12 @@ import io.mosip.pms.common.dto.PolicyRequestSearchResponseDto; import io.mosip.pms.common.dto.SearchDto; import io.mosip.pms.common.entity.PartnerType; -import io.mosip.pms.common.response.dto.ResponseWrapper; import io.mosip.pms.common.response.dto.ResponseWrapperV2; import io.mosip.pms.device.response.dto.FilterResponseCodeDto; +import io.mosip.pms.partner.dto.ApiKeyResponseDto; import io.mosip.pms.partner.dto.CertificateDto; import io.mosip.pms.partner.dto.PartnerPolicyMappingResponseDto; +import io.mosip.pms.partner.dto.PolicyDto; import io.mosip.pms.partner.request.dto.AddContactRequestDto; import io.mosip.pms.partner.request.dto.CACertificateRequestDto; import io.mosip.pms.partner.request.dto.ExtractorsDto; @@ -126,7 +127,7 @@ public interface PartnerService { * @throws JsonMappingException * @throws JsonParseException */ - public ResponseWrapperV2 getOriginalPartnerCertificate(PartnerCertDownloadRequestDto certDownloadRequestDto) throws JsonParseException, JsonMappingException, JsonProcessingException, IOException, CertificateException; + public ResponseWrapperV2 getPartnerCertificateData(PartnerCertDownloadRequestDto certDownloadRequestDto) throws JsonParseException, JsonMappingException, JsonProcessingException, IOException, CertificateException; /** * Function to add biometric extractors @@ -234,4 +235,10 @@ public interface PartnerService { */ public PartnerResponse registerPartner(PartnerRequestDto request); + public ResponseWrapperV2> getPolicyRequests(); + + public ResponseWrapperV2> getPartnerCertificatesDetails(); + + public ResponseWrapperV2> getAuthPartnerApiKeys(); + } diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/MultiPartnerAdminServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/MultiPartnerAdminServiceImpl.java deleted file mode 100644 index 531cc9a725..0000000000 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/MultiPartnerAdminServiceImpl.java +++ /dev/null @@ -1,114 +0,0 @@ -package io.mosip.pms.partner.service.impl; - -import io.mosip.kernel.core.logger.spi.Logger; -import io.mosip.pms.common.entity.DeviceDetailSBI; -import io.mosip.pms.common.repository.*; -import io.mosip.pms.common.response.dto.ResponseWrapperV2; -import io.mosip.pms.common.util.PMSLogger; -import io.mosip.pms.device.authdevice.repository.SecureBiometricInterfaceRepository; -import io.mosip.pms.device.authdevice.service.impl.DeviceDetailServiceImpl; -import io.mosip.pms.device.constant.DeviceConstant; -import io.mosip.pms.device.request.dto.UpdateDeviceDetailStatusDto; -import io.mosip.pms.partner.constant.ErrorCode; -import io.mosip.pms.partner.exception.PartnerServiceException; -import io.mosip.pms.partner.request.dto.SbiAndDeviceMappingRequestDto; -import io.mosip.pms.partner.service.MultiPartnerAdminService; -import io.mosip.pms.partner.util.PartnerHelper; -import io.mosip.pms.partner.util.MultiPartnerUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -import java.util.Objects; - -@Service -public class MultiPartnerAdminServiceImpl implements MultiPartnerAdminService { - - private static final Logger LOGGER = PMSLogger.getLogger(MultiPartnerAdminServiceImpl.class); - public static final String APPROVED = "approved"; - public static final String VERSION = "1.0"; - - @Value("${mosip.pms.api.id.approve.mapping.device.to.sbi.post:mosip.pms.approve.mapping.device.to.sbi.post}") - private String postApproveMappingDeviceToSbiId; - - @Value("${mosip.pms.api.id.reject.mapping.device.to.sbi.post:mosip.pms.reject.mapping.device.to.sbi.post}") - private String postRejectMappingDeviceToSbiId; - - @Autowired - SecureBiometricInterfaceRepository secureBiometricInterfaceRepository; - - @Autowired - DeviceDetailSbiRepository deviceDetailSbiRepository; - - @Autowired - DeviceDetailServiceImpl deviceDetailService; - - @Autowired - PartnerHelper partnerHelper; - - @Override - public ResponseWrapperV2 approveOrRejectMappingDeviceToSbi(SbiAndDeviceMappingRequestDto requestDto, boolean rejectFlag) { - ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); - try { - String partnerId = requestDto.getPartnerId(); - String sbiId = requestDto.getSbiId(); - String deviceDetailId = requestDto.getDeviceDetailId(); - if(Objects.isNull(sbiId)) { - LOGGER.info("sessionId", "idType", "id", "SBI id is null."); - if (!rejectFlag) { - throw new PartnerServiceException(ErrorCode.NO_SBI_FOUND_FOR_APPROVE.getErrorCode(), - ErrorCode.NO_SBI_FOUND_FOR_APPROVE.getErrorMessage()); - } else { - throw new PartnerServiceException(ErrorCode.NO_SBI_FOUND_FOR_REJECT.getErrorCode(), - ErrorCode.NO_SBI_FOUND_FOR_REJECT.getErrorMessage()); - } - } - if (Objects.isNull(partnerId) || Objects.isNull(deviceDetailId)) { - LOGGER.info("sessionId", "idType", "id", "Partner/Device id does not exist."); - throw new PartnerServiceException(ErrorCode.INVALID_REQUEST_PARAM.getErrorCode(), - ErrorCode.INVALID_REQUEST_PARAM.getErrorMessage()); - } - // validate sbi and device mapping - partnerHelper.validateSbiDeviceMapping(partnerId, sbiId, deviceDetailId); - - DeviceDetailSBI deviceDetailSBI = deviceDetailSbiRepository.findByDeviceProviderIdAndSbiIdAndDeviceDetailId(partnerId, sbiId, deviceDetailId); - if (Objects.isNull(deviceDetailSBI)) { - LOGGER.info("sessionId", "idType", "id", "SBI and Device mapping already exists in DB."); - throw new PartnerServiceException(ErrorCode.SBI_DEVICE_MAPPING_NOT_EXISTS.getErrorCode(), - ErrorCode.SBI_DEVICE_MAPPING_NOT_EXISTS.getErrorMessage()); - } - - UpdateDeviceDetailStatusDto deviceDetails = new UpdateDeviceDetailStatusDto(); - deviceDetails.setId(deviceDetailId); - if (rejectFlag) { - deviceDetails.setApprovalStatus(DeviceConstant.REJECT); - } else { - deviceDetails.setApprovalStatus(DeviceConstant.APPROVE); - } - deviceDetailService.updateDeviceDetailStatus(deviceDetails); - - deviceDetailSBI.setIsActive(true); - deviceDetailSbiRepository.save(deviceDetailSBI); - LOGGER.info("sessionId", "idType", "id", "updated device mapping to sbi successfully in Db."); - responseWrapper.setResponse(true); - } catch (PartnerServiceException ex) { - LOGGER.info("sessionId", "idType", "id", "In approveOrRejectMappingDeviceToSbi method of MultiPartnerAdminServiceImpl - " + ex.getMessage()); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); - } catch (Exception ex) { - LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace()); - LOGGER.error("sessionId", "idType", "id", - "In approveOrRejectMappingDeviceToSbi method of MultiPartnerAdminServiceImpl - " + ex.getMessage()); - String errorCode = ErrorCode.APPROVE_OR_REJECT_DEVICE_WITH_SBI_MAPPING_ERROR.getErrorCode(); - String errorMessage = ErrorCode.APPROVE_OR_REJECT_DEVICE_WITH_SBI_MAPPING_ERROR.getErrorMessage(); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); - } - if (rejectFlag){ - responseWrapper.setId(postRejectMappingDeviceToSbiId); - } else { - responseWrapper.setId(postApproveMappingDeviceToSbiId); - } - responseWrapper.setVersion(VERSION); - return responseWrapper; - } - -} diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/MultiPartnerServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/MultiPartnerServiceImpl.java index cad6e55115..d2a5ad99d8 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/MultiPartnerServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/MultiPartnerServiceImpl.java @@ -7,39 +7,26 @@ import io.mosip.pms.common.exception.ApiAccessibleException; import io.mosip.pms.common.repository.AuthPolicyRepository; import io.mosip.pms.common.repository.PartnerPolicyRepository; -import io.mosip.pms.common.repository.PolicyGroupRepository; import io.mosip.pms.common.repository.PartnerServiceRepository; import io.mosip.pms.common.repository.DeviceDetailSbiRepository; import io.mosip.pms.common.response.dto.ResponseWrapperV2; import io.mosip.pms.common.util.PMSLogger; -import io.mosip.pms.device.authdevice.entity.DeviceDetail; -import io.mosip.pms.device.authdevice.entity.FTPChipDetail; -import io.mosip.pms.device.authdevice.entity.SecureBiometricInterface; import io.mosip.pms.device.authdevice.repository.DeviceDetailRepository; import io.mosip.pms.device.authdevice.repository.FTPChipDetailRepository; import io.mosip.pms.device.authdevice.repository.SecureBiometricInterfaceRepository; import io.mosip.pms.device.authdevice.service.impl.FTPChipDetailServiceImpl; -import io.mosip.pms.device.request.dto.FtpChipCertDownloadRequestDto; -import io.mosip.pms.device.response.dto.FtpCertDownloadResponeDto; +import io.mosip.pms.device.dto.FtmChipDetailsDto; import io.mosip.pms.partner.constant.ErrorCode; import io.mosip.pms.partner.dto.*; import io.mosip.pms.partner.exception.PartnerServiceException; -import io.mosip.pms.partner.request.dto.PartnerCertDownloadRequestDto; -import io.mosip.pms.partner.response.dto.PartnerCertDownloadResponeDto; import io.mosip.pms.partner.service.MultiPartnerService; import io.mosip.pms.partner.util.PartnerHelper; import io.mosip.pms.partner.util.MultiPartnerUtil; -import io.mosip.pms.partner.util.PartnerUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; -import java.security.cert.X509Certificate; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.ZoneOffset; import java.util.*; @Service @@ -48,48 +35,26 @@ public class MultiPartnerServiceImpl implements MultiPartnerService { private static final Logger LOGGER = PMSLogger.getLogger(MultiPartnerServiceImpl.class); public static final String BLANK_STRING = ""; public static final String DEVICE_PROVIDER = "Device_Provider"; - public static final String FTM_PROVIDER = "FTM_Provider"; - public static final String AUTH_PARTNER = "Auth_Partner"; public static final String APPROVED = "approved"; public static final String ACTIVE = "ACTIVE"; public static final String INACTIVE = "INACTIVE"; - public static final String YES = "YES"; - public static final String PENDING_APPROVAL = "pending_approval"; public static final String VERSION = "1.0"; - @Value("${mosip.pms.api.id.partner.certificates.get}") - private String getPartnerCertificatesId; - - @Value("${mosip.pms.api.id.policy.requests.get}") - private String getPolicyRequestsId; - @Value("${mosip.pms.api.id.approved.partner.ids.with.policy.groups.get}") private String getApprovedPartnerIdsWithPolicyGroupsId; @Value("${mosip.pms.api.id.auth.partners.policies.get}") private String getAuthPartnersPoliciesId; - @Value("${mosip.pms.api.id.api.keys.for.auth.partners.get}") - private String getApiKeysForAuthPartnersId; - - @Value("${mosip.pms.api.id.sbi.details.get}") - private String getSbiDetailsId; - @Value("${mosip.pms.api.id.approved.device.provider.ids.get}") private String getApprovedDeviceProviderIds; - @Value("${mosip.pms.api.id.ftm.chip.details.get}") - private String getFtmChipDetailsId; - @Value("${mosip.pms.api.id.approved.ftm.provider.ids.get}") private String getApprovedFtmProviderIds; @Autowired PartnerServiceRepository partnerRepository; - @Autowired - PolicyGroupRepository policyGroupRepository; - @Autowired AuthPolicyRepository authPolicyRepository; @@ -120,137 +85,6 @@ public class MultiPartnerServiceImpl implements MultiPartnerService { @Autowired PartnerHelper partnerHelper; - @Override - public ResponseWrapperV2> getPartnerCertificates() { - ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); - try { - String userId = getUserId(); - List partnerList = partnerRepository.findByUserId(userId); - if (!partnerList.isEmpty()) { - List certificateDtoList = new ArrayList<>(); - for (Partner partner : partnerList) { - CertificateDto certificateDto = new CertificateDto(); - try { - if (Objects.isNull(partner.getId()) || partner.getId().equals(BLANK_STRING)) { - LOGGER.info("Partner Id is null or empty for user id : " + userId); - throw new PartnerServiceException(ErrorCode.PARTNER_ID_NOT_EXISTS.getErrorCode(), - ErrorCode.PARTNER_ID_NOT_EXISTS.getErrorMessage()); - } - PartnerCertDownloadRequestDto requestDto = new PartnerCertDownloadRequestDto(); - requestDto.setPartnerId(partner.getId()); - PartnerCertDownloadResponeDto partnerCertDownloadResponeDto = partnerServiceImpl.getPartnerCertificate(requestDto); - X509Certificate cert = MultiPartnerUtil.decodeCertificateData(partnerCertDownloadResponeDto.getCertificateData()); - - certificateDto.setIsCertificateAvailable(true); - certificateDto.setCertificateIssuedTo(PartnerUtil.getCertificateName(cert.getSubjectDN().getName())); - certificateDto.setCertificateUploadDateTime(cert.getNotBefore()); - certificateDto.setCertificateExpiryDateTime(cert.getNotAfter()); - certificateDto.setPartnerId(partner.getId()); - certificateDto.setPartnerType(partner.getPartnerTypeCode()); - } catch (PartnerServiceException ex) { - LOGGER.info("Could not fetch partner certificate :" + ex.getMessage()); - certificateDto.setIsCertificateAvailable(false); - certificateDto.setPartnerId(partner.getId()); - certificateDto.setPartnerType(partner.getPartnerTypeCode()); - } - if (partner.getApprovalStatus().equals(APPROVED) && !partner.getIsActive()) { - certificateDto.setIsPartnerActive(false); - } else { - certificateDto.setIsPartnerActive(true); - } - certificateDtoList.add(certificateDto); - } - responseWrapper.setResponse(certificateDtoList); - } else { - LOGGER.info("sessionId", "idType", "id", "User id does not exists."); - throw new PartnerServiceException(ErrorCode.USER_ID_NOT_EXISTS.getErrorCode(), - ErrorCode.USER_ID_NOT_EXISTS.getErrorMessage()); - } - } catch (ApiAccessibleException ex) { - LOGGER.info("sessionId", "idType", "id", "In getPartnerCertificates method of MultiPartnerServiceImpl - " + ex.getMessage()); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); - } catch (PartnerServiceException ex) { - LOGGER.info("sessionId", "idType", "id", "In getPartnerCertificates method of MultiPartnerServiceImpl - " + ex.getMessage()); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); - } catch (Exception ex) { - LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace()); - LOGGER.error("sessionId", "idType", "id", - "In getPartnerCertificates method of MultiPartnerServiceImpl - " + ex.getMessage()); - String errorCode = ErrorCode.PARTNER_CERTIFICATES_FETCH_ERROR.getErrorCode(); - String errorMessage = ErrorCode.PARTNER_CERTIFICATES_FETCH_ERROR.getErrorMessage(); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); - } - responseWrapper.setId(getPartnerCertificatesId); - responseWrapper.setVersion(VERSION); - return responseWrapper; - } - - @Override - public ResponseWrapperV2> getPolicyRequests() { - ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); - try { - String userId = getUserId(); - List partnerList = partnerRepository.findByUserId(userId); - if (!partnerList.isEmpty()) { - List policyDtoList = new ArrayList<>(); - for (Partner partner : partnerList) { - if (!skipDeviceOrFtmPartner(partner)) { - validatePartnerId(partner, userId); - validatePolicyGroupId(partner, userId); - PolicyGroup policyGroup = validatePolicyGroup(partner); - List partnerPolicyRequestList = partner.getPartnerPolicyRequests(); - if (!partnerPolicyRequestList.isEmpty()) { - for (PartnerPolicyRequest partnerPolicyRequest : partnerPolicyRequestList) { - AuthPolicy policyDetails = authPolicyRepository.findByPolicyGroupAndId(partner.getPolicyGroupId(), partnerPolicyRequest.getPolicyId()); - if (Objects.nonNull(policyDetails)) { - PolicyDto policyDto = new PolicyDto(); - policyDto.setPartnerId(partner.getId()); - policyDto.setPartnerType(partner.getPartnerTypeCode()); - - policyDto.setPolicyGroupId(policyGroup.getId()); - policyDto.setPolicyGroupDescription(policyGroup.getDesc()); - policyDto.setPolicyGroupName(policyGroup.getName()); - - policyDto.setPolicyId(policyDetails.getId()); - policyDto.setPolicyDescription(policyDetails.getDescr()); - policyDto.setPolicyName(policyDetails.getName()); - - policyDto.setPartnerComments(partnerPolicyRequest.getRequestDetail()); - policyDto.setUpdatedDateTime(partnerPolicyRequest.getUpdDtimes() != null ? partnerPolicyRequest.getUpdDtimes().toLocalDateTime() : null); - policyDto.setCreatedDateTime(partnerPolicyRequest.getCrDtimes().toLocalDateTime()); - policyDto.setStatus(partnerPolicyRequest.getStatusCode()); - policyDtoList.add(policyDto); - } else { - LOGGER.info("No matching policy not found for policy group ID :" + partner.getPolicyGroupId() + "and Policy ID :" + partnerPolicyRequest.getPolicyId()); - throw new PartnerServiceException(ErrorCode.MATCHING_POLICY_NOT_FOUND.getErrorCode(), - ErrorCode.MATCHING_POLICY_NOT_FOUND.getErrorMessage()); - } - } - } - } - } - responseWrapper.setResponse(policyDtoList); - } else { - LOGGER.info("sessionId", "idType", "id", "User id does not exists."); - throw new PartnerServiceException(ErrorCode.USER_ID_NOT_EXISTS.getErrorCode(), - ErrorCode.USER_ID_NOT_EXISTS.getErrorMessage()); - } - } catch (PartnerServiceException ex) { - LOGGER.info("sessionId", "idType", "id", "In getPolicyRequests method of MultiPartnerServiceImpl - " + ex.getMessage()); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); - } catch (Exception ex) { - LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace()); - LOGGER.error("sessionId", "idType", "id", - "In getPolicyRequests method of MultiPartnerServiceImpl - " + ex.getMessage()); - String errorCode = ErrorCode.PARTNER_POLICY_FETCH_ERROR.getErrorCode(); - String errorMessage = ErrorCode.PARTNER_POLICY_FETCH_ERROR.getErrorMessage(); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); - } - responseWrapper.setId(getPolicyRequestsId); - responseWrapper.setVersion(VERSION); - return responseWrapper; - } - @Override public ResponseWrapperV2> getApprovedPartnerIdsWithPolicyGroups() { ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); @@ -262,12 +96,12 @@ public ResponseWrapperV2> getApprovedPartnerIdsWithPolicyGr for (Partner partner : partnerList) { String partnerType = partner.getPartnerTypeCode(); // Ignore, If the partner is a DEVICE or FTM partnertype - if (!skipDeviceOrFtmPartner(partner) + if (!partnerHelper.skipDeviceOrFtmPartner(partner) && partner.getApprovalStatus().equalsIgnoreCase(APPROVED)) { PolicyGroupDto policyGroupDto = new PolicyGroupDto(); - validatePartnerId(partner, userId); - validatePolicyGroupId(partner, userId); - PolicyGroup policyGroup = validatePolicyGroup(partner); + partnerHelper.validatePartnerId(partner, userId); + partnerHelper.validatePolicyGroupId(partner, userId); + PolicyGroup policyGroup = partnerHelper.validatePolicyGroup(partner); policyGroupDto.setPartnerId(partner.getId()); policyGroupDto.setPartnerType(partner.getPartnerTypeCode()); policyGroupDto.setPolicyGroupId(partner.getPolicyGroupId()); @@ -307,10 +141,10 @@ public ResponseWrapperV2> getAuthPartnersPolicies() { if (!partnerList.isEmpty()) { List approvedPolicyList = new ArrayList<>(); for (Partner partner : partnerList) { - if (checkIfPartnerIsApprovedAuthPartner(partner)) { - validatePartnerId(partner, userId); - validatePolicyGroupId(partner, userId); - PolicyGroup policyGroup = validatePolicyGroup(partner); + if (partnerHelper.checkIfPartnerIsApprovedAuthPartner(partner)) { + partnerHelper.validatePartnerId(partner, userId); + partnerHelper.validatePolicyGroupId(partner, userId); + PolicyGroup policyGroup = partnerHelper.validatePolicyGroup(partner); ApprovedPolicyDto approvedPolicyDto = new ApprovedPolicyDto(); approvedPolicyDto.setPartnerId(partner.getId()); approvedPolicyDto.setPolicyGroupId(policyGroup.getId()); @@ -365,218 +199,6 @@ public ResponseWrapperV2> getAuthPartnersPolicies() { return responseWrapper; } - public static boolean checkIfPartnerIsApprovedAuthPartner(Partner partner) { - String partnerType = partner.getPartnerTypeCode(); - String approvalStatus = partner.getApprovalStatus(); - if (Objects.isNull(partnerType) || partnerType.equals(BLANK_STRING)) { - LOGGER.info("Partner Type is null or empty for partner id : " + partner.getId()); - throw new PartnerServiceException(ErrorCode.PARTNER_TYPE_NOT_EXISTS.getErrorCode(), - ErrorCode.PARTNER_TYPE_NOT_EXISTS.getErrorMessage()); - } - if ((Objects.isNull(approvalStatus) || approvalStatus.equals(BLANK_STRING))) { - LOGGER.info("Approval status is null or empty for partner id : " + partner.getId()); - throw new PartnerServiceException(ErrorCode.APPROVAL_STATUS_NOT_EXISTS.getErrorCode(), - ErrorCode.APPROVAL_STATUS_NOT_EXISTS.getErrorMessage()); - } - return partnerType.equals(AUTH_PARTNER) && approvalStatus.equals(APPROVED); - } - - public static boolean checkIfPartnerIsDevicePartner(Partner partner) { - String partnerType = partner.getPartnerTypeCode(); - return partnerType.equals(DEVICE_PROVIDER); - } - - public static boolean checkIfPartnerIsFtmPartner(Partner partner) { - String partnerType = partner.getPartnerTypeCode(); - return partnerType.equals(FTM_PROVIDER); - } - - public static void validatePartnerId(Partner partner, String userId) { - if (Objects.isNull(partner.getId()) || partner.getId().equals(BLANK_STRING)) { - LOGGER.info("Partner Id is null or empty for user id : " + userId); - throw new PartnerServiceException(ErrorCode.PARTNER_ID_NOT_EXISTS.getErrorCode(), - ErrorCode.PARTNER_ID_NOT_EXISTS.getErrorMessage()); - } - } - - public static void validatePolicyGroupId(Partner partner, String userId) { - if (Objects.isNull(partner.getPolicyGroupId()) || partner.getPolicyGroupId().equals(BLANK_STRING)) { - LOGGER.info("Policy group Id is null or empty for user id : " + userId); - throw new PartnerServiceException(ErrorCode.POLICY_GROUP_ID_NOT_EXISTS.getErrorCode(), - ErrorCode.POLICY_GROUP_ID_NOT_EXISTS.getErrorMessage()); - } - } - - public static boolean skipDeviceOrFtmPartner(Partner partner) { - String partnerType = partner.getPartnerTypeCode(); - if (Objects.isNull(partnerType) || partnerType.equals(BLANK_STRING)) { - LOGGER.info("Partner Type is null or empty for partner id : " + partner.getId()); - throw new PartnerServiceException(ErrorCode.PARTNER_TYPE_NOT_EXISTS.getErrorCode(), - ErrorCode.PARTNER_TYPE_NOT_EXISTS.getErrorMessage()); - } - return partnerType.equals(DEVICE_PROVIDER) || partnerType.equals(FTM_PROVIDER); - } - - private PolicyGroup validatePolicyGroup(Partner partner) throws PartnerServiceException { - PolicyGroup policyGroup = policyGroupRepository.findPolicyGroupById(partner.getPolicyGroupId()); - if (Objects.isNull(policyGroup) || Objects.isNull(policyGroup.getName()) || policyGroup.getName().isEmpty()) { - LOGGER.info("Policy Group is null or empty for partner id : {}", partner.getId()); - throw new PartnerServiceException(ErrorCode.POLICY_GROUP_NOT_EXISTS.getErrorCode(), ErrorCode.POLICY_GROUP_NOT_EXISTS.getErrorMessage()); - } - return policyGroup; - } - - @Override - public ResponseWrapperV2> getApiKeysForAuthPartners() { - ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); - try { - String userId = getUserId(); - List partnerList = partnerRepository.findByUserId(userId); - if (!partnerList.isEmpty()) { - List apiKeyResponseDtoList = new ArrayList<>(); - for (Partner partner : partnerList) { - if (checkIfPartnerIsApprovedAuthPartner(partner)) { - validatePartnerId(partner, userId); - validatePolicyGroupId(partner, userId); - List apiKeyRequestsList = partnerPolicyRepository.findAPIKeysByPartnerId(partner.getId()); - if (!apiKeyRequestsList.isEmpty()) { - for (PartnerPolicy partnerPolicy : apiKeyRequestsList) { - Optional authPolicy = authPolicyRepository.findById(partnerPolicy.getPolicyId()); - if (!authPolicy.isPresent()) { - LOGGER.info("Policy does not exists."); - throw new PartnerServiceException(ErrorCode.POLICY_NOT_EXIST.getErrorCode(), - ErrorCode.POLICY_NOT_EXIST.getErrorMessage()); - } - PolicyGroup policyGroup = authPolicy.get().getPolicyGroup(); - if (Objects.isNull(policyGroup)) { - LOGGER.info("Policy Group is null or empty"); - throw new PartnerServiceException(ErrorCode.POLICY_GROUP_NOT_EXISTS.getErrorCode(), - ErrorCode.POLICY_GROUP_NOT_EXISTS.getErrorMessage()); - } - ApiKeyResponseDto apiKeyResponseDto = new ApiKeyResponseDto(); - apiKeyResponseDto.setApiKeyLabel(partnerPolicy.getLabel()); - if (partnerPolicy.getIsActive()) { - apiKeyResponseDto.setStatus(ACTIVE); - } else { - apiKeyResponseDto.setStatus(INACTIVE); - } - apiKeyResponseDto.setPartnerId(partner.getId()); - apiKeyResponseDto.setPolicyGroupId(policyGroup.getId()); - apiKeyResponseDto.setPolicyGroupName(policyGroup.getName()); - apiKeyResponseDto.setPolicyGroupDescription(policyGroup.getDesc()); - apiKeyResponseDto.setPolicyId(authPolicy.get().getId()); - apiKeyResponseDto.setPolicyName(authPolicy.get().getName()); - apiKeyResponseDto.setPolicyDescription(authPolicy.get().getDescr()); - apiKeyResponseDto.setCreatedDateTime(partnerPolicy.getCrDtimes().toLocalDateTime()); - apiKeyResponseDtoList.add(apiKeyResponseDto); - } - } - } - } - responseWrapper.setResponse(apiKeyResponseDtoList); - } else { - LOGGER.info("sessionId", "idType", "id", "User id does not exists."); - throw new PartnerServiceException(ErrorCode.USER_ID_NOT_EXISTS.getErrorCode(), - ErrorCode.USER_ID_NOT_EXISTS.getErrorMessage()); - } - } catch (PartnerServiceException ex) { - LOGGER.info("sessionId", "idType", "id", "In getApiKeysForAuthPartners method of MultiPartnerServiceImpl - " + ex.getMessage()); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); - } catch (Exception ex) { - LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace()); - LOGGER.error("sessionId", "idType", "id", - "In getApiKeysForAuthPartners method of MultiPartnerServiceImpl - " + ex.getMessage()); - String errorCode = ErrorCode.API_KEY_REQUESTS_FETCH_ERROR.getErrorCode(); - String errorMessage = ErrorCode.API_KEY_REQUESTS_FETCH_ERROR.getErrorMessage(); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); - } - responseWrapper.setId(getApiKeysForAuthPartnersId); - responseWrapper.setVersion(VERSION); - return responseWrapper; - } - - @Override - public ResponseWrapperV2> sbiDetails() { - ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); - try { - String userId = getUserId(); - List partnerList = partnerRepository.findByUserId(userId); - if (partnerList.isEmpty()) { - LOGGER.info("sessionId", "idType", "id", "User id does not exists."); - throw new PartnerServiceException(ErrorCode.USER_ID_NOT_EXISTS.getErrorCode(), - ErrorCode.USER_ID_NOT_EXISTS.getErrorMessage()); - } - List sbiDetailsDtoList = new ArrayList<>(); - for (Partner partner : partnerList) { - validatePartnerId(partner, userId); - if (checkIfPartnerIsDevicePartner(partner)) { - List secureBiometricInterfaceList = secureBiometricInterfaceRepository.findByProviderId(partner.getId()); - if (!secureBiometricInterfaceList.isEmpty()) { - for (SecureBiometricInterface secureBiometricInterface : secureBiometricInterfaceList) { - SbiDetailsDto sbiDetailsDto = new SbiDetailsDto(); - List deviceDetailSBIList = deviceDetailSbiRepository.findByDeviceProviderIdAndSbiId(partner.getId(), secureBiometricInterface.getId()); - sbiDetailsDto.setSbiId(secureBiometricInterface.getId()); - sbiDetailsDto.setPartnerId(partner.getId()); - sbiDetailsDto.setSbiVersion(secureBiometricInterface.getSwVersion()); - sbiDetailsDto.setStatus(secureBiometricInterface.getApprovalStatus()); - sbiDetailsDto.setSbiActive(secureBiometricInterface.isActive()); - sbiDetailsDto.setSbiExpired(checkIfSbiExpired(secureBiometricInterface)); - sbiDetailsDto.setCountOfApprovedDevices(countDevices(deviceDetailSBIList, APPROVED)); - sbiDetailsDto.setCountOfPendingDevices(countDevices(deviceDetailSBIList, PENDING_APPROVAL)); - sbiDetailsDto.setSbiCreatedDateTime(secureBiometricInterface.getSwCreateDateTime()); - sbiDetailsDto.setSbiExpiryDateTime(secureBiometricInterface.getSwExpiryDateTime()); - sbiDetailsDto.setCreatedDateTime(secureBiometricInterface.getCrDtimes()); - - sbiDetailsDtoList.add(sbiDetailsDto); - } - } - } - } - responseWrapper.setResponse(sbiDetailsDtoList); - } catch (PartnerServiceException ex) { - LOGGER.info("sessionId", "idType", "id", "In sbiDetails method of MultiPartnerServiceImpl - " + ex.getMessage()); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); - } catch (Exception ex) { - LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace()); - LOGGER.error("sessionId", "idType", "id", - "In sbiDetails method of MultiPartnerServiceImpl - " + ex.getMessage()); - String errorCode = ErrorCode.SBI_DETAILS_LIST_FETCH_ERROR.getErrorCode(); - String errorMessage = ErrorCode.SBI_DETAILS_LIST_FETCH_ERROR.getErrorMessage(); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); - } - responseWrapper.setId(getSbiDetailsId); - responseWrapper.setVersion(VERSION); - return responseWrapper; - } - - private String countDevices(List deviceDetailSBIList, String status) { - int count = 0; - if (deviceDetailSBIList.isEmpty()) { - return String.valueOf(count); - } - for (DeviceDetailSBI deviceDetailSBI : deviceDetailSBIList) { - Optional deviceDetail = deviceDetailRepository. - findByIdAndDeviceProviderId(deviceDetailSBI.getId().getDeviceDetailId(), deviceDetailSBI.getProviderId()); - if (deviceDetail.isPresent()) { - if (status.equals(APPROVED)) { - if (deviceDetail.get().getApprovalStatus().equals(status) && deviceDetail.get().getIsActive()) { - count++; - } - } - if (status.equals(PENDING_APPROVAL)) { - if (deviceDetail.get().getApprovalStatus().equals(status)) { - count++; - } - } - } - } - return String.valueOf(count); - } - - private boolean checkIfSbiExpired(SecureBiometricInterface secureBiometricInterface) { - return secureBiometricInterface.getSwExpiryDateTime().toLocalDate().isBefore(LocalDate.now()); - } - @Override public ResponseWrapperV2> approvedDeviceProviderIds() { ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); @@ -590,8 +212,8 @@ public ResponseWrapperV2> approvedDeviceProviderIds() { } List approvedDeviceProviderIds = new ArrayList<>(); for (Partner partner : partnerList) { - validatePartnerId(partner, userId); - if (checkIfPartnerIsDevicePartner(partner) + partnerHelper.validatePartnerId(partner, userId); + if (partnerHelper.checkIfPartnerIsDevicePartner(partner) && partner.getApprovalStatus().equalsIgnoreCase(APPROVED)) { DeviceProviderDto deviceProviderDto = new DeviceProviderDto(); deviceProviderDto.setPartnerId(partner.getId()); @@ -616,73 +238,6 @@ public ResponseWrapperV2> approvedDeviceProviderIds() { return responseWrapper; } - @Override - public ResponseWrapperV2> ftmChipDetails() { - ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); - try { - String userId = getUserId(); - List partnerList = partnerRepository.findByUserId(userId); - List ftmChipDetailsDtoList = new ArrayList<>(); - if (!partnerList.isEmpty()) { - for (Partner partner : partnerList) { - if (checkIfPartnerIsFtmPartner(partner)) { - validatePartnerId(partner, userId); - List ftpChipDetailList = ftpChipDetailRepository.findByProviderId(partner.getId()); - if(!ftpChipDetailList.isEmpty()) { - for(FTPChipDetail ftpChipDetail: ftpChipDetailList) { - FtmChipDetailsDto ftmChipDetailsDto = new FtmChipDetailsDto(); - // Get certificate data if available - if (ftpChipDetail.getCertificateAlias() != null) { - ftmChipDetailsDto.setIsCertificateAvailable(true); - FtpChipCertDownloadRequestDto requestDto = new FtpChipCertDownloadRequestDto(); - requestDto.setFtpChipDetailId(ftpChipDetail.getFtpChipDetailId()); - FtpCertDownloadResponeDto ftpCertDownloadResponeDto = ftpChipDetailServiceImpl.getCertificate(requestDto); - X509Certificate cert = MultiPartnerUtil.decodeCertificateData(ftpCertDownloadResponeDto.getCertificateData()); - - ftmChipDetailsDto.setCertificateUploadDateTime(cert.getNotBefore()); - ftmChipDetailsDto.setCertificateExpiryDateTime(cert.getNotAfter()); - - // Check the certificate expiration status - LocalDateTime currentDateTime = LocalDateTime.now(ZoneId.of("UTC")); - LocalDateTime certExpiryDate = cert.getNotAfter().toInstant().atZone(ZoneId.of("UTC")).toLocalDateTime(); - ftmChipDetailsDto.setIsCertificateExpired(certExpiryDate.isBefore(currentDateTime)); - } else { - ftmChipDetailsDto.setIsCertificateAvailable(false); - ftmChipDetailsDto.setIsCertificateExpired(false); - } - ftmChipDetailsDto.setFtmId(ftpChipDetail.getFtpChipDetailId()); - ftmChipDetailsDto.setPartnerId(ftpChipDetail.getFtpProviderId()); - ftmChipDetailsDto.setMake(ftpChipDetail.getMake()); - ftmChipDetailsDto.setModel(ftpChipDetail.getModel()); - ftmChipDetailsDto.setStatus(ftpChipDetail.getApprovalStatus()); - ftmChipDetailsDto.setIsActive(ftpChipDetail.isActive()); - ftmChipDetailsDto.setCreatedDateTime(ftpChipDetail.getCrDtimes()); - ftmChipDetailsDtoList.add(ftmChipDetailsDto); - } - } - } - } - } - responseWrapper.setResponse(ftmChipDetailsDtoList); - } catch (ApiAccessibleException ex) { - LOGGER.info("sessionId", "idType", "id", "In ftmChipDetails method of MultiPartnerServiceImpl - " + ex.getMessage()); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); - } catch (PartnerServiceException ex) { - LOGGER.info("sessionId", "idType", "id", "In ftmChipDetails method of MultiPartnerServiceImpl - " + ex.getMessage()); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); - } catch (Exception ex) { - LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace()); - LOGGER.error("sessionId", "idType", "id", - "In ftmChipDetails method of MultiPartnerServiceImpl - " + ex.getMessage()); - String errorCode = ErrorCode.FTM_CHIP_DETAILS_LIST_FETCH_ERROR.getErrorCode(); - String errorMessage = ErrorCode.FTM_CHIP_DETAILS_LIST_FETCH_ERROR.getErrorMessage(); - responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); - } - responseWrapper.setId(getFtmChipDetailsId); - responseWrapper.setVersion(VERSION); - return responseWrapper; - } - @Override public ResponseWrapperV2> approvedFTMProviderIds() { ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); @@ -696,8 +251,8 @@ public ResponseWrapperV2> approvedFTMProviderIds() { ErrorCode.USER_ID_NOT_EXISTS.getErrorMessage()); } for (Partner partner : partnerList) { - validatePartnerId(partner, userId); - if (checkIfPartnerIsFtmPartner(partner) + partnerHelper.validatePartnerId(partner, userId); + if (partnerHelper.checkIfPartnerIsFtmPartner(partner) && partner.getApprovalStatus().equalsIgnoreCase(APPROVED)) { FtmProviderDto ftmProviderDto = new FtmProviderDto(); ftmProviderDto.setPartnerId(partner.getId()); diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/PartnerServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/PartnerServiceImpl.java index 059b17fdaf..5b6e0e3a34 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/PartnerServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/service/impl/PartnerServiceImpl.java @@ -5,6 +5,7 @@ import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; import java.sql.Timestamp; import java.time.LocalDateTime; import java.util.ArrayList; @@ -21,6 +22,7 @@ import io.mosip.kernel.core.authmanager.authadapter.model.AuthUserDetails; import io.mosip.pms.common.response.dto.ResponseWrapperV2; +import io.mosip.pms.partner.dto.*; import io.mosip.pms.partner.util.MultiPartnerUtil; import io.mosip.pms.partner.util.PartnerHelper; import org.json.simple.JSONObject; @@ -98,9 +100,6 @@ import io.mosip.pms.partner.constant.ErrorCode; import io.mosip.pms.partner.constant.PartnerConstants; import io.mosip.pms.partner.constant.PartnerServiceAuditEnum; -import io.mosip.pms.partner.dto.DataShareResponseDto; -import io.mosip.pms.partner.dto.PartnerPolicyMappingResponseDto; -import io.mosip.pms.partner.dto.UploadCertificateRequestDto; import io.mosip.pms.partner.exception.PartnerServiceException; import io.mosip.pms.partner.request.dto.AddContactRequestDto; import io.mosip.pms.partner.request.dto.CACertificateRequestDto; @@ -151,6 +150,12 @@ public class PartnerServiceImpl implements PartnerService { private static final String APPROVED = "approved"; + public static final String ACTIVE = "ACTIVE"; + + public static final String INACTIVE = "INACTIVE"; + + public static final String AUTH_PARTNER = "Auth_Partner"; + @Autowired PartnerServiceRepository partnerRepository; @@ -244,6 +249,15 @@ public class PartnerServiceImpl implements PartnerService { @Value("${mosip.pms.api.id.original.partner.certificate.get}") private String getOriginalPartnerCertificateId; + @Value("${mosip.pms.api.id.policy.requests.get}") + private String getPolicyRequestsId; + + @Value("${mosip.pms.api.id.partner.certificates.get}") + private String getPartnerCertificatesId; + + @Value("${mosip.pms.api.id.auth.partner.api.keys.get}") + private String getAuthPartnerApiKeysId; + @Autowired AuditUtil auditUtil; @@ -838,7 +852,7 @@ private Optional getPartner(PartnerCertDownloadRequestDto certDownloadR } @Override - public ResponseWrapperV2 getOriginalPartnerCertificate(PartnerCertDownloadRequestDto certDownloadRequestDto) { + public ResponseWrapperV2 getPartnerCertificateData(PartnerCertDownloadRequestDto certDownloadRequestDto) { ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); try { validateUser(certDownloadRequestDto); @@ -1637,7 +1651,207 @@ public PartnerPolicyMappingResponseDto requestForPolicyMapping(PartnerPolicyMapp response.setMessage("Policy mapping request submitted successfully."); return response; } - + + @Override + public ResponseWrapperV2> getPolicyRequests() { + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + try { + String userId = getUserId(); + List partnerList = partnerRepository.findByUserId(userId); + if (!partnerList.isEmpty()) { + List policyDtoList = new ArrayList<>(); + for (Partner partner : partnerList) { + if (!partnerHelper.skipDeviceOrFtmPartner(partner)) { + partnerHelper.validatePartnerId(partner, userId); + partnerHelper.validatePolicyGroupId(partner, userId); + PolicyGroup policyGroup = partnerHelper.validatePolicyGroup(partner); + List partnerPolicyRequestList = partner.getPartnerPolicyRequests(); + if (!partnerPolicyRequestList.isEmpty()) { + for (PartnerPolicyRequest partnerPolicyRequest : partnerPolicyRequestList) { + AuthPolicy policyDetails = authPolicyRepository.findByPolicyGroupAndId(partner.getPolicyGroupId(), partnerPolicyRequest.getPolicyId()); + if (Objects.nonNull(policyDetails)) { + PolicyDto policyDto = new PolicyDto(); + policyDto.setPartnerId(partner.getId()); + policyDto.setPartnerType(partner.getPartnerTypeCode()); + + policyDto.setPolicyGroupId(policyGroup.getId()); + policyDto.setPolicyGroupDescription(policyGroup.getDesc()); + policyDto.setPolicyGroupName(policyGroup.getName()); + + policyDto.setPolicyId(policyDetails.getId()); + policyDto.setPolicyDescription(policyDetails.getDescr()); + policyDto.setPolicyName(policyDetails.getName()); + + policyDto.setPartnerComment(partnerPolicyRequest.getRequestDetail()); + policyDto.setUpdatedDateTime(partnerPolicyRequest.getUpdDtimes() != null ? partnerPolicyRequest.getUpdDtimes().toLocalDateTime() : null); + policyDto.setCreatedDateTime(partnerPolicyRequest.getCrDtimes().toLocalDateTime()); + policyDto.setStatus(partnerPolicyRequest.getStatusCode()); + policyDtoList.add(policyDto); + } else { + LOGGER.info("No matching policy not found for policy group ID :" + partner.getPolicyGroupId() + "and Policy ID :" + partnerPolicyRequest.getPolicyId()); + throw new PartnerServiceException(ErrorCode.MATCHING_POLICY_NOT_FOUND.getErrorCode(), + ErrorCode.MATCHING_POLICY_NOT_FOUND.getErrorMessage()); + } + } + } + } + } + responseWrapper.setResponse(policyDtoList); + } else { + LOGGER.info("sessionId", "idType", "id", "User id does not exists."); + throw new PartnerServiceException(ErrorCode.USER_ID_NOT_EXISTS.getErrorCode(), + ErrorCode.USER_ID_NOT_EXISTS.getErrorMessage()); + } + } catch (PartnerServiceException ex) { + LOGGER.info("sessionId", "idType", "id", "In getPolicyRequests method of PartnerServiceImpl - " + ex.getMessage()); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); + } catch (Exception ex) { + LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace()); + LOGGER.error("sessionId", "idType", "id", + "In getPolicyRequests method of PartnerServiceImpl - " + ex.getMessage()); + String errorCode = ErrorCode.PARTNER_POLICY_FETCH_ERROR.getErrorCode(); + String errorMessage = ErrorCode.PARTNER_POLICY_FETCH_ERROR.getErrorMessage(); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); + } + responseWrapper.setId(getPolicyRequestsId); + responseWrapper.setVersion(VERSION); + return responseWrapper; + } + + @Override + public ResponseWrapperV2> getPartnerCertificatesDetails() { + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + try { + String userId = getUserId(); + List partnerList = partnerRepository.findByUserId(userId); + if (!partnerList.isEmpty()) { + List certificateDtoList = new ArrayList<>(); + for (Partner partner : partnerList) { + CertificateDto certificateDto = new CertificateDto(); + try { + if (Objects.isNull(partner.getId()) || partner.getId().equals(BLANK_STRING)) { + LOGGER.info("Partner Id is null or empty for user id : " + userId); + throw new PartnerServiceException(ErrorCode.PARTNER_ID_NOT_EXISTS.getErrorCode(), + ErrorCode.PARTNER_ID_NOT_EXISTS.getErrorMessage()); + } + PartnerCertDownloadRequestDto requestDto = new PartnerCertDownloadRequestDto(); + requestDto.setPartnerId(partner.getId()); + PartnerCertDownloadResponeDto partnerCertDownloadResponeDto = getPartnerCertificate(requestDto); + X509Certificate cert = MultiPartnerUtil.decodeCertificateData(partnerCertDownloadResponeDto.getCertificateData()); + + certificateDto.setIsCertificateAvailable(true); + certificateDto.setCertificateIssuedTo(PartnerUtil.getCertificateName(cert.getSubjectDN().getName())); + certificateDto.setCertificateUploadDateTime(cert.getNotBefore()); + certificateDto.setCertificateExpiryDateTime(cert.getNotAfter()); + certificateDto.setPartnerId(partner.getId()); + certificateDto.setPartnerType(partner.getPartnerTypeCode()); + } catch (PartnerServiceException ex) { + LOGGER.info("Could not fetch partner certificate :" + ex.getMessage()); + certificateDto.setIsCertificateAvailable(false); + certificateDto.setPartnerId(partner.getId()); + certificateDto.setPartnerType(partner.getPartnerTypeCode()); + } + if (partner.getApprovalStatus().equals(APPROVED) && !partner.getIsActive()) { + certificateDto.setIsPartnerActive(false); + } else { + certificateDto.setIsPartnerActive(true); + } + certificateDtoList.add(certificateDto); + } + responseWrapper.setResponse(certificateDtoList); + } else { + LOGGER.info("sessionId", "idType", "id", "User id does not exists."); + throw new PartnerServiceException(ErrorCode.USER_ID_NOT_EXISTS.getErrorCode(), + ErrorCode.USER_ID_NOT_EXISTS.getErrorMessage()); + } + } catch (PartnerServiceException ex) { + LOGGER.info("sessionId", "idType", "id", "In getPartnerCertificatesDetails method of PartnerServiceImpl - " + ex.getMessage()); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); + } catch (ApiAccessibleException ex) { + LOGGER.info("sessionId", "idType", "id", "In getPartnerCertificates method of PartnerServiceImpl - " + ex.getMessage()); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); + } catch (Exception ex) { + LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace()); + LOGGER.error("sessionId", "idType", "id", + "In getPartnerCertificatesDetails method of PartnerServiceImpl - " + ex.getMessage()); + String errorCode = ErrorCode.PARTNER_CERTIFICATES_FETCH_ERROR.getErrorCode(); + String errorMessage = ErrorCode.PARTNER_CERTIFICATES_FETCH_ERROR.getErrorMessage(); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); + } + responseWrapper.setId(getPartnerCertificatesId); + responseWrapper.setVersion(VERSION); + return responseWrapper; + } + + @Override + public ResponseWrapperV2> getAuthPartnerApiKeys() { + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + try { + String userId = getUserId(); + List partnerList = partnerRepository.findByUserId(userId); + if (!partnerList.isEmpty()) { + List apiKeyResponseDtoList = new ArrayList<>(); + for (Partner partner : partnerList) { + if (partnerHelper.checkIfPartnerIsApprovedAuthPartner(partner)) { + partnerHelper.validatePartnerId(partner, userId); + partnerHelper.validatePolicyGroupId(partner, userId); + List apiKeyRequestsList = partnerPolicyRepository.findAPIKeysByPartnerId(partner.getId()); + if (!apiKeyRequestsList.isEmpty()) { + for (PartnerPolicy partnerPolicy : apiKeyRequestsList) { + Optional authPolicy = authPolicyRepository.findById(partnerPolicy.getPolicyId()); + if (!authPolicy.isPresent()) { + LOGGER.info("Policy does not exists."); + throw new PartnerServiceException(ErrorCode.POLICY_NOT_EXIST.getErrorCode(), + ErrorCode.POLICY_NOT_EXIST.getErrorMessage()); + } + PolicyGroup policyGroup = authPolicy.get().getPolicyGroup(); + if (Objects.isNull(policyGroup)) { + LOGGER.info("Policy Group is null or empty"); + throw new PartnerServiceException(ErrorCode.POLICY_GROUP_NOT_EXISTS.getErrorCode(), + ErrorCode.POLICY_GROUP_NOT_EXISTS.getErrorMessage()); + } + ApiKeyResponseDto apiKeyResponseDto = new ApiKeyResponseDto(); + apiKeyResponseDto.setApiKeyLabel(partnerPolicy.getLabel()); + if (partnerPolicy.getIsActive()) { + apiKeyResponseDto.setStatus(ACTIVE); + } else { + apiKeyResponseDto.setStatus(INACTIVE); + } + apiKeyResponseDto.setPartnerId(partner.getId()); + apiKeyResponseDto.setPolicyGroupId(policyGroup.getId()); + apiKeyResponseDto.setPolicyGroupName(policyGroup.getName()); + apiKeyResponseDto.setPolicyGroupDescription(policyGroup.getDesc()); + apiKeyResponseDto.setPolicyId(authPolicy.get().getId()); + apiKeyResponseDto.setPolicyName(authPolicy.get().getName()); + apiKeyResponseDto.setPolicyDescription(authPolicy.get().getDescr()); + apiKeyResponseDto.setCreatedDateTime(partnerPolicy.getCrDtimes().toLocalDateTime()); + apiKeyResponseDtoList.add(apiKeyResponseDto); + } + } + } + } + responseWrapper.setResponse(apiKeyResponseDtoList); + } else { + LOGGER.info("sessionId", "idType", "id", "User id does not exists."); + throw new PartnerServiceException(ErrorCode.USER_ID_NOT_EXISTS.getErrorCode(), + ErrorCode.USER_ID_NOT_EXISTS.getErrorMessage()); + } + } catch (PartnerServiceException ex) { + LOGGER.info("sessionId", "idType", "id", "In getAuthPartnerApiKeys method of PartnerServiceImpl - " + ex.getMessage()); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(ex.getErrorCode(), ex.getErrorText())); + } catch (Exception ex) { + LOGGER.debug("sessionId", "idType", "id", ex.getStackTrace()); + LOGGER.error("sessionId", "idType", "id", + "In getAuthPartnerApiKeys method of PartnerServiceImpl - " + ex.getMessage()); + String errorCode = ErrorCode.API_KEY_REQUESTS_FETCH_ERROR.getErrorCode(); + String errorMessage = ErrorCode.API_KEY_REQUESTS_FETCH_ERROR.getErrorMessage(); + responseWrapper.setErrors(MultiPartnerUtil.setErrorResponse(errorCode, errorMessage)); + } + responseWrapper.setId(getAuthPartnerApiKeysId); + responseWrapper.setVersion(VERSION); + return responseWrapper; + } + /** * validates the loggedInUser authorization * @param loggedInUserId 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 fe3ad843a3..b511a5d902 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 @@ -5,8 +5,10 @@ import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.pms.common.constant.ApiAccessibleExceptionConstant; import io.mosip.pms.common.entity.Partner; +import io.mosip.pms.common.entity.PolicyGroup; import io.mosip.pms.common.exception.ApiAccessibleException; import io.mosip.pms.common.repository.DeviceDetailSbiRepository; +import io.mosip.pms.common.repository.PolicyGroupRepository; import io.mosip.pms.common.util.PMSLogger; import io.mosip.pms.common.util.RestUtil; import io.mosip.pms.device.authdevice.entity.DeviceDetail; @@ -42,6 +44,10 @@ public class PartnerHelper { private static final Logger LOGGER = PMSLogger.getLogger(PartnerHelper.class); public static final String APPROVED = "approved"; public static final String PENDING_APPROVAL = "pending_approval"; + public static final String DEVICE_PROVIDER = "Device_Provider"; + public static final String FTM_PROVIDER = "FTM_Provider"; + public static final String AUTH_PARTNER = "Auth_Partner"; + public static final String BLANK_STRING = ""; public final Map partnerAliasToColumnMap = new HashMap<>(); { @@ -154,6 +160,9 @@ public class PartnerHelper { @Autowired DeviceDetailRepository deviceDetailRepository; + @Autowired + PolicyGroupRepository policyGroupRepository; + @Autowired RestUtil restUtil; @@ -365,4 +374,65 @@ public Optional getUserDetailsByPartnerId(String partnerId) thr } } + + public boolean checkIfPartnerIsDevicePartner(Partner partner) { + String partnerType = partner.getPartnerTypeCode(); + return partnerType.equals(DEVICE_PROVIDER); + } + + public boolean checkIfPartnerIsFtmPartner(Partner partner) { + String partnerType = partner.getPartnerTypeCode(); + return partnerType.equals(FTM_PROVIDER); + } + + public boolean skipDeviceOrFtmPartner(Partner partner) { + String partnerType = partner.getPartnerTypeCode(); + if (Objects.isNull(partnerType) || partnerType.equals(BLANK_STRING)) { + LOGGER.info("Partner Type is null or empty for partner id : " + partner.getId()); + throw new PartnerServiceException(ErrorCode.PARTNER_TYPE_NOT_EXISTS.getErrorCode(), + ErrorCode.PARTNER_TYPE_NOT_EXISTS.getErrorMessage()); + } + return partnerType.equals(DEVICE_PROVIDER) || partnerType.equals(FTM_PROVIDER); + } + + public void validatePolicyGroupId(Partner partner, String userId) { + if (Objects.isNull(partner.getPolicyGroupId()) || partner.getPolicyGroupId().equals(BLANK_STRING)) { + LOGGER.info("Policy group Id is null or empty for user id : " + userId); + throw new PartnerServiceException(ErrorCode.POLICY_GROUP_ID_NOT_EXISTS.getErrorCode(), + ErrorCode.POLICY_GROUP_ID_NOT_EXISTS.getErrorMessage()); + } + } + + public PolicyGroup validatePolicyGroup(Partner partner) throws PartnerServiceException { + PolicyGroup policyGroup = policyGroupRepository.findPolicyGroupById(partner.getPolicyGroupId()); + if (Objects.isNull(policyGroup) || Objects.isNull(policyGroup.getName()) || policyGroup.getName().isEmpty()) { + LOGGER.info("Policy Group is null or empty for partner id : {}", partner.getId()); + throw new PartnerServiceException(ErrorCode.POLICY_GROUP_NOT_EXISTS.getErrorCode(), ErrorCode.POLICY_GROUP_NOT_EXISTS.getErrorMessage()); + } + return policyGroup; + } + + public void validatePartnerId(Partner partner, String userId) { + if (Objects.isNull(partner.getId()) || partner.getId().equals(BLANK_STRING)) { + LOGGER.info("Partner Id is null or empty for user id : " + userId); + throw new PartnerServiceException(ErrorCode.PARTNER_ID_NOT_EXISTS.getErrorCode(), + ErrorCode.PARTNER_ID_NOT_EXISTS.getErrorMessage()); + } + } + + public boolean checkIfPartnerIsApprovedAuthPartner(Partner partner) { + String partnerType = partner.getPartnerTypeCode(); + String approvalStatus = partner.getApprovalStatus(); + if (Objects.isNull(partnerType) || partnerType.equals(BLANK_STRING)) { + LOGGER.info("Partner Type is null or empty for partner id : " + partner.getId()); + throw new PartnerServiceException(ErrorCode.PARTNER_TYPE_NOT_EXISTS.getErrorCode(), + ErrorCode.PARTNER_TYPE_NOT_EXISTS.getErrorMessage()); + } + if ((Objects.isNull(approvalStatus) || approvalStatus.equals(BLANK_STRING))) { + LOGGER.info("Approval status is null or empty for partner id : " + partner.getId()); + throw new PartnerServiceException(ErrorCode.APPROVAL_STATUS_NOT_EXISTS.getErrorCode(), + ErrorCode.APPROVAL_STATUS_NOT_EXISTS.getErrorMessage()); + } + return partnerType.equals(AUTH_PARTNER) && approvalStatus.equals(APPROVED); + } } diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/user/controller/UserController.java b/partner/partner-management-service/src/main/java/io/mosip/pms/user/controller/UserController.java index 91760e3ea8..78c064b89f 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/user/controller/UserController.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/user/controller/UserController.java @@ -23,7 +23,6 @@ import java.util.Map; @RestController -@RequestMapping(value = "/users") public class UserController { @Value("${mosip.pms.oidc.clients.grantTypes:authorization_code}") @@ -58,7 +57,7 @@ public class UserController { @Autowired UserManagementService userManagementService; - @PostMapping + @PostMapping(value = "/users") @PreAuthorize("hasAnyRole('MISP_PARTNER','PARTNER_ADMIN','AUTH_PARTNER','CREDENTIAL_PARTNER','ONLINE_VERIFICATION_PARTNER','DEVICE_PROVIDER','FTM_PROVIDER','ABIS_PARTNER','MANUAL_ADJUDICATION','SDK_PARTNER')") public ResponseWrapper registerUser( @RequestBody @Valid RequestWrapper request) { @@ -69,7 +68,7 @@ public ResponseWrapper registerUser( } @PreAuthorize("hasAnyRole(@authorizedRoles.getUserconsent())") - @PostMapping(value = "/user-consent") + @PostMapping(value = "users/user-consent") @Operation(summary = "save user consent", description = "Store the user consent in the database.") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), @@ -79,7 +78,7 @@ public ResponseWrapperV2 saveUserConsent() { } @PreAuthorize("hasAnyRole(@authorizedRoles.getUserconsent())") - @GetMapping(value = "/user-consent") + @GetMapping(value = "users/user-consent") @Operation(summary = "Retrieve the user consent status.", description = "Retrieve the user consent status.") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), @@ -88,12 +87,12 @@ public ResponseWrapperV2 isUserConsentGiven() { return userManagementService.isUserConsentGiven(); } - @GetMapping(value = "/configs") + @GetMapping(value = "/system-config") @Operation(summary = "Get config", description = "Get configuration values") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))}) - public ResponseWrapperV2> getConfigValues() { + public ResponseWrapperV2> getSystemConfig() { ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); responseWrapper.setId(getConfigsId); responseWrapper.setVersion(VERSION); diff --git a/partner/partner-management-service/src/main/resources/bootstrap.properties b/partner/partner-management-service/src/main/resources/bootstrap.properties index cbce1e8087..655370cb35 100644 --- a/partner/partner-management-service/src/main/resources/bootstrap.properties +++ b/partner/partner-management-service/src/main/resources/bootstrap.properties @@ -82,12 +82,12 @@ mosip.role.pms.userconsent=AUTH_PARTNER,ABIS_PARTNER,SDK_PARTNER,DEVICE_PROVIDER mosip.role.pms.getsbidetails=DEVICE_PROVIDER,PARTNER_ADMIN mosip.role.pms.getapproveddeviceproviderids=DEVICE_PROVIDER,PARTNER_ADMIN mosip.role.pms.postinactivemappingdevicetosbi=DEVICE_PROVIDER,PARTNER_ADMIN -mosip.role.pms.postapproveorrejectdevicewithsbimapping=PARTNER_ADMIN -mosip.role.pms.postdeactivatedevice=DEVICE_PROVIDER,PARTNER_ADMIN -mosip.role.pms.postdeactivatesbi=DEVICE_PROVIDER,PARTNER_ADMIN +mosip.role.pms.postdevicewithsbimapping=PARTNER_ADMIN +mosip.role.pms.patchdeactivatedevice=DEVICE_PROVIDER,PARTNER_ADMIN +mosip.role.pms.patchdeactivatesbi=DEVICE_PROVIDER,PARTNER_ADMIN mosip.role.pms.getftmchipdetails=FTM_PROVIDER,PARTNER_ADMIN mosip.role.pms.getapprovedftmproviderids=FTM_PROVIDER,PARTNER_ADMIN -mosip.role.pms.postdeactivateftm=FTM_PROVIDER,PARTNER_ADMIN +mosip.role.pms.patchdeactivateftm=FTM_PROVIDER,PARTNER_ADMIN mosip.role.pms.getoriginalftmcertificate=FTM_PROVIDER,PARTNER_ADMIN mosip.role.pms.getpartnerdetails=PARTNER_ADMIN mosip.role.pms.getallpartners=PARTNER_ADMIN @@ -123,7 +123,7 @@ mosip.pms.api.id.policy.requests.get=mosip.pms.policy.requests.get mosip.pms.api.id.auth.partners.policies.get=mosip.pms.auth.partners.policies.get mosip.pms.api.id.approved.partner.ids.with.policy.groups.get=mosip.pms.approved.partner.ids.with.policy.groups.get mosip.pms.api.id.configs.get=mosip.pms.configs.get -mosip.pms.api.id.api.keys.for.auth.partners.get=mosip.pms.api.keys.for.auth.partners.get +mosip.pms.api.id.auth.partner.api.keys.get=mosip.pms.auth.partner.api.keys.get mosip.pms.api.id.user.consent.get=mosip.pms.user.consent.get mosip.pms.api.id.user.consent.post=mosip.pms.user.consent.post mosip.pms.api.id.original.partner.certificate.get=mosip.pms.original.partner.certificate.get @@ -133,11 +133,11 @@ mosip.pms.api.id.sbi.devices.get=mosip.pms.sbi.devices.get mosip.pms.api.id.add.inactive.mapping.device.to.sbi.id.post=mosip.pms.add.inactive.mapping.device.to.sbi.id.post mosip.pms.api.id.approve.mapping.device.to.sbi.post=mosip.pms.approve.mapping.device.to.sbi.post mosip.pms.api.id.reject.mapping.device.to.sbi.post=mosip.pms.reject.mapping.device.to.sbi.post -mosip.pms.api.id.deactivate.device.post=mosip.pms.deactivate.device.post -mosip.pms.api.id.deactivate.sbi.post=mosip.pms.deactivate.sbi.post +mosip.pms.api.id.deactivate.device.patch=mosip.pms.deactivate.device.patch +mosip.pms.api.id.deactivate.sbi.patch=mosip.pms.deactivate.sbi.patch mosip.pms.api.id.ftm.chip.details.get=mosip.pms.ftm.chip.details.get mosip.pms.api.id.approved.ftm.provider.ids.get=mosip.pms.approved.ftm.provider.ids.get -mosip.pms.api.id.deactivate.ftm.post=mosip.pms.deactivate.ftm.post +mosip.pms.api.id.deactivate.ftm.patch=mosip.pms.deactivate.ftm.patch mosip.pms.api.id.original.ftm.certificate.get=mosip.pms.original.ftm.certificate.get mosip.pms.api.id.partner.details.get=mosip.pms.partner.details.get mosip.pms.api.id.all.partners.get=mosip.pms.all.partners.get diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/DeviceDetailControllerTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/DeviceDetailControllerTest.java index 2b617c60ff..6af33648bd 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/DeviceDetailControllerTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/DeviceDetailControllerTest.java @@ -18,7 +18,6 @@ import io.mosip.pms.common.dto.PageResponseV2Dto; import io.mosip.pms.device.dto.DeviceDetailFilterDto; import io.mosip.pms.device.dto.DeviceDetailSummaryDto; -import io.mosip.pms.device.request.dto.DeactivateDeviceRequestDto; import io.mosip.pms.partner.request.dto.SbiAndDeviceMappingRequestDto; import io.mosip.pms.device.response.dto.DeviceDetailResponseDto; import io.mosip.pms.partner.util.PartnerHelper; @@ -71,6 +70,8 @@ @EnableWebMvc public class DeviceDetailControllerTest { + public static final String VERSION = "1.0"; + @Autowired private MockMvc mockMvc; @@ -474,19 +475,18 @@ public void inactiveMappingDeviceToSbi() throws Exception { @WithMockUser(roles = {"DEVICE_PROVIDER"}) public void deactivateDeviceTest() throws Exception { ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); - RequestWrapperV2 requestWrapper = new RequestWrapperV2<>(); - requestWrapper.setVersion("1.0"); - requestWrapper.setRequestTime(LocalDateTime.now()); - DeactivateDeviceRequestDto deactivateDeviceRequestDto = new DeactivateDeviceRequestDto(); - deactivateDeviceRequestDto.setDeviceId("abc"); - requestWrapper.setRequest(deactivateDeviceRequestDto); DeviceDetailResponseDto deviceDetailResponseDto = new DeviceDetailResponseDto(); responseWrapper.setResponse(deviceDetailResponseDto); - when(deviceDetaillService.deactivateDevice(Mockito.any())).thenReturn(responseWrapper); - mockMvc.perform(MockMvcRequestBuilders.post("/devicedetail/deactivate-device").contentType(MediaType.APPLICATION_JSON_VALUE) - .content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk()); + + Mockito.when(deviceDetaillService.deactivateDevice(Mockito.anyString())).thenReturn(responseWrapper); + + mockMvc.perform(MockMvcRequestBuilders.patch("/devicedetail/12345") + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isOk()); + } + @Test @WithMockUser(roles = {"PARTNER_ADMIN"}) public void getAllDeviceDetailsTest() throws Exception { @@ -528,5 +528,21 @@ public void getAllDeviceDetailsTest() throws Exception { .param("deviceId", deviceId)) .andExpect(MockMvcResultMatchers.status().isOk()); } + + @Test + @WithMockUser(roles = {"PARTNER_ADMIN"}) + public void approveOrRejectMappingDeviceToSbiTest() throws Exception { + RequestWrapperV2 requestWrapper = new RequestWrapperV2<>(); + requestWrapper.setId("mosip.pms.mapping.device.to.sbi.post"); + requestWrapper.setVersion(VERSION); + requestWrapper.setRequestTime(LocalDateTime.now()); + SbiAndDeviceMappingRequestDto sbiAndDeviceMappingRequestDto = new SbiAndDeviceMappingRequestDto(); + requestWrapper.setRequest(sbiAndDeviceMappingRequestDto); + ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); + responseWrapper.setResponse(true); + Mockito.when(deviceDetaillService.approveOrRejectMappingDeviceToSbi(any(), any())).thenReturn(responseWrapper); + mockMvc.perform(post("/devicedetail/1234/approval").contentType(MediaType.APPLICATION_JSON_VALUE) + .content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk()); + } } diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/FTPChipDetailControllerTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/FTPChipDetailControllerTest.java index 3e622be477..ce9bc0e6a7 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/FTPChipDetailControllerTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/FTPChipDetailControllerTest.java @@ -14,6 +14,7 @@ import io.mosip.pms.common.request.dto.RequestWrapperV2; import io.mosip.pms.common.response.dto.ResponseWrapperV2; +import io.mosip.pms.device.dto.FtmChipDetailsDto; import io.mosip.pms.device.dto.FtmChipFilterDto; import io.mosip.pms.device.request.dto.*; import io.mosip.pms.device.response.dto.*; @@ -385,27 +386,22 @@ public void getPartnerCertificateTest_02() throws JsonProcessingException, Excep @WithMockUser(roles = {"FTM_PROVIDER"}) public void deactivateFtmTest() throws Exception { ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); - RequestWrapperV2 requestWrapper = new RequestWrapperV2<>(); - requestWrapper.setVersion("1.0"); - requestWrapper.setRequestTime(LocalDateTime.now()); - DeactivateFtmRequestDto deactivateFtmRequestDto = new DeactivateFtmRequestDto(); - deactivateFtmRequestDto.setFtmId("abc"); - requestWrapper.setRequest(deactivateFtmRequestDto); FtmDetailResponseDto ftmDetailResponseDto = new FtmDetailResponseDto(); responseWrapper.setResponse(ftmDetailResponseDto); Mockito.when(ftpChipDetaillService.deactivateFtm(Mockito.any())).thenReturn(responseWrapper); - mockMvc.perform(MockMvcRequestBuilders.post("/ftpchipdetail/deactivate-ftm").contentType(MediaType.APPLICATION_JSON_VALUE) - .content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk()); + mockMvc.perform(MockMvcRequestBuilders.patch("/ftpchipdetail/1232") + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isOk()); } @Test @WithMockUser(roles = {"FTM_PROVIDER"}) - public void getOriginalFtmCertificateTest() throws Exception { + public void getFtmCertificateDataTest() throws Exception { ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); FtmCertificateDownloadResponseDto ftmCertificateDownloadResponseDto = new FtmCertificateDownloadResponseDto(); responseWrapper.setResponse(ftmCertificateDownloadResponseDto); - Mockito.when(ftpChipDetaillService.getOriginalFtmCertificate(Mockito.any())).thenReturn(responseWrapper); - mockMvc.perform(MockMvcRequestBuilders.get("/ftpchipdetail/1234/original-ftm-certificate")).andExpect(MockMvcResultMatchers.status().isOk()); + Mockito.when(ftpChipDetaillService.getFtmCertificateData(Mockito.any())).thenReturn(responseWrapper); + mockMvc.perform(MockMvcRequestBuilders.get("/ftpchipdetail/1234/certificate-data")).andExpect(MockMvcResultMatchers.status().isOk()); } @Test @@ -432,4 +428,17 @@ public void getPartnersFtmDetailsTest() throws Exception { .param("status", "approved")) .andExpect(MockMvcResultMatchers.status().isOk()); } + + @Test + @WithMockUser(roles = {"FTM_PROVIDER"}) + public void ftmChipDetailTest() throws Exception { + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + List ftmChipDetailsDtoList = new ArrayList<>(); + FtmChipDetailsDto ftmChipDetailsDto = new FtmChipDetailsDto(); + ftmChipDetailsDtoList.add(ftmChipDetailsDto); + responseWrapper.setResponse(ftmChipDetailsDtoList); + Mockito.when(ftpChipDetaillService.ftmChipDetail()).thenReturn(responseWrapper); + mockMvc.perform(MockMvcRequestBuilders.get("/ftpchipdetail")). + andExpect(MockMvcResultMatchers.status().isOk()); + } } diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/SecureBiometricInterfaceControllerTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/SecureBiometricInterfaceControllerTest.java index 8a3ef2d4fe..1897e31f71 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/SecureBiometricInterfaceControllerTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/controller/SecureBiometricInterfaceControllerTest.java @@ -16,8 +16,8 @@ import io.mosip.pms.device.dto.SbiFilterDto; import io.mosip.pms.device.response.dto.SbiSummaryDto; import io.mosip.pms.partner.dto.DeviceDetailDto; -import io.mosip.pms.device.request.dto.DeactivateSbiRequestDto; import io.mosip.pms.device.response.dto.SbiDetailsResponseDto; +import io.mosip.pms.device.dto.SbiDetailsDto; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -366,7 +366,7 @@ public void getAllDevicesForSbiTest() throws Exception { deviceDetailDtoList.add(deviceDetailDto); responseWrapper.setResponse(deviceDetailDtoList); Mockito.when(secureBiometricInterfaceService.getAllDevicesForSbi(Mockito.any())).thenReturn(responseWrapper); - mockMvc.perform(MockMvcRequestBuilders.get("/securebiometricinterface/sbi-devices/123").contentType(MediaType.APPLICATION_JSON_VALUE) + mockMvc.perform(MockMvcRequestBuilders.get("/securebiometricinterface/123/devices").contentType(MediaType.APPLICATION_JSON_VALUE) .content(objectMapper.writeValueAsString(responseWrapper))).andExpect(status().isOk()); } @@ -374,17 +374,14 @@ public void getAllDevicesForSbiTest() throws Exception { @WithMockUser(roles = {"DEVICE_PROVIDER"}) public void deactivateSbiTest() throws Exception { ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); - RequestWrapperV2 requestWrapper = new RequestWrapperV2<>(); - requestWrapper.setVersion("1.0"); - requestWrapper.setRequestTime(LocalDateTime.now()); - DeactivateSbiRequestDto deactivateSbiRequestDto = new DeactivateSbiRequestDto(); - deactivateSbiRequestDto.setSbiId("abc"); - requestWrapper.setRequest(deactivateSbiRequestDto); SbiDetailsResponseDto sbiDetailsResponseDto = new SbiDetailsResponseDto(); responseWrapper.setResponse(sbiDetailsResponseDto); - Mockito.when(secureBiometricInterfaceService.deactivateSbi(Mockito.any())).thenReturn(responseWrapper); - mockMvc.perform(MockMvcRequestBuilders.post("/securebiometricinterface/deactivate-sbi").contentType(MediaType.APPLICATION_JSON_VALUE) - .content(objectMapper.writeValueAsString(responseWrapper))).andExpect(status().isOk()); + + Mockito.when(secureBiometricInterfaceService.deactivateSbi(Mockito.anyString())).thenReturn(responseWrapper); + + mockMvc.perform(MockMvcRequestBuilders.patch("/securebiometricinterface/1234") + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isOk()); } private RequestWrapper createMappingRequest() { @@ -418,4 +415,17 @@ public void getAllSbiDetailsTest() throws Exception { .param("sbiExpiryStatus", "expired")) .andExpect(MockMvcResultMatchers.status().isOk()); } + + @Test + @WithMockUser(roles = {"DEVICE_PROVIDER"}) + public void getSbiDetailsTest() throws Exception { + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + List sbiDetailsDtoList = new ArrayList<>(); + SbiDetailsDto sbiDetailsDto = new SbiDetailsDto(); + sbiDetailsDtoList.add(sbiDetailsDto); + responseWrapper.setResponse(sbiDetailsDtoList); + Mockito.when(secureBiometricInterfaceService.getSbiDetails()).thenReturn(responseWrapper); + mockMvc.perform(MockMvcRequestBuilders.get("/securebiometricinterface").contentType(MediaType.APPLICATION_JSON_VALUE) + .content(objectMapper.writeValueAsString(responseWrapper))).andExpect(status().isOk()); + } } diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/DeviceDetailServiceTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/DeviceDetailServiceTest.java index 3fe3b666cb..7fd62b47f9 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/DeviceDetailServiceTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/DeviceDetailServiceTest.java @@ -19,6 +19,7 @@ import io.mosip.pms.device.authdevice.entity.SecureBiometricInterface; import io.mosip.pms.device.authdevice.repository.DeviceDetailSummaryRepository; import io.mosip.pms.device.authdevice.repository.SecureBiometricInterfaceRepository; +import io.mosip.pms.device.constant.DeviceConstant; import io.mosip.pms.partner.request.dto.SbiAndDeviceMappingRequestDto; import io.mosip.pms.partner.util.PartnerHelper; import org.junit.Before; @@ -665,6 +666,111 @@ public void testGetAllDeviceDetails_withOtherFieldSorting() { assertNotNull(response); } + @Test + public void approveOrRejectMappingDeviceToSbiTest() throws Exception { + SbiAndDeviceMappingRequestDto requestDto = new SbiAndDeviceMappingRequestDto(); + requestDto.setPartnerId("123"); + requestDto.setSbiId("112"); + requestDto.setDeviceDetailId("dgdg"); + requestDto.setStatus(DeviceConstant.APPROVE); + + DeviceDetailSBI deviceDetailSBI = new DeviceDetailSBI(); + when(deviceDetailSbiRepository.findByDeviceProviderIdAndSbiIdAndDeviceDetailId(anyString(), anyString(), anyString())).thenReturn(deviceDetailSBI); + + DeviceDetail deviceDetail = new DeviceDetail(); + deviceDetail.setDeviceProviderId("123"); + deviceDetail.setApprovalStatus("pending_approval"); + when(deviceDetailRepository.findByIdAndIsDeletedFalseOrIsDeletedIsNull(anyString())).thenReturn(deviceDetail); + + SecureBiometricInterface secureBiometricInterface = new SecureBiometricInterface(); + secureBiometricInterface.setSwCreateDateTime(LocalDateTime.now()); + secureBiometricInterface.setSwExpiryDateTime(LocalDateTime.now()); + secureBiometricInterface.setApprovalStatus("approved"); + secureBiometricInterface.setActive(true); + secureBiometricInterface.setCrDtimes(LocalDateTime.now()); + secureBiometricInterface.setSwVersion("1.0"); + secureBiometricInterface.setProviderId("123"); + when(secureBiometricInterfaceRepository.findById(anyString())).thenReturn(Optional.of(secureBiometricInterface)); + + when(deviceDetailRepository.findById(anyString())).thenReturn(Optional.of(deviceDetail)); + deviceDetailSBI.setProviderId("123"); + when(deviceDetailSbiRepository.save(any())).thenReturn(deviceDetailSBI); + + deviceDetaillService.approveOrRejectMappingDeviceToSbi("1234", requestDto); + } + + @Test + public void approveOrRejectMappingDeviceToSbiTest2() throws Exception { + SbiAndDeviceMappingRequestDto requestDto = new SbiAndDeviceMappingRequestDto(); + requestDto.setPartnerId("123"); + requestDto.setSbiId("112"); + requestDto.setDeviceDetailId("dgdg"); + requestDto.setStatus(DeviceConstant.APPROVE); + + DeviceDetailSBI deviceDetailSBI = new DeviceDetailSBI(); + when(deviceDetailSbiRepository.findByDeviceProviderIdAndSbiIdAndDeviceDetailId(anyString(), anyString(), anyString())).thenReturn(deviceDetailSBI); + + DeviceDetail deviceDetail = new DeviceDetail(); + deviceDetail.setDeviceProviderId("123"); + deviceDetail.setApprovalStatus("pending_approval"); + when(deviceDetailRepository.findByIdAndIsDeletedFalseOrIsDeletedIsNull(anyString())).thenReturn(deviceDetail); + + SecureBiometricInterface secureBiometricInterface = new SecureBiometricInterface(); + secureBiometricInterface.setSwCreateDateTime(LocalDateTime.now()); + secureBiometricInterface.setSwExpiryDateTime(LocalDateTime.now()); + secureBiometricInterface.setApprovalStatus("approved"); + secureBiometricInterface.setActive(true); + secureBiometricInterface.setCrDtimes(LocalDateTime.now()); + secureBiometricInterface.setSwVersion("1.0"); + secureBiometricInterface.setProviderId("123"); + when(secureBiometricInterfaceRepository.findById(anyString())).thenReturn(Optional.of(secureBiometricInterface)); + + when(deviceDetailRepository.findById(anyString())).thenReturn(Optional.of(deviceDetail)); + deviceDetailSBI.setProviderId("123"); + when(deviceDetailSbiRepository.save(any())).thenReturn(deviceDetailSBI); + + deviceDetaillService.approveOrRejectMappingDeviceToSbi("1234", requestDto); + } + + @Test + public void approveOrRejectMappingDeviceToSbiException() { + + SbiAndDeviceMappingRequestDto requestDto = new SbiAndDeviceMappingRequestDto(); + requestDto.setPartnerId("123"); + requestDto.setSbiId("112"); + requestDto.setStatus(DeviceConstant.APPROVE); + + deviceDetaillService.approveOrRejectMappingDeviceToSbi("1234", requestDto); + + requestDto.setDeviceDetailId("dgdg"); + + SecureBiometricInterface secureBiometricInterface = new SecureBiometricInterface(); + secureBiometricInterface.setSwCreateDateTime(LocalDateTime.now()); + secureBiometricInterface.setSwExpiryDateTime(LocalDateTime.now()); + secureBiometricInterface.setApprovalStatus("approved"); + secureBiometricInterface.setActive(true); + secureBiometricInterface.setCrDtimes(LocalDateTime.now()); + secureBiometricInterface.setSwVersion("1.0"); + secureBiometricInterface.setProviderId("123"); + + deviceDetaillService.approveOrRejectMappingDeviceToSbi("1234", requestDto); + when(secureBiometricInterfaceRepository.findById(anyString())).thenReturn(Optional.of(secureBiometricInterface)); + DeviceDetail deviceDetail = new DeviceDetail(); + deviceDetail.setDeviceProviderId("123"); + + deviceDetaillService.approveOrRejectMappingDeviceToSbi("1234", requestDto); + when(deviceDetailRepository.findById(anyString())).thenReturn(Optional.of(deviceDetail)); + + when(deviceDetailSbiRepository.findByDeviceProviderIdAndSbiIdAndDeviceDetailId(anyString(), anyString(), anyString())).thenReturn(null); + deviceDetaillService.approveOrRejectMappingDeviceToSbi("1234", requestDto); + + DeviceDetailSBI deviceDetailSBI = new DeviceDetailSBI(); + deviceDetailSBI.setProviderId("123"); + when(deviceDetailSbiRepository.findByDeviceProviderIdAndSbiIdAndDeviceDetailId(anyString(), anyString(), anyString())).thenReturn(deviceDetailSBI); + + deviceDetaillService.approveOrRejectMappingDeviceToSbi("1234", requestDto); + } + private io.mosip.kernel.openid.bridge.model.MosipUserDto getMosipUserDto() { io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = new io.mosip.kernel.openid.bridge.model.MosipUserDto(); mosipUserDto.setUserId("123"); diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/FTPChipDetailServiceTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/FTPChipDetailServiceTest.java index 44b3a56f55..ca58487ac0 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/FTPChipDetailServiceTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/FTPChipDetailServiceTest.java @@ -1099,7 +1099,7 @@ public void deactivateFtmTestException2() throws Exception { } @Test - public void getOriginalFtmCertificate_Test() throws Exception{ + public void getFtmCertificateData_Test() throws Exception{ io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); SecurityContextHolder.setContext(securityContext); @@ -1128,11 +1128,11 @@ public void getOriginalFtmCertificate_Test() throws Exception{ originalCertDownloadResponseDto.setMosipSignedCertificateData("-----BEGIN CERTIFICATE-----\\nMIIEizCCA3OgAwIBAgIIBkWQXN5LYV0wDQYJKoZIhvcNAQELBQAwdjELMAkGA1UE\\nBhMCSU4xCzAJBgNVBAgMAktBMRIwEAYDVQQHDAlCQU5HQUxPUkUxDTALBgNVBAoM\\nBElJVEIxGjAYBgNVBAsMEU1PU0lQLVRFQ0gtQ0VOVEVSMRswGQYDVQQDDBJ3d3cu\\nbW9zaXAuaW8gKFBNUykwHhcNMjQwOTE4MDgwNjU3WhcNMjUwOTE4MDgwNjU3WjBR\\nMQswCQYDVQQGEwJJTjELMAkGA1UECAwCTUgxCzAJBgNVBAcMAlBOMQwwCgYDVQQK\\nDANBQkMxDDAKBgNVBAsMA0FCQzEMMAoGA1UEAwwDQUJDMIICIjANBgkqhkiG9w0B\\nAQEFAAOCAg8AMIICCgKCAgEA1EGQeI5OMJlEThlZOWRPqTv2EHD/yAFvJaulKXMI\\nKKa3CWESBfl7wBh8odUBahaTdhJelpI5xLSLCVmHYDNGJUK/pT2An/QRUrsG5T3t\\nt4jI3ryCzwTnG6zkaYyrlWCaYXd4DrQ1d24Jh7bEoGhGY1WlatyqURKLI9z51Yn2\\n/6ebyxIvhTgsAwniEE9w4uWUWrcgQQI+uLFkfj3jrvbC9Ek0f9lmm6hQo4fI3trP\\nG2f4YbPuXabGQ+zwYwZE3szCMn7fPgZ+3sz7fnKXmrmlSme94pu8kSbdOQ1jxHuU\\n/W202/VACyFzmWTX6HUcBD0CcUxnyjU8QULEsBh177xdGNCJTRUmxyXn1yeO6L6D\\n1ojjoTwGt+ySogK8em5bCp2HRuCWMiJ0P3KsOBukzA87iZHBdm2wnJi1HON59vi3\\nPoQw04vd1BQmEUSkNmiuKAbeHr9LpHuSRiyaQ+SnUrouZ08L98A4ks7Y06oQSsXa\\n7OcL3U+lTCw+IlWb0ba9K5zDs1uDRP0az0rKnqAONVkXdU8tUXji583NTLfK0nBH\\nbeZ8oB2QWuQmccYZQqnGIKiQQHV9NXPwlPOO4HfdgLxXytOoByFawcFraPo0CbFf\\nWDkSoxco5zee7/12Tar0ecNcnnu0DTFghGcdGe4YBURxmhc7ajlnHM6nvrJMlDKR\\nfo0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUxAYPEcGciAk/\\n5FBXGmZ+z0u9uGIwDgYDVR0PAQH/BAQDAgKEMA0GCSqGSIb3DQEBCwUAA4IBAQAG\\n4TWJEafFhuAnXQXQQcF3bb3KvabpzDXCyaad7qNnojf2/e48SdLnURcHeiYFDr9a\\nrUdrrU6nBLE6NpTYD8WI+GHZ43SPeim0ACwz08+ZIXyvZt95DV1MCMKehd7YQKEQ\\n/AuvgRP/Z9FP2miZx+TH9GEU0KSAYLX8cMDNZhq3pzBihgHlzNeELDZnJ01kBWWJ\\nxVm1u9jwFDwOa11DGZ3zgEmNbh+3HhKf4zFurTFa88NaHsbvHXSadJMDBpuB42xR\\nAG6a2oUb0nNBg0QmxwAbo85JScNdWg6ncykQnROzGqpSICmIlL/E1Gl/Ti1hwrpP\\nu9J0ndrvDLo566k8h0Xr\\n-----END CERTIFICATE-----\\n"); ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); responseWrapper.setResponse(originalCertDownloadResponseDto); - ftpChipDetailService.getOriginalFtmCertificate("23456"); + ftpChipDetailService.getFtmCertificateData("23456"); } @Test - public void getOriginalFtmCertificate_Test1() throws Exception{ + public void getFtmCertificateData_Test1() throws Exception{ io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); SecurityContextHolder.setContext(securityContext); @@ -1155,11 +1155,11 @@ public void getOriginalFtmCertificate_Test1() throws Exception{ ftpChipDetail.setCertificateAlias("xxxyyxxx"); Mockito.when(ftpChipDetailRepository.findById(Mockito.anyString())).thenReturn(Optional.of(ftpChipDetail)); - ftpChipDetailService.getOriginalFtmCertificate("23456"); + ftpChipDetailService.getFtmCertificateData("23456"); } @Test - public void getOriginalFtmCertificate_Test2() throws Exception{ + public void getFtmCertificateData_Test2() throws Exception{ io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); SecurityContextHolder.setContext(securityContext); @@ -1182,7 +1182,7 @@ public void getOriginalFtmCertificate_Test2() throws Exception{ ftpChipDetail.setCertificateAlias("xxxyyxxx"); Mockito.when(ftpChipDetailRepository.findById(Mockito.anyString())).thenReturn(Optional.of(ftpChipDetail)); - ftpChipDetailService.getOriginalFtmCertificate("23456"); + ftpChipDetailService.getFtmCertificateData("23456"); } @Test @@ -1224,4 +1224,43 @@ public void getPartnersFtmChipDetailsTestException() throws Exception { when(ftmDetailsSummaryRepository.getSummaryOfPartnersFtmDetails(anyString(), anyString(), anyString(), anyString(), anyString(), any())).thenReturn(page); fTPChipDetailServiceImpl.getPartnersFtmChipDetails(sortFieldName, sortType, pageNo, pageSize, null); } + + @Test + public void ftmChipDetailTest() throws Exception { + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + partner.setId("123"); + partner.setPartnerTypeCode("FTM_Provider"); + partner.setApprovalStatus("approved"); + partner.setCertificateAlias("abs"); + partnerList.add(partner); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List ftpChipDetailList = new ArrayList<>(); + FTPChipDetail ftpChipDetail = new FTPChipDetail(); + ftpChipDetail.setFtpChipDetailId("xxx"); + ftpChipDetail.setFtpProviderId("123"); + ftpChipDetail.setMake("make"); + ftpChipDetail.setModel("model"); + ftpChipDetail.setApprovalStatus("approved"); + ftpChipDetail.setActive(true); + ftpChipDetail.setCrDtimes(LocalDateTime.now()); + ftpChipDetail.setCertificateAlias(""); + ftpChipDetailList.add(ftpChipDetail); + when(ftpChipDetailRepository.findByProviderId(anyString())).thenReturn(ftpChipDetailList); + fTPChipDetailServiceImpl.ftmChipDetail(); + } + + @Test + public void ftmChipDetailExceptionTest() throws Exception { + fTPChipDetailServiceImpl.ftmChipDetail(); + } } diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/SBIServiceTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/SBIServiceTest.java index 000adfc792..454e8ee005 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/SBIServiceTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/device/service/impl/SBIServiceTest.java @@ -659,6 +659,52 @@ public void getAllSbiDetailsExceptionTest() throws Exception { secureBiometricInterfaceService.getAllSbiDetails(sortFieldName, sortType, pageNo, pageSize, null); } + @Test + public void getSbiDetailsTest() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + partner.setId("123"); + partner.setPartnerTypeCode("Device_Provider"); + partnerList.add(partner); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + List secureBiometricInterfaceList = new ArrayList<>(); + SecureBiometricInterface secureBiometricInterface = new SecureBiometricInterface(); + secureBiometricInterface.setSwCreateDateTime(LocalDateTime.now()); + secureBiometricInterface.setSwExpiryDateTime(LocalDateTime.now()); + secureBiometricInterface.setApprovalStatus("approved"); + secureBiometricInterface.setActive(true); + secureBiometricInterface.setCrDtimes(LocalDateTime.now()); + secureBiometricInterfaceList.add(secureBiometricInterface); + secureBiometricInterface.setSwVersion("1.0"); + when(sbiRepository.findByProviderId(anyString())).thenReturn(secureBiometricInterfaceList); + List deviceDetailSBIList = new ArrayList<>(); + DeviceDetailSBI deviceDetailSBI = new DeviceDetailSBI(); + deviceDetailSBIList.add(deviceDetailSBI); + when(deviceDetailSbiRepository.findByDeviceProviderIdAndSbiId(anyString(), anyString())).thenReturn(deviceDetailSBIList); + + secureBiometricInterfaceService.getSbiDetails(); + } + + @Test + public void getSbiDetailsExceptionTest() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + + secureBiometricInterfaceService.getSbiDetails(); + } + private io.mosip.kernel.openid.bridge.model.MosipUserDto getMosipUserDto() { io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = new io.mosip.kernel.openid.bridge.model.MosipUserDto(); mosipUserDto.setUserId("123"); diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/MultiPartnerAdminServiceContollerTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/MultiPartnerAdminServiceContollerTest.java deleted file mode 100644 index df82a489cd..0000000000 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/MultiPartnerAdminServiceContollerTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package io.mosip.pms.test.partner.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import io.mosip.pms.common.request.dto.RequestWrapperV2; -import io.mosip.pms.common.response.dto.ResponseWrapperV2; -import io.mosip.pms.partner.controller.MultiPartnerAdminServiceController; -import io.mosip.pms.partner.request.dto.SbiAndDeviceMappingRequestDto; -import io.mosip.pms.partner.service.MultiPartnerAdminService; -import io.mosip.pms.partner.util.RequestValidator; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; - -import java.time.LocalDateTime; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(SpringRunner.class) -@SpringBootTest -@AutoConfigureMockMvc -@EnableWebMvc -public class MultiPartnerAdminServiceContollerTest { - - public static final String VERSION = "1.0"; - - @InjectMocks - MultiPartnerAdminServiceController multiPartnerAdminServiceController; - - @Mock - MultiPartnerAdminService multiPartnerAdminService; - - @Mock - RequestValidator requestValidator; - - @Autowired - private MockMvc mockMvc; - - @Autowired - private ObjectMapper objectMapper; - - @Test - @WithMockUser(roles = {"PARTNER_ADMIN"}) - public void approveMappingDeviceToSbiTest() throws Exception { - RequestWrapperV2 requestWrapper = new RequestWrapperV2<>(); - requestWrapper.setId("mosip.pms.approve.mapping.device.to.sbi.post"); - requestWrapper.setVersion(VERSION); - requestWrapper.setRequestTime(LocalDateTime.now()); - SbiAndDeviceMappingRequestDto sbiAndDeviceMappingRequestDto = new SbiAndDeviceMappingRequestDto(); - requestWrapper.setRequest(sbiAndDeviceMappingRequestDto); - ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); - responseWrapper.setResponse(true); - Mockito.when(multiPartnerAdminService.approveOrRejectMappingDeviceToSbi(requestWrapper.getRequest(), false)).thenReturn(responseWrapper); - mockMvc.perform(post("/admin/approve-mapping-device-to-sbi").contentType(MediaType.APPLICATION_JSON_VALUE) - .content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk()); - } - - @Test - @WithMockUser(roles = {"PARTNER_ADMIN"}) - public void approveMappingDeviceToSbiTest1() throws Exception { - RequestWrapperV2 requestWrapper = new RequestWrapperV2<>(); - requestWrapper.setVersion(VERSION); - requestWrapper.setRequestTime(LocalDateTime.now()); - SbiAndDeviceMappingRequestDto sbiAndDeviceMappingRequestDto = new SbiAndDeviceMappingRequestDto(); - requestWrapper.setRequest(sbiAndDeviceMappingRequestDto); - ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); - responseWrapper.setResponse(true); - Mockito.when(multiPartnerAdminService.approveOrRejectMappingDeviceToSbi(requestWrapper.getRequest(), false)).thenReturn(responseWrapper); - mockMvc.perform(post("/admin/approve-mapping-device-to-sbi").contentType(MediaType.APPLICATION_JSON_VALUE) - .content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk()); - } - - @Test - @WithMockUser(roles = {"PARTNER_ADMIN"}) - public void rejectMappingDeviceToSbiTest() throws Exception { - RequestWrapperV2 requestWrapper = new RequestWrapperV2<>(); - requestWrapper.setId("mosip.pms.reject.mapping.device.to.sbi.post"); - requestWrapper.setVersion(VERSION); - requestWrapper.setRequestTime(LocalDateTime.now()); - SbiAndDeviceMappingRequestDto sbiAndDeviceMappingRequestDto = new SbiAndDeviceMappingRequestDto(); - requestWrapper.setRequest(sbiAndDeviceMappingRequestDto); - ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); - responseWrapper.setResponse(true); - Mockito.when(multiPartnerAdminService.approveOrRejectMappingDeviceToSbi(requestWrapper.getRequest(), true)).thenReturn(responseWrapper); - mockMvc.perform(post("/admin/reject-mapping-device-to-sbi").contentType(MediaType.APPLICATION_JSON_VALUE) - .content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk()); - } - - @Test - @WithMockUser(roles = {"PARTNER_ADMIN"}) - public void rejectMappingDeviceToSbiTest1() throws Exception { - RequestWrapperV2 requestWrapper = new RequestWrapperV2<>(); - requestWrapper.setVersion(VERSION); - requestWrapper.setRequestTime(LocalDateTime.now()); - SbiAndDeviceMappingRequestDto sbiAndDeviceMappingRequestDto = new SbiAndDeviceMappingRequestDto(); - requestWrapper.setRequest(sbiAndDeviceMappingRequestDto); - ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); - responseWrapper.setResponse(true); - Mockito.when(multiPartnerAdminService.approveOrRejectMappingDeviceToSbi(requestWrapper.getRequest(), true)).thenReturn(responseWrapper); - mockMvc.perform(post("/admin/reject-mapping-device-to-sbi").contentType(MediaType.APPLICATION_JSON_VALUE) - .content(objectMapper.writeValueAsString(requestWrapper))).andExpect(status().isOk()); - } -} diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/MultiPartnerServiceControllerTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/MultiPartnerServiceControllerTest.java index 5396a9c5c0..3a19dcbba5 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/MultiPartnerServiceControllerTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/MultiPartnerServiceControllerTest.java @@ -1,6 +1,7 @@ package io.mosip.pms.test.partner.controller; import io.mosip.pms.common.response.dto.ResponseWrapperV2; +import io.mosip.pms.device.dto.FtmChipDetailsDto; import io.mosip.pms.partner.controller.MultiPartnerServiceController; import io.mosip.pms.partner.dto.*; import io.mosip.pms.partner.service.MultiPartnerService; @@ -36,40 +37,6 @@ public class MultiPartnerServiceControllerTest { public static final String VERSION = "1.0"; - @Test - @WithMockUser(roles = {"PARTNER"}) - public void getPartnerCertificates() throws Exception { - ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); - - CertificateDto certificateDto = new CertificateDto(); - certificateDto.setPartnerId("abc"); - certificateDto.setPartnerType("Auth_Partner"); - certificateDto.setIsCertificateAvailable(false); - - List certificateDtoList = new ArrayList<>(); - certificateDtoList.add(certificateDto); - - responseWrapper.setResponse(certificateDtoList); - Mockito.when(multiPartnerService.getPartnerCertificates()).thenReturn(responseWrapper); - ResponseWrapperV2> response = multiPartnerServiceController.getPartnerCertificates(); - } - - @Test - @WithMockUser(roles = {"PARTNER"}) - public void getPolicyRequestsTest() throws Exception { - ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); - PolicyDto policyDto = new PolicyDto(); - policyDto.setPartnerId("abc"); - policyDto.setPartnerType("Auth_Partner"); - policyDto.setPolicyGroupName("123"); - policyDto.setPolicyName("test"); - List policyDtoList = new ArrayList<>(); - policyDtoList.add(policyDto); - responseWrapper.setResponse(policyDtoList); - Mockito.when(multiPartnerService.getPolicyRequests()).thenReturn(responseWrapper); - ResponseWrapperV2> response = multiPartnerServiceController.getPolicyRequests(); - } - @Test @WithMockUser(roles = {"PARTNER"}) public void getAuthPartnersPoliciesTest() throws Exception { @@ -101,38 +68,6 @@ public void getApprovedPartnerIdsWithPolicyGroupsTest() throws Exception { ResponseWrapperV2> response = multiPartnerServiceController.getApprovedPartnerIdsWithPolicyGroups(); } - @Test - @WithMockUser(roles = {"PARTNER"}) - public void getApiKeysForAuthPartners() throws Exception { - ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); - ApiKeyResponseDto apiKeyResponseDto = new ApiKeyResponseDto(); - apiKeyResponseDto.setStatus("ACTIVE"); - apiKeyResponseDto.setApiKeyLabel("test"); - apiKeyResponseDto.setPolicyId("policy123"); - apiKeyResponseDto.setPolicyName("policy123name"); - apiKeyResponseDto.setPolicyDescription("policy123desc"); - apiKeyResponseDto.setPolicyGroupId("policygroup000"); - apiKeyResponseDto.setPolicyGroupName("policygroup000name"); - apiKeyResponseDto.setPolicyGroupDescription("policygroup000desc"); - List apiKeyResponseDtoList = new ArrayList<>(); - apiKeyResponseDtoList.add(apiKeyResponseDto); - responseWrapper.setResponse(apiKeyResponseDtoList); - Mockito.when(multiPartnerService.getApiKeysForAuthPartners()).thenReturn(responseWrapper); - ResponseWrapperV2> response = multiPartnerServiceController.getApiKeysForAuthPartners(); - } - - @Test - @WithMockUser(roles = {"DEVICE_PROVIDER"}) - public void sbiDetailsTest() throws Exception { - ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); - List sbiDetailsDtoList = new ArrayList<>(); - SbiDetailsDto sbiDetailsDto = new SbiDetailsDto(); - sbiDetailsDtoList.add(sbiDetailsDto); - responseWrapper.setResponse(sbiDetailsDtoList); - Mockito.when(multiPartnerService.sbiDetails()).thenReturn(responseWrapper); - ResponseWrapperV2> response = multiPartnerServiceController.sbiDetails(); - } - @Test @WithMockUser(roles = {"DEVICE_PROVIDER"}) public void approvedDeviceProviderIdsTest() throws Exception { @@ -145,18 +80,6 @@ public void approvedDeviceProviderIdsTest() throws Exception { ResponseWrapperV2> response = multiPartnerServiceController.approvedDeviceProviderIds(); } - @Test - @WithMockUser(roles = {"FTM_PROVIDER"}) - public void ftmChipDetailsTest() throws Exception { - ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); - List ftmChipDetailsDtoList = new ArrayList<>(); - FtmChipDetailsDto ftmChipDetailsDto = new FtmChipDetailsDto(); - ftmChipDetailsDtoList.add(ftmChipDetailsDto); - responseWrapper.setResponse(ftmChipDetailsDtoList); - Mockito.when(multiPartnerService.ftmChipDetails()).thenReturn(responseWrapper); - ResponseWrapperV2> response = multiPartnerServiceController.ftmChipDetails(); - } - @Test @WithMockUser(roles = {"FTM_PROVIDER"}) public void approvedFTMProviderIdsTest() throws Exception { diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/PartnerServiceControllerTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/PartnerServiceControllerTest.java index f344e2921a..03e35e7802 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/PartnerServiceControllerTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/PartnerServiceControllerTest.java @@ -14,6 +14,9 @@ import io.mosip.pms.common.request.dto.RequestWrapperV2; import io.mosip.pms.common.response.dto.ResponseWrapper; import io.mosip.pms.common.response.dto.ResponseWrapperV2; +import io.mosip.pms.partner.dto.ApiKeyResponseDto; +import io.mosip.pms.partner.dto.CertificateDto; +import io.mosip.pms.partner.dto.PolicyDto; import io.mosip.pms.partner.response.dto.*; import org.junit.Before; import org.junit.Test; @@ -327,15 +330,15 @@ public void getPartnerCertificateTest() throws Exception{ @Test @WithMockUser(roles = {"PARTNER"}) - public void getOriginalPartnerCertificateTest() throws Exception{ + public void getPartnerCertificateDataTest() throws Exception{ ResponseWrapperV2 responseWrapper = new ResponseWrapperV2<>(); OriginalCertDownloadResponseDto originalCertDownloadResponseDto = new OriginalCertDownloadResponseDto(); RequestWrapperV2 requestWrapper = new RequestWrapperV2<>(); PartnerCertDownloadRequestDto requestDto = new PartnerCertDownloadRequestDto(); requestWrapper.setRequest(requestDto); responseWrapper.setResponse(originalCertDownloadResponseDto); - Mockito.when(partnerService.getOriginalPartnerCertificate(requestDto)).thenReturn(responseWrapper); - mockMvc.perform(MockMvcRequestBuilders.get("/partners/1234/original-partner-certificate")).andExpect(MockMvcResultMatchers.status().isOk()); + Mockito.when(partnerService.getPartnerCertificateData(requestDto)).thenReturn(responseWrapper); + mockMvc.perform(MockMvcRequestBuilders.get("/partners/1234/certificate-data")).andExpect(MockMvcResultMatchers.status().isOk()); } private RequestWrapper createFilterRequest(){ @@ -574,6 +577,59 @@ private AddContactRequestDto addContactRequestDto() { dto.setIs_Active(true); return dto; } - - + + @Test + @WithMockUser(roles = {"PARTNER"}) + public void getPolicyRequestsTest() throws Exception { + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + PolicyDto policyDto = new PolicyDto(); + policyDto.setPartnerId("abc"); + policyDto.setPartnerType("Auth_Partner"); + policyDto.setPolicyGroupName("123"); + policyDto.setPolicyName("test"); + List policyDtoList = new ArrayList<>(); + policyDtoList.add(policyDto); + responseWrapper.setResponse(policyDtoList); + Mockito.when(partnerService.getPolicyRequests()).thenReturn(responseWrapper); + } + + @Test + @WithMockUser(roles = {"PARTNER"}) + public void getPartnerCertificatesDetailsTest() throws Exception { + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + + CertificateDto certificateDto = new CertificateDto(); + certificateDto.setPartnerId("abc"); + certificateDto.setPartnerType("Auth_Partner"); + certificateDto.setIsCertificateAvailable(false); + + List certificateDtoList = new ArrayList<>(); + certificateDtoList.add(certificateDto); + + responseWrapper.setResponse(certificateDtoList); + Mockito.when(partnerService.getPartnerCertificatesDetails()).thenReturn(responseWrapper); + mockMvc.perform(MockMvcRequestBuilders.get("/partners/partner-certificates-details")).andExpect(MockMvcResultMatchers.status().isOk()); + } + + @Test + @WithMockUser(roles = {"PARTNER"}) + public void getAuthPartnerApiKeysTest() throws Exception { + ResponseWrapperV2> responseWrapper = new ResponseWrapperV2<>(); + ApiKeyResponseDto apiKeyResponseDto = new ApiKeyResponseDto(); + apiKeyResponseDto.setStatus("ACTIVE"); + apiKeyResponseDto.setApiKeyLabel("test"); + apiKeyResponseDto.setPolicyId("policy123"); + apiKeyResponseDto.setPolicyName("policy123name"); + apiKeyResponseDto.setPolicyDescription("policy123desc"); + apiKeyResponseDto.setPolicyGroupId("policygroup000"); + apiKeyResponseDto.setPolicyGroupName("policygroup000name"); + apiKeyResponseDto.setPolicyGroupDescription("policygroup000desc"); + List apiKeyResponseDtoList = new ArrayList<>(); + apiKeyResponseDtoList.add(apiKeyResponseDto); + responseWrapper.setResponse(apiKeyResponseDtoList); + Mockito.when(partnerService.getAuthPartnerApiKeys()).thenReturn(responseWrapper); + mockMvc.perform(MockMvcRequestBuilders.get("/partners/auth-partner-api-keys")).andExpect(MockMvcResultMatchers.status().isOk()); + } + + } \ No newline at end of file diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/UserControllerTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/UserControllerTest.java index 12a4306d96..afa357b582 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/UserControllerTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/controller/UserControllerTest.java @@ -92,7 +92,7 @@ public void isUserConsentGiven() throws Exception { @Test @WithMockUser(roles = {"PARTNER"}) public void getConfigValuesTest() throws Exception { - mockMvc.perform(get("/users/configs").contentType(MediaType.APPLICATION_JSON_VALUE)) + mockMvc.perform(get("/system-config").contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(status().isOk()); } } diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/MultiPartnerAdminServiceImplTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/MultiPartnerAdminServiceImplTest.java deleted file mode 100644 index 357760a08d..0000000000 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/MultiPartnerAdminServiceImplTest.java +++ /dev/null @@ -1,162 +0,0 @@ -package io.mosip.pms.test.partner.service.impl; - -import io.mosip.kernel.openid.bridge.model.AuthUserDetails; -import io.mosip.pms.common.entity.DeviceDetailSBI; -import io.mosip.pms.common.repository.DeviceDetailSbiRepository; -import io.mosip.pms.device.authdevice.entity.DeviceDetail; -import io.mosip.pms.device.authdevice.entity.SecureBiometricInterface; -import io.mosip.pms.device.authdevice.repository.DeviceDetailRepository; -import io.mosip.pms.device.authdevice.repository.SecureBiometricInterfaceRepository; -import io.mosip.pms.partner.exception.PartnerServiceException; -import io.mosip.pms.partner.request.dto.SbiAndDeviceMappingRequestDto; -import io.mosip.pms.partner.service.impl.MultiPartnerAdminServiceImpl; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.test.context.junit4.SpringRunner; - -import java.time.LocalDateTime; -import java.util.Optional; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class MultiPartnerAdminServiceImplTest { - - @MockBean - SecureBiometricInterfaceRepository secureBiometricInterfaceRepository; - - @MockBean - DeviceDetailSbiRepository deviceDetailSbiRepository; - - @MockBean - DeviceDetailRepository deviceDetailRepository; - - @Mock - Authentication authentication; - - @Mock - SecurityContext securityContext; - - @Autowired - MultiPartnerAdminServiceImpl multiPartnerAdminServiceImpl; - - - private io.mosip.kernel.openid.bridge.model.MosipUserDto getMosipUserDto() { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = new io.mosip.kernel.openid.bridge.model.MosipUserDto(); - mosipUserDto.setUserId("123"); - mosipUserDto.setMail("abc@gmail.com"); - return mosipUserDto; - } - - @Test - public void approveOrRejectMappingDeviceToSbiTest() throws Exception { - SbiAndDeviceMappingRequestDto requestDto = new SbiAndDeviceMappingRequestDto(); - requestDto.setPartnerId("123"); - requestDto.setSbiId("112"); - requestDto.setDeviceDetailId("dgdg"); - - DeviceDetailSBI deviceDetailSBI = new DeviceDetailSBI(); - when(deviceDetailSbiRepository.findByDeviceProviderIdAndSbiIdAndDeviceDetailId(anyString(), anyString(), anyString())).thenReturn(deviceDetailSBI); - - DeviceDetail deviceDetail = new DeviceDetail(); - deviceDetail.setDeviceProviderId("123"); - deviceDetail.setApprovalStatus("pending_approval"); - when(deviceDetailRepository.findByIdAndIsDeletedFalseOrIsDeletedIsNull(anyString())).thenReturn(deviceDetail); - - SecureBiometricInterface secureBiometricInterface = new SecureBiometricInterface(); - secureBiometricInterface.setSwCreateDateTime(LocalDateTime.now()); - secureBiometricInterface.setSwExpiryDateTime(LocalDateTime.now()); - secureBiometricInterface.setApprovalStatus("approved"); - secureBiometricInterface.setActive(true); - secureBiometricInterface.setCrDtimes(LocalDateTime.now()); - secureBiometricInterface.setSwVersion("1.0"); - secureBiometricInterface.setProviderId("123"); - when(secureBiometricInterfaceRepository.findById(anyString())).thenReturn(Optional.of(secureBiometricInterface)); - - when(deviceDetailRepository.findById(anyString())).thenReturn(Optional.of(deviceDetail)); - deviceDetailSBI.setProviderId("123"); - when(deviceDetailSbiRepository.save(any())).thenReturn(deviceDetailSBI); - - multiPartnerAdminServiceImpl.approveOrRejectMappingDeviceToSbi(requestDto, false); - } - - @Test - public void approveOrRejectMappingDeviceToSbiTest2() throws Exception { - SbiAndDeviceMappingRequestDto requestDto = new SbiAndDeviceMappingRequestDto(); - requestDto.setPartnerId("123"); - requestDto.setSbiId("112"); - requestDto.setDeviceDetailId("dgdg"); - - DeviceDetailSBI deviceDetailSBI = new DeviceDetailSBI(); - when(deviceDetailSbiRepository.findByDeviceProviderIdAndSbiIdAndDeviceDetailId(anyString(), anyString(), anyString())).thenReturn(deviceDetailSBI); - - DeviceDetail deviceDetail = new DeviceDetail(); - deviceDetail.setDeviceProviderId("123"); - deviceDetail.setApprovalStatus("pending_approval"); - when(deviceDetailRepository.findByIdAndIsDeletedFalseOrIsDeletedIsNull(anyString())).thenReturn(deviceDetail); - - SecureBiometricInterface secureBiometricInterface = new SecureBiometricInterface(); - secureBiometricInterface.setSwCreateDateTime(LocalDateTime.now()); - secureBiometricInterface.setSwExpiryDateTime(LocalDateTime.now()); - secureBiometricInterface.setApprovalStatus("approved"); - secureBiometricInterface.setActive(true); - secureBiometricInterface.setCrDtimes(LocalDateTime.now()); - secureBiometricInterface.setSwVersion("1.0"); - secureBiometricInterface.setProviderId("123"); - when(secureBiometricInterfaceRepository.findById(anyString())).thenReturn(Optional.of(secureBiometricInterface)); - - when(deviceDetailRepository.findById(anyString())).thenReturn(Optional.of(deviceDetail)); - deviceDetailSBI.setProviderId("123"); - when(deviceDetailSbiRepository.save(any())).thenReturn(deviceDetailSBI); - - multiPartnerAdminServiceImpl.approveOrRejectMappingDeviceToSbi(requestDto, true); - } - - @Test - public void approveDeviceWithSbiMappingException() { - - SbiAndDeviceMappingRequestDto requestDto = new SbiAndDeviceMappingRequestDto(); - requestDto.setPartnerId("123"); - requestDto.setSbiId("112"); - - multiPartnerAdminServiceImpl.approveOrRejectMappingDeviceToSbi(requestDto, false); - - requestDto.setDeviceDetailId("dgdg"); - - SecureBiometricInterface secureBiometricInterface = new SecureBiometricInterface(); - secureBiometricInterface.setSwCreateDateTime(LocalDateTime.now()); - secureBiometricInterface.setSwExpiryDateTime(LocalDateTime.now()); - secureBiometricInterface.setApprovalStatus("approved"); - secureBiometricInterface.setActive(true); - secureBiometricInterface.setCrDtimes(LocalDateTime.now()); - secureBiometricInterface.setSwVersion("1.0"); - secureBiometricInterface.setProviderId("123"); - - multiPartnerAdminServiceImpl.approveOrRejectMappingDeviceToSbi(requestDto, false); - when(secureBiometricInterfaceRepository.findById(anyString())).thenReturn(Optional.of(secureBiometricInterface)); - DeviceDetail deviceDetail = new DeviceDetail(); - deviceDetail.setDeviceProviderId("123"); - - multiPartnerAdminServiceImpl.approveOrRejectMappingDeviceToSbi(requestDto, false); - when(deviceDetailRepository.findById(anyString())).thenReturn(Optional.of(deviceDetail)); - - when(deviceDetailSbiRepository.findByDeviceProviderIdAndSbiIdAndDeviceDetailId(anyString(), anyString(), anyString())).thenReturn(null); - multiPartnerAdminServiceImpl.approveOrRejectMappingDeviceToSbi(requestDto, false); - - DeviceDetailSBI deviceDetailSBI = new DeviceDetailSBI(); - deviceDetailSBI.setProviderId("123"); - when(deviceDetailSbiRepository.findByDeviceProviderIdAndSbiIdAndDeviceDetailId(anyString(), anyString(), anyString())).thenReturn(deviceDetailSBI); - - multiPartnerAdminServiceImpl.approveOrRejectMappingDeviceToSbi(requestDto, false); - } -} diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/MultiPartnerServiceImplTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/MultiPartnerServiceImplTest.java index 4811976ef3..122a85bf95 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/MultiPartnerServiceImplTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/MultiPartnerServiceImplTest.java @@ -59,265 +59,11 @@ public class MultiPartnerServiceImplTest { @MockBean FTPChipDetailRepository ftpChipDetailRepository; - @Mock - Environment environment; @Mock Authentication authentication; @Mock SecurityContext securityContext; - @Test - public void getPartnerCertificatesTest() throws Exception { - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - partner.setId("123"); - partner.setCertificateAlias("abs"); - partnerList.add(partner); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - Map apiResponse = new HashMap<>(); - Map response = new HashMap<>(); - response.put("certificateData", "-----BEGIN CERTIFICATE-----\n" + - "MIIFfTCCA2WgAwIBAgIUOVZNyD46U0OAEhaGC/Y7NXbu+OkwDQYJKoZIhvcNAQEL\n" + - "BQAwTjELMAkGA1UEBhMCSU4xCzAJBgNVBAgMAk1IMQswCQYDVQQHDAJQTjELMAkG\n" + - "A1UECgwCQ0ExCzAJBgNVBAsMAkNBMQswCQYDVQQDDAJDQTAeFw0yNDA1MDkwNzI1\n" + - "MDJaFw0yOTA1MDkwNzI1MDJaME4xCzAJBgNVBAYTAklOMQswCQYDVQQIDAJNSDEL\n" + - "MAkGA1UEBwwCUE4xCzAJBgNVBAoMAkNBMQswCQYDVQQLDAJDQTELMAkGA1UEAwwC\n" + - "Q0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCzdWD2DvhSnmLqU3fX\n" + - "RT3z8ikS6qHxn5Hu/a2ijkuZxAZj0UCUJ83kM20NwocJDHT1qx6+yjdl+BECsgoI\n" + - "ro9MXgFOsHCphyR5KiP4mY95qRlE03h7WBfr4wDn/6f5tCbqCcBqdXMAQxUp34D+\n" + - "Pro0EwkXNulHNMTvz5hpoCEiGyfXUP48I4q2nb8rMXaplhqz+vAYgA4rsK6K9IUh\n" + - "uJDxtZRHdIfxnvbfjxDbuPkN0ehOQ1uQrDVY6ENCIUxdgR/p94kZ+CNsD21c57gJ\n" + - "2wYg+BceQn1rVSGnfpqMoogZCMUWFvaE4i91419VXxDLgeC/4Qw8n5onBY+dVHjW\n" + - "04OolR2DqotFyaPlZiVdpUys6+KZ7fS9mwWEY0kqtLzcBeb4g4nPvObfKnqSmVMZ\n" + - "DHRuAx6MG3oFZrnNuS6oIYGwLpoko6iqEiGohHsSxMulT43XOxoNgDq9noQc9SYv\n" + - "tzdzijBRLAxNBDTB0rgZra27tLIFlqP1TpqZtM3ThOmPJQn6JG8WeiVWnmUkpmXX\n" + - "6opGqhLWMM/u1n4fdf716h7340RbCPJoOpTPphYo/WedFQskqZvhTU6HMIj4JQAj\n" + - "OVVwgtrDOdx051ps2hhiSU5tL4LmjLHIsfyoCSuHkzBhVMZ/jKFm8C4Or2RRG85A\n" + - "wtzEANSxVZRjw6S1hsHsI+8m2QIDAQABo1MwUTAdBgNVHQ4EFgQUjDli1GMiclHK\n" + - "igNm2kuKh48AON8wHwYDVR0jBBgwFoAUjDli1GMiclHKigNm2kuKh48AON8wDwYD\n" + - "VR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAgEAk6IWcDdBc1tngCaPNLhU\n" + - "c3pXRdTjDuLHMxHRiP/7Vi3V2xcKRak5ZMzYAJK6YThp3Z04V9d5jJoi/CDhMuPK\n" + - "RV1GmbdA7b24Jic2fQHWOJkgafT2Gx4yHmLo5ctSuDHPfSvzUgeghG0k3eNJgCai\n" + - "Ctr+wvCRZGvvbl2JnJUcWiHBxH/PaWJ4Jd1T4UKmhlFhTw26TXQGHuW/UJwgh8OR\n" + - "V8A+WeMXxKFsh38b8RnWVa6XdajIq9UAZvvd4Q16zjdnMWx/7zcIK5D1MDb/KmSJ\n" + - "yho1LKRZx5YtSeI4FWs8dzZ0nCCiTe7TrnnhlXThJ6rXeo5AshtM4fGrvizaf4n3\n" + - "7I9mJkqiccp1ml+2EcgsdX7HbnGE/R8VVbh3jUhWHuysLCiVSMbjnktCLWoXjSb9\n" + - "JqOYF3yo6JQslQB0fQMyKmvsn/FplQBbU0PUrg9vpAg9nZlZf3UHO5z072pXD6ky\n" + - "5pKjh+q0JOk00Eln9AoU6YuIyPBQ9mI3X8iYB5UhUBbgAPeg1pwWCWhdt40f0D5t\n" + - "JkVnICy+Gh1ps8QPA6coEaajbIq14Uh6eYEwxFHPsxlbn7pzjoCJG2v7N8VwgfuL\n" + - "DdGs4hFikdUAfBT/Diug/n9/ZgfdN6Ctf4U/SM65vZvfRqtLIoTIs4PcF3YtKK04\n" + - "m0UA3Sxxre0vVWYO4GmmZUY=\n" + - "-----END CERTIFICATE-----"); - apiResponse.put("response", response); - - when(environment.getProperty("pmp.partner.certificaticate.get.rest.uri")).thenReturn("uri"); - when(restUtil.getApi(anyString(), any(), eq(Map.class))).thenReturn(apiResponse); - multiPartnerServiceImpl.getPartnerCertificates(); - } - - @Test - public void getPartnerCertificatesTestException() throws Exception { - multiPartnerServiceImpl.getPartnerCertificates(); - } - - @Test - public void getPartnerCertificatesTestException1() throws Exception { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - partner.setId(""); - partner.setCertificateAlias(""); - partnerList.add(partner); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - multiPartnerServiceImpl.getPartnerCertificates(); - } - - @Test - public void getPartnerCertificatesTestException2() throws Exception { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - multiPartnerServiceImpl.getPartnerCertificates(); - } - - @Test - public void getAllPoliciesTest() throws Exception { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - partner.setId("123"); - partner.setPartnerTypeCode("AUTH"); - partner.setPolicyGroupId("abc"); - List partnerPolicyRequestList = new ArrayList<>(); - PartnerPolicyRequest partnerPolicyRequest = new PartnerPolicyRequest(); - partnerPolicyRequest.setPolicyId("xyz"); - partnerPolicyRequest.setCrDtimes(Timestamp.valueOf(LocalDateTime.now())); - partnerPolicyRequest.setStatusCode("approved"); - partnerPolicyRequestList.add(partnerPolicyRequest); - partner.setPartnerPolicyRequests(partnerPolicyRequestList); - partnerList.add(partner); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - PolicyGroup policyGroup = new PolicyGroup(); - policyGroup.setId("abc"); - policyGroup.setName("group1"); - policyGroup.setDesc("dgvhsd"); - when(policyGroupRepository.findPolicyGroupById(anyString())).thenReturn(policyGroup); - - String policyGroupName = "test"; - AuthPolicy authPolicy = new AuthPolicy(); - authPolicy.setName("policy123"); - when(policyGroupRepository.findPolicyGroupNameById(anyString())).thenReturn(policyGroupName); - when(authPolicyRepository.findByPolicyGroupAndId(anyString(), anyString())).thenReturn(authPolicy); - multiPartnerServiceImpl.getPolicyRequests(); - - when(authPolicyRepository.findByPolicyGroupAndId(anyString(), anyString())).thenReturn(null); - multiPartnerServiceImpl.getPolicyRequests(); - } - - @Test - public void getAllPoliciesTest1() throws Exception { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - partner.setId("123"); - partner.setPartnerTypeCode("AUTH"); - partner.setPolicyGroupId("abc"); - List partnerPolicyRequestList = new ArrayList<>(); - partner.setPartnerPolicyRequests(partnerPolicyRequestList); - partnerList.add(partner); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - PolicyGroup policyGroup = new PolicyGroup(); - policyGroup.setId("abc"); - policyGroup.setName("group1"); - policyGroup.setDesc("dgvhsd"); - when(policyGroupRepository.findPolicyGroupById(anyString())).thenReturn(policyGroup); - - AuthPolicy authPolicy = new AuthPolicy(); - authPolicy.setName("policy123"); - when(authPolicyRepository.findByPolicyGroupAndId(anyString(), anyString())).thenReturn(authPolicy); - - multiPartnerServiceImpl.getPolicyRequests(); - } - - @Test - public void getAllPoliciesTest2() throws Exception { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - partner.setId("123"); - partner.setPartnerTypeCode(""); - partner.setPolicyGroupId("abc"); - List partnerPolicyRequestList = new ArrayList<>(); - PartnerPolicyRequest partnerPolicyRequest = new PartnerPolicyRequest(); - partnerPolicyRequest.setPolicyId("xyz"); - partnerPolicyRequest.setCrDtimes(Timestamp.valueOf(LocalDateTime.now())); - partnerPolicyRequest.setStatusCode("approved"); - partnerPolicyRequestList.add(partnerPolicyRequest); - partner.setPartnerPolicyRequests(partnerPolicyRequestList); - partnerList.add(partner); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - multiPartnerServiceImpl.getPolicyRequests(); - } - - @Test - public void getAllPoliciesTest3() throws Exception { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - partner.setId(""); - partner.setPartnerTypeCode("Auth_Partner"); - partner.setPolicyGroupId("abc"); - partnerList.add(partner); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - multiPartnerServiceImpl.getPolicyRequests(); - } - - @Test - public void getAllPoliciesTest4() throws Exception { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - partner.setId("ddd"); - partner.setPartnerTypeCode("Auth_Partner"); - partner.setPolicyGroupId(""); - partnerList.add(partner); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - multiPartnerServiceImpl.getPolicyRequests(); - } - - @Test - public void getAllPoliciesTestException() throws Exception { - multiPartnerServiceImpl.getPolicyRequests(); - } - - @Test - public void getAllPoliciesTestException1() throws Exception { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - multiPartnerServiceImpl.getPolicyRequests(); - } - - @Test public void getAuthPartnersPolicies() throws Exception { io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); @@ -500,192 +246,6 @@ public void getApprovedPartnerIdsWithPolicyGroupssTestException1() throws Except multiPartnerServiceImpl.getApprovedPartnerIdsWithPolicyGroups(); } - @Test - public void getApiKeysForAuthPartnersTest() throws Exception{ - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - partner.setId("123"); - partner.setPartnerTypeCode("Auth_Partner"); - partner.setPolicyGroupId("abc"); - partner.setApprovalStatus("approved"); - partnerList.add(partner); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - - PartnerPolicy partnerPolicy = new PartnerPolicy(); - partnerPolicy.setPolicyApiKey("apikey123"); - partnerPolicy.setLabel("request"); - partnerPolicy.setIsActive(true); - partnerPolicy.setPartner(partner); - partnerPolicy.setPolicyId("test"); - List partnerPolicies = new ArrayList<>(); - partnerPolicies.add(partnerPolicy); - when(partnerPolicyRepository.findAPIKeysByPartnerId(anyString())).thenReturn(partnerPolicies); - - AuthPolicy authPolicy = new AuthPolicy(); - authPolicy.setId("test"); - authPolicy.setName("hjfvhd"); - authPolicy.setDescr("tttt"); - PolicyGroup policyGroup = new PolicyGroup(); - policyGroup.setId("abc"); - policyGroup.setName("group1"); - policyGroup.setDesc("group1d"); - authPolicy.setPolicyGroup(policyGroup); - Optional authPolicyDetails = Optional.of(authPolicy); - when(authPolicyRepository.findById(anyString())).thenReturn(authPolicyDetails); - multiPartnerServiceImpl.getApiKeysForAuthPartners(); - } - - @Test - public void getApiKeysForAuthPartnersTest1() throws Exception { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - partner.setId("123"); - partner.setPartnerTypeCode("Auth_Partner"); - partner.setPolicyGroupId("abc"); - partner.setApprovalStatus("approved"); - partnerList.add(partner); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - - PartnerPolicy partnerPolicy = new PartnerPolicy(); - partnerPolicy.setPolicyApiKey("apikey123"); - partnerPolicy.setLabel("request"); - partnerPolicy.setIsActive(false); - partnerPolicy.setPartner(partner); - partnerPolicy.setPolicyId("test"); - List partnerPolicies = new ArrayList<>(); - partnerPolicies.add(partnerPolicy); - when(partnerPolicyRepository.findAPIKeysByPartnerId(anyString())).thenReturn(partnerPolicies); - - AuthPolicy authPolicy = new AuthPolicy(); - authPolicy.setId("test"); - authPolicy.setName("hjfvhd"); - authPolicy.setDescr("tttt"); - PolicyGroup policyGroup = new PolicyGroup(); - policyGroup.setId("abc"); - policyGroup.setName("group1"); - policyGroup.setDesc("group1d"); - authPolicy.setPolicyGroup(policyGroup); - Optional authPolicyDetails = Optional.of(authPolicy); - when(authPolicyRepository.findById(anyString())).thenReturn(authPolicyDetails); - multiPartnerServiceImpl.getApiKeysForAuthPartners(); - } - - @Test - public void getApiKeysForAuthPartnersTest2() throws Exception{ - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - partner.setId("123"); - partner.setPartnerTypeCode("Auth_Partner"); - partner.setPolicyGroupId("abc"); - partner.setApprovalStatus("approved"); - partnerList.add(partner); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - - PartnerPolicy partnerPolicy = new PartnerPolicy(); - partnerPolicy.setPolicyApiKey("apikey123"); - partnerPolicy.setLabel("request"); - partnerPolicy.setIsActive(true); - partnerPolicy.setPartner(partner); - partnerPolicy.setPolicyId("test"); - List partnerPolicies = new ArrayList<>(); - partnerPolicies.add(partnerPolicy); - when(partnerPolicyRepository.findAPIKeysByPartnerId(anyString())).thenReturn(partnerPolicies); - multiPartnerServiceImpl.getApiKeysForAuthPartners(); - - AuthPolicy authPolicy = new AuthPolicy(); - PolicyGroup policyGroup = new PolicyGroup(); - authPolicy.setPolicyGroup(policyGroup); - when(authPolicyRepository.findById(any())).thenReturn(Optional.of(authPolicy)); - multiPartnerServiceImpl.getApiKeysForAuthPartners(); - } - - @Test - public void getApiKeysForAuthPartnersTestException() throws Exception { - multiPartnerServiceImpl.getApiKeysForAuthPartners(); - } - - @Test - public void getApiKeysForAuthPartnersTestException1() throws Exception { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - multiPartnerServiceImpl.getApiKeysForAuthPartners(); - } - - @Test - public void sbiDetailsTest() throws Exception { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - partner.setId("123"); - partner.setPartnerTypeCode("Device_Provider"); - partnerList.add(partner); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - List secureBiometricInterfaceList = new ArrayList<>(); - SecureBiometricInterface secureBiometricInterface = new SecureBiometricInterface(); - secureBiometricInterface.setSwCreateDateTime(LocalDateTime.now()); - secureBiometricInterface.setSwExpiryDateTime(LocalDateTime.now()); - secureBiometricInterface.setApprovalStatus("approved"); - secureBiometricInterface.setActive(true); - secureBiometricInterface.setCrDtimes(LocalDateTime.now()); - secureBiometricInterfaceList.add(secureBiometricInterface); - secureBiometricInterface.setSwVersion("1.0"); - when(secureBiometricInterfaceRepository.findByProviderId(anyString())).thenReturn(secureBiometricInterfaceList); - List deviceDetailSBIList = new ArrayList<>(); - DeviceDetailSBI deviceDetailSBI = new DeviceDetailSBI(); - deviceDetailSBIList.add(deviceDetailSBI); - when(deviceDetailSbiRepository.findByDeviceProviderIdAndSbiId(anyString(), anyString())).thenReturn(deviceDetailSBIList); - - multiPartnerServiceImpl.sbiDetails(); - } - - @Test - public void sbiDetailsExceptionTest() throws Exception { - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List partnerList = new ArrayList<>(); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - - multiPartnerServiceImpl.sbiDetails(); - } - @Test public void approvedDeviceProviderIdsTest() throws Exception { io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); @@ -724,45 +284,6 @@ public void approvedDeviceProviderIdsExceptionTest1() throws Exception { multiPartnerServiceImpl.approvedDeviceProviderIds(); } - @Test - public void ftmChipDetailsTest() throws Exception { - - List partnerList = new ArrayList<>(); - Partner partner = new Partner(); - partner.setId("123"); - partner.setPartnerTypeCode("FTM_Provider"); - partner.setApprovalStatus("approved"); - partner.setCertificateAlias("abs"); - partnerList.add(partner); - when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); - when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); - - io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); - AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(authUserDetails); - when(securityContext.getAuthentication()).thenReturn(authentication); - - List ftpChipDetailList = new ArrayList<>(); - FTPChipDetail ftpChipDetail = new FTPChipDetail(); - ftpChipDetail.setFtpChipDetailId("xxx"); - ftpChipDetail.setFtpProviderId("123"); - ftpChipDetail.setMake("make"); - ftpChipDetail.setModel("model"); - ftpChipDetail.setApprovalStatus("approved"); - ftpChipDetail.setActive(true); - ftpChipDetail.setCrDtimes(LocalDateTime.now()); - ftpChipDetail.setCertificateAlias(""); - ftpChipDetailList.add(ftpChipDetail); - when(ftpChipDetailRepository.findByProviderId(anyString())).thenReturn(ftpChipDetailList); - multiPartnerServiceImpl.ftmChipDetails(); - } - - @Test - public void ftmChipDetailsExceptionTest() throws Exception { - multiPartnerServiceImpl.ftmChipDetails(); - } - @Test public void approvedFTMProviderIdsTest() throws Exception { io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerServiceImplTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerServiceImplTest.java index df4ffc79d4..69ed3415c7 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerServiceImplTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerServiceImplTest.java @@ -33,6 +33,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; +import org.springframework.core.env.Environment; import org.springframework.data.domain.PageImpl; import org.springframework.http.MediaType; import org.springframework.security.core.Authentication; @@ -149,6 +150,9 @@ public class PartnerServiceImplTest { @Mock Authentication authentication; + @Mock + Environment environment; + FilterValueDto deviceFilterValueDto = new FilterValueDto(); FilterDto filterDto = new FilterDto(); SearchFilter searchFilter = new SearchFilter(); @@ -264,7 +268,7 @@ public void getPartnerCertificate_Test() throws Exception{ } @Test - public void getOriginalPartnerCertificate_Test() throws Exception{ + public void getPartnerCertificateData_Test() throws Exception{ io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); SecurityContextHolder.setContext(securityContext); @@ -281,14 +285,14 @@ public void getOriginalPartnerCertificate_Test() throws Exception{ partnerCertDownloadRequestDto.setPartnerId("id"); Mockito.when(partnerRepository.findById(Mockito.anyString())).thenReturn(Optional.empty()); - pserviceImpl.getOriginalPartnerCertificate(partnerCertDownloadRequestDto); + pserviceImpl.getPartnerCertificateData(partnerCertDownloadRequestDto); Optional getPartner = Optional.of(createPartner(Boolean.TRUE)); Optional policyGroup = Optional.of(createPolicyGroup(Boolean.TRUE)); Mockito.when(partnerRepository.findById(Mockito.anyString())).thenReturn(getPartner); Mockito.when(policyGroupRepository.findById(getPartner.get().getPolicyGroupId())).thenReturn(policyGroup); - ResponseWrapperV2 originalCertDownloadResponseDto = pserviceImpl.getOriginalPartnerCertificate(partnerCertDownloadRequestDto); + ResponseWrapperV2 originalCertDownloadResponseDto = pserviceImpl.getPartnerCertificateData(partnerCertDownloadRequestDto); assertNotNull(originalCertDownloadResponseDto); Mockito.doNothing().when(webSubPublisher).notify(Mockito.any(),Mockito.any(),Mockito.any()); } @@ -1466,4 +1470,396 @@ private String caCertResponse() { + "\"errors\": null\n" + "}" ; } + + @Test + public void getAllPoliciesTest() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + partner.setId("123"); + partner.setPartnerTypeCode("AUTH"); + partner.setPolicyGroupId("abc"); + List partnerPolicyRequestList = new ArrayList<>(); + PartnerPolicyRequest partnerPolicyRequest = new PartnerPolicyRequest(); + partnerPolicyRequest.setPolicyId("xyz"); + partnerPolicyRequest.setCrDtimes(Timestamp.valueOf(LocalDateTime.now())); + partnerPolicyRequest.setStatusCode("approved"); + partnerPolicyRequestList.add(partnerPolicyRequest); + partner.setPartnerPolicyRequests(partnerPolicyRequestList); + partnerList.add(partner); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + PolicyGroup policyGroup = new PolicyGroup(); + policyGroup.setId("abc"); + policyGroup.setName("group1"); + policyGroup.setDesc("dgvhsd"); + when(policyGroupRepository.findPolicyGroupById(anyString())).thenReturn(policyGroup); + + String policyGroupName = "test"; + AuthPolicy authPolicy = new AuthPolicy(); + authPolicy.setName("policy123"); + when(policyGroupRepository.findPolicyGroupNameById(anyString())).thenReturn(policyGroupName); + when(authPolicyRepository.findByPolicyGroupAndId(anyString(), anyString())).thenReturn(authPolicy); + pserviceImpl.getPolicyRequests(); + + when(authPolicyRepository.findByPolicyGroupAndId(anyString(), anyString())).thenReturn(null); + pserviceImpl.getPolicyRequests(); + } + + @Test + public void getAllPoliciesTest1() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + partner.setId("123"); + partner.setPartnerTypeCode("AUTH"); + partner.setPolicyGroupId("abc"); + List partnerPolicyRequestList = new ArrayList<>(); + partner.setPartnerPolicyRequests(partnerPolicyRequestList); + partnerList.add(partner); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + PolicyGroup policyGroup = new PolicyGroup(); + policyGroup.setId("abc"); + policyGroup.setName("group1"); + policyGroup.setDesc("dgvhsd"); + when(policyGroupRepository.findPolicyGroupById(anyString())).thenReturn(policyGroup); + + AuthPolicy authPolicy = new AuthPolicy(); + authPolicy.setName("policy123"); + when(authPolicyRepository.findByPolicyGroupAndId(anyString(), anyString())).thenReturn(authPolicy); + + pserviceImpl.getPolicyRequests(); + } + + @Test + public void getAllPoliciesTest2() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + partner.setId("123"); + partner.setPartnerTypeCode(""); + partner.setPolicyGroupId("abc"); + List partnerPolicyRequestList = new ArrayList<>(); + PartnerPolicyRequest partnerPolicyRequest = new PartnerPolicyRequest(); + partnerPolicyRequest.setPolicyId("xyz"); + partnerPolicyRequest.setCrDtimes(Timestamp.valueOf(LocalDateTime.now())); + partnerPolicyRequest.setStatusCode("approved"); + partnerPolicyRequestList.add(partnerPolicyRequest); + partner.setPartnerPolicyRequests(partnerPolicyRequestList); + partnerList.add(partner); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + pserviceImpl.getPolicyRequests(); + } + + @Test + public void getAllPoliciesTest3() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + partner.setId(""); + partner.setPartnerTypeCode("Auth_Partner"); + partner.setPolicyGroupId("abc"); + partnerList.add(partner); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + pserviceImpl.getPolicyRequests(); + } + + @Test + public void getAllPoliciesTest4() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + partner.setId("ddd"); + partner.setPartnerTypeCode("Auth_Partner"); + partner.setPolicyGroupId(""); + partnerList.add(partner); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + pserviceImpl.getPolicyRequests(); + } + + @Test + public void getAllPoliciesTestException() throws Exception { + pserviceImpl.getPolicyRequests(); + } + + @Test + public void getAllPoliciesTestException1() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + pserviceImpl.getPolicyRequests(); + } + + @Test + public void getPartnerCertificatesDetailsTest() throws Exception { + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + partner.setId("123"); + partner.setCertificateAlias("abs"); + partnerList.add(partner); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + Map apiResponse = new HashMap<>(); + Map response = new HashMap<>(); + response.put("certificateData", "-----BEGIN CERTIFICATE-----\n" + + "MIIFfTCCA2WgAwIBAgIUOVZNyD46U0OAEhaGC/Y7NXbu+OkwDQYJKoZIhvcNAQEL\n" + + "BQAwTjELMAkGA1UEBhMCSU4xCzAJBgNVBAgMAk1IMQswCQYDVQQHDAJQTjELMAkG\n" + + "A1UECgwCQ0ExCzAJBgNVBAsMAkNBMQswCQYDVQQDDAJDQTAeFw0yNDA1MDkwNzI1\n" + + "MDJaFw0yOTA1MDkwNzI1MDJaME4xCzAJBgNVBAYTAklOMQswCQYDVQQIDAJNSDEL\n" + + "MAkGA1UEBwwCUE4xCzAJBgNVBAoMAkNBMQswCQYDVQQLDAJDQTELMAkGA1UEAwwC\n" + + "Q0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCzdWD2DvhSnmLqU3fX\n" + + "RT3z8ikS6qHxn5Hu/a2ijkuZxAZj0UCUJ83kM20NwocJDHT1qx6+yjdl+BECsgoI\n" + + "ro9MXgFOsHCphyR5KiP4mY95qRlE03h7WBfr4wDn/6f5tCbqCcBqdXMAQxUp34D+\n" + + "Pro0EwkXNulHNMTvz5hpoCEiGyfXUP48I4q2nb8rMXaplhqz+vAYgA4rsK6K9IUh\n" + + "uJDxtZRHdIfxnvbfjxDbuPkN0ehOQ1uQrDVY6ENCIUxdgR/p94kZ+CNsD21c57gJ\n" + + "2wYg+BceQn1rVSGnfpqMoogZCMUWFvaE4i91419VXxDLgeC/4Qw8n5onBY+dVHjW\n" + + "04OolR2DqotFyaPlZiVdpUys6+KZ7fS9mwWEY0kqtLzcBeb4g4nPvObfKnqSmVMZ\n" + + "DHRuAx6MG3oFZrnNuS6oIYGwLpoko6iqEiGohHsSxMulT43XOxoNgDq9noQc9SYv\n" + + "tzdzijBRLAxNBDTB0rgZra27tLIFlqP1TpqZtM3ThOmPJQn6JG8WeiVWnmUkpmXX\n" + + "6opGqhLWMM/u1n4fdf716h7340RbCPJoOpTPphYo/WedFQskqZvhTU6HMIj4JQAj\n" + + "OVVwgtrDOdx051ps2hhiSU5tL4LmjLHIsfyoCSuHkzBhVMZ/jKFm8C4Or2RRG85A\n" + + "wtzEANSxVZRjw6S1hsHsI+8m2QIDAQABo1MwUTAdBgNVHQ4EFgQUjDli1GMiclHK\n" + + "igNm2kuKh48AON8wHwYDVR0jBBgwFoAUjDli1GMiclHKigNm2kuKh48AON8wDwYD\n" + + "VR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAgEAk6IWcDdBc1tngCaPNLhU\n" + + "c3pXRdTjDuLHMxHRiP/7Vi3V2xcKRak5ZMzYAJK6YThp3Z04V9d5jJoi/CDhMuPK\n" + + "RV1GmbdA7b24Jic2fQHWOJkgafT2Gx4yHmLo5ctSuDHPfSvzUgeghG0k3eNJgCai\n" + + "Ctr+wvCRZGvvbl2JnJUcWiHBxH/PaWJ4Jd1T4UKmhlFhTw26TXQGHuW/UJwgh8OR\n" + + "V8A+WeMXxKFsh38b8RnWVa6XdajIq9UAZvvd4Q16zjdnMWx/7zcIK5D1MDb/KmSJ\n" + + "yho1LKRZx5YtSeI4FWs8dzZ0nCCiTe7TrnnhlXThJ6rXeo5AshtM4fGrvizaf4n3\n" + + "7I9mJkqiccp1ml+2EcgsdX7HbnGE/R8VVbh3jUhWHuysLCiVSMbjnktCLWoXjSb9\n" + + "JqOYF3yo6JQslQB0fQMyKmvsn/FplQBbU0PUrg9vpAg9nZlZf3UHO5z072pXD6ky\n" + + "5pKjh+q0JOk00Eln9AoU6YuIyPBQ9mI3X8iYB5UhUBbgAPeg1pwWCWhdt40f0D5t\n" + + "JkVnICy+Gh1ps8QPA6coEaajbIq14Uh6eYEwxFHPsxlbn7pzjoCJG2v7N8VwgfuL\n" + + "DdGs4hFikdUAfBT/Diug/n9/ZgfdN6Ctf4U/SM65vZvfRqtLIoTIs4PcF3YtKK04\n" + + "m0UA3Sxxre0vVWYO4GmmZUY=\n" + + "-----END CERTIFICATE-----"); + apiResponse.put("response", response); + + when(environment.getProperty("pmp.partner.certificaticate.get.rest.uri")).thenReturn("uri"); + when(restUtil.getApi(anyString(), any(), eq(Map.class))).thenReturn(apiResponse); + pserviceImpl.getPartnerCertificatesDetails(); + } + + @Test + public void getPartnerCertificatesDetailsTestException() throws Exception { + pserviceImpl.getPartnerCertificatesDetails(); + } + + @Test + public void getPartnerCertificatesDetailsTestException1() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + partner.setId(""); + partner.setCertificateAlias(""); + partnerList.add(partner); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + pserviceImpl.getPartnerCertificatesDetails(); + } + + @Test + public void getPartnerCertificatesDetailsTestException2() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + pserviceImpl.getPartnerCertificatesDetails(); + } + + @Test + public void getAuthPartnerApiKeysTest() throws Exception{ + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + partner.setId("123"); + partner.setPartnerTypeCode("Auth_Partner"); + partner.setPolicyGroupId("abc"); + partner.setApprovalStatus("approved"); + partnerList.add(partner); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + + PartnerPolicy partnerPolicy = new PartnerPolicy(); + partnerPolicy.setPolicyApiKey("apikey123"); + partnerPolicy.setLabel("request"); + partnerPolicy.setIsActive(true); + partnerPolicy.setPartner(partner); + partnerPolicy.setPolicyId("test"); + List partnerPolicies = new ArrayList<>(); + partnerPolicies.add(partnerPolicy); + when(partnerPolicyRepository.findAPIKeysByPartnerId(anyString())).thenReturn(partnerPolicies); + + AuthPolicy authPolicy = new AuthPolicy(); + authPolicy.setId("test"); + authPolicy.setName("hjfvhd"); + authPolicy.setDescr("tttt"); + PolicyGroup policyGroup = new PolicyGroup(); + policyGroup.setId("abc"); + policyGroup.setName("group1"); + policyGroup.setDesc("group1d"); + authPolicy.setPolicyGroup(policyGroup); + Optional authPolicyDetails = Optional.of(authPolicy); + when(authPolicyRepository.findById(anyString())).thenReturn(authPolicyDetails); + pserviceImpl.getAuthPartnerApiKeys(); + } + + @Test + public void getAuthPartnerApiKeysTest1() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + partner.setId("123"); + partner.setPartnerTypeCode("Auth_Partner"); + partner.setPolicyGroupId("abc"); + partner.setApprovalStatus("approved"); + partnerList.add(partner); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + + PartnerPolicy partnerPolicy = new PartnerPolicy(); + partnerPolicy.setPolicyApiKey("apikey123"); + partnerPolicy.setLabel("request"); + partnerPolicy.setIsActive(false); + partnerPolicy.setPartner(partner); + partnerPolicy.setPolicyId("test"); + List partnerPolicies = new ArrayList<>(); + partnerPolicies.add(partnerPolicy); + when(partnerPolicyRepository.findAPIKeysByPartnerId(anyString())).thenReturn(partnerPolicies); + + AuthPolicy authPolicy = new AuthPolicy(); + authPolicy.setId("test"); + authPolicy.setName("hjfvhd"); + authPolicy.setDescr("tttt"); + PolicyGroup policyGroup = new PolicyGroup(); + policyGroup.setId("abc"); + policyGroup.setName("group1"); + policyGroup.setDesc("group1d"); + authPolicy.setPolicyGroup(policyGroup); + Optional authPolicyDetails = Optional.of(authPolicy); + when(authPolicyRepository.findById(anyString())).thenReturn(authPolicyDetails); + pserviceImpl.getAuthPartnerApiKeys(); + } + + @Test + public void getAuthPartnerApiKeysTest2() throws Exception{ + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + partner.setId("123"); + partner.setPartnerTypeCode("Auth_Partner"); + partner.setPolicyGroupId("abc"); + partner.setApprovalStatus("approved"); + partnerList.add(partner); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + + PartnerPolicy partnerPolicy = new PartnerPolicy(); + partnerPolicy.setPolicyApiKey("apikey123"); + partnerPolicy.setLabel("request"); + partnerPolicy.setIsActive(true); + partnerPolicy.setPartner(partner); + partnerPolicy.setPolicyId("test"); + List partnerPolicies = new ArrayList<>(); + partnerPolicies.add(partnerPolicy); + when(partnerPolicyRepository.findAPIKeysByPartnerId(anyString())).thenReturn(partnerPolicies); + pserviceImpl.getAuthPartnerApiKeys(); + + AuthPolicy authPolicy = new AuthPolicy(); + PolicyGroup policyGroup = new PolicyGroup(); + authPolicy.setPolicyGroup(policyGroup); + when(authPolicyRepository.findById(any())).thenReturn(Optional.of(authPolicy)); + pserviceImpl.getAuthPartnerApiKeys(); + } + + @Test + public void getAuthPartnerApiKeysTestException() throws Exception { + pserviceImpl.getAuthPartnerApiKeys(); + } + + @Test + public void getAuthPartnerApiKeysTestException1() throws Exception { + io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); + AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + SecurityContextHolder.setContext(securityContext); + when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(securityContext.getAuthentication()).thenReturn(authentication); + + List partnerList = new ArrayList<>(); + Partner partner = new Partner(); + when(partnerRepository.findByUserId(anyString())).thenReturn(partnerList); + when(partnerRepository.findById(anyString())).thenReturn(Optional.of(partner)); + pserviceImpl.getAuthPartnerApiKeys(); + } + } diff --git a/partner/partner-management-service/src/test/resources/application.properties b/partner/partner-management-service/src/test/resources/application.properties index 13d6c5c7f5..51ff74150c 100644 --- a/partner/partner-management-service/src/test/resources/application.properties +++ b/partner/partner-management-service/src/test/resources/application.properties @@ -317,11 +317,11 @@ mosip.role.pms.getsbidetails=DEVICE_PROVIDER,PARTNER_ADMIN mosip.role.pms.getapproveddeviceproviderids=DEVICE_PROVIDER,PARTNER_ADMIN mosip.role.pms.postinactivemappingdevicetosbi=DEVICE_PROVIDER,PARTNER_ADMIN mosip.role.pms.postapproveorrejectdevicewithsbimapping=PARTNER_ADMIN -mosip.role.pms.postdeactivatedevice=DEVICE_PROVIDER,PARTNER_ADMIN -mosip.role.pms.postdeactivatesbi=DEVICE_PROVIDER,PARTNER_ADMIN +mosip.role.pms.patchdeactivatedevice=DEVICE_PROVIDER,PARTNER_ADMIN +mosip.role.pms.patchdeactivatesbi=DEVICE_PROVIDER,PARTNER_ADMIN mosip.role.pms.getftmchipdetails=FTM_PROVIDER,PARTNER_ADMIN mosip.role.pms.getapprovedftmproviderids=FTM_PROVIDER,PARTNER_ADMIN -mosip.role.pms.postdeactivateftm=FTM_PROVIDER,PARTNER_ADMIN +mosip.role.pms.patchdeactivateftm=FTM_PROVIDER,PARTNER_ADMIN mosip.role.pms.getoriginalftmcertificate=FTM_PROVIDER,PARTNER_ADMIN mosip.role.pms.getpartnerdetails=PARTNER_ADMIN mosip.role.pms.getallpartners=PARTNER_ADMIN @@ -340,7 +340,7 @@ mosip.pms.api.id.policy.requests.get=mosip.pms.policy.requests.get mosip.pms.api.id.auth.partners.policies.get=mosip.pms.auth.partners.policies.get mosip.pms.api.id.approved.partner.ids.with.policy.groups.get=mosip.pms.approved.partner.ids.with.policy.groups.get mosip.pms.api.id.configs.get=mosip.pms.configs.get -mosip.pms.api.id.api.keys.for.auth.partners.get=mosip.pms.api.keys.for.auth.partners.get +mosip.pms.api.id.auth.partner.api.keys.get=mosip.pms.auth.partner.api.keys.get mosip.pms.api.id.user.consent.get=mosip.pms.user.consent.get mosip.pms.api.id.user.consent.post=mosip.pms.user.consent.post mosip.pms.api.id.original.partner.certificate.get=mosip.pms.original.partner.certificate.get @@ -350,11 +350,11 @@ mosip.pms.api.id.sbi.devices.get=mosip.pms.sbi.devices.get mosip.pms.api.id.add.inactive.mapping.device.to.sbi.id.post=mosip.pms.add.inactive.mapping.device.to.sbi.id.post mosip.pms.api.id.approve.mapping.device.to.sbi.post=mosip.pms.approve.mapping.device.to.sbi.post mosip.pms.api.id.reject.mapping.device.to.sbi.post=mosip.pms.reject.mapping.device.to.sbi.post -mosip.pms.api.id.deactivate.device.post=mosip.pms.deactivate.device.post -mosip.pms.api.id.deactivate.sbi.post=mosip.pms.deactivate.sbi.post +mosip.pms.api.id.deactivate.device.patch=mosip.pms.deactivate.device.patch +mosip.pms.api.id.deactivate.sbi.patch=mosip.pms.deactivate.sbi.patch mosip.pms.api.id.ftm.chip.details.get=mosip.pms.ftm.chip.details.get mosip.pms.api.id.approved.ftm.provider.ids.get=mosip.pms.approved.ftm.provider.ids.get -mosip.pms.api.id.deactivate.ftm.post=mosip.pms.deactivate.ftm.post +mosip.pms.api.id.deactivate.ftm.patch=mosip.pms.deactivate.ftm.patch mosip.pms.api.id.original.ftm.certificate.get=mosip.pms.original.ftm.certificate.get mosip.pms.api.id.partner.details.get=mosip.pms.partner.details.get mosip.pms.api.id.all.partners.get=mosip.pms.all.partners.get diff --git a/partner/policy-management-service/src/main/java/io/mosip/pms/policy/dto/PolicyGroupDto.java b/partner/policy-management-service/src/main/java/io/mosip/pms/policy/dto/PolicyGroupDto.java index dc55bd2754..ee27446399 100644 --- a/partner/policy-management-service/src/main/java/io/mosip/pms/policy/dto/PolicyGroupDto.java +++ b/partner/policy-management-service/src/main/java/io/mosip/pms/policy/dto/PolicyGroupDto.java @@ -6,6 +6,5 @@ public class PolicyGroupDto { private String id; private String description; - private Boolean isActive; private String name; } \ No newline at end of file diff --git a/partner/policy-management-service/src/main/java/io/mosip/pms/policy/service/PolicyManagementService.java b/partner/policy-management-service/src/main/java/io/mosip/pms/policy/service/PolicyManagementService.java index 6ae64a8f13..abbf6969d0 100644 --- a/partner/policy-management-service/src/main/java/io/mosip/pms/policy/service/PolicyManagementService.java +++ b/partner/policy-management-service/src/main/java/io/mosip/pms/policy/service/PolicyManagementService.java @@ -1103,7 +1103,6 @@ public ResponseWrapperV2> getPolicyGroups() { policyGroupDto.setId(policyGroup.getId()); policyGroupDto.setDescription(policyGroup.getDesc()); policyGroupDto.setName(policyGroup.getName()); - policyGroupDto.setIsActive(policyGroup.getIsActive()); policyGroupDtoList.add(policyGroupDto); }