use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED 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.CREATED in project dhis2-core by dhis2.
the class EventDataValueRowCallbackHandler method getDataValue.
private List<DataValue> getDataValue(ResultSet rs) throws SQLException {
// TODO not sure this is the most efficient way to handle JSONB -> java
List<DataValue> dataValues = new ArrayList<>();
PGobject values = (PGobject) rs.getObject("eventdatavalues");
Map<String, ?> eventDataValuesJson = gson.fromJson(values.getValue(), Map.class);
for (String dataElementUid : eventDataValuesJson.keySet()) {
Map jsonValues = (Map) eventDataValuesJson.get(dataElementUid);
DataValue value = new DataValue(dataElementUid, (String) jsonValues.get("value"));
value.setCreated((String) jsonValues.get("created"));
value.setLastUpdated((String) jsonValues.get("lastUpdated"));
value.setStoredBy((String) jsonValues.get("storedBy"));
value.setProvidedElsewhere((Boolean) jsonValues.get("providedElsewhere"));
dataValues.add(value);
}
return dataValues;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED 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.CREATED in project dhis2-core by dhis2.
the class DefaultObjectBundleService method handleCreates.
// -----------------------------------------------------------------------------------
// Utility Methods
// -----------------------------------------------------------------------------------
private <T extends IdentifiableObject> TypeReport handleCreates(Session session, Class<T> klass, List<T> objects, ObjectBundle bundle) {
TypeReport typeReport = new TypeReport(klass);
handleDeprecationIfEventReport(klass, objects);
if (objects.isEmpty()) {
return typeReport;
}
String message = "(" + bundle.getUsername() + ") Creating " + objects.size() + " object(s) of type " + objects.get(0).getClass().getSimpleName();
log.info(message);
if (bundle.hasJobId()) {
notifier.notify(bundle.getJobId(), message);
}
objects.forEach(object -> objectBundleHooks.getObjectHooks(object).forEach(hook -> hook.preCreate(object, bundle)));
session.flush();
for (T object : objects) {
ObjectReport objectReport = new ObjectReport(object, bundle);
objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
typeReport.addObjectReport(objectReport);
preheatService.connectReferences(object, bundle.getPreheat(), bundle.getPreheatIdentifier());
if (bundle.getOverrideUser() != null) {
object.setCreatedBy(bundle.getOverrideUser());
if (object instanceof User) {
(object).setCreatedBy(bundle.getOverrideUser());
}
}
session.save(object);
bundle.getPreheat().replace(bundle.getPreheatIdentifier(), object);
if (log.isDebugEnabled()) {
String msg = "(" + bundle.getUsername() + ") Created object '" + bundle.getPreheatIdentifier().getIdentifiersWithName(object) + "'";
log.debug(msg);
}
if (FlushMode.OBJECT == bundle.getFlushMode()) {
session.flush();
}
}
session.flush();
objects.forEach(object -> objectBundleHooks.getObjectHooks(object).forEach(hook -> hook.postCreate(object, bundle)));
return typeReport;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.
the class MetadataSyncPreProcessor method handleMetadataVersionsList.
public List<MetadataVersion> handleMetadataVersionsList(MetadataRetryContext context, MetadataVersion metadataVersion) {
log.debug("Fetching the list of remote versions");
List<MetadataVersion> metadataVersionList;
try {
metadataVersionList = metadataVersionDelegate.getMetaDataDifference(metadataVersion);
if (metadataVersion == null) {
log.info("There is no initial version in the system");
}
if (isRemoteVersionEmpty(metadataVersion, metadataVersionList)) {
log.info("There are no metadata versions created in the remote instance.");
return metadataVersionList;
}
if (isUsingLatestVersion(metadataVersion, metadataVersionList)) {
log.info("Your instance is already using the latest version:" + metadataVersion);
return metadataVersionList;
}
MetadataVersion latestVersion = getLatestVersion(metadataVersionList);
assert latestVersion != null;
systemSettingManager.saveSystemSetting(SettingKey.REMOTE_METADATA_VERSION, latestVersion.getName());
log.info("Remote system is at version: " + latestVersion.getName());
} catch (MetadataVersionServiceException e) {
String message = setVersionListErrorInfoInContext(context, metadataVersion, e);
throw new MetadataSyncServiceException(message, e);
} catch (Exception ex) {
if (ex instanceof MetadataSyncServiceException) {
log.error(ex.getMessage(), ex);
throw ex;
}
String message = setVersionListErrorInfoInContext(context, metadataVersion, ex);
log.error(message, ex);
throw new MetadataSyncServiceException(message, ex);
}
return metadataVersionList;
}
Aggregations