Search in sources :

Example 31 with CREATED

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;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)

Example 32 with CREATED

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;
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) PGobject(org.postgresql.util.PGobject)

Example 33 with CREATED

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;
}
Also used : Attribute(org.hisp.dhis.dxf2.events.trackedentity.Attribute)

Example 34 with CREATED

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;
}
Also used : HibernateCacheManager(org.hisp.dhis.cache.HibernateCacheManager) PreheatService(org.hisp.dhis.preheat.PreheatService) IdentifiableObjectUtils(org.hisp.dhis.common.IdentifiableObjectUtils) EventReportCompatibilityGuard.handleDeprecationIfEventReport(org.hisp.dhis.dxf2.metadata.objectbundle.EventReportCompatibilityGuard.handleDeprecationIfEventReport) MergeService(org.hisp.dhis.schema.MergeService) Session(org.hibernate.Session) Preheat(org.hisp.dhis.preheat.Preheat) HashMap(java.util.HashMap) MergeParams(org.hisp.dhis.schema.MergeParams) FlushMode(org.hisp.dhis.dxf2.metadata.FlushMode) TypeReport(org.hisp.dhis.feedback.TypeReport) Notifier(org.hisp.dhis.system.notification.Notifier) ObjectBundleCommitReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) DbmsManager(org.hisp.dhis.dbms.DbmsManager) Service(org.springframework.stereotype.Service) Map(java.util.Map) User(org.hisp.dhis.user.User) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) SessionFactory(org.hibernate.SessionFactory) SchemaService(org.hisp.dhis.schema.SchemaService) MergeMode(org.hisp.dhis.common.MergeMode) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) PreheatParams(org.hisp.dhis.preheat.PreheatParams) CurrentUserService(org.hisp.dhis.user.CurrentUserService) AllArgsConstructor(lombok.AllArgsConstructor) Transactional(org.springframework.transaction.annotation.Transactional) User(org.hisp.dhis.user.User) TypeReport(org.hisp.dhis.feedback.TypeReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport)

Example 35 with CREATED

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;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)12 Test (org.junit.jupiter.api.Test)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ArrayList (java.util.ArrayList)8 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)7 Date (java.util.Date)6 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)6 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)6 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)6 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)6 HttpUtils (org.hisp.dhis.system.util.HttpUtils)6 User (org.hisp.dhis.user.User)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 List (java.util.List)5 Map (java.util.Map)5 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)4 Event (org.hisp.dhis.dxf2.events.event.Event)4 HashMap (java.util.HashMap)3