ReportDataController { @RequestMapping(headers = {"Accept=application/json"}, value = "/report/update", method = RequestMethod.POST) @ResponseBody public String updateReports(@RequestBody ReportDataUpdateRequest request) throws ReportDataMissingException { logger.info(MessageFormat.format("Flushing reports for reporting month {0} to {1} for indicator {2} for service type {3}", request.startDate(), request.endDate(), request.indicator(), request.type())); List<ReportingData> reportingData = request.reportingData(); if (ReportDataParameters.SERVICE_PROVIDED_DATA_TYPE.equals(request.type())) { throwExceptionIfMandatoryDataIsNotPresentForServiceProvidedReport(reportingData); servicesProvidedRepository.update(request); } else if (ReportDataParameters.ANM_REPORT_DATA_TYPE.equals(request.type())) { throwExceptionIfMandatoryDataIsNotPresentForANMReport(reportingData); anmReportsRepository.update(request); } return "Success."; } @Autowired  ReportDataController(ServicesProvidedRepository servicesProvidedRepository,
                                ANMReportsRepository anmReportsRepository); @RequestMapping(value = "/report/submit", method = RequestMethod.POST) @ResponseBody String submit(@RequestBody ReportingData reportingData); @RequestMapping(headers = {"Accept=application/json"}, value = "/report/update", method = RequestMethod.POST) @ResponseBody String updateReports(@RequestBody ReportDataUpdateRequest request); @RequestMapping(headers = {"Accept=application/json"}, value = "/report/delete", method = RequestMethod.POST) @ResponseBody String deleteReports(@RequestBody ReportDataDeleteRequest request); @RequestMapping(value = "/report/fetchForAllANMs", method = RequestMethod.GET) @ResponseBody List<ANMReport> getAllANMsIndicatorSummaries();  }
@Test public void shouldUpdateListOfServiceProvidedIndicatorRowsForReportingMonthForAllANMs() throws Exception { HashMap<String, String> data = new HashMap<String, String>(); String type = "serviceProvided"; data.put(SERVICE_PROVIDER_TYPE, type); data.put(EXTERNAL_ID, "external id 1"); data.put(SERVICE_PROVIDED_DATE, "2013-01-26"); data.put(VILLAGE, "village 1"); data.put(SUB_CENTER, "sub center 1"); data.put(PHC, "phc"); data.put(QUANTITY, "1"); data.put(INDICATOR, "INDICATOR 1"); data.put(ANM_IDENTIFIER, "anm id 1"); data.put(DRISTHI_ENTITY_ID, "entity id 1"); ReportingData reportingData = new ReportingData("serviceProvided", data); ReportDataUpdateRequest reportDataUpdateRequest = new ReportDataUpdateRequest() .withType(type) .withStartDate("2013-01-26") .withEndDate("2013-02-25") .withReportingData(asList(reportingData)); String result = controller.updateReports(reportDataUpdateRequest); verify(servicesProvidedRepository).update(reportDataUpdateRequest); assertEquals("Success.", result); }
@Test public void shouldDeleteListOfANMReportsIndicatorRowsForReportingMonthForAllANMs() throws Exception { String indicator = "INDICATOR 1"; String startDate = "2013-01-26"; String endDate = "2013-02-25"; HashMap<String, String> data = new HashMap<String, String>(); data.put(SERVICE_PROVIDER_TYPE, "anmReport"); data.put(EXTERNAL_ID, "external id 1"); data.put(SERVICE_PROVIDED_DATE, startDate); data.put(VILLAGE, "village 1"); data.put(SUB_CENTER, "sub center 1"); data.put(PHC, "phc"); data.put(QUANTITY, "1"); data.put(INDICATOR, indicator); data.put(ANM_IDENTIFIER, "anm id 1"); ReportingData reportingData = new ReportingData("anmReportData", data); ReportDataUpdateRequest reportDataUpdateRequest = new ReportDataUpdateRequest() .withType("anmReportData") .withReportingData(asList(reportingData)) .withStartDate(startDate) .withEndDate(endDate) .withIndicator(indicator); String result = controller.updateReports(reportDataUpdateRequest); verify(anmReportsRepository).update(reportDataUpdateRequest); assertEquals("Success.", result); }