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