Search in sources :

Example 1 with CuidAdapter.activityFormClass

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);
}
Also used : Response(javax.ws.rs.core.Response) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) FormField(org.activityinfo.model.form.FormField) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 2 with CuidAdapter.activityFormClass

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"))));
}
Also used : CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) Test(org.junit.Test)

Example 3 with CuidAdapter.activityFormClass

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));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) ResourceId(org.activityinfo.model.resource.ResourceId) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) Test(org.junit.Test)

Example 4 with CuidAdapter.activityFormClass

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);
}
Also used : CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) Test(org.junit.Test)

Aggregations

CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)4 Test (org.junit.Test)4 Response (javax.ws.rs.core.Response)1 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)1 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)1 EnumType (org.activityinfo.model.type.enumerated.EnumType)1 QuantityType (org.activityinfo.model.type.number.QuantityType)1 OnDataSet (org.activityinfo.server.database.OnDataSet)1