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