Search in sources :

Example 71 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.

the class UidGeneratorTest method verifyEventsGetUidAssigned.

@Test
void verifyEventsGetUidAssigned() {
    final String uid = CodeGenerator.generateUid();
    // Given
    Event event1 = new Event();
    Event event2 = new Event();
    Event event3 = new Event();
    Event event4 = new Event();
    event4.setEvent(uid);
    // When
    List<Event> events = subject.assignUidToEvents(Lists.newArrayList(event1, event2, event3, event4));
    // Then
    assertThat(events, hasSize(4));
    events.forEach(e -> assertNotNull(e.getUid()));
    // make sure we got 4 distinct UIDs
    assertThat(events.stream().collect(Collectors.toMap(Event::getUid, Function.identity())).keySet(), hasSize(4));
    // make sure Event4 has retained the original UID
    assertThat(event4.getUid(), is(uid));
    assertThat(event4.getEvent(), is(uid));
}
Also used : Event(org.hisp.dhis.dxf2.events.event.Event) Test(org.junit.jupiter.api.Test)

Example 72 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.

the class ProgramOrgUnitCheckTest method verifySuccessWhenProgramHasOrgUnitMatchingEventOrgUnit.

private void verifySuccessWhenProgramHasOrgUnitMatchingEventOrgUnit(String orgUnitId, IdScheme scheme) {
    // assign a UID to the event's org unit
    event.setOrgUnit(orgUnitId);
    // Prepare data
    Program program = createProgram('P');
    program.setId(1);
    OrganisationUnit ou = new OrganisationUnit();
    ou.setId(1);
    ou.setUid(orgUnitId);
    when(workContext.getOrganisationUnitMap()).thenReturn(ImmutableMap.of(event.getUid(), ou));
    when(workContext.getProgramWithOrgUnitsMap()).thenReturn(ImmutableMap.of(1L, ImmutableList.of(1L)));
    ProgramInstance pi = new ProgramInstance();
    pi.setProgram(program);
    Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
    programInstanceMap.put(event.getUid(), pi);
    when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
    ImportOptions importOptions = ImportOptions.getDefaultImportOptions();
    importOptions.setOrgUnitIdScheme(scheme.name());
    when(workContext.getImportOptions()).thenReturn(importOptions);
    // method under test
    ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
    assertNoError(summary);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent)

Example 73 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID 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)

Example 74 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID 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 75 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.

the class MapViewController method getMapViewData.

// --------------------------------------------------------------------------
// Get data
// --------------------------------------------------------------------------
@GetMapping(value = { "/{uid}/data", "/{uid}/data.png" })
public void getMapViewData(@PathVariable String uid, HttpServletResponse response) throws Exception {
    MapView mapView = mappingService.getMapView(uid);
    if (mapView == null) {
        throw new WebMessageException(notFound("Map view does not exist: " + uid));
    }
    renderMapViewPng(mapView, response);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) MapView(org.hisp.dhis.mapping.MapView) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)92 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)52 Event (org.hisp.dhis.dxf2.events.event.Event)39 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)37 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)34 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)29 GetMapping (org.springframework.web.bind.annotation.GetMapping)28 User (org.hisp.dhis.user.User)23 Test (org.junit.jupiter.api.Test)21 HashMap (java.util.HashMap)19 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)19 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)19 InputStream (java.io.InputStream)18 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)18 ArrayList (java.util.ArrayList)17 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)17 List (java.util.List)16 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)16 DataElement (org.hisp.dhis.dataelement.DataElement)15 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)15