use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class CurlExamplesGenerator method getFormSchema.
public static Example getFormSchema() {
FormClass exampleForm = new FormClass(ResourceId.generateId()).setDatabaseId(54).setLabel("NFI Distribution").setDescription("Form for collecting results of NFI distributions in North Kivu");
exampleForm.addField(ResourceId.generateId()).setLabel("Date of Distribution").setType(LocalDateType.INSTANCE).setRequired(true);
exampleForm.addField(CuidAdapter.partnerField(33)).setLabel("Partner").setType(ReferenceType.single(CuidAdapter.partnerFormId(54))).setRequired(true).setDescription("The implementing partner who conducted the distribution");
exampleForm.addField(ResourceId.generateId()).setLabel("Donor").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.generateId(), "USAID"), new EnumItem(ResourceId.generateId(), "DFID"), new EnumItem(ResourceId.generateId(), "ECHO"))).setRequired(true);
exampleForm.addField(ResourceId.generateId()).setLabel("Number of households receiving a kit").setType(new QuantityType("households")).setRequired(true);
return new Example("curl https://www.activityinfo.org/form/" + exampleForm.getId() + "/schema", exampleForm.toJson());
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class XlsFormBuilder method build.
public void build(ResourceId formClassId) {
FormClass formClass = formClassProvider.getFormClass(formClassId);
symbolHandler = new XlsSymbolHandler(formClass.getFields());
xPathBuilder = new XPathBuilder(symbolHandler);
writeFields(formClass);
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class ActivityInfoClient method getFormSchema.
public FormClass getFormSchema(ResourceId formId) {
String json = client.resource(root).path("resources").path("form").path(formId.asString()).path("schema").accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
JsonValue jsonObject = parse(json);
FormClass formClass = FormClass.fromJson(jsonObject);
return formClass;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class LookupKeySet method addLevels.
private LookupKey addLevels(FormClass formClass) {
ResourceId formId = formClass.getId();
if (formMap.containsKey(formId)) {
return formMap.get(formId);
}
// if serial number is present, we use that exclusively.
Optional<FormField> serialNumberField = findSerialNumberField(formClass);
if (serialNumberField.isPresent()) {
LookupKey lookupKey = serialNumberLevel(formClass, serialNumberField.get());
lookupKeys.add(lookupKey);
return lookupKey;
}
LookupKey parentKey = null;
String parentFieldId = null;
// If there is a reference key, then we climb the reference tree recursively.
Optional<FormField> referenceKey = findReferenceKey(formClass);
if (referenceKey.isPresent()) {
ReferenceType referenceType = (ReferenceType) referenceKey.get().getType();
ResourceId referencedFormId = Iterables.getOnlyElement(referenceType.getRange());
FormClass referencedFormClass = formTree.getFormClass(referencedFormId);
parentMap.put(formId, referencedFormId);
parentKey = addLevels(referencedFormClass);
parentFieldId = referenceKey.get().getId().asString();
}
// Now check for text key fields
for (FormField formField : formClass.getFields()) {
if (isTextLikeKey(formField)) {
LookupKey lookupKey = textKeyLevel(formClass, parentKey, parentFieldId, formField);
lookupKeys.add(lookupKey);
parentKey = lookupKey;
parentFieldId = null;
}
}
// If there is really no other key fields, then use the autogenerated id as a key
if (parentKey == null) {
parentKey = idLevel(formClass);
lookupKeys.add(parentKey);
}
formMap.put(formId, parentKey);
return parentKey;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class FormTree method parentTree.
public FormTree parentTree() {
FormClass rootFormClass = getRootFormClass();
assert rootFormClass.isSubForm();
ResourceId parentFormId = rootFormClass.getParentFormId().get();
return subTree(parentFormId);
}
Aggregations