Search in sources :

Example 6 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)

Example 7 with MergeParams

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

the class MergeServiceTest method simpleReplace.

@Test
public void simpleReplace() {
    Date date = new Date();
    Simple source = new Simple("string", 10, date, false, 123, 2.5f);
    Simple target = new Simple();
    mergeService.merge(new MergeParams<>(source, target).setMergeMode(MergeMode.REPLACE));
    assertEquals("string", target.getString());
    assertEquals(10, (int) target.getInteger());
    assertEquals(date, target.getDate());
    assertEquals(false, target.getBool());
    assertEquals(123, target.getAnInt());
}
Also used : MergeParams(org.hisp.dhis.schema.MergeParams) Date(java.util.Date) Simple(org.hisp.dhis.dxf2.metadata.merge.Simple) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with MergeParams

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

the class MergeServiceTest method mergeOrgUnitGroup.

@Test
public void mergeOrgUnitGroup() {
    OrganisationUnit organisationUnitA = createOrganisationUnit('A');
    OrganisationUnit organisationUnitB = createOrganisationUnit('B');
    OrganisationUnit organisationUnitC = createOrganisationUnit('C');
    OrganisationUnit organisationUnitD = createOrganisationUnit('D');
    OrganisationUnitGroup organisationUnitGroupA = createOrganisationUnitGroup('A');
    OrganisationUnitGroup organisationUnitGroupB = createOrganisationUnitGroup('B');
    organisationUnitGroupA.getMembers().add(organisationUnitA);
    organisationUnitGroupA.getMembers().add(organisationUnitB);
    organisationUnitGroupA.getMembers().add(organisationUnitC);
    organisationUnitGroupA.getMembers().add(organisationUnitD);
    OrganisationUnitGroupSet organisationUnitGroupSetA = createOrganisationUnitGroupSet('A');
    organisationUnitGroupSetA.addOrganisationUnitGroup(organisationUnitGroupA);
    mergeService.merge(new MergeParams<>(organisationUnitGroupA, organisationUnitGroupB).setMergeMode(MergeMode.REPLACE));
    assertFalse(organisationUnitGroupB.getMembers().isEmpty());
    assertEquals(4, organisationUnitGroupB.getMembers().size());
    assertNotNull(organisationUnitGroupB.getGroupSets());
    assertFalse(organisationUnitGroupB.getGroupSets().isEmpty());
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MergeParams(org.hisp.dhis.schema.MergeParams) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 9 with MergeParams

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

the class MergeServiceTest method simpleMerge.

@Test
public void simpleMerge() {
    Date date = new Date();
    Simple source = new Simple(null, 10, date, null, 123, 2.5f);
    Simple target = new Simple("hello", 20, date, true, 123, 2.5f);
    mergeService.merge(new MergeParams<>(source, target).setMergeMode(MergeMode.MERGE));
    assertEquals("hello", target.getString());
    assertEquals(10, (int) target.getInteger());
    assertEquals(date, target.getDate());
    assertEquals(true, target.getBool());
}
Also used : MergeParams(org.hisp.dhis.schema.MergeParams) Date(java.util.Date) Simple(org.hisp.dhis.dxf2.metadata.merge.Simple) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 10 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)

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