Search in sources :

Example 1 with FieldPath

use of org.activityinfo.model.formTree.FieldPath in project activityinfo by bedatadriven.

the class SingleClassTargetBuilder method newImporter.

public SingleClassImporter newImporter(Map<TargetSiteId, ColumnAccessor> mappings) {
    List<ColumnAccessor> sourceColumns = Lists.newArrayList();
    Map<FieldPath, Integer> referenceValues = targetCollector.getPathMap(mappings, sourceColumns);
    List<FieldImporterColumn> fieldImporterColumns = targetCollector.fieldImporterColumns(mappings);
    ResourceId rangeClassId = Iterables.getOnlyElement(rootField.getRange());
    return new SingleClassImporter(rangeClassId, rootField.getField().isRequired(), sourceColumns, referenceValues, fieldImporterColumns, rootField.getFieldId());
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FieldPath(org.activityinfo.model.formTree.FieldPath)

Example 2 with FieldPath

use of org.activityinfo.model.formTree.FieldPath in project activityinfo by bedatadriven.

the class TargetCollector method getPathMap.

public Map<FieldPath, Integer> getPathMap(Map<TargetSiteId, ColumnAccessor> mappings, List<ColumnAccessor> sourceColumns) {
    Map<FieldPath, Integer> referenceValues = new HashMap<>();
    List<FieldImporterColumn> importerColumns = Lists.newArrayList();
    int columnIndex = 0;
    for (Map.Entry<TargetSiteId, ColumnAccessor> entry : mappings.entrySet()) {
        ImportTarget target = getTargetBySiteId(entry.getKey());
        ColumnAccessor source = entry.getValue();
        importerColumns.add(new FieldImporterColumn(target, source));
        sourceColumns.add(entry.getValue());
        ResourceId fieldId = ResourceId.valueOf(entry.getKey().asString());
        for (FieldPath path : getFieldPathMap().get(fieldId)) {
            referenceValues.put(path, columnIndex);
        }
        columnIndex++;
    }
    return referenceValues;
}
Also used : HashMap(java.util.HashMap) FieldPath(org.activityinfo.model.formTree.FieldPath) ResourceId(org.activityinfo.model.resource.ResourceId) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with FieldPath

use of org.activityinfo.model.formTree.FieldPath in project activityinfo by bedatadriven.

the class DefaultQueryBuilder method simpleColumnModel.

private List<ColumnModel> simpleColumnModel(String aliasPrefix, FieldPath pathPrefix, FormField formField) {
    ColumnModel column = new ColumnModel();
    column.setId(aliasPrefix + formatFieldAlias(formField));
    column.setFormula(new FieldPath(pathPrefix, fieldFormula(formField)));
    return Collections.singletonList(column);
}
Also used : FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnModel(org.activityinfo.model.query.ColumnModel)

Example 4 with FieldPath

use of org.activityinfo.model.formTree.FieldPath in project activityinfo by bedatadriven.

the class DefaultQueryBuilder method geoPointColumns.

private List<ColumnModel> geoPointColumns(String aliasPrefix, FieldPath pathPrefix, FormField field) {
    String fieldAlias = aliasPrefix + formatFieldAlias(field);
    FieldPath fieldPath = new FieldPath(pathPrefix, fieldFormula(field));
    ColumnModel latitudeColumn = new ColumnModel();
    latitudeColumn.setId(fieldAlias + ".latitude");
    latitudeColumn.setFormula(new FieldPath(fieldPath, ResourceId.valueOf(GeoPointType.LATITUDE)));
    ColumnModel longitudeColumn = new ColumnModel();
    longitudeColumn.setId(fieldAlias + ".longitude");
    longitudeColumn.setFormula(new FieldPath(fieldPath, ResourceId.valueOf(GeoPointType.LONGITUDE)));
    return Arrays.asList(latitudeColumn, longitudeColumn);
}
Also used : FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnModel(org.activityinfo.model.query.ColumnModel)

Example 5 with FieldPath

use of org.activityinfo.model.formTree.FieldPath in project activityinfo by bedatadriven.

the class DefaultQueryBuilder method build.

public QueryModel build() {
    LOGGER.info("No query fields provided, querying all.");
    addFields("", new FieldPath(), tree.getRootFields());
    this.queryModel = new QueryModel(tree.getRootFormId());
    this.queryModel.selectResourceId().as("@id");
    for (ColumnModel columnModel : columns.values()) {
        this.queryModel.addColumn(columnModel);
    }
    return queryModel;
}
Also used : FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnModel(org.activityinfo.model.query.ColumnModel) QueryModel(org.activityinfo.model.query.QueryModel)

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