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());
}
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;
}
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;
}
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);
}
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;
}
Aggregations