diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/misp/service/impl/InfraProviderServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/misp/service/impl/InfraProviderServiceImpl.java index 433ff62422..91ad6756da 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/partner/misp/service/impl/InfraProviderServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/partner/misp/service/impl/InfraProviderServiceImpl.java @@ -274,7 +274,30 @@ public MISPLicenseResponseDto regenerateKey(String mispId) { response.setLicenseKeyExpiry(newLicenseKey.getValidToDate()); response.setLicenseKeyStatus("Active"); response.setProviderId(mispId); - notify(MapperUtils.mapDataToPublishDto(newLicenseKey), EventType.MISP_LICENSE_UPDATED); + List approvedPolicyMappedReq = partnerPolicyRequestRepository.findByPartnerId(mispId); + Optional mispPolicyFromDb = Optional.empty(); + if(!approvedPolicyMappedReq.isEmpty()) { + if(!approvedPolicyMappedReq.stream().allMatch(p->p.getStatusCode().equalsIgnoreCase(APPROVED_STATUS))){ + throw new MISPServiceException(MISPErrorMessages.MISP_POLICY_NOT_APPROVED.getErrorCode(), + MISPErrorMessages.MISP_POLICY_NOT_APPROVED.getErrorMessage()); + } + + mispPolicyFromDb = authPolicyRepository.findById(approvedPolicyMappedReq.get(0).getPolicyId()); + if(mispPolicyFromDb.isEmpty()) { + throw new MISPServiceException(MISPErrorMessages.MISP_POLICY_NOT_EXISTS.getErrorCode(), + MISPErrorMessages.MISP_POLICY_NOT_EXISTS.getErrorMessage()); + } + } + + String policyId = mispPolicyFromDb.isPresent()?mispPolicyFromDb.get().getId():null; + if(mispPolicyFromDb.isPresent()) { + notify(MapperUtils.mapDataToPublishDto(newLicenseKey), MapperUtils.mapPolicyToPublishDto(mispPolicyFromDb.get(), + getPolicyObject(mispPolicyFromDb.get().getPolicyFileId())), EventType.MISP_LICENSE_UPDATED); + } + else { + notify(MapperUtils.mapDataToPublishDto(newLicenseKey), EventType.MISP_LICENSE_UPDATED); + } + } if (licenseKey.getIsActive() && licenseKey.getValidToDate().isAfter(LocalDateTime.now())) {