Search in sources :

Example 16 with UPDATED

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

the class EventController method postJsonEventForNote.

@PostMapping(value = "/{uid}/note", consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage postJsonEventForNote(@PathVariable("uid") String uid, HttpServletRequest request, ImportOptions importOptions) throws IOException {
    if (!programStageInstanceService.programStageInstanceExists(uid)) {
        return notFound("Event not found for ID " + uid);
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Event event = renderService.fromJson(inputStream, Event.class);
    event.setEvent(uid);
    eventService.updateEventForNote(event);
    return ok("Event updated: " + uid);
}
Also used : InputStream(java.io.InputStream) Event(org.hisp.dhis.dxf2.events.event.Event) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 17 with UPDATED

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

the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithLastUpdatedParameter.

@Test
void testFetchTrackedEntityInstancesWithLastUpdatedParameter() {
    doInTransaction(() -> {
        this.persistTrackedEntityInstance();
        this.persistTrackedEntityInstance();
        this.persistTrackedEntityInstance();
        this.persistTrackedEntityInstance();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setLastUpdatedStartDate(Date.from(Instant.now().minus(1, ChronoUnit.DAYS)));
    queryParams.setLastUpdatedEndDate(new Date());
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(trackedEntityInstances, hasSize(4));
    assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(0));
    // Update last updated start date to today
    queryParams.setLastUpdatedStartDate(Date.from(Instant.now().plus(1, ChronoUnit.DAYS)));
    final List<TrackedEntityInstance> limitedTTrackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(limitedTTrackedEntityInstances, hasSize(0));
}
Also used : TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Date(java.util.Date) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.dxf2.TrackerTest)

Example 18 with UPDATED

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

the class AbstractCrudController method patchObject.

// --------------------------------------------------------------------------
// PATCH
// --------------------------------------------------------------------------
/**
 * Adds support for HTTP Patch using JSON Patch (RFC 6902), updated object
 * is run through normal metadata importer and internally looks like a
 * normal PUT (after the JSON Patch has been applied).
 *
 * For now we only support the official mimetype
 * "application/json-patch+json" but in future releases we might also want
 * to support "application/json" after the old patch behavior has been
 * removed.
 */
@ResponseBody
@PatchMapping(path = "/{uid}", consumes = "application/json-patch+json")
public WebMessage patchObject(@PathVariable("uid") String pvUid, @RequestParam Map<String, String> rpParameters, @CurrentUser User currentUser, HttpServletRequest request) throws Exception {
    WebOptions options = new WebOptions(rpParameters);
    List<T> entities = getEntity(pvUid, options);
    if (entities.isEmpty()) {
        return notFound(getEntityClass(), pvUid);
    }
    final T persistedObject = entities.get(0);
    if (!aclService.canUpdate(currentUser, persistedObject)) {
        throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
    }
    manager.resetNonOwnerProperties(persistedObject);
    prePatchEntity(persistedObject);
    final JsonPatch patch = jsonMapper.readValue(request.getInputStream(), JsonPatch.class);
    final T patchedObject = jsonPatchManager.apply(patch, persistedObject);
    // we don't allow changing IDs
    ((BaseIdentifiableObject) patchedObject).setId(persistedObject.getId());
    // we don't allow changing UIDs
    ((BaseIdentifiableObject) patchedObject).setUid(persistedObject.getUid());
    // Only supports new Sharing format
    ((BaseIdentifiableObject) patchedObject).clearLegacySharingCollections();
    prePatchEntity(persistedObject, patchedObject);
    Map<String, List<String>> parameterValuesMap = contextService.getParameterValuesMap();
    if (!parameterValuesMap.containsKey("importReportMode")) {
        parameterValuesMap.put("importReportMode", Collections.singletonList("ERRORS_NOT_OWNER"));
    }
    MetadataImportParams params = importService.getParamsFromMap(parameterValuesMap);
    params.setUser(currentUser).setImportStrategy(ImportStrategy.UPDATE).addObject(patchedObject);
    ImportReport importReport = importService.importMetadata(params);
    WebMessage webMessage = objectReport(importReport);
    if (importReport.getStatus() == Status.OK) {
        T entity = manager.get(getEntityClass(), pvUid);
        postPatchEntity(entity);
    } else {
        webMessage.setStatus(Status.ERROR);
    }
    return webMessage;
}
Also used : BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) BulkJsonPatch(org.hisp.dhis.jsonpatch.BulkJsonPatch) JsonPatch(org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 19 with UPDATED

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

the class TrackerSynchronization method synchronizePage.

private void synchronizePage(TrackedEntityInstanceQueryParams queryParams, int page, int pageSize) {
    queryParams.setPage(page);
    List<TrackedEntityInstance> dtoTeis = teiService.getTrackedEntityInstances(queryParams, TrackedEntityInstanceParams.DATA_SYNCHRONIZATION, true, true);
    log.info(String.format("Synchronizing page %d with page size %d", page, pageSize));
    if (log.isDebugEnabled()) {
        log.debug("TEIs that are going to be synchronized are: " + dtoTeis);
    }
    if (sendSyncRequest(dtoTeis)) {
        List<String> teiUIDs = dtoTeis.stream().map(TrackedEntityInstance::getTrackedEntityInstance).collect(Collectors.toList());
        log.info("The lastSynchronized flag of these TEIs will be updated: " + teiUIDs);
        teiService.updateTrackedEntityInstancesSyncTimestamp(teiUIDs, new Date(clock.getStartTime()));
    } else {
        syncResult = false;
    }
}
Also used : TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Date(java.util.Date)

Example 20 with UPDATED

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

the class MetadataImportServiceTest method testImportSharingWithMergeModeReplace.

/**
 * 1. Create an object with UserGroupAccessA 2. Update object with only
 * UserGroupAccessB in payload and mergeMode=REPLACE Expected: updated
 * object will have only UserGroupAccessB
 *
 * @throws IOException
 */
@Test
void testImportSharingWithMergeModeReplace() throws IOException {
    User user = createUser("A", "ALL");
    manager.save(user);
    injectSecurityContext(user);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_accesses_skipSharing.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
    params.setUser(user);
    ImportReport report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    DataSet dataSet = manager.get(DataSet.class, "em8Bg4LCr5k");
    assertNotNull(dataSet.getSharing().getUserGroups());
    assertEquals(1, dataSet.getSharing().getUserGroups().size());
    metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_accesses_merge_mode.json").getInputStream(), RenderFormat.JSON);
    params = createParams(ImportStrategy.CREATE_AND_UPDATE, metadata);
    params.setMergeMode(MergeMode.REPLACE);
    params.setUser(user);
    report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    dataSet = manager.get(DataSet.class, "em8Bg4LCr5k");
    assertNotNull(dataSet.getSharing().getUserGroups());
    assertEquals(1, dataSet.getSharing().getUserGroups().size());
    assertNotNull(dataSet.getSharing().getUserGroups().get("FnJeHbPOtVF"));
}
Also used : User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)9 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)8 User (org.hisp.dhis.user.User)8 Test (org.junit.jupiter.api.Test)8 Date (java.util.Date)7 List (java.util.List)7 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)6 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)6 DataSet (org.hisp.dhis.dataset.DataSet)6 ClassPathResource (org.springframework.core.io.ClassPathResource)6 Event (org.hisp.dhis.dxf2.events.event.Event)5 ImportCount (org.hisp.dhis.dxf2.importsummary.ImportCount)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4 DataElement (org.hisp.dhis.dataelement.DataElement)3 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)3 Events (org.hisp.dhis.dxf2.events.event.Events)3 TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)3 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)3