Search in sources :

Example 21 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 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());
}
Also used : User(org.hisp.dhis.user.User) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) UserGroup(org.hisp.dhis.user.UserGroup) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 22 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 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());
}
Also used : User(org.hisp.dhis.user.User) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) UserGroup(org.hisp.dhis.user.UserGroup) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 23 with UPDATED

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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Example 24 with UPDATED

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;
    }
}
Also used : Events(org.hisp.dhis.dxf2.events.event.Events) Date(java.util.Date)

Example 25 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.

@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);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InputStream(java.io.InputStream) Event(org.hisp.dhis.dxf2.events.event.Event) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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