Search in sources :

Example 1 with Map

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

the class MapController method putJsonObject.

@Override
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void putJsonObject(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map map = mappingService.getMap(uid);
    if (map == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Map does not exist: " + uid));
    }
    MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap());
    Map newMap = deserializeJsonEntity(request, response);
    newMap.setUid(uid);
    mergeService.merge(new MergeParams<>(newMap, map).setMergeMode(params.getMergeMode()));
    mappingService.updateMap(map);
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) MergeParams(org.hisp.dhis.schema.MergeParams) Map(org.hisp.dhis.mapping.Map) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Map

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

the class MapController method postJsonObject.

//--------------------------------------------------------------------------
// CRUD
//--------------------------------------------------------------------------
@Override
@RequestMapping(method = RequestMethod.POST, consumes = "application/json")
@ResponseStatus(HttpStatus.CREATED)
public void postJsonObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map map = deserializeJsonEntity(request, response);
    map.getTranslations().clear();
    mappingService.addMap(map);
    response.addHeader("Location", MapSchemaDescriptor.API_ENDPOINT + "/" + map.getUid());
    webMessageService.send(WebMessageUtils.created("Map created"), response, request);
}
Also used : Map(org.hisp.dhis.mapping.Map) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Map

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

the class AclServiceTest method testCanUpdatePrivateMap.

@Test
void testCanUpdatePrivateMap() {
    User user = createAdminUser("F_DATAELEMENT_PRIVATE_ADD");
    Map map = new Map();
    map.setAutoFields();
    map.setCreatedBy(user);
    map.getSharing().setOwner(user);
    map.setPublicAccess(AccessStringHelper.DEFAULT);
    assertTrue(aclService.canUpdate(user, map));
}
Also used : User(org.hisp.dhis.user.User) Map(org.hisp.dhis.mapping.Map) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with Map

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

the class MapController method deserializeJsonEntity.

@Override
protected Map deserializeJsonEntity(HttpServletRequest request) throws IOException {
    Map map = super.deserializeJsonEntity(request);
    mergeMap(map);
    return map;
}
Also used : Map(org.hisp.dhis.mapping.Map)

Example 5 with Map

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

the class MapController method getMapData.

// --------------------------------------------------------------------------
// Get data
// --------------------------------------------------------------------------
@GetMapping(value = { "/{uid}/data", "/{uid}/data.png" })
public void getMapData(@PathVariable String uid, @RequestParam(value = "date", required = false) Date date, @RequestParam(value = "ou", required = false) String ou, @RequestParam(required = false) Integer width, @RequestParam(required = false) Integer height, @RequestParam(value = "attachment", required = false) boolean attachment, HttpServletResponse response) throws Exception {
    Map map = mappingService.getMapNoAcl(uid);
    if (map == null) {
        throw new WebMessageException(notFound("Map does not exist: " + uid));
    }
    if (width != null && width < MAP_MIN_WIDTH) {
        throw new WebMessageException(conflict("Min map width is " + MAP_MIN_WIDTH + ": " + width));
    }
    if (height != null && height < MAP_MIN_HEIGHT) {
        throw new WebMessageException(conflict("Min map height is " + MAP_MIN_HEIGHT + ": " + height));
    }
    OrganisationUnit unit = ou != null ? organisationUnitService.getOrganisationUnit(ou) : null;
    renderMapViewPng(map, date, unit, width, height, attachment, response);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Map(org.hisp.dhis.mapping.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping)

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