Search in sources :

Example 21 with FormStorage

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

the class MySqlCatalogTest method singlePartner.

@Test
public void singlePartner() {
    FormStorage form = catalog.getForm(CuidAdapter.partnerFormId(1)).get();
    Optional<FormRecord> partnerRecord = form.get(CuidAdapter.partnerRecordId(1));
}
Also used : VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) FormStorage(org.activityinfo.store.spi.FormStorage) Test(org.junit.Test)

Example 22 with FormStorage

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

the class MySqlCatalogTest method singleSiteWithBoundLocation.

@Test
public void singleSiteWithBoundLocation() {
    FormStorage siteStorage = catalog.getForm(CuidAdapter.activityFormClass(4)).get();
    FormRecord siteRecord = siteStorage.get(CuidAdapter.cuid(CuidAdapter.SITE_DOMAIN, 6)).get();
    FormInstance site = FormInstance.toFormInstance(siteStorage.getFormClass(), siteRecord);
    FieldValue location = site.get(CuidAdapter.locationField(4));
}
Also used : VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) FormStorage(org.activityinfo.store.spi.FormStorage) FieldValue(org.activityinfo.model.type.FieldValue) Test(org.junit.Test)

Example 23 with FormStorage

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

the class TargetFormProvider method openForms.

@Override
public Map<ResourceId, FormStorage> openForms(QueryExecutor executor, Set<ResourceId> formIds) throws SQLException {
    Set<Integer> targetIds = Sets.newHashSet();
    for (ResourceId resourceId : formIds) {
        if (accept(resourceId)) {
            targetIds.add(CuidAdapter.getLegacyIdFromCuid(resourceId));
        }
    }
    Map<ResourceId, FormStorage> collectionMap = Maps.newHashMap();
    if (!targetIds.isEmpty()) {
        Map<Integer, DatabaseTargetForm> targetMap = Maps.newHashMap();
        try (ResultSet rs = executor.query("SELECT " + "D.DatabaseId, " + "D.Name, " + "I.IndicatorId, " + "I.Name, " + "I.Units, " + "A.schemaVersion " + " FROM userdatabase D " + " LEFT JOIN activity A ON (D.DatabaseId = A.DatabaseId and A.dateDeleted IS NULL) " + " LEFT JOIN indicator I ON (A.ActivityId=I.ActivityId and I.dateDeleted IS NULL and I.type = 'QUANTITY') " + " WHERE D.databaseID IN (" + Joiner.on(',').join(targetIds) + ")")) {
            while (rs.next()) {
                int databaseId = rs.getInt(1);
                DatabaseTargetForm target = targetMap.get(databaseId);
                if (target == null) {
                    target = new DatabaseTargetForm(databaseId, rs.getString(2), rs.getLong(6));
                    targetMap.put(databaseId, target);
                }
                int indicatorId = rs.getInt(3);
                if (!rs.wasNull()) {
                    target.addIndicator(indicatorId, rs.getString(4), rs.getString(5));
                }
            }
        }
        for (DatabaseTargetForm target : targetMap.values()) {
            collectionMap.put(target.getFormClassId(), new TargetFormStorage(executor, target));
        }
    }
    return collectionMap;
}
Also used : FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) ResultSet(java.sql.ResultSet) DatabaseTargetForm(org.activityinfo.store.mysql.metadata.DatabaseTargetForm)

Example 24 with FormStorage

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

the class TargetFormProvider method openForm.

@Override
public FormStorage openForm(QueryExecutor executor, ResourceId formId) throws SQLException {
    Map<ResourceId, FormStorage> result = openForms(executor, Collections.singleton(formId));
    FormStorage collection = result.get(formId);
    if (collection == null) {
        throw new IllegalArgumentException("no such target collection: " + formId);
    }
    return collection;
}
Also used : FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId)

Example 25 with FormStorage

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

the class FormSourceSyncImpl method getFormMetadata.

public FormMetadata getFormMetadata(ResourceId formId) {
    Optional<FormStorage> storage = formCatalog.getForm(formId);
    if (!storage.isPresent()) {
        return FormMetadata.notFound(formId);
    }
    FormPermissions permissions = storage.get().getPermissions(userId);
    if (!permissions.isVisible()) {
        return FormMetadata.forbidden(formId);
    }
    return FormMetadata.of(storage.get().cacheVersion(), storage.get().getFormClass(), permissions);
}
Also used : FormPermissions(org.activityinfo.model.form.FormPermissions) FormStorage(org.activityinfo.store.spi.FormStorage)

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