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