Search in sources :

Example 1 with FormStorage

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))));
}
Also used : VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) FormStorage(org.activityinfo.store.spi.FormStorage)

Example 2 with FormStorage

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));
}
Also used : JobResult(org.activityinfo.model.job.JobResult) Promise(org.activityinfo.promise.Promise) UserDatabaseMeta(org.activityinfo.model.database.UserDatabaseMeta) TestingStorageProvider(org.activityinfo.store.testing.TestingStorageProvider) FormRecordUpdateBuilder(org.activityinfo.api.client.FormRecordUpdateBuilder) org.activityinfo.model.form(org.activityinfo.model.form) ResourceId(org.activityinfo.model.resource.ResourceId) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) Analysis(org.activityinfo.model.analysis.Analysis) Optional(com.google.common.base.Optional) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) NullFormScanCache(org.activityinfo.store.query.shared.NullFormScanCache) RecordLockSet(org.activityinfo.model.database.RecordLockSet) NewFormRecordBuilder(org.activityinfo.api.client.NewFormRecordBuilder) ActivityInfoClientAsync(org.activityinfo.api.client.ActivityInfoClientAsync) JobStatus(org.activityinfo.model.job.JobStatus) AnalysisUpdate(org.activityinfo.model.analysis.AnalysisUpdate) FormStorage(org.activityinfo.store.spi.FormStorage) List(java.util.List) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) RecordTransaction(org.activityinfo.model.resource.RecordTransaction) JobDescriptor(org.activityinfo.model.job.JobDescriptor) Maybe(org.activityinfo.promise.Maybe) ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) FormTree(org.activityinfo.model.formTree.FormTree) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) FormStorage(org.activityinfo.store.spi.FormStorage) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage)

Example 3 with FormStorage

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);
}
Also used : ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) FormStorage(org.activityinfo.store.spi.FormStorage) File(java.io.File) IOException(java.io.IOException)

Example 4 with FormStorage

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;
}
Also used : VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) Operation(io.swagger.v3.oas.annotations.Operation)

Example 5 with FormStorage

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());
    }
}
Also used : FormRecordSnapshotEntity(org.activityinfo.store.hrd.entity.FormRecordSnapshotEntity) User(org.activityinfo.server.database.hibernate.entity.User) FormStorage(org.activityinfo.store.spi.FormStorage) FormClass(org.activityinfo.model.form.FormClass) FormEntity(org.activityinfo.store.hrd.entity.FormEntity) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

FormStorage (org.activityinfo.store.spi.FormStorage)25 ResourceId (org.activityinfo.model.resource.ResourceId)9 VersionedFormStorage (org.activityinfo.store.spi.VersionedFormStorage)9 Test (org.junit.Test)6 FormClass (org.activityinfo.model.form.FormClass)4 NotFoundException (com.sun.jersey.api.NotFoundException)3 FormField (org.activityinfo.model.form.FormField)3 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)3 HrdFormStorage (org.activityinfo.store.hrd.HrdFormStorage)3 FormStorageProvider (org.activityinfo.store.spi.FormStorageProvider)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 ParseException (com.vividsolutions.jts.io.ParseException)2 Operation (io.swagger.v3.oas.annotations.Operation)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 RecordLockSet (org.activityinfo.model.database.RecordLockSet)2 UserDatabaseMeta (org.activityinfo.model.database.UserDatabaseMeta)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 QueryModel (org.activityinfo.model.query.QueryModel)2 InvalidUpdateException (org.activityinfo.store.query.server.InvalidUpdateException)2