use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.
the class FormulaValidatorTest method invalidFormSchema.
@Test
public void invalidFormSchema() {
FormClass formClass = new FormClass(ResourceId.valueOf("XYZ"));
formClass.addField(ResourceId.valueOf("F1")).setCode("A").setLabel("Field A1").setType(TextType.SIMPLE);
formClass.addField(ResourceId.valueOf("F2")).setCode("A").setLabel("Field A2").setType(TextType.SIMPLE);
TestBatchFormClassProvider formProvider = new TestBatchFormClassProvider();
formProvider.add(formClass);
FormTreeBuilder formTreeBuilder = new FormTreeBuilder(formProvider);
FormTree formTree = formTreeBuilder.queryTree(formClass.getId());
FormulaValidator validator = new FormulaValidator(formTree);
assertFalse(validator.validate(FormulaParser.parse("A")));
assertThat(validator.getErrors(), hasSize(1));
}
use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.
the class FormInputViewModelTest method hiddenSubForm.
/**
* Test the ViewModel for when the user does not have access to a referenced sub form.
*/
@Test
public void hiddenSubForm() {
FormClass parentForm = new FormClass(ResourceId.valueOf("PARENT_FORM"));
parentForm.addField(ResourceId.valueOf("F1")).setLabel("What is your name?").setType(TextType.SIMPLE);
parentForm.addField(ResourceId.valueOf("F2")).setLabel("What are your secrets?").setType(new SubFormReferenceType(ResourceId.valueOf("SECRET_FORM")));
FormTreeBuilder treeBuilder = new FormTreeBuilder(new FormMetadataProvider() {
@Override
public FormMetadata getFormMetadata(ResourceId formId) {
if (formId.equals(parentForm.getId())) {
return FormMetadata.of(1, parentForm, FormPermissions.owner());
} else {
return FormMetadata.forbidden(formId);
}
}
});
FormTree formTree = treeBuilder.queryTree(parentForm.getId());
FormStore formStore = EasyMock.createMock(FormStore.class);
EasyMock.replay(formStore);
FormInputViewModelBuilder viewModelBuilder = new FormInputViewModelBuilder(formStore, formTree, new TestingActivePeriodMemory());
FormInputViewModel viewModel = viewModelBuilder.build(new FormInputModel(new RecordRef(parentForm.getId(), ResourceId.valueOf("R1"))));
}
use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.
the class GeoAdminClient method getFormTree.
public FormTree getFormTree(ResourceId resourceId) {
if (localCatalog.isLocalResource(resourceId)) {
FormTreeBuilder treeBuilder = new FormTreeBuilder(localCatalog);
return treeBuilder.queryTree(resourceId);
} else {
String json = formResource(resourceId).path("tree").get(String.class);
JsonValue object = new Gson().fromJson(json, JsonValue.class);
return JsonFormTreeBuilder.fromJson(object);
}
}
use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.
the class ActivityInfoClientAsyncImpl method getFormTree.
@Override
public Promise<FormTree> getFormTree(final ResourceId formId) {
return get(formUrl(formId) + "/tree", jsonElement -> {
JsonValue root = jsonElement;
JsonValue forms = root.get("forms");
final Map<ResourceId, FormClass> formMap = new HashMap<>();
for (Map.Entry<String, JsonValue> entry : forms.entrySet()) {
FormClass formClass = FormClass.fromJson(entry.getValue());
formMap.put(formClass.getId(), formClass);
}
FormTreeBuilder builder = new FormTreeBuilder(new FormClassProvider() {
@Override
public FormClass getFormClass(ResourceId formId1) {
FormClass formClass = formMap.get(formId1);
assert formClass != null;
return formClass;
}
});
return builder.queryTree(formId);
});
}
use of org.activityinfo.model.formTree.FormTreeBuilder in project activityinfo by bedatadriven.
the class FormResource method fetchTree.
private FormTree fetchTree() {
assertVisible(formId);
FormTreeBuilder builder = new FormTreeBuilder(backend.getStorage());
return builder.queryTree(formId);
}
Aggregations