Search in sources :

Example 51 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class MySqlCatalogIntegrationTest method testActivity.

@Test
public void testActivity() throws IOException {
    QueryModel model = new QueryModel(activityFormClass(33));
    model.selectField("date1");
    model.selectField("date2");
    model.selectExpr("Partner.name");
    FormTree formTree = new FormTreeBuilder(catalog).queryTree(activityFormClass(33));
    FormTreePrettyPrinter.print(formTree);
    FormClass formClass = catalog.getForm(activityFormClass(33)).get().getFormClass();
    for (FormField field : formClass.getFields()) {
        if (field.getType() instanceof QuantityType) {
            model.selectField(field.getId()).as("I" + CuidAdapter.getLegacyIdFromCuid(field.getId()));
        }
    }
    Stopwatch stopwatch = Stopwatch.createStarted();
    ColumnSet columnSet = columnSetBuilder.build(model);
    System.out.println("Query executed in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
    assertThat(columnSet.getNumRows(), equalTo(652));
    StringWriter stringWriter = new StringWriter();
    RowBasedJsonWriter writer = new RowBasedJsonWriter(stringWriter);
    writer.write(columnSet);
    System.out.println(stringWriter.toString());
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) StringWriter(java.io.StringWriter) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) Stopwatch(com.google.common.base.Stopwatch) ColumnSet(org.activityinfo.model.query.ColumnSet) RowBasedJsonWriter(org.activityinfo.store.query.output.RowBasedJsonWriter) QueryModel(org.activityinfo.model.query.QueryModel) FormField(org.activityinfo.model.form.FormField) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) Test(org.junit.Test)

Example 52 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class RecordFetcher method get.

public Optional<FormRecord> get(ResourceId resourceId) {
    FormClass formClass = collection.getFormClass();
    FormRecord.Builder formRecord = FormRecord.builder();
    formRecord.setRecordId(resourceId);
    formRecord.setFormId(formClass.getId());
    IdCollector id = new IdCollector();
    ColumnQueryBuilder query = collection.newColumnQuery();
    query.addResourceId(id);
    query.only(resourceId);
    for (FormField formField : formClass.getFields()) {
        if (hasValues(formField)) {
            query.addField(formField.getId(), new FieldCollector(formField.getId(), formRecord));
        }
    }
    query.execute();
    if (id.value == null) {
        return Optional.absent();
    } else {
        return Optional.of(formRecord.build());
    }
}
Also used : ColumnQueryBuilder(org.activityinfo.store.spi.ColumnQueryBuilder) FormClass(org.activityinfo.model.form.FormClass) FormRecord(org.activityinfo.model.form.FormRecord) FormField(org.activityinfo.model.form.FormField)

Example 53 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class MySqlUpdateTest method createForm.

@Test
public void createForm() {
    KeyGenerator generator = new KeyGenerator();
    int activityId = generator.generateInt();
    FormClass formClass = new FormClass(CuidAdapter.activityFormClass(activityId));
    formClass.setDatabaseId(1);
    formClass.setLabel("New Form");
    formClass.addElement(new FormField(CuidAdapter.generateIndicatorId()).setType(TextType.SIMPLE).setLabel("Name").setRequired(true));
    catalog.createOrUpdateFormSchema(formClass);
    System.out.println("Created activity " + activityId);
// FormClass reform = catalog.getFormClass(formClass.getId());
// 
// // Ensure that partner field is automatically added
// FormField partnerField = reform.getField(CuidAdapter.partnerField(activityId));
// 
// assertThat(partnerField.getType(), instanceOf(ReferenceType.class));
}
Also used : FormClass(org.activityinfo.model.form.FormClass) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) FormField(org.activityinfo.model.form.FormField) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) Test(org.junit.Test)

Example 54 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class ActivityLoaderTest method serializationTest.

@Test
public void serializationTest() throws IOException, ClassNotFoundException {
    // Large form class
    FormClass formClass = new FormClass(ResourceId.generateId());
    formClass.setLabel("Widget survey");
    for (int i = 0; i < 1000; i++) {
        formClass.addField(ResourceId.generateId()).setLabel("How many widgets?").setType(new QuantityType("people"));
    }
    assertTrue(formClass.toJsonString().length() > 0xFFFF);
    Activity activity = new Activity();
    activity.serializedFormClass = new Activity.FormClassHolder();
    activity.serializedFormClass.value = formClass;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(activity);
    // Re-read
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    Activity reread = (Activity) ois.readObject();
    assertThat(reread.getSerializedFormClass().toJsonString(), equalTo(formClass.toJsonString()));
}
Also used : QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) Test(org.junit.Test)

Example 55 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class ColumnSetBuilder method enqueue.

public static Slot<ColumnSet> enqueue(FormTree tree, QueryModel model, FormScanBatch batch) {
    FormClass formClass = tree.getRootFormClass();
    Preconditions.checkNotNull(formClass);
    QueryEvaluator evaluator = new QueryEvaluator(FilterLevel.PERMISSIONS, tree, batch);
    return evaluator.evaluate(model);
}
Also used : FormClass(org.activityinfo.model.form.FormClass)

Aggregations

FormClass (org.activityinfo.model.form.FormClass)109 FormField (org.activityinfo.model.form.FormField)49 ResourceId (org.activityinfo.model.resource.ResourceId)41 Test (org.junit.Test)38 QuantityType (org.activityinfo.model.type.number.QuantityType)20 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)19 FormInstance (org.activityinfo.model.form.FormInstance)14 EnumType (org.activityinfo.model.type.enumerated.EnumType)12 JsonValue (org.activityinfo.json.JsonValue)11 FormTree (org.activityinfo.model.formTree.FormTree)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 ColumnSet (org.activityinfo.model.query.ColumnSet)8 QueryModel (org.activityinfo.model.query.QueryModel)8 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)8 FieldValue (org.activityinfo.model.type.FieldValue)7 Quantity (org.activityinfo.model.type.number.Quantity)7 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)6 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)6 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)6 ColumnView (org.activityinfo.model.query.ColumnView)5