use of org.activityinfo.model.form.FormField 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.FormField in project activityinfo by bedatadriven.
the class DatabaseTargetForm method addIndicator.
public void addIndicator(int id, String name, String units) {
FormField field = new FormField(CuidAdapter.cuid(CuidAdapter.TARGET_INDICATOR_FIELD_DOMAIN, id));
field.setLabel(name);
field.setSuperProperty(CuidAdapter.indicatorField(id));
field.setType(new QuantityType(units));
indicatorFields.add(field);
fieldMap.put(id, field);
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class ActivityLoader method addFields.
private void addFields(Activity activity, FormClass formClass) {
int sortOrder = 1;
for (FormField formField : formClass.getFields()) {
// include also built-in fields
activity.fieldsOrder.put(formField.getId(), sortOrder);
switch(formField.getId().getDomain()) {
case CuidAdapter.ATTRIBUTE_GROUP_FIELD_DOMAIN:
case CuidAdapter.INDICATOR_DOMAIN:
int fieldId = CuidAdapter.getLegacyIdFromCuid(formField.getId());
activity.fields.add(new ActivityField(fieldId, null, formField, sortOrder++));
break;
}
}
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class ActivityTableMappingBuilder method addPartnerField.
public void addPartnerField() {
FormField partnerField = new FormField(field(classId, PARTNER_FIELD)).setLabel("Partner").setCode("partner").setType(ReferenceType.single(activity.getPartnerFormClassId())).setRequired(true);
formClass.addElement(partnerField);
addPartnerField(partnerField);
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class IndicatorDTO method asFormField.
@Override
public FormField asFormField() {
FormField field = new FormField(CuidAdapter.indicatorField(getId()));
field.setLabel(getName());
field.setDescription(getDescription());
field.setRelevanceConditionExpression(getRelevanceExpression());
field.setRequired(isMandatory());
field.setVisible(isVisible());
String code = getNameInExpression();
if (!Strings.isNullOrEmpty(code)) {
field.setCode(code);
}
if (isCalculated()) {
field.setType(new CalculatedFieldType(getExpression()));
} else if (Strings.isNullOrEmpty(getTypeId()) || getTypeId().equals(QuantityType.TYPE_CLASS.getId())) {
String units = getUnits();
if (units == null) {
units = "";
}
field.setType(new QuantityType().setUnits(units).setAggregation(getAggregation()));
} else {
field.setType(getType().createType());
}
return field;
}
Aggregations