Search in sources :

Example 76 with FormField

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

the class AdminEntityBinding method getParentId.

private ResourceId getParentId(FormClass form) {
    ResourceId parentFieldId = CuidAdapter.field(form.getId(), CuidAdapter.ADMIN_PARENT_FIELD);
    Optional<FormField> potentialParentField = form.getFieldIfPresent(parentFieldId);
    if (potentialParentField.isPresent()) {
        FormField parentField = potentialParentField.get();
        ReferenceType parentFieldType = (ReferenceType) parentField.getType();
        return parentFieldType.getRange().iterator().next();
    } else {
        return null;
    }
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 77 with FormField

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

the class RelevanceExpressionTest method createFormClass.

private static FormClass createFormClass() {
    EnumItem male = new EnumItem(ResourceId.generateId(), "Male");
    EnumItem female = new EnumItem(ResourceId.generateId(), "Female");
    EnumItem pregnantYes = new EnumItem(ResourceId.generateId(), "Yes");
    EnumItem pregnantNo = new EnumItem(ResourceId.generateId(), "No");
    FormField genderField = new FormField(GENDER_FIELD_ID);
    genderField.setLabel("Gender");
    genderField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(male, female)));
    FormField pregnantField = new FormField(PREGNANT_FIELD_ID);
    pregnantField.setLabel("are you currently pregnant?");
    pregnantField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(pregnantYes, pregnantNo)));
    FormField textField = new FormField(TEXT_FIELD_ID);
    textField.setLabel("Text");
    textField.setType(TextType.SIMPLE);
    FormField quantityField = new FormField(QUANTITY_FIELD_ID);
    quantityField.setLabel("Quantity");
    quantityField.setType(QuantityType.TYPE_CLASS.createType());
    final FormClass formClass = new FormClass(CuidAdapter.activityFormClass(1));
    formClass.addElement(genderField);
    formClass.addElement(pregnantField);
    formClass.addElement(textField);
    formClass.addElement(quantityField);
    return formClass;
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) FormClass(org.activityinfo.model.form.FormClass) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

Example 78 with FormField

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

the class SkipExpressionTest method createFormClass.

private static FormClass createFormClass() {
    EnumItem male = new EnumItem(ResourceId.generateId(), "Male");
    EnumItem female = new EnumItem(ResourceId.generateId(), "Female");
    EnumItem pregnantYes = new EnumItem(ResourceId.generateId(), "Yes");
    EnumItem pregnantNo = new EnumItem(ResourceId.generateId(), "No");
    FormField genderField = new FormField(GENDER_FIELD_ID);
    genderField.setLabel("Gender");
    genderField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(male, female)));
    FormField pregnantField = new FormField(PREGNANT_FIELD_ID);
    pregnantField.setLabel("are you currently pregnant?");
    pregnantField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(pregnantYes, pregnantNo)));
    FormField textField = new FormField(TEXT_FIELD_ID);
    textField.setLabel("Text");
    textField.setType(TextType.SIMPLE);
    FormField quantityField = new FormField(QUANTITY_FIELD_ID);
    quantityField.setLabel("Quantity");
    quantityField.setType(QuantityType.TYPE_CLASS.createType());
    final FormClass formClass = new FormClass(CuidAdapter.activityFormClass(1));
    formClass.addElement(genderField);
    formClass.addElement(pregnantField);
    formClass.addElement(textField);
    formClass.addElement(quantityField);
    return formClass;
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) FormClass(org.activityinfo.model.form.FormClass) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

Example 79 with FormField

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

the class CustomerCalcIndicatorTest method createFormClass.

private FormClass createFormClass() {
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO db = schema.getDatabaseById(1);
    LocationTypeDTO locType = schema.getCountryById(1).getLocationTypes().get(0);
    ActivityFormDTO act = new ActivityFormDTO();
    act.setName("Calculated indicators");
    act.setLocationType(locType);
    act.setReportingFrequency(ActivityFormDTO.REPORT_ONCE);
    CreateResult createResult = execute(CreateEntity.Activity(db, act));
    ResourceId classId = activityFormClass(createResult.getNewId());
    FormClass formClass = assertResolves(locator.getFormClass(classId));
    FormField typeField = new FormField(ResourceId.generateFieldId(EnumType.TYPE_CLASS));
    typeField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(new EnumItem(EnumItem.generateId(), "Budgeted"), new EnumItem(EnumItem.generateId(), "Spent"))));
    typeField.setLabel("Typology");
    formClass.addElement(typeField);
    FormField expField = new FormField(quantityId());
    expField.setType(new QuantityType().setUnits("currency"));
    expField.setLabel("Expenditure");
    expField.setCode("EXP");
    FormField waterAllocField = new FormField(quantityId());
    waterAllocField.setType(new QuantityType().setUnits("%"));
    waterAllocField.setLabel("Allocation watter programme");
    waterAllocField.setCode("WATER_ALLOC");
    FormField pctInitialField = new FormField(quantityId());
    pctInitialField.setType(new QuantityType().setUnits("%"));
    pctInitialField.setLabel("Initial Cost - Not specified");
    pctInitialField.setCode("PCT_INITIAL");
    FormField pctInitialHardField = new FormField(quantityId());
    pctInitialHardField.setType(new QuantityType().setUnits("%"));
    pctInitialHardField.setLabel("Initial Cost - Cap Hard");
    pctInitialHardField.setCode("PCT_INITIAL_HARD");
    FormField pctInitialSoftField = new FormField(quantityId());
    pctInitialSoftField.setType(new QuantityType().setUnits("%"));
    pctInitialSoftField.setLabel("Initial Cost - Cap Soft");
    pctInitialSoftField.setCode("PCT_INITIAL_SOFT");
    FormField pctExtensionField = new FormField(quantityId());
    pctExtensionField.setType(new QuantityType().setUnits("%"));
    pctExtensionField.setLabel("Extension Cost - Not specified");
    pctExtensionField.setCode("PCT_EXTENSION");
    FormField pctExtensionHardField = new FormField(quantityId());
    pctExtensionHardField.setType(new QuantityType().setUnits("%"));
    pctExtensionHardField.setLabel("Extension Cost - Hard");
    pctExtensionHardField.setCode("PCT_EXTENSION_HARD");
    FormField pctExtensionSoftField = new FormField(quantityId());
    pctExtensionSoftField.setType(new QuantityType().setUnits("%"));
    pctExtensionSoftField.setLabel("Extension Cost - Soft");
    pctExtensionSoftField.setCode("PCT_EXTENSION_SOFT");
    FormField pctOpField = new FormField(quantityId());
    pctOpField.setType(new QuantityType().setUnits("%"));
    pctOpField.setLabel("Operational Cost");
    pctOpField.setCode("PCT_OP");
    FormField pctMaintenanceField = new FormField(quantityId());
    pctMaintenanceField.setType(new QuantityType().setUnits("%"));
    pctMaintenanceField.setLabel("Maintenance Cost");
    pctMaintenanceField.setCode("PCT_MAINTENANCE");
    FormField pctOpMaintField = new FormField(quantityId());
    pctOpMaintField.setType(new QuantityType().setUnits("%"));
    pctOpMaintField.setLabel("Operational & Maintenance Cost");
    pctOpMaintField.setCode("PCT_OP_MAINT");
    FormField waterExpField = new FormField(quantityId());
    waterExpField.setType(new QuantityType().setUnits("%"));
    waterExpField.setLabel("Expenditure on water programme");
    waterExpField.setCode("WATER_EXP");
    waterExpField.setType(new CalculatedFieldType("{EXP}*({WATER_ALLOC}/100)"));
    FormField initialField = new FormField(quantityId());
    initialField.setType(new QuantityType().setUnits("%"));
    initialField.setLabel("Value of Initial Cost - Not specified");
    initialField.setCode("INITIAL");
    initialField.setType(new CalculatedFieldType("{WATER_EXP}*({PCT_INITIAL}/100)"));
    FormField initialHardField = new FormField(quantityId());
    initialHardField.setType(new QuantityType().setUnits("%"));
    initialHardField.setLabel("Value of Initial Cost - Cap Hard");
    initialHardField.setCode("INITIAL_HARD");
    initialHardField.setType(new CalculatedFieldType("{WATER_EXP}*({PCT_INITIAL_HARD}/100)"));
    FormField initialSoftField = new FormField(quantityId());
    initialSoftField.setType(new QuantityType().setUnits("%"));
    initialSoftField.setLabel("Value of Initial Cost – Cap Soft");
    initialSoftField.setCode("INITIAL_SOFT");
    initialSoftField.setType(new CalculatedFieldType("{WATER_EXP}*({PCT_INITIAL_SOFT}/100)"));
    FormField initialTotalField = new FormField(quantityId());
    initialTotalField.setType(new QuantityType().setUnits("%"));
    initialTotalField.setLabel("Total Value of Initial Cost");
    initialTotalField.setCode("INITIAL_TOTAL");
    initialTotalField.setType(new CalculatedFieldType("{INITIAL}+{INITIAL_HARD}+{INITIAL_SOFT}"));
    formClass.addElement(expField);
    formClass.addElement(waterAllocField);
    formClass.addElement(pctInitialField);
    formClass.addElement(pctInitialHardField);
    formClass.addElement(pctInitialSoftField);
    formClass.addElement(pctExtensionField);
    formClass.addElement(pctExtensionHardField);
    formClass.addElement(pctExtensionSoftField);
    formClass.addElement(pctOpField);
    formClass.addElement(pctMaintenanceField);
    formClass.addElement(pctOpMaintField);
    formClass.addElement(waterExpField);
    formClass.addElement(initialField);
    formClass.addElement(initialHardField);
    formClass.addElement(initialSoftField);
    formClass.addElement(initialTotalField);
    assertResolves(locator.persist(formClass));
    FormClass reform = assertResolves(locator.getFormClass(formClass.getId()));
    assertHasFieldWithLabel(reform, "Expenditure");
    assertHasFieldWithLabel(reform, "Allocation watter programme");
    assertHasFieldWithLabel(reform, "Initial Cost - Not specified");
    assertHasFieldWithLabel(reform, "Initial Cost - Cap Hard");
    assertHasFieldWithLabel(reform, "Initial Cost - Cap Soft");
    assertHasFieldWithLabel(reform, "Extension Cost - Not specified");
    assertHasFieldWithLabel(reform, "Extension Cost - Hard");
    assertHasFieldWithLabel(reform, "Extension Cost - Soft");
    assertHasFieldWithLabel(reform, "Operational Cost");
    assertHasFieldWithLabel(reform, "Maintenance Cost");
    assertHasFieldWithLabel(reform, "Operational & Maintenance Cost");
    assertHasFieldWithLabel(reform, "Expenditure on water programme");
    assertHasFieldWithLabel(reform, "Value of Initial Cost - Not specified");
    assertHasFieldWithLabel(reform, "Value of Initial Cost - Cap Hard");
    assertHasFieldWithLabel(reform, "Value of Initial Cost – Cap Soft");
    assertHasFieldWithLabel(reform, "Total Value of Initial Cost");
    return reform;
}
Also used : CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) ResourceId(org.activityinfo.model.resource.ResourceId) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

Example 80 with FormField

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

the class FormPersisterTest method barcodes.

@Test
public void barcodes() {
    FormClass formClass = assertResolves(locator.getFormClass(CuidAdapter.activityFormClass(11218)));
    ResourceId barcodeId = ResourceId.generateFieldId(BarcodeType.TYPE_CLASS);
    formClass.addElement(new FormField(barcodeId).setLabel("HH ID").setType(BarcodeType.INSTANCE).setVisible(true));
    assertResolves(locator.persist(formClass));
    FormClass formClass2 = assertResolves(locator.getFormClass(CuidAdapter.activityFormClass(11218)));
    FormField field = findFieldByLabel(formClass2.getFields(), "HH ID");
    assertThat(field.getType(), instanceOf(BarcodeType.class));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField) BarcodeType(org.activityinfo.model.type.barcode.BarcodeType) Test(org.junit.Test)

Aggregations

FormField (org.activityinfo.model.form.FormField)119 FormClass (org.activityinfo.model.form.FormClass)48 ResourceId (org.activityinfo.model.resource.ResourceId)32 Test (org.junit.Test)30 QuantityType (org.activityinfo.model.type.number.QuantityType)18 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)17 ReferenceType (org.activityinfo.model.type.ReferenceType)16 EnumType (org.activityinfo.model.type.enumerated.EnumType)14 FieldValue (org.activityinfo.model.type.FieldValue)12 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)11 JsonValue (org.activityinfo.json.JsonValue)9 FormTree (org.activityinfo.model.formTree.FormTree)9 FormInstance (org.activityinfo.model.form.FormInstance)8 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)8 ColumnSet (org.activityinfo.model.query.ColumnSet)6 QueryModel (org.activityinfo.model.query.QueryModel)6 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)5 Quantity (org.activityinfo.model.type.number.Quantity)5 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)5 ArrayList (java.util.ArrayList)4