use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class LocationFieldBinding method getColumnQuery.
@Override
public List<ColumnModel> getColumnQuery(FormTree formTree) {
locationBindings.clear();
// Query for generic location info - exists regardless of location range or type
locationBindings.add(new GenericLocationFieldBinding());
Iterator<ResourceId> locationRange = getRange(locationField);
while (locationRange.hasNext()) {
ResourceId locationReference = locationRange.next();
FormClass locationForm = formTree.getFormClass(locationReference);
buildLocationBindings(locationForm, formTree);
}
return buildColumnQuery(formTree);
}
use of org.activityinfo.model.form.FormClass 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;
}
use of org.activityinfo.model.form.FormClass 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;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class CloneDatabaseTest method assertFormClassesCloned.
private void assertFormClassesCloned(UserDatabaseDTO sourceDb, UserDatabaseDTO targetDb) {
assertEquals(sourceDb.getActivities().size(), targetDb.getActivities().size());
for (ActivityDTO activityDTO : sourceDb.getActivities()) {
ActivityFormDTO sourceActivity = execute(new GetActivityForm(activityDTO.getId()));
ActivityFormDTO targetActivity = execute(new GetActivityForm(entityByName(targetDb.getActivities(), sourceActivity.getName()).getId()));
// legacy level
assertActivityClone(sourceActivity, targetActivity);
// form class level
FormClass sourceFormClass = assertResolves(locator.getFormClass(sourceActivity.getResourceId()));
FormClass targetFormClass = assertResolves(locator.getFormClass(targetActivity.getResourceId()));
assertFormClass(sourceFormClass, targetFormClass);
}
}
use of org.activityinfo.model.form.FormClass 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));
}
Aggregations