use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class AsyncClientStub method getRecords.
@Override
public Promise<FormRecordSet> getRecords(String formId, String parentId) {
if (!connected) {
return offlineResult();
}
Optional<FormStorage> form = storageProvider.getForm(ResourceId.valueOf(formId));
if (!form.isPresent()) {
return Promise.rejected(new RuntimeException("No such form"));
}
FormStorage formStorage = form.get();
return Promise.resolved(new FormRecordSet(form.get().getFormClass().getId(), formStorage.getSubRecords(ResourceId.valueOf(parentId))));
}
use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class AsyncClientStub method getRecordVersionRange.
@Override
public Promise<FormSyncSet> getRecordVersionRange(String formId, long localVersion, long toVersion) {
if (!connected) {
return offlineResult();
}
Optional<FormStorage> form = storageProvider.getForm(ResourceId.valueOf(formId));
if (!form.isPresent()) {
return Promise.rejected(new RuntimeException("No such form"));
}
VersionedFormStorage formStorage = (VersionedFormStorage) form.get();
return Promise.resolved(formStorage.getVersionRange(localVersion, toVersion, resourceId -> true));
}
use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class FeatureSourceStorageProvider method getForm.
@Override
public Optional<FormStorage> getForm(ResourceId formId) {
FeatureSourceStorage accessor = sources.get(formId);
if (accessor == null) {
Preconditions.checkArgument(formId.asString().startsWith(FILE_PREFIX), "FeatureSourceCatalog supports only resourceIds starting with file://");
try {
File shapeFile = new File(formId.asString().substring(FILE_PREFIX.length()));
ShapefileDataStore dataStore = new ShapefileDataStore(shapeFile.toURI().toURL());
accessor = new FeatureSourceStorage(formId, dataStore.getFeatureSource());
sources.put(formId, accessor);
} catch (Exception e) {
throw new IllegalArgumentException("Could not load " + formId, e);
}
}
return Optional.<FormStorage>of(accessor);
}
use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class FormResource method getVersionRange.
@GET
@NoCache
@Path("records/versionRange")
@Operation(summary = "Get the records that have changed between two versions of this form")
public FormSyncSet getVersionRange(@QueryParam("localVersion") long localVersion, @QueryParam("version") long version) {
FormStorage collection = assertVisible(formId);
// Compute a predicate that will tell us whether a given
// record should be visible to the user, based on their *current* permissions.
java.util.function.Predicate<ResourceId> visibilityPredicate = computeVisibilityPredicate();
FormSyncSet syncSet;
if (collection instanceof VersionedFormStorage) {
syncSet = ((VersionedFormStorage) collection).getVersionRange(localVersion, version, visibilityPredicate);
} else {
syncSet = FormSyncSet.emptySet(formId);
}
return syncSet;
}
use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class AuditLogWriter method writeForm.
public void writeForm(FormStorageProvider catalog, ResourceId formId) throws IOException {
FormStorage formStorage = catalog.getForm(formId).get();
FormClass formClass = formStorage.getFormClass();
Key<FormEntity> parentKey = FormEntity.key(formId);
Query<FormRecordSnapshotEntity> query = Hrd.ofy().load().type(FormRecordSnapshotEntity.class).ancestor(parentKey);
for (FormRecordSnapshotEntity snapshot : query) {
User user;
try {
user = userCache.get((int) snapshot.getUserId());
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
csv.writeLine(formatTime(snapshot.getTime()), snapshot.getType().name(), user.getEmail(), user.getName(), databaseId(), db.getName(), formId.asString(), formClass.getLabel(), // Field ID
"", // Field Name
"", snapshot.getRecordId().asString(), partner());
}
}
Aggregations