use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.
the class WebMessageUtils method errorReports.
public static WebMessage errorReports(List<ErrorReport> errorReports) {
WebMessage webMessage = new WebMessage();
webMessage.setResponse(new ErrorReportsWebMessageResponse(errorReports));
if (!errorReports.isEmpty()) {
webMessage.setStatus(Status.ERROR);
webMessage.setHttpStatus(HttpStatus.BAD_REQUEST);
}
return webMessage;
}
use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.
the class WebMessageUtils method objectReport.
public static WebMessage objectReport(ObjectReport objectReport) {
WebMessage webMessage = new WebMessage();
webMessage.setResponse(new ObjectReportWebMessageResponse(objectReport));
if (objectReport.isEmpty()) {
webMessage.setStatus(Status.OK);
webMessage.setHttpStatus(HttpStatus.OK);
} else {
webMessage.setMessage("One more more errors occurred, please see full details in import report.");
webMessage.setStatus(Status.WARNING);
webMessage.setHttpStatus(HttpStatus.CONFLICT);
}
return webMessage;
}
use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.
the class AbstractCrudController method replaceTranslations.
@RequestMapping(value = "/{uid}/translations", method = RequestMethod.PUT)
public void replaceTranslations(@PathVariable("uid") String pvUid, @RequestParam Map<String, String> rpParameters, HttpServletRequest request, HttpServletResponse response) throws Exception {
WebOptions options = new WebOptions(rpParameters);
List<T> entities = getEntity(pvUid, options);
if (entities.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound(getEntityClass(), pvUid));
}
T persistedObject = entities.get(0);
User user = currentUserService.getCurrentUser();
if (!aclService.canUpdate(user, persistedObject)) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
T object = renderService.fromJson(request.getInputStream(), getEntityClass());
TypeReport typeReport = new TypeReport(ObjectTranslation.class);
List<ObjectTranslation> objectTranslations = Lists.newArrayList(object.getTranslations());
for (int idx = 0; idx < object.getTranslations().size(); idx++) {
ObjectReport objectReport = new ObjectReport(ObjectTranslation.class, idx);
ObjectTranslation translation = objectTranslations.get(idx);
if (translation.getLocale() == null) {
objectReport.addErrorReport(new ErrorReport(ObjectTranslation.class, ErrorCode.E4000, "locale").setErrorKlass(getEntityClass()));
}
if (translation.getProperty() == null) {
objectReport.addErrorReport(new ErrorReport(ObjectTranslation.class, ErrorCode.E4000, "property").setErrorKlass(getEntityClass()));
}
if (translation.getValue() == null) {
objectReport.addErrorReport(new ErrorReport(ObjectTranslation.class, ErrorCode.E4000, "value").setErrorKlass(getEntityClass()));
}
typeReport.addObjectReport(objectReport);
if (!objectReport.isEmpty()) {
typeReport.getStats().incIgnored();
}
}
if (!typeReport.getErrorReports().isEmpty()) {
WebMessage webMessage = WebMessageUtils.typeReport(typeReport);
webMessageService.send(webMessage, response, request);
return;
}
manager.updateTranslations(persistedObject, object.getTranslations());
manager.update(persistedObject);
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessage 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.webmessage.WebMessage in project dhis2-core by dhis2.
the class EventController method postCsvEvents.
@PostMapping(consumes = { "application/csv", "text/csv" })
@ResponseBody
public WebMessage postCsvEvents(@RequestParam(required = false, defaultValue = "false") boolean skipFirst, HttpServletRequest request, ImportOptions importOptions) throws IOException, ParseException {
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
List<Event> events = csvEventService.readEvents(inputStream, skipFirst);
if (!importOptions.isAsync()) {
ImportSummaries importSummaries = eventService.addEvents(events, importOptions, null);
importSummaries.setImportOptions(importOptions);
return importSummaries(importSummaries);
}
return startAsyncImport(importOptions, events);
}
Aggregations