Search in sources :

Example 56 with FormClass

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

the class ActivityTableMappingBuilder method reportingPeriod.

public static ActivityTableMappingBuilder reportingPeriod(Activity activity) {
    ActivityTableMappingBuilder mapping = new ActivityTableMappingBuilder();
    mapping.activity = activity;
    mapping.baseTable = "reportingperiod";
    mapping.baseFromClause = "reportingperiod base";
    mapping.baseFilter = "base.deleted=0 AND base.activityId=" + activity.getId();
    mapping.classId = CuidAdapter.reportingPeriodFormClass(activity.getId());
    mapping.formClass = new FormClass(mapping.classId);
    mapping.formClass.setLabel(activity.getName() + " Monthly Reports");
    mapping.formClass.setDatabaseId(activity.getDatabaseId());
    mapping.primaryKeyMapping = new PrimaryKeyMapping(CuidAdapter.MONTHLY_REPORT, "reportingPeriodId");
    mapping.addSiteField();
    mapping.addDateFields();
    for (ActivityField indicatorField : activity.getIndicatorFields()) {
        mapping.addIndicatorOrAttributeField(indicatorField);
    }
    sortFormClassFields(mapping.formClass, activity.getFieldsOrder());
    return mapping;
}
Also used : FormClass(org.activityinfo.model.form.FormClass) ActivityField(org.activityinfo.store.mysql.metadata.ActivityField)

Example 57 with FormClass

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

the class ActivityTableMappingBuilder method site.

public static ActivityTableMappingBuilder site(Activity activity) {
    if (activity.getSerializedFormClass() != null) {
        return newForm(activity);
    }
    ActivityTableMappingBuilder mapping = new ActivityTableMappingBuilder();
    mapping.activity = activity;
    mapping.baseTable = "site";
    mapping.baseFromClause = "site base";
    mapping.baseFilter = "base.deleted=0     AND base.activityId=" + activity.getId();
    mapping.classId = CuidAdapter.activityFormClass(activity.getId());
    mapping.formClass = new FormClass(mapping.classId);
    mapping.formClass.setSchemaVersion(activity.getActivityVersion().getSchemaVersion());
    mapping.formClass.setLabel(activity.getName());
    mapping.formClass.setDatabaseId(activity.getDatabaseId());
    mapping.primaryKeyMapping = new PrimaryKeyMapping(CuidAdapter.SITE_DOMAIN, "siteId");
    if (activity.getReportingFrequency() == Activity.REPORT_ONCE) {
        mapping.addDateFields();
    }
    mapping.addPartnerField();
    mapping.addProjectField();
    if (activity.hasLocationType()) {
        mapping.addLocationField();
    }
    for (ActivityField field : activity.getAttributeAndIndicatorFields()) {
        mapping.addIndicatorOrAttributeField(field);
    }
    mapping.addComments();
    sortFormClassFields(mapping.formClass, activity.getFieldsOrder());
    return mapping;
}
Also used : FormClass(org.activityinfo.model.form.FormClass) ActivityField(org.activityinfo.store.mysql.metadata.ActivityField)

Example 58 with FormClass

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

the class FormTreeBuilder method embeddedForm.

private FormMetadata embeddedForm(FormTree.Node childNode) {
    FormClass embeddedFormSchema = ((RecordFieldType) childNode.getType()).getFormClass();
    long formVersion = 1L;
    return FormMetadata.of(formVersion, embeddedFormSchema, FormPermissions.readonly());
}
Also used : FormClass(org.activityinfo.model.form.FormClass) RecordFieldType(org.activityinfo.model.type.RecordFieldType)

Example 59 with FormClass

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

the class FormTreePrettyPrinter method distinctFormClasses.

private List<FormClass> distinctFormClasses(List<FormTree.Node> nodes) {
    Set<ResourceId> formClassIds = Sets.newHashSet();
    List<FormClass> formClasses = Lists.newArrayList();
    for (FormTree.Node node : nodes) {
        ResourceId formClassId = node.getDefiningFormClass().getId();
        if (!formClassIds.contains(formClassId)) {
            formClassIds.add(formClassId);
            formClasses.add(node.getDefiningFormClass());
        }
    }
    return formClasses;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass)

Example 60 with FormClass

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

the class FormTreePrettyPrinter method classNode.

private String classNode(List<FormClass> formClasses) {
    StringBuilder sb = new StringBuilder("[");
    boolean needsPipe = false;
    for (FormClass formClass : formClasses) {
        if (needsPipe) {
            sb.append(" | ");
        }
        sb.append(formClass.getLabel());
        needsPipe = true;
    }
    sb.append("]");
    return sb.toString();
}
Also used : FormClass(org.activityinfo.model.form.FormClass)

Aggregations

FormClass (org.activityinfo.model.form.FormClass)109 FormField (org.activityinfo.model.form.FormField)49 ResourceId (org.activityinfo.model.resource.ResourceId)41 Test (org.junit.Test)38 QuantityType (org.activityinfo.model.type.number.QuantityType)20 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)19 FormInstance (org.activityinfo.model.form.FormInstance)14 EnumType (org.activityinfo.model.type.enumerated.EnumType)12 JsonValue (org.activityinfo.json.JsonValue)11 FormTree (org.activityinfo.model.formTree.FormTree)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 ColumnSet (org.activityinfo.model.query.ColumnSet)8 QueryModel (org.activityinfo.model.query.QueryModel)8 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)8 FieldValue (org.activityinfo.model.type.FieldValue)7 Quantity (org.activityinfo.model.type.number.Quantity)7 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)6 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)6 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)6 ColumnView (org.activityinfo.model.query.ColumnView)5