Search in sources :

Example 51 with FormField

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));
}
Also used : FormClass(org.activityinfo.model.form.FormClass) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) FormField(org.activityinfo.model.form.FormField) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) Test(org.junit.Test)

Example 52 with FormField

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);
}
Also used : QuantityType(org.activityinfo.model.type.number.QuantityType) FormField(org.activityinfo.model.form.FormField)

Example 53 with FormField

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;
        }
    }
}
Also used : FormField(org.activityinfo.model.form.FormField)

Example 54 with FormField

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);
}
Also used : FormField(org.activityinfo.model.form.FormField)

Example 55 with FormField

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;
}
Also used : CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) QuantityType(org.activityinfo.model.type.number.QuantityType) FormField(org.activityinfo.model.form.FormField)

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