Search in sources :

Example 1 with FormStorageProvider

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

the class ActivityInfoClientAsyncStub method updateRecord.

@Override
public Promise<Void> updateRecord(String formId, String recordId, FormRecordUpdateBuilder query) {
    try {
        FormStorageProvider catalog = newCatalog();
        Updater updater = new Updater(catalog, currentUserId(), blobAuthorizer, new SerialNumberProviderStub());
        updater.execute(ResourceId.valueOf(formId), ResourceId.valueOf(recordId), query.toJsonObject());
        return Promise.resolved(null);
    } catch (Exception e) {
        return Promise.rejected(e);
    }
}
Also used : FormStorageProvider(org.activityinfo.store.spi.FormStorageProvider) Updater(org.activityinfo.store.query.server.Updater)

Example 2 with FormStorageProvider

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

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

the class ActivityInfoClientAsyncStub method createRecord.

@Override
public Promise<Void> createRecord(String formId, NewFormRecordBuilder query) {
    try {
        FormStorageProvider catalog = newCatalog();
        Updater updater = new Updater(catalog, currentUserId(), blobAuthorizer, new SerialNumberProviderStub());
        updater.create(ResourceId.valueOf(formId), query.toJsonObject());
        return Promise.resolved(null);
    } catch (Exception e) {
        return Promise.rejected(e);
    }
}
Also used : FormStorageProvider(org.activityinfo.store.spi.FormStorageProvider) Updater(org.activityinfo.store.query.server.Updater)

Example 4 with FormStorageProvider

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

the class ActivityInfoClientAsyncStub method queryTableColumns.

@Override
public Promise<ColumnSet> queryTableColumns(QueryModel query) {
    try {
        FormStorageProvider catalog = newCatalog();
        ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormSupervisor());
        return Promise.resolved(builder.build(query));
    } catch (Exception e) {
        return Promise.rejected(e);
    }
}
Also used : FormStorageProvider(org.activityinfo.store.spi.FormStorageProvider) ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor)

Example 5 with FormStorageProvider

use of org.activityinfo.store.spi.FormStorageProvider 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)

Aggregations

FormStorageProvider (org.activityinfo.store.spi.FormStorageProvider)8 HrdFormStorage (org.activityinfo.store.hrd.HrdFormStorage)3 FormStorage (org.activityinfo.store.spi.FormStorage)3 Updater (org.activityinfo.store.query.server.Updater)2 EntityTransaction (javax.persistence.EntityTransaction)1 JsonValue (org.activityinfo.json.JsonValue)1 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)1 MySqlStorageProvider (org.activityinfo.store.mysql.MySqlStorageProvider)1 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)1 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)1