Search in sources :

Example 1 with RecordVersion

use of org.activityinfo.store.spi.RecordVersion in project activityinfo by bedatadriven.

the class QueryVersions method run.

@Override
public List<RecordVersion> run() {
    Query<FormRecordSnapshotEntity> query;
    if (recordId != null) {
        Key<FormRecordEntity> recordKey = FormRecordEntity.key(formClass, recordId);
        query = ofy().load().type(FormRecordSnapshotEntity.class).ancestor(recordKey);
    } else {
        Key<FormEntity> rootKey = FormEntity.key(formClass);
        query = ofy().load().type(FormRecordSnapshotEntity.class).ancestor(rootKey).filter("parentRecordId", parentRecordId.asString());
    }
    List<RecordVersion> versions = new ArrayList<>();
    for (FormRecordSnapshotEntity snapshot : query.iterable()) {
        RecordVersion version = new RecordVersion();
        version.setRecordId(snapshot.getRecordId());
        version.setVersion(snapshot.getVersion());
        version.setUserId(snapshot.getUserId());
        version.setTime(snapshot.getTime().getTime());
        version.setType(snapshot.getType());
        if (formClass.isSubForm()) {
            version.setSubformKind(formClass.getSubFormKind());
            version.setSubformKey(subformKey(snapshot));
        }
        version.getValues().putAll(snapshot.getRecord().toFieldValueMap(formClass));
        versions.add(version);
    }
    return versions;
}
Also used : FormRecordSnapshotEntity(org.activityinfo.store.hrd.entity.FormRecordSnapshotEntity) RecordVersion(org.activityinfo.store.spi.RecordVersion) FormEntity(org.activityinfo.store.hrd.entity.FormEntity) FormRecordEntity(org.activityinfo.store.hrd.entity.FormRecordEntity) ArrayList(java.util.ArrayList)

Example 2 with RecordVersion

use of org.activityinfo.store.spi.RecordVersion in project activityinfo by bedatadriven.

the class SiteHistoryReader method read.

public List<RecordVersion> read() throws SQLException {
    String sql = "SELECT h.siteId, h.timecreated, h.initial, h.json, h.userId " + "FROM sitehistory h " + "WHERE siteid = " + siteId + " " + "ORDER BY h.timecreated";
    List<RecordVersion> changes = new ArrayList<>();
    try (ResultSet rs = executor.query(sql)) {
        while (rs.next()) {
            int siteId = rs.getInt(1);
            long time = rs.getLong(2);
            boolean initial = rs.getBoolean(3);
            String json = rs.getString(4);
            long userId = rs.getInt(5);
            RecordVersion change = new RecordVersion();
            change.setRecordId(CuidAdapter.cuid(CuidAdapter.SITE_DOMAIN, siteId));
            change.setTime(time);
            change.setUserId(userId);
            JsonValue jsonObject = (JsonValue) parser.parse(json);
            if (jsonObject.hasKey("_DELETE")) {
                change.setType(RecordChangeType.DELETED);
            } else {
                change.setType(initial ? RecordChangeType.CREATED : RecordChangeType.UPDATED);
                change.getValues().putAll(parseChanges(jsonObject));
            }
            changes.add(change);
        }
    }
    return changes;
}
Also used : RecordVersion(org.activityinfo.store.spi.RecordVersion) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) JsonValue(org.activityinfo.json.JsonValue)

Aggregations

ArrayList (java.util.ArrayList)2 RecordVersion (org.activityinfo.store.spi.RecordVersion)2 ResultSet (java.sql.ResultSet)1 JsonValue (org.activityinfo.json.JsonValue)1 FormEntity (org.activityinfo.store.hrd.entity.FormEntity)1 FormRecordEntity (org.activityinfo.store.hrd.entity.FormRecordEntity)1 FormRecordSnapshotEntity (org.activityinfo.store.hrd.entity.FormRecordSnapshotEntity)1