Search in sources :

Example 46 with FormClass

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

the class SerialNumberTest method testWithPrefix.

@Test
public void testWithPrefix() {
    TestDatabase database = harness.createDatabase();
    ActivityInfoClient client = harness.client();
    FormClass formClass = new FormClass(harness.newFormId());
    formClass.setLabel("Test Prefix");
    formClass.setDatabaseId(database.getId());
    FormField partnerField = CuidAdapter.partnerField(formClass);
    formClass.addElement(partnerField);
    FormField provinceField = formClass.addField(harness.newFieldId()).setType(TextType.SIMPLE).setLabel("Province Code").setCode("PROVINCE").setRequired(true);
    FormField fileNumberField = formClass.addField(harness.newFieldId()).setCode("SN").setType(new SerialNumberType("PROVINCE", 5)).setLabel("Record Number");
    client.createForm(formClass);
    FormInstance kunduz1 = new FormInstance(harness.newRecordId(), formClass.getId());
    kunduz1.set(provinceField.getId(), "KUNDUZ");
    kunduz1.set(partnerField.getId(), database.getDefaultPartner());
    client.createRecord(kunduz1);
    FormInstance kunduz2 = new FormInstance(harness.newRecordId(), formClass.getId());
    kunduz2.set(provinceField.getId(), "KUNDUZ");
    kunduz2.set(partnerField.getId(), database.getDefaultPartner());
    client.createRecord(kunduz2);
    FormInstance takhar = new FormInstance(harness.newRecordId(), formClass.getId());
    takhar.set(provinceField.getId(), "TAKHAR");
    takhar.set(partnerField.getId(), database.getDefaultPartner());
    client.createRecord(takhar);
    // Verify that the serial numbers have been assigned
    kunduz1 = client.getTypedRecord(formClass, kunduz1.getId());
    kunduz2 = client.getTypedRecord(formClass, kunduz2.getId());
    takhar = client.getTypedRecord(formClass, takhar.getId());
    assertThat(kunduz1.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber("KUNDUZ", 1)));
    assertThat(kunduz2.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber("KUNDUZ", 2)));
    assertThat(takhar.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber("TAKHAR", 1)));
    // Now verify that we can query a table with serial numbers
    QueryModel queryModel = new QueryModel(formClass.getId());
    queryModel.selectResourceId().as("id");
    queryModel.selectField("SN");
    ColumnSet columnSet = client.queryTable(queryModel);
    ColumnView sn = columnSet.getColumnView("SN");
}
Also used : SerialNumber(org.activityinfo.model.type.SerialNumber) ActivityInfoClient(org.activityinfo.client.ActivityInfoClient) FormClass(org.activityinfo.model.form.FormClass) ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance) FormField(org.activityinfo.model.form.FormField) SerialNumberType(org.activityinfo.model.type.SerialNumberType) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 47 with FormClass

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

the class XFormResourceTest method invalidExpr.

@Test
@OnDataSet("/dbunit/invalid-relevance.db.xml")
public void invalidExpr() throws Exception {
    setUser(USER_ID);
    FormClass formClass = resourceLocator.getFormClass(CuidAdapter.activityFormClass(ACTIVITY_ID));
    FormField field = new FormField(ResourceId.generateFieldId(QuantityType.TYPE_CLASS));
    field.setLabel("Question");
    field.setType(new QuantityType());
    field.setRelevanceConditionExpression("DELETED_FIELD=1");
    formClass.addElement(field);
    resourceLocator.persist(formClass);
    Response form = this.formResource.form(ACTIVITY_ID);
    validate(form);
}
Also used : Response(javax.ws.rs.core.Response) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) FormField(org.activityinfo.model.form.FormField) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 48 with FormClass

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

the class SchemaCsvWriterV3Test method setupSurveyForm.

private void setupSurveyForm() {
    surveyForm = new FormClass(ResourceId.valueOf("FORM1"));
    surveyForm.setLabel("Household Survey");
    surveyForm.addElement(new FormField(ResourceId.valueOf("F1")).setCode("NAME").setLabel("What is your name?").setDescription("The head of household's name").setRequired(true).setType(TextType.SIMPLE));
    surveyForm.addElement(new FormField(ResourceId.valueOf("F2")).setCode("AGE").setLabel("What is your age?").setType(new QuantityType("years")).setRequired(true));
    surveyForm.addElement(new FormField(ResourceId.valueOf("F3")).setCode("GENDER").setLabel("Gender of head of household").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.valueOf("GF"), "Female"), new EnumItem(ResourceId.valueOf("GM"), "Male"))).setRequired(true));
    surveyForm.addElement(new FormField(ResourceId.valueOf("F4")).setLabel("Are you currently pregnant?").setRelevanceConditionExpression("AGE > 18 && GENDER == 'Female'").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.valueOf("PY"), "Yes"), new EnumItem(ResourceId.valueOf("PN"), "No"))).setRequired(true));
    surveyForm.addElement(new FormField(ResourceId.valueOf("F5")).setLabel("Remarks").setType(NarrativeType.INSTANCE).setRequired(false));
    FormClass subFormClass = new FormClass(ResourceId.valueOf("FORM2"));
    subFormClass.setSubFormKind(SubFormKind.REPEATING);
    subFormClass.addElement(new FormField(ResourceId.valueOf("F21")).setLabel("Name").setType(TextType.SIMPLE).setRequired(true));
    subFormClass.addElement(new FormField(ResourceId.valueOf("F22")).setLabel("Age").setType(new QuantityType("years")).setRequired(true));
    subFormClass.addElement(new FormField(ResourceId.valueOf("F23")).setLabel("Gender").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.valueOf("GF"), "Female"), new EnumItem(ResourceId.valueOf("GM"), "Male"))).setRequired(true));
    subFormClass.addElement(new FormField(ResourceId.valueOf("F24")).setLabel("Vaccinations").setType(new EnumType(Cardinality.MULTIPLE, new EnumItem(ResourceId.valueOf("V1"), "Measles"), new EnumItem(ResourceId.valueOf("V2"), "Mumps"), new EnumItem(ResourceId.valueOf("V3"), "Rubella"))));
    surveyForm.addElement(new FormField(ResourceId.valueOf("SF")).setLabel("Household members").setType(new SubFormReferenceType(subFormClass.getId())));
    formClassProvider.add(surveyForm);
    formClassProvider.add(subFormClass);
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

Example 49 with FormClass

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

the class SchemaCsvWriterV3Test method importSurveyForm.

@Test
public void importSurveyForm() {
    PastedTable pastedTable = new PastedTable(expectedSurveyExport);
    SchemaImporterV3 importer = new SchemaImporterV3(database.getId(), null, null);
    assertTrue("columns found", importer.parseColumns(pastedTable));
    boolean success = importer.processRows();
    for (SafeHtml warning : importer.getWarnings()) {
        System.out.println(warning);
    }
    assertTrue(success);
    List<FormClass> formClasses = importer.toSave();
    formClassProvider.addAll(formClasses);
    FormTreeBuilder treeBuilder = new FormTreeBuilder(formClassProvider);
    FormTreePrettyPrinter prettyPrinter = new FormTreePrettyPrinter();
    for (FormClass formClass : formClasses) {
        if (!formClass.isSubForm()) {
            prettyPrinter.printTree(treeBuilder.queryTree(formClass.getId()));
        }
    }
}
Also used : SchemaImporterV3(org.activityinfo.ui.client.page.config.design.importer.SchemaImporterV3) PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) FormClass(org.activityinfo.model.form.FormClass) FormTreePrettyPrinter(org.activityinfo.model.formTree.FormTreePrettyPrinter) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) Test(org.junit.Test)

Example 50 with FormClass

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

the class SchemaCsvWriterV3Test method setupMonthly.

private void setupMonthly() {
    washForm = new FormClass(ResourceId.valueOf("FORM3"));
    washForm.setLabel("Emergency WASH");
    washForm.addElement(new FormField(ResourceId.valueOf("WF1")).setLabel("Partner").setRequired(true).setType(new ReferenceType(Cardinality.SINGLE, ResourceId.valueOf("PARTNER_FORM"))));
    washForm.addElement(new FormField(ResourceId.valueOf("Population")).setCode("POP").setLabel("Affected Population Size").setType(new QuantityType("households")).setRequired(true));
    washForm.addElement(new FormField(ResourceId.valueOf("Population")).setCode("POP").setLabel("Affected Population Size").setType(new QuantityType("households")).setRequired(true));
    FormClass subFormClass = new FormClass(ResourceId.valueOf("FORM4"));
    subFormClass.setSubFormKind(SubFormKind.WEEKLY);
    subFormClass.addElement(new FormField(ResourceId.valueOf("WSF1")).setLabel("Water Trucking").setType(new QuantityType("households")).setRequired(true));
    subFormClass.addElement(new FormField(ResourceId.valueOf("WSF2")).setLabel("Cholorination").setType(new QuantityType("households")).setRequired(true));
    washForm.addElement(new FormField(ResourceId.valueOf("SF")).setLabel("Monthly Output").setType(new SubFormReferenceType(subFormClass.getId())));
    formClassProvider.add(washForm);
    formClassProvider.add(subFormClass);
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ReferenceType(org.activityinfo.model.type.ReferenceType)

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