Search in sources :

Example 86 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class CurlExamplesGenerator method getRecord.

public static Example getRecord() {
    ResourceId formId = ResourceId.generateId();
    ResourceId recordId = ResourceId.generateId();
    FormRecord.Builder record = new FormRecord.Builder();
    record.setFormId(formId);
    record.setRecordId(recordId);
    record.setFieldValue(ResourceId.generateId(), TextValue.valueOf("Text Value"));
    record.setFieldValue(ResourceId.generateId(), new Quantity(1500));
    record.setFieldValue(ResourceId.generateId(), new LocalDate(2016, 10, 5));
    record.setFieldValue(ResourceId.generateId(), new GeoPoint(52.078663, 4.288788));
    record.setFieldValue(ResourceId.generateId(), new EnumValue(ResourceId.generateId()));
    return new Example(String.format("curl https://www.activityinfo.org/resources/form/%s/record/%s", formId, recordId), record.build().toJson());
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) ResourceId(org.activityinfo.model.resource.ResourceId) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) Quantity(org.activityinfo.model.type.number.Quantity) FormRecord(org.activityinfo.model.form.FormRecord) LocalDate(org.activityinfo.model.type.time.LocalDate)

Example 87 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class FieldPath method toExpr.

public FormulaNode toExpr() {
    Iterator<ResourceId> it = path.iterator();
    FormulaNode expr = new SymbolNode(it.next());
    while (it.hasNext()) {
        expr = new CompoundExpr(expr, new SymbolNode(it.next()));
    }
    return expr;
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) ResourceId(org.activityinfo.model.resource.ResourceId)

Example 88 with ResourceId

use of org.activityinfo.model.resource.ResourceId 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 89 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class JsonFormTreeBuilder method fromJson.

public static FormTree fromJson(JsonValue object) {
    ResourceId rootFormClassId = ResourceId.valueOf(object.get("root").asString());
    JsonValue forms = object.get("forms");
    final Map<ResourceId, FormClass> formMap = new HashMap<>();
    for (String key : forms.keys()) {
        JsonValue value = forms.get(key);
        FormClass formClass = FormClass.fromJson(value);
        formMap.put(formClass.getId(), formClass);
    }
    FormClassProvider provider = new FormClassProvider() {

        @Override
        public FormClass getFormClass(ResourceId formId) {
            FormClass formClass = formMap.get(formId);
            assert formClass != null : "FormClass " + formId + " was referenced but not include in the " + "list of forms";
            return formClass;
        }
    };
    FormTreeBuilder builder = new FormTreeBuilder(provider);
    return builder.queryTree(rootFormClassId);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) HashMap(java.util.HashMap) FormClass(org.activityinfo.model.form.FormClass) JsonValue(org.activityinfo.json.JsonValue)

Example 90 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class JsonFormTreeBuilder method toJson.

public static JsonValue toJson(FormTree tree) {
    ResourceId rootFormClassId = tree.getRootFormId();
    JsonValue forms = createObject();
    collectForms(forms, tree.getRootFields());
    JsonValue object = createObject();
    object.put("root", rootFormClassId.asString());
    object.put("forms", forms);
    return object;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) JsonValue(org.activityinfo.json.JsonValue)

Aggregations

ResourceId (org.activityinfo.model.resource.ResourceId)198 Test (org.junit.Test)42 FormClass (org.activityinfo.model.form.FormClass)41 FormField (org.activityinfo.model.form.FormField)34 RecordRef (org.activityinfo.model.type.RecordRef)30 JsonValue (org.activityinfo.json.JsonValue)21 FormTree (org.activityinfo.model.formTree.FormTree)18 ReferenceValue (org.activityinfo.model.type.ReferenceValue)17 FieldValue (org.activityinfo.model.type.FieldValue)16 FormInstance (org.activityinfo.model.form.FormInstance)15 HashMap (java.util.HashMap)14 QuantityType (org.activityinfo.model.type.number.QuantityType)13 ColumnSet (org.activityinfo.model.query.ColumnSet)12 QueryModel (org.activityinfo.model.query.QueryModel)12 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)11 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)11 ReferenceType (org.activityinfo.model.type.ReferenceType)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 FormStorage (org.activityinfo.store.spi.FormStorage)10 ArrayList (java.util.ArrayList)9