Search in sources :

Example 6 with ReferenceType

use of org.activityinfo.model.type.ReferenceType 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;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 7 with ReferenceType

use of org.activityinfo.model.type.ReferenceType in project activityinfo by bedatadriven.

the class CloneDatabaseTest method assertFormClass.

private void assertFormClass(FormClass sourceFormClass, FormClass targetFormClass) {
    assertNotEquals(sourceFormClass.getId(), targetFormClass.getId());
    assertEquals(sourceFormClass.getLabel(), targetFormClass.getLabel());
    assertEquals(sourceFormClass.getDescription(), targetFormClass.getDescription());
    // fields
    for (FormField sourceField : sourceFormClass.getFields()) {
        FormField targetField = (FormField) elementByName(targetFormClass.getElements(), sourceField.getLabel());
        assertNotEquals(sourceField.getId(), targetField.getId());
        assertEquals(sourceField.getDescription(), targetField.getDescription());
        assertEquals(sourceField.getCode(), targetField.getCode());
        assertEquals(sourceField.getRelevanceConditionExpression(), targetField.getRelevanceConditionExpression());
        assertEquals(sourceField.getType().getTypeClass(), targetField.getType().getTypeClass());
        // todo
        if (sourceField.getType() instanceof ReferenceType) {
        // need something more sophisticated to check equality of ReferenceType
        } else if (sourceField.getType() instanceof EnumType) {
        // need something more sophisticated to check equality of ReferenceType
        }
    }
    // sections
    for (FormSection sourceSection : sourceFormClass.getSections()) {
        FormSection targetSection = (FormSection) elementByName(targetFormClass.getElements(), sourceSection.getLabel());
        assertNotEquals(sourceSection.getId(), targetSection.getId());
        assertEquals(sourceSection.getLabel(), targetSection.getLabel());
    }
}
Also used : FormSection(org.activityinfo.model.form.FormSection) EnumType(org.activityinfo.model.type.enumerated.EnumType) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 8 with ReferenceType

use of org.activityinfo.model.type.ReferenceType in project activityinfo by bedatadriven.

the class HierarchyTest method buildViewModelTest.

@Test
public void buildViewModelTest() {
    FormClass campForm = assertResolves(locator.getFormClass(CAMP_CLASS));
    FormField adminField = campForm.getField(CuidAdapter.field(CAMP_CLASS, CuidAdapter.ADMIN_FIELD));
    Set<RecordRef> fieldValue = Collections.singleton(new RecordRef(CAMP_DISTRICT_CLASS, entity(325703)));
    Hierarchy tree = assertResolves(Hierarchy.get(locator, (ReferenceType) adminField.getType()));
    prettyPrintTree(tree);
    assertThat(tree.getRoots(), hasSize(1));
    createWidgets(tree);
    Presenter presenter = new Presenter(locator, tree, widgets, new ValueUpdater() {

        @Override
        public void update(Object value) {
            System.out.println("VALUE = " + value);
        }
    });
    assertResolves(presenter.setInitialSelection(fieldValue));
    assertThat(presenter.getSelectionLabel(CAMP_DISTRICT_CLASS), equalTo("District 5"));
    // now try to get options for the root level
    List<Choice> choices = assertResolves(widgets.get(REGION).choices.get());
    System.out.println(choices);
    assertThat(choices, hasSize(3));
    // if we change the root item, then all descendants should be cleared
    widgets.get(REGION).setSelection("South");
    prettyPrintWidgets(tree);
    assertThat(widgets.get(CAMP_DISTRICT_CLASS).selection, isEmptyOrNullString());
    assertThat(widgets.get(GOVERNORATE_ID).choices, Matchers.notNullValue());
    List<Choice> governorateChoices = assertResolves(widgets.get(GOVERNORATE_ID).choices.get());
    System.out.println(governorateChoices);
    assertThat(governorateChoices, hasSize(4));
}
Also used : ValueUpdater(com.google.gwt.cell.client.ValueUpdater) FormClass(org.activityinfo.model.form.FormClass) RecordRef(org.activityinfo.model.type.RecordRef) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType) Test(org.junit.Test)

Example 9 with ReferenceType

use of org.activityinfo.model.type.ReferenceType in project activityinfo by bedatadriven.

the class BatchingFormTreeBuilder method queryTrees.

public Map<ResourceId, FormTree> queryTrees(Collection<ResourceId> rootFormIds) {
    // Fetch Required FormClasses in batches
    Set<ResourceId> toFetch = Sets.newHashSet();
    toFetch.addAll(rootFormIds);
    while (!toFetch.isEmpty()) {
        // First round: fetch root form classes
        List<FormClass> fetched = fetchFormClasses(toFetch);
        toFetch.clear();
        // Find newly referenced forms
        for (FormClass formClass : fetched) {
            if (formClass.isSubForm()) {
                if (!formCache.containsKey(formClass.getParentFormId().get())) {
                    toFetch.add(formClass.getParentFormId().get());
                }
            }
            for (FormField formField : formClass.getFields()) {
                if (formField.getType() instanceof ReferenceType) {
                    ReferenceType refType = (ReferenceType) formField.getType();
                    for (ResourceId refFormId : refType.getRange()) {
                        if (!formCache.containsKey(refFormId)) {
                            toFetch.add(refFormId);
                        }
                    }
                } else if (formField.getType() instanceof SubFormReferenceType) {
                    SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
                    if (!formCache.containsKey(subFormType.getClassId())) {
                        toFetch.add(subFormType.getClassId());
                    }
                }
            }
        }
    }
    // Now assemble trees
    Map<ResourceId, FormTree> treeMap = new HashMap<>();
    FormTreeBuilder builder = new FormTreeBuilder(new FormClassProvider() {

        @Override
        public FormClass getFormClass(ResourceId formId) {
            return formCache.get(formId);
        }
    });
    for (ResourceId rootFormId : rootFormIds) {
        treeMap.put(rootFormId, builder.queryTree(rootFormId));
    }
    return treeMap;
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ReferenceType(org.activityinfo.model.type.ReferenceType) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormClassProvider(org.activityinfo.model.formTree.FormClassProvider) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField)

Example 10 with ReferenceType

use of org.activityinfo.model.type.ReferenceType in project activityinfo by bedatadriven.

the class SchemaCsvWriterV3Test method setupMonthly.

private void setupMonthly() {
    washForm = new FormClass(ResourceId.valueOf("FORM3"));
    washForm.setLabel("Emergency WASH");
    washForm.addElement(new FormField(ResourceId.valueOf("WF1")).setLabel("Partner").setRequired(true).setType(new ReferenceType(Cardinality.SINGLE, ResourceId.valueOf("PARTNER_FORM"))));
    washForm.addElement(new FormField(ResourceId.valueOf("Population")).setCode("POP").setLabel("Affected Population Size").setType(new QuantityType("households")).setRequired(true));
    washForm.addElement(new FormField(ResourceId.valueOf("Population")).setCode("POP").setLabel("Affected Population Size").setType(new QuantityType("households")).setRequired(true));
    FormClass subFormClass = new FormClass(ResourceId.valueOf("FORM4"));
    subFormClass.setSubFormKind(SubFormKind.WEEKLY);
    subFormClass.addElement(new FormField(ResourceId.valueOf("WSF1")).setLabel("Water Trucking").setType(new QuantityType("households")).setRequired(true));
    subFormClass.addElement(new FormField(ResourceId.valueOf("WSF2")).setLabel("Cholorination").setType(new QuantityType("households")).setRequired(true));
    washForm.addElement(new FormField(ResourceId.valueOf("SF")).setLabel("Monthly Output").setType(new SubFormReferenceType(subFormClass.getId())));
    formClassProvider.add(washForm);
    formClassProvider.add(subFormClass);
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ReferenceType(org.activityinfo.model.type.ReferenceType)

Aggregations

ReferenceType (org.activityinfo.model.type.ReferenceType)21 FormField (org.activityinfo.model.form.FormField)16 ResourceId (org.activityinfo.model.resource.ResourceId)10 FormClass (org.activityinfo.model.form.FormClass)6 FormTree (org.activityinfo.model.formTree.FormTree)6 Test (org.junit.Test)6 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)4 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)2 RecordRef (org.activityinfo.model.type.RecordRef)2 EnumType (org.activityinfo.model.type.enumerated.EnumType)2 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)2 QuantityType (org.activityinfo.model.type.number.QuantityType)2 Optional (com.google.common.base.Optional)1 ValueUpdater (com.google.gwt.cell.client.ValueUpdater)1 LinkedList (java.util.LinkedList)1 FormProfile (org.activityinfo.geoadmin.merge2.view.profile.FormProfile)1 FormSection (org.activityinfo.model.form.FormSection)1 FormClassProvider (org.activityinfo.model.formTree.FormClassProvider)1 FormMetadataProviderStub (org.activityinfo.model.formTree.FormMetadataProviderStub)1 LookupKeySet (org.activityinfo.model.formTree.LookupKeySet)1