use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class FormTreeBuilder method queryTree.
public FormTree queryTree(ResourceId rootFormId) {
FormTree tree = new FormTree(rootFormId);
FormMetadata root = metadataProvider.getFormMetadata(rootFormId);
if (root.isDeleted()) {
tree.setRootState(FormTree.State.DELETED);
return tree;
}
if (!root.isVisible()) {
tree.setRootState(FormTree.State.FORBIDDEN);
return tree;
}
FormClass rootSchema = root.getSchema();
List<ResourceId> stack = Lists.newArrayList(rootFormId);
Optional<FormField> parentField = rootSchema.getParentField();
if (parentField.isPresent()) {
if (!stack.contains(parentField.get().getId())) {
tree.addFormMetadata(root);
FormTree.Node node = tree.addRootField(root, parentField.get());
fetchChildren(stack, tree, node, rootSchema.getParentFormId().asSet());
}
}
// Add fields defined by this FormClass
for (FormField field : rootSchema.getFields()) {
tree.addFormMetadata(root);
FormTree.Node node = tree.addRootField(root, field);
if (node.isReference()) {
fetchChildren(stack, tree, node, node.getRange());
} else if (field.getType() instanceof RecordFieldType) {
addChildren(stack, tree, node, embeddedForm(node));
}
}
return tree;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class FormEvalContextTest method circularRefs.
@Test
public void circularRefs() {
FormField a = new FormField(ResourceId.generateId());
a.setCode("A");
a.setType(new CalculatedFieldType("B+1"));
a.setLabel("A");
FormField b = new FormField(ResourceId.generateId());
b.setCode("B");
b.setType(new CalculatedFieldType("A/50"));
b.setLabel("B");
FormClass formClass = new FormClass(ResourceId.generateId());
formClass.addElement(a);
formClass.addElement(b);
FormEvalContext context = new FormEvalContext(formClass);
context.setInstance(new FormInstance(ResourceId.generateSubmissionId(formClass), formClass.getId()));
assertThat(context.getFieldValue(a.getId()), instanceOf(ErrorValue.class));
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class GeoPointType method getFormClass.
@Override
public FormClass getFormClass() {
FormClass formClass = new FormClass(ResourceId.valueOf("geoPoint"));
formClass.setLabel(I18N.CONSTANTS.geographicCoordinatesFieldLabel());
formClass.addField(ResourceId.valueOf(LATITUDE)).setCode(LATITUDE).setLabel(I18N.CONSTANTS.latitude()).setType(new QuantityType("degrees")).setRequired(true);
formClass.addField(ResourceId.valueOf(LONGITUDE)).setCode(LONGITUDE).setLabel(I18N.CONSTANTS.longitude()).setType(new QuantityType("degrees")).setRequired(true);
return formClass;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class XFormResources method form.
@GET
@Path("{id}/xform")
@Produces(MediaType.TEXT_XML)
public Response form(@PathParam("id") int id) {
AuthenticatedUser user = authProvider.get();
LOGGER.finer("ODK activity form " + id + " requested by " + user.getEmail() + " (" + user.getId() + ")");
FormClass formClass = fetchFormClass(id);
String authenticationToken = authenticationTokenService.createAuthenticationToken(user.getId(), formClass.getId());
XForm xForm = new XFormBuilder(factory).setUserId(authenticationToken).build(formClass);
return Response.ok(xForm).build();
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class ItemSetBuilder method findRanges.
private Set<ResourceId> findRanges(ResourceId formClassId) {
FormClass formClass = locator.getFormClass(formClassId);
Set<ResourceId> rangeClassIds = Sets.newHashSet();
for (FormField field : formClass.getFields()) {
if (field.getType() instanceof ReferenceType) {
rangeClassIds.addAll(((ReferenceType) field.getType()).getRange());
}
}
return rangeClassIds;
}
Aggregations