@Test public void shouldNotUpdateIfRecordIsSetAsFinal() throws Exception { AnnualFacilityEstimateEntry facilityEstimateEntry = make(a(AnnualFacilityEstimateBuilder.defaultAnnualFacilityEstimateEntry, with(AnnualFacilityEstimateBuilder.id, 3L), with(AnnualFacilityEstimateBuilder.isFinal, true))); when(repository.getEntryBy(facilityEstimateEntry.getYear(), facilityEstimateEntry.getFacilityId(), facilityEstimateEntry.getProgramId(), facilityEstimateEntry.getDemographicEstimateId())) .thenReturn(facilityEstimateEntry); EstimateForm form = getDemographicEstimateFormForOneFacility(facilityEstimateEntry); facilityEstimateEntry.setIsFinal(true); service.save(form, 2L); verify(repository, never()).insert(facilityEstimateEntry); verify(repository, never()).update(facilityEstimateEntry); }
public void save(EstimateForm estimateForm, Long userId) { for (EstimateFormLineItem dto : ListUtil.emptyIfNull(estimateForm.getEstimateLineItems())) { for (AnnualFacilityEstimateEntry estimate : ListUtil.emptyIfNull(dto.getFacilityEstimates())) { AnnualFacilityEstimateEntry existingEstimateEntry = repository.getEntryBy(estimate.getYear(), estimate.getFacilityId(), estimate.getProgramId(), estimate.getDemographicEstimateId()); if (existingEstimateEntry != null && (!existingEstimateEntry.getId().equals(estimate.getId()) || existingEstimateEntry.getIsFinal())) { continue; } estimate.setFacilityId(dto.getId()); if (!estimate.hasId()) { estimate.setCreatedBy(userId); repository.insert(estimate); } else { estimate.setModifiedBy(userId); repository.update(estimate); } } } }
AnnualFacilityDemographicEstimateService { public void save(EstimateForm estimateForm, Long userId) { for (EstimateFormLineItem dto : ListUtil.emptyIfNull(estimateForm.getEstimateLineItems())) { for (AnnualFacilityEstimateEntry estimate : ListUtil.emptyIfNull(dto.getFacilityEstimates())) { AnnualFacilityEstimateEntry existingEstimateEntry = repository.getEntryBy(estimate.getYear(), estimate.getFacilityId(), estimate.getProgramId(), estimate.getDemographicEstimateId()); if (existingEstimateEntry != null && (!existingEstimateEntry.getId().equals(estimate.getId()) || existingEstimateEntry.getIsFinal())) { continue; } estimate.setFacilityId(dto.getId()); if (!estimate.hasId()) { estimate.setCreatedBy(userId); repository.insert(estimate); } else { estimate.setModifiedBy(userId); repository.update(estimate); } } } } }
AnnualFacilityDemographicEstimateService { public void save(EstimateForm estimateForm, Long userId) { for (EstimateFormLineItem dto : ListUtil.emptyIfNull(estimateForm.getEstimateLineItems())) { for (AnnualFacilityEstimateEntry estimate : ListUtil.emptyIfNull(dto.getFacilityEstimates())) { AnnualFacilityEstimateEntry existingEstimateEntry = repository.getEntryBy(estimate.getYear(), estimate.getFacilityId(), estimate.getProgramId(), estimate.getDemographicEstimateId()); if (existingEstimateEntry != null && (!existingEstimateEntry.getId().equals(estimate.getId()) || existingEstimateEntry.getIsFinal())) { continue; } estimate.setFacilityId(dto.getId()); if (!estimate.hasId()) { estimate.setCreatedBy(userId); repository.insert(estimate); } else { estimate.setModifiedBy(userId); repository.update(estimate); } } } }  }
AnnualFacilityDemographicEstimateService { public void save(EstimateForm estimateForm, Long userId) { for (EstimateFormLineItem dto : ListUtil.emptyIfNull(estimateForm.getEstimateLineItems())) { for (AnnualFacilityEstimateEntry estimate : ListUtil.emptyIfNull(dto.getFacilityEstimates())) { AnnualFacilityEstimateEntry existingEstimateEntry = repository.getEntryBy(estimate.getYear(), estimate.getFacilityId(), estimate.getProgramId(), estimate.getDemographicEstimateId()); if (existingEstimateEntry != null && (!existingEstimateEntry.getId().equals(estimate.getId()) || existingEstimateEntry.getIsFinal())) { continue; } estimate.setFacilityId(dto.getId()); if (!estimate.hasId()) { estimate.setCreatedBy(userId); repository.insert(estimate); } else { estimate.setModifiedBy(userId); repository.update(estimate); } } } }  void save(EstimateForm estimateForm, Long userId); void finalizeEstimate(EstimateForm form, Long userId); void undoFinalize(EstimateForm form, Long userId); EstimateForm getEstimateForm(Long userId, Long programId, Integer year); List<AnnualFacilityEstimateEntry> getEstimateValuesForFacility(Long facilityId, Long programId, Integer year); }
AnnualFacilityDemographicEstimateService { public void save(EstimateForm estimateForm, Long userId) { for (EstimateFormLineItem dto : ListUtil.emptyIfNull(estimateForm.getEstimateLineItems())) { for (AnnualFacilityEstimateEntry estimate : ListUtil.emptyIfNull(dto.getFacilityEstimates())) { AnnualFacilityEstimateEntry existingEstimateEntry = repository.getEntryBy(estimate.getYear(), estimate.getFacilityId(), estimate.getProgramId(), estimate.getDemographicEstimateId()); if (existingEstimateEntry != null && (!existingEstimateEntry.getId().equals(estimate.getId()) || existingEstimateEntry.getIsFinal())) { continue; } estimate.setFacilityId(dto.getId()); if (!estimate.hasId()) { estimate.setCreatedBy(userId); repository.insert(estimate); } else { estimate.setModifiedBy(userId); repository.update(estimate); } } } }  void save(EstimateForm estimateForm, Long userId); void finalizeEstimate(EstimateForm form, Long userId); void undoFinalize(EstimateForm form, Long userId); EstimateForm getEstimateForm(Long userId, Long programId, Integer year); List<AnnualFacilityEstimateEntry> getEstimateValuesForFacility(Long facilityId, Long programId, Integer year);  }