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;
}
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());
}
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());
}
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());
}
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);
}
Aggregations