Search in sources :

Example 26 with UPDATED

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

the class EnrollmentRowCallbackHandler method getEnrollment.

private Enrollment getEnrollment(ResultSet rs) throws SQLException {
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(rs.getString(getColumnName(UID)));
    MapperGeoUtils.resolveGeometry(rs.getBytes(getColumnName(GEOMETRY))).ifPresent(enrollment::setGeometry);
    enrollment.setTrackedEntityType(rs.getString(getColumnName(TEI_TYPE_UID)));
    enrollment.setTrackedEntityInstance(rs.getString(getColumnName(TEI_UID)));
    enrollment.setOrgUnit(rs.getString(getColumnName(ORGUNIT_UID)));
    enrollment.setOrgUnitName(rs.getString(getColumnName(ORGUNIT_NAME)));
    enrollment.setCreated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATED))));
    enrollment.setCreatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(CREATED_BY), enrollment::setCreatedByUserInfo);
    enrollment.setLastUpdated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATED))));
    enrollment.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(LAST_UPDATED_BY), enrollment::setLastUpdatedByUserInfo);
    enrollment.setProgram(rs.getString(getColumnName(PROGRAM_UID)));
    enrollment.setStatus(EnrollmentStatus.fromStatusString(rs.getString(getColumnName(STATUS))));
    enrollment.setEnrollmentDate(rs.getTimestamp(getColumnName(ENROLLMENTDATE)));
    enrollment.setIncidentDate(rs.getTimestamp(getColumnName(INCIDENTDATE)));
    final boolean followup = rs.getBoolean(getColumnName(FOLLOWUP));
    enrollment.setFollowup(rs.wasNull() ? null : followup);
    enrollment.setCompletedDate(rs.getTimestamp(getColumnName(COMPLETED)));
    enrollment.setCompletedBy(rs.getString(getColumnName(COMPLETEDBY)));
    enrollment.setStoredBy(rs.getString(getColumnName(STOREDBY)));
    enrollment.setDeleted(rs.getBoolean(getColumnName(DELETED)));
    enrollment.setId(rs.getLong(getColumnName(ID)));
    return enrollment;
}
Also used : Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment)

Example 27 with UPDATED

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

the class TrackedEntityInstanceRowCallbackHandler method getTei.

private TrackedEntityInstance getTei(ResultSet rs) throws SQLException {
    TrackedEntityInstance tei = new TrackedEntityInstance();
    tei.setTrackedEntityInstance(rs.getString(getColumnName(UID)));
    tei.setOrgUnit(rs.getString(getColumnName(ORGUNIT_UID)));
    tei.setTrackedEntityType(rs.getString(getColumnName(TYPE_UID)));
    tei.setCreated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATED))));
    tei.setCreatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(CREATED_BY), tei::setCreatedByUserInfo);
    tei.setLastUpdated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATED))));
    tei.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(LAST_UPDATED_BY), tei::setLastUpdatedByUserInfo);
    tei.setInactive(rs.getBoolean(getColumnName(INACTIVE)));
    tei.setDeleted(rs.getBoolean(getColumnName(DELETED)));
    Optional<Geometry> geo = MapperGeoUtils.resolveGeometry(rs.getBytes(getColumnName(GEOMETRY)));
    if (geo.isPresent()) {
        tei.setGeometry(geo.get());
        tei.setFeatureType(FeatureType.getTypeFromName(geo.get().getGeometryType()));
        tei.setCoordinates(GeoUtils.getCoordinatesFromGeometry(geo.get()));
    }
    return tei;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)

Example 28 with UPDATED

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

the class TrackedEntityAttributeRowCallbackHandler method getAttribute.

private Attribute getAttribute(ResultSet rs) throws SQLException {
    Attribute attribute = new Attribute();
    attribute.setCreated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATED))));
    attribute.setLastUpdated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATED))));
    attribute.setDisplayName(rs.getString(getColumnName(ATTR_NAME)));
    attribute.setAttribute(rs.getString(getColumnName(ATTR_UID)));
    attribute.setValueType(ValueType.fromString(rs.getString(getColumnName(ATTR_VALUE_TYPE))));
    attribute.setCode(rs.getString(getColumnName(ATTR_CODE)));
    attribute.setValue(rs.getString(getColumnName(VALUE)));
    attribute.setStoredBy(rs.getString(getColumnName(STOREDBY)));
    attribute.setSkipSynchronization(rs.getBoolean(getColumnName(ATTR_SKIP_SYNC)));
    return attribute;
}
Also used : Attribute(org.hisp.dhis.dxf2.events.trackedentity.Attribute)

Example 29 with UPDATED

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

the class DefaultSynchronizationManager method executeDataValuePush.

/**
 * Executes a push of data values to the given remote instance.
 *
 * @param instance the remote system instance.
 * @return an ImportSummary.
 */
private ImportConflicts executeDataValuePush(SystemInstance instance) throws WebMessageParseException {
    // ---------------------------------------------------------------------
    // Set time for last success to start of process to make data saved
    // subsequently part of next synch process without being ignored
    // ---------------------------------------------------------------------
    final Date startTime = new Date();
    final Date lastSuccessTime = SyncUtils.getLastSyncSuccess(systemSettingManager, SettingKey.LAST_SUCCESSFUL_DATA_VALUE_SYNC);
    final Date skipChangedBefore = systemSettingManager.getDateSetting(SettingKey.SKIP_SYNCHRONIZATION_FOR_DATA_CHANGED_BEFORE);
    final Date lastUpdatedAfter = lastSuccessTime.after(skipChangedBefore) ? lastSuccessTime : skipChangedBefore;
    final int objectsToSynchronize = dataValueService.getDataValueCountLastUpdatedAfter(lastUpdatedAfter, true);
    log.info("DataValues last changed before " + skipChangedBefore + " will not be synchronized.");
    if (objectsToSynchronize == 0) {
        SyncUtils.setLastSyncSuccess(systemSettingManager, SettingKey.LAST_SUCCESSFUL_DATA_VALUE_SYNC, startTime);
        log.debug("Skipping data values push, no new or updated data values");
        ImportCount importCount = new ImportCount(0, 0, 0, 0);
        return new ImportSummary(ImportStatus.SUCCESS, "No new or updated data values to push.", importCount);
    }
    log.info("Data Values: " + objectsToSynchronize + " to push since last synchronization success: " + lastSuccessTime);
    log.info("Remote server POST URL: " + instance.getUrl());
    final RequestCallback requestCallback = request -> {
        request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
        request.getHeaders().add(HEADER_AUTHORIZATION, CodecUtils.getBasicAuthString(instance.getUsername(), instance.getPassword()));
        dataValueSetService.exportDataValueSetJson(lastUpdatedAfter, request.getBody(), new IdSchemes());
    };
    final int maxSyncAttempts = systemSettingManager.getIntSetting(SettingKey.MAX_SYNC_ATTEMPTS);
    Optional<AbstractWebMessageResponse> responseSummary = SyncUtils.runSyncRequest(restTemplate, requestCallback, SyncEndpoint.DATA_VALUE_SETS.getKlass(), instance.getUrl(), maxSyncAttempts);
    ImportSummary summary = null;
    if (responseSummary.isPresent()) {
        summary = (ImportSummary) responseSummary.get();
        if (ImportStatus.SUCCESS.equals(summary.getStatus())) {
            log.info("Push successful: " + summary);
        } else {
            log.warn("Push failed: " + summary);
        }
    }
    return summary;
}
Also used : AtomicMode(org.hisp.dhis.dxf2.metadata.AtomicMode) WebMessageParseException(org.hisp.dhis.dxf2.webmessage.WebMessageParseException) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Date(java.util.Date) ImportCount(org.hisp.dhis.dxf2.importsummary.ImportCount) SyncEndpoint(org.hisp.dhis.dxf2.sync.SyncEndpoint) DataValueService(org.hisp.dhis.datavalue.DataValueService) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Metadata(org.hisp.dhis.dxf2.metadata.Metadata) ImportConflicts(org.hisp.dhis.dxf2.importsummary.ImportConflicts) MetadataImportService(org.hisp.dhis.dxf2.metadata.MetadataImportService) AbstractWebMessageResponse(org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse) User(org.hisp.dhis.user.User) SyncUtils(org.hisp.dhis.dxf2.sync.SyncUtils) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) RestTemplate(org.springframework.web.client.RestTemplate) IdSchemes(org.hisp.dhis.common.IdSchemes) DataValueSetService(org.hisp.dhis.dxf2.datavalueset.DataValueSetService) MediaType(org.springframework.http.MediaType) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) SchemaService(org.hisp.dhis.schema.SchemaService) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) RequestCallback(org.springframework.web.client.RequestCallback) CodecUtils(org.hisp.dhis.system.util.CodecUtils) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Optional(java.util.Optional) SettingKey(org.hisp.dhis.setting.SettingKey) RequestCallback(org.springframework.web.client.RequestCallback) IdSchemes(org.hisp.dhis.common.IdSchemes) AbstractWebMessageResponse(org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse) ImportCount(org.hisp.dhis.dxf2.importsummary.ImportCount) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Date(java.util.Date) SyncEndpoint(org.hisp.dhis.dxf2.sync.SyncEndpoint)

Example 30 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 testUpdateWithSkipTranslationIsFalse.

/**
 * 1. Create object with 2 translations 2. Update object with empty
 * translations and skipTranslation = false Expected: updated object has
 * empty translations
 */
@Test
void testUpdateWithSkipTranslationIsFalse() 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.setSkipTranslation(false);
    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(2, dataSet.getTranslations().size());
    metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_accesses_update_skipSharing.json").getInputStream(), RenderFormat.JSON);
    params = createParams(ImportStrategy.UPDATE, metadata);
    params.setSkipTranslation(false);
    params.setUser(user);
    report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    dataSet = manager.get(DataSet.class, "em8Bg4LCr5k");
    assertNotNull(dataSet.getSharing().getUserGroups());
    assertEquals(0, dataSet.getTranslations().size());
}
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