Search in sources :

Example 11 with Translation

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);
}
Also used : Translation(org.hisp.dhis.translation.Translation) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) HashSet(java.util.HashSet) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Translation (org.hisp.dhis.translation.Translation)11 HashSet (java.util.HashSet)5 Test (org.junit.jupiter.api.Test)4 Locale (java.util.Locale)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Set (java.util.Set)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 DhisTest (org.hisp.dhis.DhisTest)1 CategoryCombo (org.hisp.dhis.category.CategoryCombo)1 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)1 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)1 Expression (org.hisp.dhis.expression.Expression)1 ErrorReport (org.hisp.dhis.feedback.ErrorReport)1 ObjectReport (org.hisp.dhis.feedback.ObjectReport)1