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