@Test public void shouldThrowErrorIfThereAreNoFacilitiesInDeliveryZone(){ List<Facility> facilities = Collections.EMPTY_LIST; when(facilityService.getAllForDeliveryZoneAndProgram(1L, 3L)).thenReturn(facilities); when(messageService.message("message.no.facility.available", null, null)).thenReturn("no faicilites in delivery zone"); Distribution distribution = new Distribution(); DeliveryZone deliveryZone = new DeliveryZone(1L); Program program = new Program(3L); distribution.setDeliveryZone(deliveryZone); distribution.setProgram(program); expectedException.expect(DataException.class); expectedException.expectMessage("no faicilites in delivery zone"); facilityDistributionService.createFor(distribution); }
public Map<Long, FacilityDistribution> createFor(Distribution distribution) { Long deliveryZoneId = distribution.getDeliveryZone().getId(); Long programId = distribution.getProgram().getId(); Map<Long, FacilityDistribution> facilityDistributions = new HashMap<>(); List<Facility> facilities = facilityService.getAllForDeliveryZoneAndProgram(deliveryZoneId, programId); if (facilities.size() == 0) { throw new DataException(messageService.message("message.no.facility.available", distribution.getProgram().getName(), distribution.getDeliveryZone().getName())); } List<Refrigerator> distributionRefrigerators = refrigeratorService.getRefrigeratorsForADeliveryZoneAndProgram(deliveryZoneId, programId); List<TargetGroupProduct> targetGroupProducts = vaccinationCoverageService.getVaccinationProducts(); List<TargetGroupProduct> childrenTargetGroupProducts = new ArrayList<>(); List<TargetGroupProduct> adultTargetGroupProducts = new ArrayList<>(); filterTargetGroupProducts(targetGroupProducts, childrenTargetGroupProducts, adultTargetGroupProducts); List<ProductVial> productVials = vaccinationCoverageService.getProductVials(); List<ProductVial> childProductVials = new ArrayList<>(); List<ProductVial> adultProductVials = new ArrayList<>(); filterProductVials(productVials, childProductVials, adultProductVials); for (Facility facility : facilities) { facilityDistributions.put(facility.getId(), createDistributionData(facility, distribution, distributionRefrigerators, childrenTargetGroupProducts, adultTargetGroupProducts, childProductVials, adultProductVials)); } return facilityDistributions; }
FacilityDistributionService { public Map<Long, FacilityDistribution> createFor(Distribution distribution) { Long deliveryZoneId = distribution.getDeliveryZone().getId(); Long programId = distribution.getProgram().getId(); Map<Long, FacilityDistribution> facilityDistributions = new HashMap<>(); List<Facility> facilities = facilityService.getAllForDeliveryZoneAndProgram(deliveryZoneId, programId); if (facilities.size() == 0) { throw new DataException(messageService.message("message.no.facility.available", distribution.getProgram().getName(), distribution.getDeliveryZone().getName())); } List<Refrigerator> distributionRefrigerators = refrigeratorService.getRefrigeratorsForADeliveryZoneAndProgram(deliveryZoneId, programId); List<TargetGroupProduct> targetGroupProducts = vaccinationCoverageService.getVaccinationProducts(); List<TargetGroupProduct> childrenTargetGroupProducts = new ArrayList<>(); List<TargetGroupProduct> adultTargetGroupProducts = new ArrayList<>(); filterTargetGroupProducts(targetGroupProducts, childrenTargetGroupProducts, adultTargetGroupProducts); List<ProductVial> productVials = vaccinationCoverageService.getProductVials(); List<ProductVial> childProductVials = new ArrayList<>(); List<ProductVial> adultProductVials = new ArrayList<>(); filterProductVials(productVials, childProductVials, adultProductVials); for (Facility facility : facilities) { facilityDistributions.put(facility.getId(), createDistributionData(facility, distribution, distributionRefrigerators, childrenTargetGroupProducts, adultTargetGroupProducts, childProductVials, adultProductVials)); } return facilityDistributions; } }
FacilityDistributionService { public Map<Long, FacilityDistribution> createFor(Distribution distribution) { Long deliveryZoneId = distribution.getDeliveryZone().getId(); Long programId = distribution.getProgram().getId(); Map<Long, FacilityDistribution> facilityDistributions = new HashMap<>(); List<Facility> facilities = facilityService.getAllForDeliveryZoneAndProgram(deliveryZoneId, programId); if (facilities.size() == 0) { throw new DataException(messageService.message("message.no.facility.available", distribution.getProgram().getName(), distribution.getDeliveryZone().getName())); } List<Refrigerator> distributionRefrigerators = refrigeratorService.getRefrigeratorsForADeliveryZoneAndProgram(deliveryZoneId, programId); List<TargetGroupProduct> targetGroupProducts = vaccinationCoverageService.getVaccinationProducts(); List<TargetGroupProduct> childrenTargetGroupProducts = new ArrayList<>(); List<TargetGroupProduct> adultTargetGroupProducts = new ArrayList<>(); filterTargetGroupProducts(targetGroupProducts, childrenTargetGroupProducts, adultTargetGroupProducts); List<ProductVial> productVials = vaccinationCoverageService.getProductVials(); List<ProductVial> childProductVials = new ArrayList<>(); List<ProductVial> adultProductVials = new ArrayList<>(); filterProductVials(productVials, childProductVials, adultProductVials); for (Facility facility : facilities) { facilityDistributions.put(facility.getId(), createDistributionData(facility, distribution, distributionRefrigerators, childrenTargetGroupProducts, adultTargetGroupProducts, childProductVials, adultProductVials)); } return facilityDistributions; }  }
FacilityDistributionService { public Map<Long, FacilityDistribution> createFor(Distribution distribution) { Long deliveryZoneId = distribution.getDeliveryZone().getId(); Long programId = distribution.getProgram().getId(); Map<Long, FacilityDistribution> facilityDistributions = new HashMap<>(); List<Facility> facilities = facilityService.getAllForDeliveryZoneAndProgram(deliveryZoneId, programId); if (facilities.size() == 0) { throw new DataException(messageService.message("message.no.facility.available", distribution.getProgram().getName(), distribution.getDeliveryZone().getName())); } List<Refrigerator> distributionRefrigerators = refrigeratorService.getRefrigeratorsForADeliveryZoneAndProgram(deliveryZoneId, programId); List<TargetGroupProduct> targetGroupProducts = vaccinationCoverageService.getVaccinationProducts(); List<TargetGroupProduct> childrenTargetGroupProducts = new ArrayList<>(); List<TargetGroupProduct> adultTargetGroupProducts = new ArrayList<>(); filterTargetGroupProducts(targetGroupProducts, childrenTargetGroupProducts, adultTargetGroupProducts); List<ProductVial> productVials = vaccinationCoverageService.getProductVials(); List<ProductVial> childProductVials = new ArrayList<>(); List<ProductVial> adultProductVials = new ArrayList<>(); filterProductVials(productVials, childProductVials, adultProductVials); for (Facility facility : facilities) { facilityDistributions.put(facility.getId(), createDistributionData(facility, distribution, distributionRefrigerators, childrenTargetGroupProducts, adultTargetGroupProducts, childProductVials, adultProductVials)); } return facilityDistributions; }  Map<Long, FacilityDistribution> createFor(Distribution distribution); FacilityDistribution save(FacilityDistribution facilityDistribution); FacilityDistribution setSynced(FacilityDistribution facilityDistribution); Map<Long, FacilityDistribution> get(Distribution distribution); }
FacilityDistributionService { public Map<Long, FacilityDistribution> createFor(Distribution distribution) { Long deliveryZoneId = distribution.getDeliveryZone().getId(); Long programId = distribution.getProgram().getId(); Map<Long, FacilityDistribution> facilityDistributions = new HashMap<>(); List<Facility> facilities = facilityService.getAllForDeliveryZoneAndProgram(deliveryZoneId, programId); if (facilities.size() == 0) { throw new DataException(messageService.message("message.no.facility.available", distribution.getProgram().getName(), distribution.getDeliveryZone().getName())); } List<Refrigerator> distributionRefrigerators = refrigeratorService.getRefrigeratorsForADeliveryZoneAndProgram(deliveryZoneId, programId); List<TargetGroupProduct> targetGroupProducts = vaccinationCoverageService.getVaccinationProducts(); List<TargetGroupProduct> childrenTargetGroupProducts = new ArrayList<>(); List<TargetGroupProduct> adultTargetGroupProducts = new ArrayList<>(); filterTargetGroupProducts(targetGroupProducts, childrenTargetGroupProducts, adultTargetGroupProducts); List<ProductVial> productVials = vaccinationCoverageService.getProductVials(); List<ProductVial> childProductVials = new ArrayList<>(); List<ProductVial> adultProductVials = new ArrayList<>(); filterProductVials(productVials, childProductVials, adultProductVials); for (Facility facility : facilities) { facilityDistributions.put(facility.getId(), createDistributionData(facility, distribution, distributionRefrigerators, childrenTargetGroupProducts, adultTargetGroupProducts, childProductVials, adultProductVials)); } return facilityDistributions; }  Map<Long, FacilityDistribution> createFor(Distribution distribution); FacilityDistribution save(FacilityDistribution facilityDistribution); FacilityDistribution setSynced(FacilityDistribution facilityDistribution); Map<Long, FacilityDistribution> get(Distribution distribution);  }