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;
}
}
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);
}
}
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));
}
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);
}
}
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()));
}
Aggregations