Search in sources :

Example 16 with EnumValue

use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.

the class CurlExamplesGenerator method getRecord.

public static Example getRecord() {
    ResourceId formId = ResourceId.generateId();
    ResourceId recordId = ResourceId.generateId();
    FormRecord.Builder record = new FormRecord.Builder();
    record.setFormId(formId);
    record.setRecordId(recordId);
    record.setFieldValue(ResourceId.generateId(), TextValue.valueOf("Text Value"));
    record.setFieldValue(ResourceId.generateId(), new Quantity(1500));
    record.setFieldValue(ResourceId.generateId(), new LocalDate(2016, 10, 5));
    record.setFieldValue(ResourceId.generateId(), new GeoPoint(52.078663, 4.288788));
    record.setFieldValue(ResourceId.generateId(), new EnumValue(ResourceId.generateId()));
    return new Example(String.format("curl https://www.activityinfo.org/resources/form/%s/record/%s", formId, recordId), record.build().toJson());
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) ResourceId(org.activityinfo.model.resource.ResourceId) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) Quantity(org.activityinfo.model.type.number.Quantity) FormRecord(org.activityinfo.model.form.FormRecord) LocalDate(org.activityinfo.model.type.time.LocalDate)

Example 17 with EnumValue

use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.

the class XPathBuilder method resolveSymbol.

private String resolveSymbol(ConstantNode constantNode) throws XSymbolException {
    String resolved;
    if (constantNode.getType() instanceof EnumType) {
        EnumValue enumValue = (EnumValue) constantNode.getValue();
        resolved = symbolHandler.resolveSymbol(enumValue.getValueId().asString());
    } else {
        resolved = symbolHandler.resolveSymbol(constantNode.getValue().toString());
    }
    return resolved;
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumValue(org.activityinfo.model.type.enumerated.EnumValue)

Example 18 with EnumValue

use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.

the class RelevanceExpressionTest method enumType.

@Test
public void enumType() {
    FormInstance instance = new FormInstance(ResourceId.generateSubmissionId(formClass), formClass.getId());
    instance.set(GENDER_FIELD_ID, enumFieldValue(GENDER_FIELD_ID, "Male"));
    eval(String.format("{%s}=={%s}", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), true, instance);
    eval(String.format("{%s}!={%s}", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), false, instance);
    eval(String.format("{%s}=={%s}", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    eval(String.format("({%s}=={%s})&&({%s}!={%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId(), GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), true, instance);
    // contains all
    eval(String.format("containsAll({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), true, instance);
    eval(String.format("containsAll({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    eval(String.format("containsAll({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId(), enumValue(GENDER_FIELD_ID, "Female").getId()), true, instance);
    eval(String.format("containsAny({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), true, instance);
    eval(String.format("containsAny({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId(), enumValue(GENDER_FIELD_ID, "Female").getId()), true, instance);
    eval(String.format("containsAny({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    // enum with 2 values
    instance.set(GENDER_FIELD_ID, new EnumValue(enumValue(GENDER_FIELD_ID, "Male").getId(), enumValue(GENDER_FIELD_ID, "Female").getId()));
    eval(String.format("containsAny({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), true, instance);
    eval(String.format("containsAll({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId(), enumValue(GENDER_FIELD_ID, "Female").getId()), true, instance);
    eval(String.format("notContainsAll({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), true, instance);
    eval(String.format("notContainsAll({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    eval(String.format("notContainsAny({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), false, instance);
    eval(String.format("notContainsAny({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    instance.set(GENDER_FIELD_ID, new EnumValue());
    eval(String.format("{%s}=={%s}", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    eval(String.format("containsAll({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), false, instance);
    eval(String.format("containsAll({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
    eval(String.format("containsAny({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Male").getId()), false, instance);
    eval(String.format("containsAny({%s},{%s})", GENDER_FIELD_ID.asString(), enumValue(GENDER_FIELD_ID, "Female").getId()), false, instance);
}
Also used : EnumValue(org.activityinfo.model.type.enumerated.EnumValue) FormInstance(org.activityinfo.model.form.FormInstance) Test(org.junit.Test)

Example 19 with EnumValue

use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.

the class CreateSiteTest method persistSite.

@Test
public void persistSite() {
    ResourceId locationClassId = CuidAdapter.locationFormClass(1);
    FormInstance location = new FormInstance(CuidAdapter.generateLocationCuid(), locationClassId);
    location.set(field(locationClassId, CuidAdapter.NAME_FIELD), "Virunga");
    location.set(field(locationClassId, CuidAdapter.AXE_FIELD), "Goma - Rutshuru");
    location.set(field(locationClassId, CuidAdapter.GEOMETRY_FIELD), new GeoPoint(27.432, 1.23));
    assertResolves(locator.persist(location));
    int databaseId = 1;
    ResourceId formClassId = CuidAdapter.activityFormClass(1);
    FormInstance instance = new FormInstance(CuidAdapter.generateSiteCuid(), formClassId);
    instance.set(field(formClassId, LOCATION_FIELD), new ReferenceValue(new RecordRef(locationClassId, location.getId())));
    instance.set(field(formClassId, PARTNER_FIELD), CuidAdapter.partnerRef(databaseId, 1));
    instance.set(field(formClassId, START_DATE_FIELD), new LocalDate(2008, 12, 1));
    instance.set(field(formClassId, END_DATE_FIELD), new LocalDate(2009, 1, 3));
    instance.set(indicatorField(1), 996.0);
    instance.set(attributeField(1), new EnumValue(CuidAdapter.attributeId(1), CuidAdapter.attributeField(2)));
    instance.set(commentsField(1), "objection!");
    instance.set(field(formClassId, PROJECT_FIELD), CuidAdapter.projectRef(PROJECT_DOMAIN, 1));
    assertResolves(locator.persist(instance));
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) RecordRef(org.activityinfo.model.type.RecordRef) FormInstance(org.activityinfo.model.form.FormInstance) LocalDate(org.activityinfo.model.type.time.LocalDate) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) Test(org.junit.Test)

Example 20 with EnumValue

use of org.activityinfo.model.type.enumerated.EnumValue 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)

Aggregations

EnumValue (org.activityinfo.model.type.enumerated.EnumValue)28 Test (org.junit.Test)13 ResourceId (org.activityinfo.model.resource.ResourceId)11 FormInstance (org.activityinfo.model.form.FormInstance)6 RecordRef (org.activityinfo.model.type.RecordRef)6 LocalDate (org.activityinfo.model.type.time.LocalDate)6 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)5 FieldValue (org.activityinfo.model.type.FieldValue)4 EnumType (org.activityinfo.model.type.enumerated.EnumType)4 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)4 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)4 FormClass (org.activityinfo.model.form.FormClass)3 Quantity (org.activityinfo.model.type.number.Quantity)3 CheckBox (com.sencha.gxt.widget.core.client.form.CheckBox)2 FormRecord (org.activityinfo.model.form.FormRecord)2 ReferenceValue (org.activityinfo.model.type.ReferenceValue)2 FieldInput (org.activityinfo.ui.client.input.model.FieldInput)2 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1