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;
}
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());
}
}
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));
}
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;
}
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);
}
Aggregations