use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UPDATED in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testUpdateImmutableCreatedByField.
@Test
void testUpdateImmutableCreatedByField() throws IOException {
User userA = createUser('A', Lists.newArrayList("ALL"));
userService.addUser(userA);
injectSecurityContext(userA);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/usergroups.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
params.setUser(userA);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
UserGroup userGroup = manager.get(UserGroup.class, "OPVIvvXzNTw");
assertEquals(userA.getUid(), userGroup.getCreatedBy().getUid());
User userB = createUser("B", "ALL");
userB.setUid("userabcdefB");
userService.addUser(userB);
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/usergroups_update.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setUser(userA);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
userGroup = manager.get(UserGroup.class, "OPVIvvXzNTw");
assertEquals("TA user group updated", userGroup.getName());
assertEquals(userA.getUid(), userGroup.getCreatedBy().getUid());
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UPDATED in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testUpdateUserGroupWithoutCreatedUserProperty.
@Test
void testUpdateUserGroupWithoutCreatedUserProperty() throws IOException {
User userA = createUser('A', Lists.newArrayList("ALL"));
userService.addUser(userA);
injectSecurityContext(userA);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/usergroups.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
params.setUser(userA);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
UserGroup userGroup = manager.get(UserGroup.class, "OPVIvvXzNTw");
assertEquals(userA.getUid(), userGroup.getSharing().getOwner());
User userB = createUser("B", "ALL");
userService.addUser(userB);
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/usergroups_update.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setUser(userB);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
userGroup = manager.get(UserGroup.class, "OPVIvvXzNTw");
assertEquals("TA user group updated", userGroup.getName());
assertEquals(userA.getUid(), userGroup.getSharing().getOwner());
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UPDATED in project dhis2-core by dhis2.
the class EventBaseCheckTest method verifyErrorOnInvalidLastUpdatedAtClientDate.
@Test
void verifyErrorOnInvalidLastUpdatedAtClientDate() {
event.setEvent(event.getUid());
event.setLastUpdatedAtClient("111-12-122");
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(importSummary, event, null);
assertHasConflict(importSummary, event, "Invalid event last updated at client date: " + event.getLastUpdatedAtClient());
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UPDATED in project dhis2-core by dhis2.
the class EventSynchronization method synchronizePage.
protected void synchronizePage(int page, int pageSize) {
Events events = eventService.getAnonymousEventsForSync(pageSize, skipChangedBefore, psdesWithSkipSyncTrue);
filterOutDataValuesMarkedWithSkipSynchronizationFlag(events);
log.info(String.format("Synchronizing page %d with page size %d", page, pageSize));
if (log.isDebugEnabled()) {
log.debug("Events that are going to be synchronized are: " + events);
}
if (sendSyncRequest(events)) {
List<String> eventsUIDs = events.getEvents().stream().map(Event::getEvent).collect(Collectors.toList());
log.info("The lastSynchronized flag of these Events will be updated: " + eventsUIDs);
eventService.updateEventsSyncTimestamp(eventsUIDs, 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 EventController method postJsonEventForNote.
@RequestMapping(value = "/{uid}/note", method = RequestMethod.POST, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void postJsonEventForNote(@PathVariable("uid") String uid, HttpServletResponse response, HttpServletRequest request, ImportOptions importOptions) throws IOException, WebMessageException {
if (!programStageInstanceService.programStageInstanceExists(uid)) {
throw new WebMessageException(WebMessageUtils.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);
webMessageService.send(WebMessageUtils.ok("Event updated: " + uid), response, request);
}
Aggregations