Search in sources :

Example 6 with FieldPath

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

Example 7 with FieldPath

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);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FieldPath(org.activityinfo.model.formTree.FieldPath) QueryModel(org.activityinfo.model.query.QueryModel)

Example 8 with FieldPath

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));
}
Also used : PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnSet(org.activityinfo.model.query.ColumnSet) FormTree(org.activityinfo.model.formTree.FormTree) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 9 with FieldPath

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();
    }
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnModel(org.activityinfo.model.query.ColumnModel)

Example 10 with FieldPath

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

Aggregations

FieldPath (org.activityinfo.model.formTree.FieldPath)15 ResourceId (org.activityinfo.model.resource.ResourceId)6 ColumnModel (org.activityinfo.model.query.ColumnModel)5 QueryModel (org.activityinfo.model.query.QueryModel)4 ColumnSet (org.activityinfo.model.query.ColumnSet)3 HashMap (java.util.HashMap)2 FieldProfile (org.activityinfo.geoadmin.merge2.view.profile.FieldProfile)2 FormClass (org.activityinfo.model.form.FormClass)2 FormTree (org.activityinfo.model.formTree.FormTree)2 Test (org.junit.Test)2 Function (com.google.common.base.Function)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 ReferenceMatch (org.activityinfo.geoadmin.merge2.model.ReferenceMatch)1 FormInstance (org.activityinfo.model.form.FormInstance)1 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)1 RecordRef (org.activityinfo.model.type.RecordRef)1 ReferenceValue (org.activityinfo.model.type.ReferenceValue)1 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)1 LocalDate (org.activityinfo.model.type.time.LocalDate)1