use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class FixSubForm method maybeFixForm.
private boolean maybeFixForm(final PrintWriter logger, MySqlQueryExecutor executor, ResourceId parentFormId) {
logger.println("Fixing " + parentFormId + "...");
final MySqlStorageProvider catalog = new MySqlStorageProvider(executor);
FormStorage parentForm = catalog.getForm(parentFormId).get();
final FormClass formClass = parentForm.getFormClass();
logger.println("Loaded activity " + parentForm.getFormClass().getLabel());
final List<FormField> updated = new ArrayList<>();
ObjectifyService.run(new VoidWork() {
@Override
public void vrun() {
Hrd.ofy().transact(new VoidWork() {
@Override
public void vrun() {
for (FormField formField : formClass.getFields()) {
if (formField.getType() instanceof SubFormReferenceType) {
if (maybeFixForm(logger, formClass, formField)) {
updated.add(formField);
}
}
}
}
});
}
});
logger.println("TX COMPLETED!");
if (!updated.isEmpty()) {
logger.println("Updating parent form schema...");
catalog.createOrUpdateFormSchema(formClass);
return true;
} else {
return false;
}
}
use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class FormFolder method getChildren.
public List<CatalogEntry> getChildren(ResourceId formId) {
Optional<FormStorage> storage = catalog.getForm(formId);
if (!storage.isPresent()) {
return Collections.emptyList();
}
List<CatalogEntry> entries = new ArrayList<>();
FormClass formClass = storage.get().getFormClass();
for (FormField formField : formClass.getFields()) {
if (formField.getType() instanceof SubFormReferenceType) {
SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
ResourceId subFormId = subFormType.getClassId();
CatalogEntry catalogEntry = new CatalogEntry(subFormId.asString(), formField.getLabel(), CatalogEntryType.FORM);
catalogEntry.setLeaf(true);
entries.add(catalogEntry);
}
}
return entries;
}
use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class HrdStorageProvider method getForm.
@Override
public Optional<FormStorage> getForm(ResourceId formId) {
FormSchemaEntity schemaEntity = Hrd.ofy().load().key(FormSchemaEntity.key(formId)).now();
if (schemaEntity == null) {
return Optional.absent();
}
HrdFormStorage accessor = new HrdFormStorage(schemaEntity.readFormClass());
return Optional.<FormStorage>of(accessor);
}
use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class MySqlCatalogTest method singleSite.
@Test
public void singleSite() {
FormStorage siteStorage = catalog.getForm(CuidAdapter.activityFormClass(1)).get();
FormRecord siteRecord = siteStorage.get(CuidAdapter.cuid(CuidAdapter.SITE_DOMAIN, 1)).get();
FormInstance site = FormInstance.toFormInstance(siteStorage.getFormClass(), siteRecord);
EnumValue cause = (EnumValue) site.get(CuidAdapter.attributeGroupField(1));
EnumValue kitContents = (EnumValue) site.get(CuidAdapter.attributeGroupField(2));
assertThat(cause, nullValue());
assertThat(kitContents.getResourceIds(), contains(CuidAdapter.attributeId(3), CuidAdapter.attributeField(4)));
}
use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class MySqlUpdateTest method updateGeometry.
@Test
public void updateGeometry() throws SQLException {
userId = 3;
ResourceId formId = CuidAdapter.adminLevelFormClass(1);
ResourceId recordId = entity(1);
ResourceId fieldId = CuidAdapter.field(formId, CuidAdapter.GEOMETRY_FIELD);
Optional<FormStorage> storage = catalog.getForm(formId);
GeometryFactory factory = new GeometryFactory();
Polygon polygon = new Polygon(new LinearRing(new CoordinateArraySequence(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 0), new Coordinate(101, 1), new Coordinate(100, 1), new Coordinate(100, 0) }), factory), new LinearRing[0], factory);
storage.get().updateGeometry(recordId, fieldId, polygon);
query(formId, "_id", "ST_XMIN(boundary)", "ST_XMAX(boundary)");
}
Aggregations