use of org.activityinfo.model.type.ReferenceValue 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.type.ReferenceValue in project activityinfo by bedatadriven.
the class ActivityFormClassBuilderTest method partnersFieldIsAlwaysVisible.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void partnersFieldIsAlwaysVisible() {
setUser(BAVON_USER_ID);
FormClass formClass = assertResolves(locator.getFormClass(CuidAdapter.activityFormClass(1)));
int databaseId = 1;
ResourceId partnerFieldId = CuidAdapter.field(formClass.getId(), CuidAdapter.PARTNER_FIELD);
FormField partnerField = formClass.getField(partnerFieldId);
// according to ai-1009 : partner field is always visible
assertThat(partnerField, hasProperty("visible", equalTo(true)));
// Make sure we can update if partner is not specified
FormInstance instance = new FormInstance(CuidAdapter.newLegacyFormInstanceId(formClass.getId()), formClass.getId());
instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.START_DATE_FIELD), new LocalDate(2014, 1, 1));
instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.END_DATE_FIELD), new LocalDate(2014, 1, 2));
instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.LOCATION_FIELD), new ReferenceValue(new RecordRef(CuidAdapter.locationFormClass(1), CuidAdapter.locationInstanceId(1))));
instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.PARTNER_FIELD), CuidAdapter.partnerRef(databaseId, 1));
assertResolves(locator.persist(instance));
}
use of org.activityinfo.model.type.ReferenceValue in project activityinfo by bedatadriven.
the class ForeignKeyTest method multipleReferencedForms.
@Test
public void multipleReferencedForms() {
// Build the unfiltered foreign key map
// That maps row indexes to foreign keys
ResourceId province = ResourceId.valueOf("g00001");
ResourceId territory = ResourceId.valueOf("g00002");
ForeignKeyBuilder builder = new ForeignKeyBuilder(province, new PendingSlot<ForeignKey>());
// Row 0: Missing
builder.onNext(null);
// Row 1: Multiple Provinces
builder.onNext(new ReferenceValue(new RecordRef(province, ResourceId.valueOf("P1")), new RecordRef(province, ResourceId.valueOf("P2"))));
// Row 2: One province, one territory
builder.onNext(new ReferenceValue(new RecordRef(province, ResourceId.valueOf("P1")), new RecordRef(territory, ResourceId.valueOf("T1"))));
// Row 3: Two territories
builder.onNext(new ReferenceValue(new RecordRef(territory, ResourceId.valueOf("T1")), new RecordRef(territory, ResourceId.valueOf("T2"))));
// Row 4: Missing
builder.onNext(null);
// Row 5: Missing
builder.onNext(null);
ForeignKey fkMap = builder.build();
assertThat(fkMap.numRows(), equalTo(6));
assertThat(fkMap.getKey(0), nullValue());
assertThat(fkMap.getKey(1), nullValue());
assertThat(fkMap.getKey(2), equalTo("P1"));
assertThat(fkMap.getKey(3), nullValue());
assertThat(fkMap.getKey(4), nullValue());
assertThat(fkMap.getKey(5), nullValue());
}
use of org.activityinfo.model.type.ReferenceValue in project activityinfo by bedatadriven.
the class ForeignKeyBuilder method onNext.
@Override
public void onNext(FieldValue fieldValue) {
int count = 0;
int key = -1;
if (fieldValue instanceof ReferenceValue) {
ReferenceValue referenceValue = (ReferenceValue) fieldValue;
for (RecordRef id : referenceValue.getReferences()) {
if (id.getFormId().equals(rightFormId)) {
count++;
key = keyId(id);
}
}
}
if (count == 1) {
keys.add(key);
} else {
keys.add(-1);
}
}
use of org.activityinfo.model.type.ReferenceValue in project activityinfo by bedatadriven.
the class RefGenerator method get.
@Override
public FieldValue get() {
TestForm rangeForm;
if (rangeForms.size() == 1) {
rangeForm = rangeForms.get(0);
} else {
rangeForm = rangeForms.get(random.nextInt(rangeForms.size()));
}
int index = random.nextInt(rangeForm.getRecords().size());
RecordRef recordRef = rangeForm.getRecords().get(index).getRef();
return new ReferenceValue(recordRef);
}
Aggregations