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