Search in sources :

Example 6 with Map

use of org.hisp.dhis.mapping.Map in project dhis2-core by dhis2.

the class MapController method putJsonObject.

// --------------------------------------------------------------------------
// CRUD
// --------------------------------------------------------------------------
@Override
@PutMapping(value = "/{uid}", consumes = APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public WebMessage putJsonObject(@PathVariable String uid, @CurrentUser User currentUser, HttpServletRequest request) throws Exception {
    Map map = mappingService.getMap(uid);
    if (map == null) {
        return notFound("Map does not exist: " + uid);
    }
    MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap());
    Map newMap = deserializeJsonEntity(request);
    newMap.setUid(uid);
    mergeService.merge(new MergeParams<>(newMap, map).setMergeMode(params.getMergeMode()).setSkipSharing(params.isSkipSharing()).setSkipTranslation(params.isSkipTranslation()));
    mappingService.updateMap(map);
    return null;
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) MergeParams(org.hisp.dhis.schema.MergeParams) Map(org.hisp.dhis.mapping.Map) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with Map

use of org.hisp.dhis.mapping.Map in project dhis2-core by dhis2.

the class CascadeSharingTest method createMap.

protected Map createMap(String name) {
    MapView mapView = createMapView("Test");
    Map map = new Map();
    map.setName("map" + name);
    map.setMapViews(Lists.newArrayList(mapView));
    map.setAutoFields();
    return map;
}
Also used : MapView(org.hisp.dhis.mapping.MapView) Map(org.hisp.dhis.mapping.Map)

Example 8 with Map

use of org.hisp.dhis.mapping.Map in project dhis2-core by dhis2.

the class DashboardCascadeSharingTest method testCascadeSharePublicAccess.

/**
 * Dashboard has publicAccess READ and not shared to any User or UserGroup.
 * <p>
 * Expected cascade sharing for PublicAccess is not supported, so user can't
 * access dashboardItem's objects.
 */
@Test
void testCascadeSharePublicAccess() {
    Map map = createMap("A");
    map.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
    objectManager.save(map, false);
    Dashboard dashboard = createDashboardWithItem("dashboardA", Sharing.builder().publicAccess(READ).build());
    dashboard.getItems().get(0).setMap(map);
    objectManager.save(dashboard, false);
    CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, new CascadeSharingParameters());
    assertEquals(0, report.getErrorReports().size());
    assertFalse(aclService.canRead(userA, dashboard.getItems().get(0).getMap()));
    assertFalse(aclService.canRead(userB, dashboard.getItems().get(0).getMap()));
}
Also used : Dashboard(org.hisp.dhis.dashboard.Dashboard) Map(org.hisp.dhis.mapping.Map) Test(org.junit.jupiter.api.Test)

Example 9 with Map

use of org.hisp.dhis.mapping.Map in project dhis2-core by dhis2.

the class DashboardCascadeSharingTest method testAtomicFalse.

@Test
void testAtomicFalse() {
    Map mapA = createMap("A");
    mapA.setSharing(sharingReadWriteForUserB);
    objectManager.save(mapA, false);
    Map mapB = createMap("A");
    mapB.setSharing(defaultSharing());
    objectManager.save(mapB, false);
    DashboardItem itemB = createDashboardItem("B");
    itemB.setMap(mapB);
    Dashboard dashboard = createDashboardWithItem("A", sharingReadForUserA);
    dashboard.getItems().get(0).setMap(mapA);
    dashboard.getItems().add(itemB);
    objectManager.save(dashboard, false);
    CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, CascadeSharingParameters.builder().atomic(false).user(userB).build());
    assertEquals(1, report.getErrorReports().size());
    assertEquals(1, report.getUpdateObjects().size());
    assertTrue(aclService.canRead(userA, mapA));
    assertFalse(aclService.canRead(userA, mapB));
}
Also used : Dashboard(org.hisp.dhis.dashboard.Dashboard) DashboardItem(org.hisp.dhis.dashboard.DashboardItem) Map(org.hisp.dhis.mapping.Map) Test(org.junit.jupiter.api.Test)

Example 10 with Map

use of org.hisp.dhis.mapping.Map in project dhis2-core by dhis2.

the class DashboardCascadeSharingTest method testDryRunFalse.

@Test
void testDryRunFalse() {
    Map map = createMap("A");
    map.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
    objectManager.save(map, false);
    Dashboard dashboard = createDashboardWithItem("A", sharingReadForUserA);
    dashboard.getItems().get(0).setMap(map);
    objectManager.save(dashboard, false);
    CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, CascadeSharingParameters.builder().dryRun(false).build());
    assertEquals(0, report.getErrorReports().size());
    assertEquals(1, report.getUpdateObjects().size());
    assertTrue(aclService.canRead(userA, dashboard.getItems().get(0).getMap()));
    assertFalse(aclService.canRead(userB, dashboard.getItems().get(0).getMap()));
}
Also used : Dashboard(org.hisp.dhis.dashboard.Dashboard) Map(org.hisp.dhis.mapping.Map) Test(org.junit.jupiter.api.Test)

Aggregations

Map (org.hisp.dhis.mapping.Map)19 Test (org.junit.jupiter.api.Test)10 Dashboard (org.hisp.dhis.dashboard.Dashboard)8 DashboardItem (org.hisp.dhis.dashboard.DashboardItem)3 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)2 MergeParams (org.hisp.dhis.schema.MergeParams)2 HashMap (java.util.HashMap)1 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 Interpretation (org.hisp.dhis.interpretation.Interpretation)1 MapView (org.hisp.dhis.mapping.MapView)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 User (org.hisp.dhis.user.User)1 Sharing (org.hisp.dhis.user.sharing.Sharing)1 UserAccess (org.hisp.dhis.user.sharing.UserAccess)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1