Search in sources :

Example 36 with RecordRef

use of org.activityinfo.model.type.RecordRef 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 37 with RecordRef

use of org.activityinfo.model.type.RecordRef 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));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) FormInstance(org.activityinfo.model.form.FormInstance) FormField(org.activityinfo.model.form.FormField) LocalDate(org.activityinfo.model.type.time.LocalDate) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 38 with RecordRef

use of org.activityinfo.model.type.RecordRef 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());
}
Also used : ForeignKeyBuilder(org.activityinfo.store.query.server.join.ForeignKeyBuilder) ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) ForeignKey(org.activityinfo.store.query.shared.columns.ForeignKey) Test(org.junit.Test)

Example 39 with RecordRef

use of org.activityinfo.model.type.RecordRef 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);
    }
}
Also used : ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef)

Example 40 with RecordRef

use of org.activityinfo.model.type.RecordRef 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);
}
Also used : ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef)

Aggregations

RecordRef (org.activityinfo.model.type.RecordRef)66 Test (org.junit.Test)31 ResourceId (org.activityinfo.model.resource.ResourceId)26 ReferenceValue (org.activityinfo.model.type.ReferenceValue)26 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)14 FormInstance (org.activityinfo.model.form.FormInstance)7 FormTree (org.activityinfo.model.formTree.FormTree)7 LocalDate (org.activityinfo.model.type.time.LocalDate)7 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)6 Optional (com.google.common.base.Optional)5 FieldValue (org.activityinfo.model.type.FieldValue)5 FieldInput (org.activityinfo.ui.client.input.model.FieldInput)5 FormClass (org.activityinfo.model.form.FormClass)4 ResultSet (java.sql.ResultSet)3 FormField (org.activityinfo.model.form.FormField)3 RecordTree (org.activityinfo.model.formTree.RecordTree)3 ColumnSet (org.activityinfo.model.query.ColumnSet)3 ColumnView (org.activityinfo.model.query.ColumnView)3 RecordTransaction (org.activityinfo.model.resource.RecordTransaction)3 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)3