use of org.activityinfo.model.formTree.FieldPath in project activityinfo by bedatadriven.
the class DefaultQueryBuilder method addReferencedFields.
private void addReferencedFields(String parentAliasPrefix, FieldPath parentPathPrefix, FormTree.Node node) {
// If this field has a 'code', then use this code both as the alias,
// and as the query expression.
// This has the effect of merging fields with the same code into a single column.
String aliasPrefix = parentAliasPrefix + formatFieldAlias(node.getField()) + ".";
FieldPath pathPrefix = new FieldPath(parentPathPrefix, fieldFormula(node.getField()));
addFields(aliasPrefix, pathPrefix, node.getChildren());
}
use of org.activityinfo.model.formTree.FieldPath in project activityinfo by bedatadriven.
the class InstanceScoreTest method query.
private Promise<ColumnSet> query(Map<FieldPath, Integer> referenceFields, int adminLevel) {
ResourceId formId = CuidAdapter.adminLevelFormClass(adminLevel);
QueryModel queryModel = new QueryModel(formId);
queryModel.selectResourceId().as("_id");
for (FieldPath fieldPath : referenceFields.keySet()) {
queryModel.selectField(fieldPath).as(fieldPath.toString());
}
return locator.queryTable(queryModel);
}
use of org.activityinfo.model.formTree.FieldPath in project activityinfo by bedatadriven.
the class InstanceScoreTest method adminEntityScoring.
@OnDataSet("/dbunit/nfi-import.db.xml")
@Test
public void adminEntityScoring() throws IOException {
setUser(3);
FormTree formTree = assertResolves(locator.getFormTree(ImportWithMultiClassRangeTest.SCHOOL_FORM_CLASS));
FormTreePrettyPrinter.print(formTree);
importModel = new ImportModel(formTree);
importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
// Step 1: User pastes in data to import
PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "school-import.csv"), Charsets.UTF_8));
importModel.setSource(source);
dumpList("COLUMNS", source.getColumns());
importModel.setColumnAction(columnIndex("School"), target("Name"));
// Province is at the root of both hierarchies
importModel.setColumnAction(columnIndex("Province"), target("Province Name"));
// Admin hierarchy
importModel.setColumnAction(columnIndex("District"), target("District Name"));
importModel.setColumnAction(columnIndex("Territoire"), target("Territoire Name"));
importModel.setColumnAction(columnIndex("Secteur"), target("Secteur Name"));
importModel.setColumnAction(columnIndex("Groupement"), target("Secteur Name"));
// health ministry hierarchy
importModel.setColumnAction(columnIndex("Zone de Santé"), target("Zone de Santé Name"));
FormTree.Node rootField = formTree.getRootField(ADMINISTRATIVE_UNIT_FIELD);
TargetCollector targetCollector = new TargetCollector(rootField);
Map<TargetSiteId, ColumnAccessor> mappedColumns = importModel.getMappedColumns(rootField.getFieldId());
List<ColumnAccessor> sourceColumns = Lists.newArrayList();
Map<FieldPath, Integer> referenceFields = targetCollector.getPathMap(mappedColumns, sourceColumns);
// Province level
ColumnSet columnSet = assertResolves(query(referenceFields, ImportWithMultiClassRangeTest.PROVINCE_LEVEL));
InstanceScoreSource scoreSource = new InstanceScoreSourceBuilder(CuidAdapter.adminLevelFormClass(ImportWithMultiClassRangeTest.PROVINCE_LEVEL), referenceFields, sourceColumns).build(columnSet);
InstanceScorer.Score score = score(source.getRows().get(0), scoreSource);
assertScore(score, "Katanga");
// District level
columnSet = assertResolves(query(referenceFields, ImportWithMultiClassRangeTest.DISTRICT_LEVEL));
scoreSource = new InstanceScoreSourceBuilder(CuidAdapter.adminLevelFormClass(ImportWithMultiClassRangeTest.DISTRICT_LEVEL), referenceFields, sourceColumns).build(columnSet);
score = score(source.getRows().get(1), scoreSource);
assertScore(score, "Katanga");
assertScore(score, "Tanganika");
// Territoire level
columnSet = assertResolves(query(referenceFields, ImportWithMultiClassRangeTest.TERRITOIRE_LEVEL));
scoreSource = new InstanceScoreSourceBuilder(CuidAdapter.adminLevelFormClass(ImportWithMultiClassRangeTest.TERRITOIRE_LEVEL), referenceFields, sourceColumns).build(columnSet);
score = score(source.getRows().get(2), scoreSource);
assertScore(score, "Katanga");
assertScore(score, "Tanganika");
assertScore(score, "Kalemie");
assertThat(scoreSource.getReferenceInstanceIds().get(score.getBestMatchIndex()), equalTo(ImportWithMultiClassRangeTest.TERRITOIRE_KALEMIE));
}
use of org.activityinfo.model.formTree.FieldPath in project activityinfo by bedatadriven.
the class AdminDimBinding method getColumnQuery.
@Override
public List<ColumnModel> getColumnQuery(FormTree formTree) {
ResourceId levelClassId = adminLevelFormClass(model.getLevelId());
Optional<FormClass> adminClass = formTree.getFormClassIfPresent(levelClassId);
if (adminClass.isPresent()) {
ColumnModel id = new ColumnModel();
id.setFormula(new CompoundExpr(levelClassId, ColumnModel.ID_SYMBOL));
id.setId(idColumn);
ColumnModel label = new ColumnModel();
label.setFormula(new FieldPath(levelClassId, field(levelClassId, NAME_FIELD)));
label.setId(labelColumn);
return Arrays.asList(id, label);
} else {
return Collections.emptyList();
}
}
use of org.activityinfo.model.formTree.FieldPath in project activityinfo by bedatadriven.
the class AttributeDimBinding method getColumnQuery.
@Override
public List<ColumnModel> getColumnQuery(FormTree formTree) {
List<FormTree.Node> fields = formTree.getLeaves();
// Does this form tree have the specific attribute group identified by the id?
FieldPath fieldId = findFieldById(fields);
if (fieldId == null) {
fieldId = findFieldByName(fields);
}
if (fieldId != null) {
return Collections.singletonList(new ColumnModel().setFormula(fieldId).as(columnId));
} else {
// this form has no corresponding attribute
return Collections.emptyList();
}
}
Aggregations