use of org.hisp.dhis.translation.Translation in project dhis2-core by dhis2.
the class AbstractCrudController method replaceTranslations.
@PutMapping(value = "/{uid}/translations")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public WebMessage replaceTranslations(@PathVariable("uid") String pvUid, @RequestParam Map<String, String> rpParameters, @CurrentUser User currentUser, HttpServletRequest request) throws Exception {
WebOptions options = new WebOptions(rpParameters);
List<T> entities = getEntity(pvUid, options);
if (entities.isEmpty()) {
return notFound(getEntityClass(), pvUid);
}
BaseIdentifiableObject persistedObject = (BaseIdentifiableObject) entities.get(0);
if (!aclService.canUpdate(currentUser, persistedObject)) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
T inputObject = renderService.fromJson(request.getInputStream(), getEntityClass());
HashSet<Translation> translations = new HashSet<>(inputObject.getTranslations());
persistedObject.setTranslations(translations);
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap());
params.setUser(currentUser).setImportStrategy(ImportStrategy.UPDATE).addObject(persistedObject).setImportMode(ObjectBundleMode.VALIDATE);
ImportReport importReport = importService.importMetadata(params);
if (!importReport.hasErrorReports()) {
manager.save(persistedObject);
return null;
}
return importReport(importReport);
}
Aggregations