use of org.activityinfo.model.legacy.CuidAdapter.activityFormClass in project activityinfo by bedatadriven.
the class XFormResourceTest method invalidExpr.
@Test
@OnDataSet("/dbunit/invalid-relevance.db.xml")
public void invalidExpr() throws Exception {
setUser(USER_ID);
FormClass formClass = resourceLocator.getFormClass(CuidAdapter.activityFormClass(ACTIVITY_ID));
FormField field = new FormField(ResourceId.generateFieldId(QuantityType.TYPE_CLASS));
field.setLabel("Question");
field.setType(new QuantityType());
field.setRelevanceConditionExpression("DELETED_FIELD=1");
formClass.addElement(field);
resourceLocator.persist(formClass);
Response form = this.formResource.form(ACTIVITY_ID);
validate(form);
}
use of org.activityinfo.model.legacy.CuidAdapter.activityFormClass in project activityinfo by bedatadriven.
the class ActivityTest method createAttributeGroup.
@Test
public void createAttributeGroup() {
FormClass formClass = assertResolves(locator.getFormClass(CuidAdapter.activityFormClass(1)));
FormField newField = new FormField(ResourceId.generateFieldId(EnumType.TYPE_CLASS));
newField.setLabel("New Group");
EnumItem yes = new EnumItem(EnumItem.generateId(), "Yes");
EnumItem no = new EnumItem(EnumItem.generateId(), "No");
newField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(yes, no)));
formClass.getElements().add(newField);
locator.persist(formClass);
// verify that it appears as attribute group
ActivityFormDTO activity = getActivity(1);
AttributeGroupDTO group = findGroup(activity, "New Group");
assertThat(group.isMultipleAllowed(), equalTo(false));
assertThat(group.getAttributes(), hasSize(2));
assertThat(group.getAttributes().get(0), hasProperty("name", Matchers.equalTo("Yes")));
assertThat(group.getAttributes().get(1), hasProperty("name", Matchers.equalTo("No")));
// Now update the same attribute group and a value
newField.setLabel("Do you like ice cream?");
yes.setLabel("Oui");
no.setLabel("Non");
locator.persist(formClass);
group = findGroup(getActivity(1), "Do you like ice cream?");
assertThat(group.isMultipleAllowed(), equalTo(false));
assertThat(group.getAttributes(), contains(hasProperty("name", Matchers.equalTo("Oui")), hasProperty("name", Matchers.equalTo("Non"))));
// Remove one of our new enum values
newField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(yes)));
locator.persist(formClass);
group = findGroup(getActivity(1), "Do you like ice cream?");
assertThat(group.isMultipleAllowed(), equalTo(false));
assertThat(group.getAttributes(), contains(hasProperty("name", Matchers.equalTo("Oui"))));
}
use of org.activityinfo.model.legacy.CuidAdapter.activityFormClass in project activityinfo by bedatadriven.
the class ActivityTest method newFormWithoutDates.
@Test
public void newFormWithoutDates() {
// Create an activity in the same way that the Design Presenter does...
int databaseId = 1;
ActivityDTO newEntity = new ActivityDTO();
newEntity.setName("My Form");
newEntity.set("databaseId", databaseId);
newEntity.set("classicView", false);
newEntity.set("reportingFrequency", ActivityFormDTO.REPORT_ONCE);
newEntity.set("locationTypeId", 2);
newEntity.set("published", 0);
CreateResult createResult = execute(new CreateEntity(newEntity));
// Some definitions...
int activityId = createResult.getNewId();
ResourceId formId = CuidAdapter.activityFormClass(activityId);
ResourceId startDateId = CuidAdapter.field(formId, CuidAdapter.START_DATE_FIELD);
ResourceId endDateId = CuidAdapter.field(formId, CuidAdapter.END_DATE_FIELD);
// Now delete the date fields in the form designer...
FormClass formClass = assertResolves(locator.getFormClass(formId));
formClass.removeField(startDateId);
formClass.removeField(endDateId);
assertResolves(locator.persist(formClass));
// Now verify that the form class no longer has the date fields
formClass = assertResolves(locator.getFormClass(formId));
assertThat(formClass.getFields(), not(hasItem(withId(startDateId))));
assertThat(formClass.getFields(), not(hasItem(withId(endDateId))));
// Now submit a new entry without dates...
FormInstance newInstance = new FormInstance(ResourceId.generateSubmissionId(formId), formId);
newInstance.set(CuidAdapter.partnerField(activityId), CuidAdapter.partnerRef(databaseId, 1));
assertResolves(locator.persist(newInstance));
}
use of org.activityinfo.model.legacy.CuidAdapter.activityFormClass in project activityinfo by bedatadriven.
the class ActivityTest method deleteAttributeGroup.
@Test
public void deleteAttributeGroup() {
FormClass formClass = assertResolves(locator.getFormClass(CuidAdapter.activityFormClass(1)));
// Remove attribute
ListIterator<FormElement> it = formClass.getElements().listIterator();
while (it.hasNext()) {
FormElement element = it.next();
if (element.getLabel().equals("Cause")) {
it.remove();
}
}
assertResolves(locator.persist(formClass));
// Ensure deleted
ActivityFormDTO form = execute(new GetActivityForm(1));
assertTrue("Cause attribute is gone", form.getAttributeGroupById(1) == null);
}
Aggregations