Search in sources :

Example 1 with FormTreeBuilder

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));
}
Also used : FormulaValidator(org.activityinfo.analysis.FormulaValidator) FormTree(org.activityinfo.model.formTree.FormTree) FormClass(org.activityinfo.model.form.FormClass) TestBatchFormClassProvider(org.activityinfo.model.formTree.TestBatchFormClassProvider) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) Test(org.junit.Test)

Example 2 with FormTreeBuilder

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"))));
}
Also used : FormMetadataProvider(org.activityinfo.model.formTree.FormMetadataProvider) RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) FormMetadata(org.activityinfo.model.form.FormMetadata) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) TestingFormStore(org.activityinfo.ui.client.store.TestingFormStore) FormStore(org.activityinfo.ui.client.store.FormStore) Test(org.junit.Test)

Example 3 with FormTreeBuilder

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);
    }
}
Also used : JsonValue(org.activityinfo.json.JsonValue) Gson(com.google.gson.Gson) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) JsonFormTreeBuilder(org.activityinfo.model.formTree.JsonFormTreeBuilder)

Example 4 with FormTreeBuilder

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);
    });
}
Also used : FormClassProvider(org.activityinfo.model.formTree.FormClassProvider) ResourceId(org.activityinfo.model.resource.ResourceId) HashMap(java.util.HashMap) JsonValue(org.activityinfo.json.JsonValue) HashMap(java.util.HashMap) Map(java.util.Map) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder)

Example 5 with FormTreeBuilder

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);
}
Also used : FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) JsonFormTreeBuilder(org.activityinfo.model.formTree.JsonFormTreeBuilder)

Aggregations

FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)16 FormTree (org.activityinfo.model.formTree.FormTree)10 FormClass (org.activityinfo.model.form.FormClass)7 Test (org.junit.Test)7 JsonFormTreeBuilder (org.activityinfo.model.formTree.JsonFormTreeBuilder)5 ResourceId (org.activityinfo.model.resource.ResourceId)4 JsonValue (org.activityinfo.json.JsonValue)3 FormField (org.activityinfo.model.form.FormField)3 FormClassProvider (org.activityinfo.model.formTree.FormClassProvider)3 ColumnSet (org.activityinfo.model.query.ColumnSet)2 ColumnView (org.activityinfo.model.query.ColumnView)2 QueryModel (org.activityinfo.model.query.QueryModel)2 ReferenceType (org.activityinfo.model.type.ReferenceType)2 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)2 Stopwatch (com.google.common.base.Stopwatch)1 Gson (com.google.gson.Gson)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1