@Test public void shouldGetEstimateForm() throws Exception { EstimateCategory category1 = new EstimateCategory(); category1.setDefaultConversionFactor(50.0); EstimateCategory category2 = new EstimateCategory(); category2.setDefaultConversionFactor(5.0); Facility facility = new Facility(); facility.setId(39L); facility.setCatchmentPopulation(20000L); facility.setGeographicZone(new GeographicZone()); facility.getGeographicZone().setName("Geo Name"); List<SupervisoryNode> nodes = asList(new SupervisoryNode()); when(supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(1L, 2L, RightName.MANAGE_DEMOGRAPHIC_ESTIMATES)).thenReturn(nodes); List<RequisitionGroup> groups = asList(new RequisitionGroup()); groups.get(0).setId(1L); when(requisitionGroupService.getRequisitionGroupsBy(nodes)).thenReturn(groups); when(facilityService.getUserSupervisedFacilities(1L, 2L, RightName.MANAGE_DEMOGRAPHIC_ESTIMATES)).thenReturn(asList(facility)); when(estimateCategoryService.getAll()).thenReturn(asList(category1, category2)); when(commaSeparator.commaSeparateIds(groups)).thenReturn("{1}"); when(repository.getFacilityList(2L, "{1}")).thenReturn(asList(new EstimateFormLineItem())); EstimateForm form = service.getEstimateForm(1L, 2L, 2005); verify(estimateCategoryService, atMost(1)).getAll(); assertThat(form.getEstimateLineItems().size(), is(1)); assertThat(form.getEstimateLineItems().get(0).getFacilityEstimates().size(), is(2)); assertThat(form.getEstimateLineItems().get(0).getFacilityEstimates().get(0).getConversionFactor(), is(category1.getDefaultConversionFactor())); }
public EstimateForm getEstimateForm(Long userId, Long programId, Integer year) { EstimateForm form = new EstimateForm(); List<EstimateCategory> categories = estimateCategoryService.getAll(); form.setEstimateLineItems(new ArrayList<EstimateFormLineItem>()); List<SupervisoryNode> supervisoryNodes = supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, programId, RightName.MANAGE_DEMOGRAPHIC_ESTIMATES); List<RequisitionGroup> requisitionGroups = requisitionGroupService.getRequisitionGroupsBy(supervisoryNodes); List<EstimateFormLineItem> facilities = repository.getFacilityList(programId, commaSeparator.commaSeparateIds(requisitionGroups)); for (EstimateFormLineItem facility : facilities) { facility.setFacilityEstimates(repository.getFacilityEstimate(year, facility.getId(), programId)); if (facility.getFacilityEstimates().isEmpty()) { facility.setFacilityEstimates(createDefaultEstimateEntries(categories, facility.getId(), programId, year, false)); } form.getEstimateLineItems().add(facility); } return form; }
AnnualFacilityDemographicEstimateService { public EstimateForm getEstimateForm(Long userId, Long programId, Integer year) { EstimateForm form = new EstimateForm(); List<EstimateCategory> categories = estimateCategoryService.getAll(); form.setEstimateLineItems(new ArrayList<EstimateFormLineItem>()); List<SupervisoryNode> supervisoryNodes = supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, programId, RightName.MANAGE_DEMOGRAPHIC_ESTIMATES); List<RequisitionGroup> requisitionGroups = requisitionGroupService.getRequisitionGroupsBy(supervisoryNodes); List<EstimateFormLineItem> facilities = repository.getFacilityList(programId, commaSeparator.commaSeparateIds(requisitionGroups)); for (EstimateFormLineItem facility : facilities) { facility.setFacilityEstimates(repository.getFacilityEstimate(year, facility.getId(), programId)); if (facility.getFacilityEstimates().isEmpty()) { facility.setFacilityEstimates(createDefaultEstimateEntries(categories, facility.getId(), programId, year, false)); } form.getEstimateLineItems().add(facility); } return form; } }
AnnualFacilityDemographicEstimateService { public EstimateForm getEstimateForm(Long userId, Long programId, Integer year) { EstimateForm form = new EstimateForm(); List<EstimateCategory> categories = estimateCategoryService.getAll(); form.setEstimateLineItems(new ArrayList<EstimateFormLineItem>()); List<SupervisoryNode> supervisoryNodes = supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, programId, RightName.MANAGE_DEMOGRAPHIC_ESTIMATES); List<RequisitionGroup> requisitionGroups = requisitionGroupService.getRequisitionGroupsBy(supervisoryNodes); List<EstimateFormLineItem> facilities = repository.getFacilityList(programId, commaSeparator.commaSeparateIds(requisitionGroups)); for (EstimateFormLineItem facility : facilities) { facility.setFacilityEstimates(repository.getFacilityEstimate(year, facility.getId(), programId)); if (facility.getFacilityEstimates().isEmpty()) { facility.setFacilityEstimates(createDefaultEstimateEntries(categories, facility.getId(), programId, year, false)); } form.getEstimateLineItems().add(facility); } return form; }  }
AnnualFacilityDemographicEstimateService { public EstimateForm getEstimateForm(Long userId, Long programId, Integer year) { EstimateForm form = new EstimateForm(); List<EstimateCategory> categories = estimateCategoryService.getAll(); form.setEstimateLineItems(new ArrayList<EstimateFormLineItem>()); List<SupervisoryNode> supervisoryNodes = supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, programId, RightName.MANAGE_DEMOGRAPHIC_ESTIMATES); List<RequisitionGroup> requisitionGroups = requisitionGroupService.getRequisitionGroupsBy(supervisoryNodes); List<EstimateFormLineItem> facilities = repository.getFacilityList(programId, commaSeparator.commaSeparateIds(requisitionGroups)); for (EstimateFormLineItem facility : facilities) { facility.setFacilityEstimates(repository.getFacilityEstimate(year, facility.getId(), programId)); if (facility.getFacilityEstimates().isEmpty()) { facility.setFacilityEstimates(createDefaultEstimateEntries(categories, facility.getId(), programId, year, false)); } form.getEstimateLineItems().add(facility); } return form; }  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 EstimateForm getEstimateForm(Long userId, Long programId, Integer year) { EstimateForm form = new EstimateForm(); List<EstimateCategory> categories = estimateCategoryService.getAll(); form.setEstimateLineItems(new ArrayList<EstimateFormLineItem>()); List<SupervisoryNode> supervisoryNodes = supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, programId, RightName.MANAGE_DEMOGRAPHIC_ESTIMATES); List<RequisitionGroup> requisitionGroups = requisitionGroupService.getRequisitionGroupsBy(supervisoryNodes); List<EstimateFormLineItem> facilities = repository.getFacilityList(programId, commaSeparator.commaSeparateIds(requisitionGroups)); for (EstimateFormLineItem facility : facilities) { facility.setFacilityEstimates(repository.getFacilityEstimate(year, facility.getId(), programId)); if (facility.getFacilityEstimates().isEmpty()) { facility.setFacilityEstimates(createDefaultEstimateEntries(categories, facility.getId(), programId, year, false)); } form.getEstimateLineItems().add(facility); } return form; }  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);  }