Search in sources :

Example 11 with MergeParams

use of org.hisp.dhis.schema.MergeParams in project dhis2-core by dhis2.

the class LegendSetController method putJsonObject.

@Override
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json")
@PreAuthorize("hasRole('F_GIS_ADMIN') or hasRole('F_LEGEND_SET_PUBLIC_ADD') or hasRole('F_LEGEND_SET_PRIVATE_ADD')  or hasRole('ALL')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void putJsonObject(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws Exception {
    LegendSet legendSet = legendSetService.getLegendSet(uid);
    if (legendSet == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Legend set does not exist: " + uid));
    }
    MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap());
    LegendSet newLegendSet = renderService.fromJson(request.getInputStream(), LegendSet.class);
    newLegendSet.setUser(currentUserService.getCurrentUser());
    newLegendSet.setUid(legendSet.getUid());
    mergeService.merge(new MergeParams<>(newLegendSet, legendSet).setMergeMode(params.getMergeMode()));
    legendSetService.updateLegendSet(legendSet);
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) MergeParams(org.hisp.dhis.schema.MergeParams) LegendSet(org.hisp.dhis.legend.LegendSet) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with MergeParams

use of org.hisp.dhis.schema.MergeParams in project dhis2-core by dhis2.

the class DefaultDimensionService method getDimensionalObjectCopy.

@Override
public DimensionalObject getDimensionalObjectCopy(String uid, boolean filterCanRead) {
    DimensionalObject dimension = idObjectManager.get(DimensionalObject.DYNAMIC_DIMENSION_CLASSES, uid);
    BaseDimensionalObject copy = new BaseDimensionalObject();
    mergeService.merge(new MergeParams<>(dimension, copy).setMergeMode(MergeMode.MERGE));
    if (filterCanRead) {
        User user = currentUserService.getCurrentUser();
        List<DimensionalItemObject> items = getCanReadObjects(user, dimension.getItems());
        copy.setItems(items);
    }
    return copy;
}
Also used : User(org.hisp.dhis.user.User) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MergeParams(org.hisp.dhis.schema.MergeParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject)

Aggregations

MergeParams (org.hisp.dhis.schema.MergeParams)12 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 Test (org.junit.Test)5 Date (java.util.Date)4 User (org.hisp.dhis.user.User)4 Simple (org.hisp.dhis.dxf2.metadata.merge.Simple)3 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)3 UserCredentials (org.hisp.dhis.user.UserCredentials)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1