Search in sources :

Example 16 with FormStorage

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

the class ActivityFormProvider method openForms.

@Override
public Map<ResourceId, FormStorage> openForms(QueryExecutor executor, Set<ResourceId> formIds) throws SQLException {
    Set<Integer> activityIds = new HashSet<>();
    for (ResourceId collectionId : formIds) {
        if (accept(collectionId)) {
            activityIds.add(CuidAdapter.getLegacyIdFromCuid(collectionId));
        }
    }
    if (activityIds.isEmpty()) {
        return Collections.emptyMap();
    } else {
        Map<Integer, Activity> activityMap = activityLoader.load(activityIds);
        Map<ResourceId, FormStorage> collectionMap = new HashMap<>();
        for (ResourceId collectionId : formIds) {
            if (accept(collectionId)) {
                Activity activity = activityMap.get(CuidAdapter.getLegacyIdFromCuid(collectionId));
                if (activity != null) {
                    collectionMap.put(collectionId, new SiteFormStorage(activity, buildMapping(activity, collectionId), executor, activityLoader.getPermissionCache()));
                }
            }
        }
        return collectionMap;
    }
}
Also used : FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) Activity(org.activityinfo.store.mysql.metadata.Activity)

Example 17 with FormStorage

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

the class ActivityInfoClientAsyncStub method updateFormSchema.

@Override
public Promise<Void> updateFormSchema(String formId, FormClass updatedSchema) {
    FormStorageProvider catalog = newCatalog();
    try {
        EntityTransaction tx = entityManager.get().getTransaction();
        tx.begin();
        Optional<FormStorage> collection = catalog.getForm(updatedSchema.getId());
        if (collection.isPresent()) {
            collection.get().updateFormClass(updatedSchema);
        } else {
            ((MySqlStorageProvider) catalog).createOrUpdateFormSchema(updatedSchema);
        }
        tx.commit();
        return Promise.resolved(null);
    } catch (Exception e) {
        return Promise.rejected(e);
    }
}
Also used : FormStorageProvider(org.activityinfo.store.spi.FormStorageProvider) EntityTransaction(javax.persistence.EntityTransaction) FormStorage(org.activityinfo.store.spi.FormStorage) HrdFormStorage(org.activityinfo.store.hrd.HrdFormStorage) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider)

Example 18 with FormStorage

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

the class ActivityInfoClientAsyncStub method getRecords.

@Override
public Promise<FormRecordSet> getRecords(String formId, String parentId) {
    FormStorageProvider catalog = newCatalog();
    Optional<FormStorage> collection = catalog.getForm(ResourceId.valueOf(formId));
    JsonValue recordArray = Json.createArray();
    if (collection.isPresent()) {
        if (collection.get() instanceof HrdFormStorage) {
            HrdFormStorage hrdForm = (HrdFormStorage) collection.get();
            Iterable<FormRecord> records = hrdForm.getSubRecords(ResourceId.valueOf(parentId));
            for (FormRecord record : records) {
                recordArray.add(record.toJson());
            }
        }
    }
    JsonValue object = createObject();
    object.put("formId", formId);
    object.put("records", recordArray);
    return Promise.resolved(FormRecordSet.fromJson(object));
}
Also used : FormStorageProvider(org.activityinfo.store.spi.FormStorageProvider) FormStorage(org.activityinfo.store.spi.FormStorage) HrdFormStorage(org.activityinfo.store.hrd.HrdFormStorage) JsonValue(org.activityinfo.json.JsonValue) HrdFormStorage(org.activityinfo.store.hrd.HrdFormStorage)

Example 19 with FormStorage

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

the class ActivityInfoClientAsyncStub method getRecord.

@Override
public Promise<Maybe<FormRecord>> getRecord(String formId, String recordId) {
    try {
        FormStorageProvider catalog = newCatalog();
        Optional<FormStorage> storage = catalog.getForm(ResourceId.valueOf(formId));
        if (!storage.isPresent()) {
            return Promise.resolved(Maybe.<FormRecord>notFound());
        }
        Optional<FormRecord> record = storage.get().get(ResourceId.valueOf(recordId));
        if (!record.isPresent()) {
            return Promise.resolved(Maybe.<FormRecord>notFound());
        }
        return Promise.resolved(Maybe.of(record.get()));
    } catch (Exception e) {
        return Promise.rejected(e);
    }
}
Also used : FormStorageProvider(org.activityinfo.store.spi.FormStorageProvider) FormStorage(org.activityinfo.store.spi.FormStorage) HrdFormStorage(org.activityinfo.store.hrd.HrdFormStorage)

Example 20 with FormStorage

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

the class MySqlUpdateTest method updateLocation.

@Test
public void updateLocation() throws SQLException {
    ResourceId recordId = CuidAdapter.cuid(LOCATION_DOMAIN, 1);
    ResourceId formId = CuidAdapter.locationFormClass(1);
    RecordUpdate update = new RecordUpdate();
    update.setFormId(formId);
    update.setRecordId(recordId);
    update.setFieldValue(CuidAdapter.field(formId, CuidAdapter.NAME_FIELD), TextValue.valueOf("New Name"));
    Updater updater = updater();
    updater.executeChange(update);
    newRequest();
    FormStorage formStorage = catalog.getForm(formId).get();
    FormRecord record = formStorage.get(recordId).get();
    FormInstance typedRecord = FormInstance.toFormInstance(formStorage.getFormClass(), record);
    GeoPoint point = (GeoPoint) typedRecord.get(CuidAdapter.field(formId, CuidAdapter.GEOMETRY_FIELD));
    assertThat(point, not(nullValue()));
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) RecordUpdate(org.activityinfo.model.resource.RecordUpdate) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) Updater(org.activityinfo.store.query.server.Updater) FormRecord(org.activityinfo.model.form.FormRecord) FormInstance(org.activityinfo.model.form.FormInstance) Test(org.junit.Test)

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