use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.
the class SimpleConditionParser method parseEnumCondition.
private static SimpleCondition parseEnumCondition(CompoundExpr node) {
ResourceId fieldId = parseFieldId(node.getValue());
ResourceId enumItem = node.getField().asResourceId();
return new SimpleCondition(fieldId, SimpleOperator.INCLUDES, new EnumValue(enumItem));
}
use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.
the class SkipExpressionTest 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);
}
use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.
the class ActivityFormClassBuilderTest method nullLocationTypeIsNotVisible.
@Test
@OnDataSet("/dbunit/chad-form.db.xml")
public void nullLocationTypeIsNotVisible() {
setUser(9944);
int databaseId = 1470;
FormClass formClass = assertResolves(locator.getFormClass(CuidAdapter.activityFormClass(11218)));
ResourceId locationFieldId = CuidAdapter.field(formClass.getId(), CuidAdapter.LOCATION_FIELD);
assertThat(formClass.getFields(), not(hasItem(withId(locationFieldId))));
// Make sure we can update if location 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.PARTNER_FIELD), CuidAdapter.partnerRef(databaseId, 1734));
instance.set(ResourceId.valueOf("Q0000031845"), new EnumValue(CuidAdapter.attributeField(166617)));
assertResolves(locator.persist(instance));
// Make sure the null location object is visible to legacy code
SiteDTO site = execute(GetSites.byId(CuidAdapter.getLegacyIdFromCuid(instance.getId()))).getData().get(0);
assertThat(site.getLocationName(), equalTo("Chad"));
}
use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.
the class CompactingEnumColumnBuilderTest method buildCompact.
@Test
public void buildCompact() {
EnumItem a = new EnumItem(ResourceId.valueOf("a"), "Enumerated Item A");
EnumItem b = new EnumItem(ResourceId.valueOf("b"), "Enumerated Item B");
EnumItem c = new EnumItem(ResourceId.valueOf("c"), "Enumerated Item C");
EnumType enumType = new EnumType(Cardinality.SINGLE, a, b, c);
CompactingEnumColumnBuilder builder = new CompactingEnumColumnBuilder(new PendingSlot<ColumnView>(), enumType);
for (int i = 0; i < 13; i++) {
builder.onNext(new EnumValue(a.getId()));
builder.onNext(new EnumValue(b.getId()));
builder.onNext(new EnumValue(c.getId()));
builder.onNext(null);
}
ColumnView column8 = builder.build8();
ColumnView column32 = builder.build32();
for (int i = 0; i < column32.numRows(); i++) {
if (!Objects.equals(column8.getString(i), column32.getString(i))) {
throw new AssertionError("Vectors not equal at index " + i);
}
}
assertThat(builder.build(), instanceOf(DiscreteStringColumnView8.class));
}
use of org.activityinfo.model.type.enumerated.EnumValue in project activityinfo by bedatadriven.
the class EnumGenerator method get.
@Override
public FieldValue get() {
double missing = random.nextDouble();
if (missing < probabilityMissing) {
return null;
}
int itemIndex = random.nextInt(enumType.getValues().size());
EnumItem item = enumType.getValues().get(itemIndex);
return new EnumValue(item.getId());
}
Aggregations