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