Search in sources :

Example 1 with VersionedFormStorage

use of org.activityinfo.store.spi.VersionedFormStorage 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 2 with VersionedFormStorage

use of org.activityinfo.store.spi.VersionedFormStorage 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 3 with VersionedFormStorage

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

the class MySqlCatalogTest method partnerVersionRange.

@Test
public void partnerVersionRange() {
    ResourceId partnerFormId = CuidAdapter.partnerFormId(1);
    VersionedFormStorage form = (VersionedFormStorage) catalog.getForm(partnerFormId).get();
    System.out.println("version = " + form.cacheVersion());
    assertThat(form.cacheVersion(), greaterThan(0L));
    FormSyncSet versionRange = form.getVersionRange(0, form.cacheVersion(), resourceId -> true);
    assertThat(versionRange.getUpdatedRecordCount(), equalTo(3));
    System.out.println(versionRange);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) Test(org.junit.Test)

Aggregations

ResourceId (org.activityinfo.model.resource.ResourceId)3 VersionedFormStorage (org.activityinfo.store.spi.VersionedFormStorage)3 FormStorage (org.activityinfo.store.spi.FormStorage)2 Optional (com.google.common.base.Optional)1 Operation (io.swagger.v3.oas.annotations.Operation)1 List (java.util.List)1 ActivityInfoClientAsync (org.activityinfo.api.client.ActivityInfoClientAsync)1 FormRecordUpdateBuilder (org.activityinfo.api.client.FormRecordUpdateBuilder)1 NewFormRecordBuilder (org.activityinfo.api.client.NewFormRecordBuilder)1 Analysis (org.activityinfo.model.analysis.Analysis)1 AnalysisUpdate (org.activityinfo.model.analysis.AnalysisUpdate)1 RecordLockSet (org.activityinfo.model.database.RecordLockSet)1 UserDatabaseMeta (org.activityinfo.model.database.UserDatabaseMeta)1 org.activityinfo.model.form (org.activityinfo.model.form)1 FormTree (org.activityinfo.model.formTree.FormTree)1 JobDescriptor (org.activityinfo.model.job.JobDescriptor)1 JobResult (org.activityinfo.model.job.JobResult)1 JobStatus (org.activityinfo.model.job.JobStatus)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 QueryModel (org.activityinfo.model.query.QueryModel)1