Search in sources :

Example 26 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem 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 27 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem 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 28 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem 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 29 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class ActivityTest method createAttributeGroup.

@Test
public void createAttributeGroup() {
    FormClass formClass = assertResolves(locator.getFormClass(CuidAdapter.activityFormClass(1)));
    FormField newField = new FormField(ResourceId.generateFieldId(EnumType.TYPE_CLASS));
    newField.setLabel("New Group");
    EnumItem yes = new EnumItem(EnumItem.generateId(), "Yes");
    EnumItem no = new EnumItem(EnumItem.generateId(), "No");
    newField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(yes, no)));
    formClass.getElements().add(newField);
    locator.persist(formClass);
    // verify that it appears as attribute group
    ActivityFormDTO activity = getActivity(1);
    AttributeGroupDTO group = findGroup(activity, "New Group");
    assertThat(group.isMultipleAllowed(), equalTo(false));
    assertThat(group.getAttributes(), hasSize(2));
    assertThat(group.getAttributes().get(0), hasProperty("name", Matchers.equalTo("Yes")));
    assertThat(group.getAttributes().get(1), hasProperty("name", Matchers.equalTo("No")));
    // Now update the same attribute group and a value
    newField.setLabel("Do you like ice cream?");
    yes.setLabel("Oui");
    no.setLabel("Non");
    locator.persist(formClass);
    group = findGroup(getActivity(1), "Do you like ice cream?");
    assertThat(group.isMultipleAllowed(), equalTo(false));
    assertThat(group.getAttributes(), contains(hasProperty("name", Matchers.equalTo("Oui")), hasProperty("name", Matchers.equalTo("Non"))));
    // Remove one of our new enum values
    newField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(yes)));
    locator.persist(formClass);
    group = findGroup(getActivity(1), "Do you like ice cream?");
    assertThat(group.isMultipleAllowed(), equalTo(false));
    assertThat(group.getAttributes(), contains(hasProperty("name", Matchers.equalTo("Oui"))));
}
Also used : CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) Test(org.junit.Test)

Example 30 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class ActivityTest method createActivity.

@Test
public void createActivity() {
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO db = schema.getDatabaseById(1);
    LocationTypeDTO locType = schema.getCountryById(1).getLocationTypes().get(0);
    ActivityFormDTO act = new ActivityFormDTO();
    act.setName("Household Survey");
    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 newField = new FormField(ResourceId.generateFieldId(QuantityType.TYPE_CLASS));
    newField.setLabel("How old are you?");
    newField.setType(new QuantityType().setUnits("years"));
    formClass.addElement(newField);
    FormField newTextField = new FormField(ResourceId.generateFieldId(TextType.TYPE_CLASS));
    newTextField.setLabel("What is your name?");
    newTextField.setType(TextType.SIMPLE);
    formClass.addElement(newTextField);
    assertResolves(locator.persist(formClass));
    FormClass reform = assertResolves(locator.getFormClass(formClass.getId()));
    assertHasFieldWithLabel(reform, "How old are you?");
    newField.setLabel("How old are you today?");
    // save again
    assertResolves(locator.persist(formClass));
    reform = assertResolves(locator.getFormClass(formClass.getId()));
    assertHasFieldWithLabel(reform, "How old are you today?");
    System.out.println(reform.getFields().toString());
    assertThat(reform.getFields(), hasSize(8));
    List<EnumItem> values = Lists.newArrayList();
    values.add(new EnumItem(EnumItem.generateId(), "Option 1"));
    values.add(new EnumItem(EnumItem.generateId(), "Option 2"));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) ResourceId(org.activityinfo.model.resource.ResourceId) QuantityType(org.activityinfo.model.type.number.QuantityType) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) Test(org.junit.Test)

Aggregations

EnumItem (org.activityinfo.model.type.enumerated.EnumItem)44 EnumType (org.activityinfo.model.type.enumerated.EnumType)30 FormField (org.activityinfo.model.form.FormField)11 FormClass (org.activityinfo.model.form.FormClass)9 ResourceId (org.activityinfo.model.resource.ResourceId)9 Test (org.junit.Test)7 QuantityType (org.activityinfo.model.type.number.QuantityType)6 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)5 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)4 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)3 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)2 SymbolNode (org.activityinfo.model.formula.SymbolNode)2 ColumnModel (org.activityinfo.model.query.ColumnModel)2 ColumnView (org.activityinfo.model.query.ColumnView)2 Cardinality (org.activityinfo.model.type.Cardinality)2 FieldValue (org.activityinfo.model.type.FieldValue)2 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)2 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)2 ActivityField (org.activityinfo.store.mysql.metadata.ActivityField)2 Optional (com.google.common.base.Optional)1