From 088ae72ff7705c40f43a462050ad771e2e8200f5 Mon Sep 17 00:00:00 2001 From: kanishq-egov Date: Thu, 19 Oct 2023 18:55:08 +0530 Subject: [PATCH] HLM-3376: removed not used validators --- .../service/ReferralManagementService.java | 20 ++- .../RmFacilityEntitiesIdValidator.java | 100 ------------- .../RmProjectEntitiesIdValidator.java | 134 ------------------ .../validator/RmSideEffectIdValidator.java | 18 +-- 4 files changed, 19 insertions(+), 253 deletions(-) delete mode 100644 health-services/referralmanagement/src/main/java/org/egov/referralmanagement/validator/RmFacilityEntitiesIdValidator.java delete mode 100644 health-services/referralmanagement/src/main/java/org/egov/referralmanagement/validator/RmProjectEntitiesIdValidator.java diff --git a/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/service/ReferralManagementService.java b/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/service/ReferralManagementService.java index a1fc7507eb5..603cd6ae1fb 100644 --- a/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/service/ReferralManagementService.java +++ b/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/service/ReferralManagementService.java @@ -1,28 +1,26 @@ package org.egov.referralmanagement.service; import lombok.extern.slf4j.Slf4j; +import org.egov.common.ds.Tuple; +import org.egov.common.models.ErrorDetails; +import org.egov.common.models.referralmanagement.Referral; +import org.egov.common.models.referralmanagement.ReferralBulkRequest; +import org.egov.common.models.referralmanagement.ReferralRequest; +import org.egov.common.models.referralmanagement.ReferralSearchRequest; +import org.egov.common.service.IdGenService; +import org.egov.common.utils.CommonUtils; +import org.egov.common.validator.Validator; import org.egov.referralmanagement.Constants; import org.egov.referralmanagement.config.ReferralManagementConfiguration; import org.egov.referralmanagement.repository.ReferralRepository; import org.egov.referralmanagement.service.enrichment.ReferralManagementEnrichmentService; -import org.egov.referralmanagement.validator.RmFacilityEntitiesIdValidator; import org.egov.referralmanagement.validator.RmIsDeletedValidator; import org.egov.referralmanagement.validator.RmNonExistentEntityValidator; import org.egov.referralmanagement.validator.RmNullIdValidator; import org.egov.referralmanagement.validator.RmProjectBeneficiaryIdValidator; -import org.egov.referralmanagement.validator.RmProjectEntitiesIdValidator; import org.egov.referralmanagement.validator.RmRecipientIdValidator; import org.egov.referralmanagement.validator.RmSideEffectIdValidator; import org.egov.referralmanagement.validator.RmUniqueEntityValidator; -import org.egov.common.ds.Tuple; -import org.egov.common.models.ErrorDetails; -import org.egov.common.models.referralmanagement.Referral; -import org.egov.common.models.referralmanagement.ReferralBulkRequest; -import org.egov.common.models.referralmanagement.ReferralRequest; -import org.egov.common.models.referralmanagement.ReferralSearchRequest; -import org.egov.common.service.IdGenService; -import org.egov.common.utils.CommonUtils; -import org.egov.common.validator.Validator; import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Service; import org.springframework.util.ReflectionUtils; diff --git a/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/validator/RmFacilityEntitiesIdValidator.java b/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/validator/RmFacilityEntitiesIdValidator.java deleted file mode 100644 index ac79e49cc04..00000000000 --- a/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/validator/RmFacilityEntitiesIdValidator.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.egov.referralmanagement.validator; - -import lombok.extern.slf4j.Slf4j; -import org.egov.common.data.query.exception.QueryBuilderException; -import org.egov.common.http.client.ServiceRequestClient; -import org.egov.common.models.Error; -import org.egov.common.models.facility.Facility; -import org.egov.common.models.facility.FacilityBulkResponse; -import org.egov.common.models.facility.FacilitySearch; -import org.egov.common.models.facility.FacilitySearchRequest; -import org.egov.common.models.referralmanagement.Referral; -import org.egov.common.models.referralmanagement.ReferralBulkRequest; -import org.egov.common.validator.Validator; -import org.egov.referralmanagement.config.ReferralManagementConfiguration; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; - -import static org.egov.common.utils.CommonUtils.notHavingErrors; -import static org.egov.common.utils.CommonUtils.populateErrorDetails; -import static org.egov.common.utils.ValidatorUtils.getErrorForNonExistentEntity; -import static org.egov.referralmanagement.Constants.FACILITY; - - -@Component -@Order(value = 3) -@Slf4j -public class RmFacilityEntitiesIdValidator implements Validator { - private final ServiceRequestClient serviceRequestClient; - private final ReferralManagementConfiguration referralManagementConfiguration; - - @Autowired - public RmFacilityEntitiesIdValidator(ServiceRequestClient serviceRequestClient, ReferralManagementConfiguration referralManagementConfiguration) { - this.serviceRequestClient = serviceRequestClient; - this.referralManagementConfiguration = referralManagementConfiguration; - } - - - @Override - public Map> validate(ReferralBulkRequest request) { - log.info("validating facility id"); - Map> errorDetailsMap = new HashMap<>(); - List entities = request.getReferrals(); - Map> tenantIdReferralMap = entities.stream().collect(Collectors.groupingBy(Referral::getTenantId)); - List tenantIds = new ArrayList<>(tenantIdReferralMap.keySet()); - tenantIds.forEach(tenantId -> { - List referralList = tenantIdReferralMap.get(tenantId); - if (!referralList.isEmpty()) { - List existingFacilityList = null; - final List facilityIdList = new ArrayList<>(); - try { - referralList.forEach(referral -> { - if(referral.getRecipientType().equals(FACILITY)){ - addIgnoreNull(facilityIdList, referral.getRecipientId()); - } - }); - FacilitySearch facilitySearch = FacilitySearch.builder() - .id(facilityIdList.isEmpty() ? null : facilityIdList) - .build(); - FacilityBulkResponse facilityBulkResponse = serviceRequestClient.fetchResult( - new StringBuilder(referralManagementConfiguration.getFacilityHost() - + referralManagementConfiguration.getFacilitySearchUrl() - +"?limit=" + entities.size() - + "&offset=0&tenantId=" + tenantId), - FacilitySearchRequest.builder().requestInfo(request.getRequestInfo()).facility(facilitySearch).build(), - FacilityBulkResponse.class - ); - existingFacilityList = facilityBulkResponse.getFacilities(); - } catch (QueryBuilderException e) { - existingFacilityList = Collections.emptyList(); - } catch (Exception e) { - throw new RuntimeException(e); - } - final List existingFacilityIds = new ArrayList<>(); - existingFacilityList.forEach(facility -> existingFacilityIds.add(facility.getId())); - List invalidEntities = entities.stream().filter(notHavingErrors()).filter(entity -> - (!entity.getRecipientType().equals(FACILITY) || !existingFacilityIds.contains(entity.getRecipientId())) - ).collect(Collectors.toList()); - invalidEntities.forEach(referral -> { - Error error = getErrorForNonExistentEntity(); - populateErrorDetails(referral, error, errorDetailsMap); - }); - - } - }); - return errorDetailsMap; - } - - private void addIgnoreNull(List list, String item) { - if(Objects.nonNull(item)) list.add(item); - } -} diff --git a/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/validator/RmProjectEntitiesIdValidator.java b/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/validator/RmProjectEntitiesIdValidator.java deleted file mode 100644 index a36d725f61e..00000000000 --- a/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/validator/RmProjectEntitiesIdValidator.java +++ /dev/null @@ -1,134 +0,0 @@ -package org.egov.referralmanagement.validator; - -import lombok.extern.slf4j.Slf4j; -import org.egov.common.data.query.exception.QueryBuilderException; -import org.egov.common.http.client.ServiceRequestClient; -import org.egov.common.models.Error; -import org.egov.common.models.project.BeneficiaryBulkResponse; -import org.egov.common.models.project.BeneficiarySearchRequest; -import org.egov.common.models.project.ProjectBeneficiary; -import org.egov.common.models.project.ProjectBeneficiarySearch; -import org.egov.common.models.project.ProjectStaff; -import org.egov.common.models.project.ProjectStaffBulkResponse; -import org.egov.common.models.project.ProjectStaffSearch; -import org.egov.common.models.project.ProjectStaffSearchRequest; -import org.egov.common.models.referralmanagement.Referral; -import org.egov.common.models.referralmanagement.ReferralBulkRequest; -import org.egov.common.validator.Validator; -import org.egov.referralmanagement.config.ReferralManagementConfiguration; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; - -import static org.egov.referralmanagement.Constants.STAFF; -import static org.egov.common.utils.CommonUtils.notHavingErrors; -import static org.egov.common.utils.CommonUtils.populateErrorDetails; -import static org.egov.common.utils.ValidatorUtils.getErrorForNonExistentEntity; - - -@Component -@Order(value = 3) -@Slf4j -public class RmProjectEntitiesIdValidator implements Validator { - private final ServiceRequestClient serviceRequestClient; - private final ReferralManagementConfiguration referralManagementConfiguration; - - @Autowired - public RmProjectEntitiesIdValidator(ServiceRequestClient serviceRequestClient, ReferralManagementConfiguration referralManagementConfiguration) { - this.serviceRequestClient = serviceRequestClient; - this.referralManagementConfiguration = referralManagementConfiguration; - } - - - @Override - public Map> validate(ReferralBulkRequest request) { - log.info("validating project beneficiary id, project staff id"); - Map> errorDetailsMap = new HashMap<>(); - List entities = request.getReferrals(); - Map> tenantIdReferralMap = entities.stream().collect(Collectors.groupingBy(Referral::getTenantId)); - List tenantIds = new ArrayList<>(tenantIdReferralMap.keySet()); - tenantIds.forEach(tenantId -> { - List referralList = tenantIdReferralMap.get(tenantId); - if (!referralList.isEmpty()) { - List existingProjectBeneficiaries = null; - List existingProjectStaffList = null; - final List projectBeneficiaryIdList = new ArrayList<>(); // done - final List projectBeneficiaryClientReferenceIdList = new ArrayList<>(); - final List projectStaffIdList = new ArrayList<>(); - try { - referralList.forEach(referral -> { - addIgnoreNull(projectBeneficiaryIdList, referral.getProjectBeneficiaryId()); - addIgnoreNull(projectBeneficiaryClientReferenceIdList, referral.getProjectBeneficiaryClientReferenceId()); - addIgnoreNull(projectStaffIdList, referral.getReferrerId()); - if(referral.getRecipientType().equals(STAFF)){ - addIgnoreNull(projectStaffIdList, referral.getRecipientId()); - } - }); - ProjectBeneficiarySearch projectBeneficiarySearch = ProjectBeneficiarySearch.builder() - .id(projectBeneficiaryIdList.isEmpty() ? null : projectBeneficiaryIdList) - .clientReferenceId(projectBeneficiaryClientReferenceIdList.isEmpty() ? null : projectBeneficiaryClientReferenceIdList) - .build(); - BeneficiaryBulkResponse beneficiaryBulkResponse = serviceRequestClient.fetchResult( - new StringBuilder(referralManagementConfiguration.getProjectHost() - + referralManagementConfiguration.getProjectBeneficiarySearchUrl() - +"?limit=" + entities.size() - + "&offset=0&tenantId=" + tenantId), - BeneficiarySearchRequest.builder().requestInfo(request.getRequestInfo()).projectBeneficiary(projectBeneficiarySearch).build(), - BeneficiaryBulkResponse.class - ); - existingProjectBeneficiaries = beneficiaryBulkResponse.getProjectBeneficiaries(); - ProjectStaffSearch projectStaffSearch = ProjectStaffSearch.builder() - .id(projectStaffIdList.isEmpty() ? null : projectStaffIdList) - .build(); - ProjectStaffBulkResponse projectStaffBulkResponse = serviceRequestClient.fetchResult( - new StringBuilder(referralManagementConfiguration.getProjectHost() - + referralManagementConfiguration.getProjectStaffSearchUrl() - +"?limit=" + entities.size() - + "&offset=0&tenantId=" + tenantId), - ProjectStaffSearchRequest.builder().requestInfo(request.getRequestInfo()).projectStaff(projectStaffSearch).build(), - ProjectStaffBulkResponse.class - ); - existingProjectStaffList = projectStaffBulkResponse.getProjectStaff(); - - } catch (QueryBuilderException e) { - if(existingProjectBeneficiaries == null) existingProjectBeneficiaries = Collections.emptyList(); - existingProjectStaffList = Collections.emptyList(); - } catch (Exception e) { - throw new RuntimeException(e); - } - final List existingProjectBeneficiaryIds = new ArrayList<>(); - final List existingProjectBeneficiaryClientReferenceIds = new ArrayList<>(); - existingProjectBeneficiaries.forEach(projectBeneficiary -> { - existingProjectBeneficiaryIds.add(projectBeneficiary.getId()); - existingProjectBeneficiaryClientReferenceIds.add(projectBeneficiary.getClientReferenceId()); - }); - final List existingProjectStaffIds = new ArrayList<>(); - existingProjectStaffList.forEach(projectStaff -> existingProjectStaffIds.add(projectStaff.getId())); - List invalidEntities = entities.stream().filter(notHavingErrors()).filter(entity -> - !existingProjectStaffIds.contains(entity.getReferrerId()) - && !existingProjectBeneficiaryIds.contains(entity.getProjectBeneficiaryId()) - && !existingProjectBeneficiaryClientReferenceIds.contains(entity.getProjectBeneficiaryClientReferenceId()) - && (!entity.getRecipientType().equals(STAFF) || !existingProjectStaffIds.contains(entity.getRecipientId())) - ).collect(Collectors.toList()); - invalidEntities.forEach(referral -> { - Error error = getErrorForNonExistentEntity(); - populateErrorDetails(referral, error, errorDetailsMap); - }); - - } - }); - return errorDetailsMap; - } - - private void addIgnoreNull(List list, String item) { - if(Objects.nonNull(item)) list.add(item); - } -} diff --git a/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/validator/RmSideEffectIdValidator.java b/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/validator/RmSideEffectIdValidator.java index 1d519333f58..e49a030f49c 100644 --- a/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/validator/RmSideEffectIdValidator.java +++ b/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/validator/RmSideEffectIdValidator.java @@ -52,14 +52,16 @@ public Map> validate(ReferralBulkRequest request) { if (Objects.nonNull(referral.getSideEffect())) addIgnoreNull(sideEffectIds, referral.getSideEffect().getId()); }); - List validSideEffectIds; - try { - validSideEffectIds = sideEffectService.search( - SideEffectSearchRequest.builder().sideEffect(SideEffectSearch.builder().id(sideEffectIds).build()).build(), - sideEffectIds.size(), 0, tenantId, null, false - ).stream().map(SideEffect::getId).collect(Collectors.toList()); - } catch (Exception e) { - throw new CustomException("Side Effect failed to fetch", "Exception : " + e.getMessage()); + List validSideEffectIds = new ArrayList<>(); + if(!sideEffectIds.isEmpty()) { + try { + validSideEffectIds = sideEffectService.search( + SideEffectSearchRequest.builder().sideEffect(SideEffectSearch.builder().id(sideEffectIds).build()).build(), + sideEffectIds.size(), 0, tenantId, null, false + ).stream().map(SideEffect::getId).collect(Collectors.toList()); + } catch (Exception e) { + throw new CustomException("Side Effect failed to fetch", "Exception : " + e.getMessage()); + } } sideEffectIds.removeAll(validSideEffectIds); List invalidSideEffectIds = new ArrayList<>(sideEffectIds);