use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class AbstractCrudController method deleteObject.
//--------------------------------------------------------------------------
// DELETE
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.OK)
public void deleteObject(@PathVariable("uid") String pvUid, HttpServletRequest request, HttpServletResponse response) throws Exception {
List<T> objects = getEntity(pvUid);
if (objects.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound(getEntityClass(), pvUid));
}
User user = currentUserService.getCurrentUser();
if (!aclService.canDelete(user, objects.get(0))) {
throw new DeleteAccessDeniedException("You don't have the proper permissions to delete this object.");
}
preDeleteEntity(objects.get(0));
MetadataImportParams params = new MetadataImportParams().setImportReportMode(ImportReportMode.FULL).setUser(user).setImportStrategy(ImportStrategy.DELETE).addObject(objects.get(0));
ImportReport importReport = importService.importMetadata(params);
postDeleteEntity();
webMessageService.send(WebMessageUtils.objectReport(importReport), response, request);
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class AbstractCrudController method putJsonObject.
//--------------------------------------------------------------------------
// PUT
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void putJsonObject(@PathVariable("uid") String pvUid, HttpServletRequest request, HttpServletResponse response) throws Exception {
List<T> objects = getEntity(pvUid);
if (objects.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound(getEntityClass(), pvUid));
}
User user = currentUserService.getCurrentUser();
if (!aclService.canUpdate(user, objects.get(0))) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
T parsed = deserializeJsonEntity(request, response);
((BaseIdentifiableObject) parsed).setUid(pvUid);
preUpdateEntity(objects.get(0), parsed);
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap()).setImportReportMode(ImportReportMode.FULL).setUser(user).setImportStrategy(ImportStrategy.UPDATE).addObject(parsed);
ImportReport importReport = importService.importMetadata(params);
WebMessage webMessage = WebMessageUtils.objectReport(importReport);
if (importReport.getStatus() == Status.OK) {
T entity = manager.get(getEntityClass(), pvUid);
postUpdateEntity(entity);
} else {
webMessage.setStatus(Status.ERROR);
}
webMessageService.send(webMessage, response, request);
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportController method postXmlMetadata.
@RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML_VALUE)
public void postXmlMetadata(HttpServletRequest request, HttpServletResponse response) throws IOException {
MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
Metadata metadata = renderService.fromXml(StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream()), Metadata.class);
params.addMetadata(schemaService.getMetadataSchemas(), metadata);
if (params.hasTaskId()) {
startAsync(params);
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
} else {
ImportReport importReport = metadataImportService.importMetadata(params);
renderService.toXml(response.getOutputStream(), importReport);
}
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class SynchronizationController method importMetaData.
@PreAuthorize("hasRole('ALL')")
@RequestMapping(value = "/metadataPull", method = RequestMethod.POST)
public void importMetaData(@RequestBody String url, HttpServletResponse response) throws IOException {
ImportReport importReport = synchronizationManager.executeMetadataPull(url);
response.setContentType(CONTENT_TYPE_JSON);
renderService.toJson(response.getOutputStream(), importReport);
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataRetryContextTest method testIfSummaryIsNotNull.
@Test
public void testIfSummaryIsNotNull() throws Exception {
MetadataSyncSummary testSummary = new MetadataSyncSummary();
ImportReport importReport = new ImportReport();
importReport.setStatus(Status.ERROR);
testSummary.setImportReport(importReport);
metadataRetryContext.updateRetryContext(testKey, testMessage, mockVersion, testSummary);
verify(retryContext).setAttribute(testKey, testMessage);
}
Aggregations