Search in sources :

Example 11 with FieldPath

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

the class SitePersisterTest method test.

@Test
public void test() {
    FormClass formClass = assertResolves(locator.getFormClass(PEAR_Activity));
    FormInstance siteFormInstance = new FormInstance(CuidAdapter.generateSiteCuid(), formClass.getId());
    siteFormInstance.set(CONTENU_DI_KIT_FIELD, new EnumValue(CONTENU_DI_KIT_FIELD_ATTR_VALUE));
    // built-in values
    siteFormInstance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.PARTNER_FIELD), new ReferenceValue(new RecordRef(CuidAdapter.partnerFormId(DATABASE_ID), CuidAdapter.partnerRecordId(1))));
    siteFormInstance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.START_DATE_FIELD), new LocalDate(2014, 1, 1));
    siteFormInstance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.END_DATE_FIELD), new LocalDate(2014, 1, 2));
    siteFormInstance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.LOCATION_FIELD), new ReferenceValue(new RecordRef(CuidAdapter.locationFormClass(1), CuidAdapter.locationInstanceId(1))));
    assertResolves(locator.persist(siteFormInstance));
    // query by id
    FormInstance fromServer = assertResolves(locator.getFormInstance(siteFormInstance.getFormId(), siteFormInstance.getId()));
    Assert.assertNotNull(fromServer);
    Assert.assertEquals(fromServer.get(CONTENU_DI_KIT_FIELD), new EnumValue(CONTENU_DI_KIT_FIELD_ATTR_VALUE));
    FormTree formTree = assertResolves(locator.getFormTree(formClass.getId()));
    final List<FieldPath> paths = Lists.newArrayList(formTree.getRootPaths());
    Assert.assertTrue(paths.contains(new FieldPath(CONTENU_DI_KIT_FIELD)));
    // query projection
    FormInstance instance = assertResolves(locator.getFormInstance(formClass.getId(), siteFormInstance.getId()));
    EnumValue fieldValue = (EnumValue) instance.get(CONTENU_DI_KIT_FIELD);
    assertThat(fieldValue.getValueId(), equalTo(CONTENU_DI_KIT_FIELD_ATTR_VALUE));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) FormClass(org.activityinfo.model.form.FormClass) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) ReferenceValue(org.activityinfo.model.type.ReferenceValue) FieldPath(org.activityinfo.model.formTree.FieldPath) RecordRef(org.activityinfo.model.type.RecordRef) FormInstance(org.activityinfo.model.form.FormInstance) LocalDate(org.activityinfo.model.type.time.LocalDate) Test(org.junit.Test)

Example 12 with FieldPath

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

the class HierarchyClassImporter method prepare.

@Override
public Promise<Void> prepare(ResourceLocator locator, List<? extends SourceRow> batch) {
    final List<Promise<Void>> promises = Lists.newArrayList();
    for (final ResourceId formId : rootField.getRange()) {
        if (isMatchableAtLevel(formId, referenceFields.keySet())) {
            QueryModel queryModel = new QueryModel(formId);
            queryModel.selectResourceId().as("_id");
            for (FieldPath referenceFieldPath : referenceFields.keySet()) {
                queryModel.selectField(referenceFieldPath).as(referenceFieldPath.toString());
            }
            promises.add(locator.queryTable(queryModel).then(new Function<ColumnSet, Void>() {

                @Override
                public Void apply(ColumnSet columnSet) {
                    scoreSources.put(formId, new InstanceScoreSourceBuilder(formId, referenceFields, sourceColumns).build(columnSet));
                    return null;
                }
            }));
        }
    }
    return Promise.waitAll(promises);
}
Also used : Promise(org.activityinfo.promise.Promise) Function(com.google.common.base.Function) ResourceId(org.activityinfo.model.resource.ResourceId) FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel)

Example 13 with FieldPath

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

the class SingleClassImporter method prepare.

@Override
public Promise<Void> prepare(ResourceLocator locator, List<? extends SourceRow> batch) {
    QueryModel queryModel = new QueryModel(rangeFormId);
    queryModel.selectResourceId().as("_id");
    for (FieldPath fieldPath : referenceFields.keySet()) {
        queryModel.selectField(fieldPath).as(fieldPath.toString());
    }
    return locator.queryTable(queryModel).then(new Function<ColumnSet, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable ColumnSet input) {
            scoreSource = new InstanceScoreSourceBuilder(rangeFormId, referenceFields, sources).build(input);
            instanceScorer = new InstanceScorer(scoreSource);
            return null;
        }
    });
}
Also used : FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Nullable(javax.annotation.Nullable)

Example 14 with FieldPath

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

the class LookupDialog method buildReferenceMatch.

/**
 * Build a ReferenceMatch that can be stored as part of the model.
 * since this will form part of the model "state" it cannot depend
 * on computed values in any way, so we need to map our row indices and SourceKeys
 * back to the original ids.
 *
 * @param candidateIndex the index within the list of candidate target matches (from LookupGraph)
 */
private ReferenceMatch buildReferenceMatch(int candidateIndex) {
    ResourceId targetId = tableModel.getTargetInstanceId(candidateIndex);
    Map<FieldPath, String> keyMap = new HashMap<>();
    java.util.List<FieldProfile> keyFields = lookupTable.getSourceKeyFields();
    for (int i = 0; i < keyFields.size(); i++) {
        keyMap.put(keyFields.get(i).getPath(), sourceKey.get(i));
    }
    return new ReferenceMatch(keyMap, targetId);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) HashMap(java.util.HashMap) FieldPath(org.activityinfo.model.formTree.FieldPath) FieldProfile(org.activityinfo.geoadmin.merge2.view.profile.FieldProfile) ReferenceMatch(org.activityinfo.geoadmin.merge2.model.ReferenceMatch)

Example 15 with FieldPath

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

the class LookupTable method userMatchToKey.

private SourceLookupKey userMatchToKey(Map<FieldPath, String> valueMap) {
    List<FieldProfile> keyFields = sourceKeySet.getSourceFields();
    String[] keyValues = new String[keyFields.size()];
    for (int i = 0; i < keyFields.size(); ++i) {
        FieldPath keyPath = keyFields.get(i).getPath();
        if (!valueMap.containsKey(keyPath)) {
            return null;
        }
        keyValues[i] = valueMap.get(keyPath);
    }
    return new SourceLookupKey(keyValues);
}
Also used : FieldPath(org.activityinfo.model.formTree.FieldPath) FieldProfile(org.activityinfo.geoadmin.merge2.view.profile.FieldProfile)

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