Search in sources :

Example 6 with FormStorage

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;
    }
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormStorage(org.activityinfo.store.spi.FormStorage) VoidWork(com.googlecode.objectify.VoidWork) FormClass(org.activityinfo.model.form.FormClass) ArrayList(java.util.ArrayList) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider) FormField(org.activityinfo.model.form.FormField)

Example 7 with FormStorage

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;
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) CatalogEntry(org.activityinfo.model.form.CatalogEntry) ArrayList(java.util.ArrayList) FormField(org.activityinfo.model.form.FormField)

Example 8 with FormStorage

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);
}
Also used : FormStorage(org.activityinfo.store.spi.FormStorage) FormSchemaEntity(org.activityinfo.store.hrd.entity.FormSchemaEntity)

Example 9 with FormStorage

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)));
}
Also used : VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) FormStorage(org.activityinfo.store.spi.FormStorage) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) Test(org.junit.Test)

Example 10 with FormStorage

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)");
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) Coordinate(com.vividsolutions.jts.geom.Coordinate) Polygon(com.vividsolutions.jts.geom.Polygon) LinearRing(com.vividsolutions.jts.geom.LinearRing) CoordinateArraySequence(com.vividsolutions.jts.geom.impl.CoordinateArraySequence) 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