use of org.hisp.dhis.dxf2.common.ImportSummary in project dhis2-core by dhis2.
the class EnrollmentController method postEnrollmentJson.
// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')")
public void postEnrollmentJson(@RequestParam(defaultValue = "CREATE") ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
importOptions.setStrategy(strategy);
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
ImportSummaries importSummaries = enrollmentService.addEnrollmentsJson(inputStream, importOptions);
importSummaries.setImportOptions(importOptions);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
importSummaries.getImportSummaries().stream().filter(importSummary -> !importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR) && !importOptions.getImportStrategy().isDelete()).forEach(importSummary -> importSummary.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + importSummary.getReference()));
if (importSummaries.getImportSummaries().size() == 1) {
ImportSummary importSummary = importSummaries.getImportSummaries().get(0);
importSummary.setImportOptions(importOptions);
if (!importSummary.getStatus().equals(ImportStatus.ERROR)) {
response.setHeader("Location", getResourcePath(request, importSummary));
}
}
response.setStatus(HttpServletResponse.SC_CREATED);
webMessageService.send(WebMessageUtils.importSummaries(importSummaries), response, request);
}
use of org.hisp.dhis.dxf2.common.ImportSummary in project dhis2-core by dhis2.
the class EventController method deleteEvent.
// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_DELETE')")
public void deleteEvent(HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid) throws WebMessageException {
if (!programStageInstanceService.programStageInstanceExists(uid)) {
throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
}
response.setStatus(HttpServletResponse.SC_OK);
try {
ImportSummary importSummary = eventService.deleteEvent(uid);
webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
} catch (Exception ex) {
webMessageService.send(WebMessageUtils.conflict("Unable to delete event " + uid, ex.getMessage()), response, request);
}
}
use of org.hisp.dhis.dxf2.common.ImportSummary in project dhis2-core by dhis2.
the class SystemController method getTaskSummaryJson.
@RequestMapping(value = "/taskSummaries/{category}", method = RequestMethod.GET, produces = { "*/*", "application/json" })
public void getTaskSummaryJson(HttpServletResponse response, @PathVariable("category") String category) throws IOException {
if (category != null) {
TaskCategory taskCategory = TaskCategory.valueOf(category.toUpperCase());
TaskId taskId = new TaskId(taskCategory, currentUserService.getCurrentUser());
Object summary = notifier.getTaskSummary(taskId);
if (//TODO improve this
summary != null && summary.getClass().isAssignableFrom(ImportSummary.class)) {
ImportSummary importSummary = (ImportSummary) summary;
renderService.toJson(response.getOutputStream(), importSummary);
return;
} else {
renderService.toJson(response.getOutputStream(), summary);
return;
}
}
renderService.toJson(response.getOutputStream(), new ImportSummary());
}
use of org.hisp.dhis.dxf2.common.ImportSummary in project dhis2-core by dhis2.
the class AdxController method postXMLDataValueSet.
@RequestMapping(method = RequestMethod.POST, consumes = "application/xml")
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
public void postXMLDataValueSet(ImportOptions importOptions, HttpServletResponse response, InputStream in, Model model) throws IOException {
ImportSummary importSummary = adxService.saveDataValueSet(in, importOptions, null);
importSummary.setImportOptions(importOptions);
log.debug("Data values set saved");
response.setContentType(CONTENT_TYPE_XML);
DefaultRenderService.getXmlMapper().writeValue(response.getOutputStream(), importSummary);
}
use of org.hisp.dhis.dxf2.common.ImportSummary in project dhis2-core by dhis2.
the class DataValueSetServiceIntegrationTest method testImportDeleteValuesXml.
// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
/**
* Import 3 data values, then delete 3 data values.
*/
@Test
public void testImportDeleteValuesXml() throws Exception {
assertEquals(0, dataValueService.getAllDataValues().size());
in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
ImportSummary summary = dataValueSetService.saveDataValueSet(in);
assertEquals(3, summary.getImportCount().getImported());
assertEquals(0, summary.getImportCount().getUpdated());
assertEquals(0, summary.getImportCount().getDeleted());
assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertEquals(3, dataValueService.getAllDataValues().size());
// Delete values
in = new ClassPathResource("datavalueset/dataValueSetADeleted.xml").getInputStream();
summary = dataValueSetService.saveDataValueSet(in);
assertEquals(0, summary.getImportCount().getImported());
assertEquals(0, summary.getImportCount().getUpdated());
assertEquals(3, summary.getImportCount().getDeleted());
assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertEquals(0, dataValueService.getAllDataValues().size());
}
Aggregations