Search in sources :

Example 21 with EnumValue

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

the class MySqlUpdateTest method testSingleSiteResource.

@Test
public void testSingleSiteResource() throws IOException {
    int databaseId = 1;
    ResourceId formId = CuidAdapter.activityFormClass(1);
    TypedRecordUpdate update = new TypedRecordUpdate();
    update.setUserId(userId);
    update.setFormId(formId);
    update.setRecordId(cuid(SITE_DOMAIN, 1));
    update.set(field(formId, PARTNER_FIELD), CuidAdapter.partnerRef(databaseId, 2));
    update.set(indicatorField(1), new Quantity(900));
    update.set(attributeGroupField(1), new EnumValue(attributeId(CATASTROPHE_NATURELLE_ID)));
    Updater updater = updater();
    updater.execute(update);
    query(CuidAdapter.activityFormClass(1), "_id", "partner", "BENE", "cause");
    assertThat(column("_id"), hasValues(cuid(SITE_DOMAIN, 1), cuid(SITE_DOMAIN, 2), cuid(SITE_DOMAIN, 3)));
    assertThat(column("partner"), hasValues(partnerRecordId(2), partnerRecordId(1), partnerRecordId(2)));
    assertThat(column("BENE"), hasValues(900, 3600, 10000));
    assertThat(column("cause"), hasValues("Catastrophe Naturelle", "Deplacement", "Catastrophe Naturelle"));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) Updater(org.activityinfo.store.query.server.Updater) Quantity(org.activityinfo.model.type.number.Quantity) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Test(org.junit.Test)

Example 22 with EnumValue

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

the class MySqlUpdateTest method addNewAttributes.

@Test
public void addNewAttributes() {
    KeyGenerator generator = new KeyGenerator();
    int activityId = generator.generateInt();
    EnumType enumType = new EnumType(Cardinality.SINGLE, new EnumItem(EnumItem.generateId(), "A"), new EnumItem(EnumItem.generateId(), "B"));
    FormField selectField = new FormField(ResourceId.generateFieldId(EnumType.TYPE_CLASS)).setType(enumType).setLabel("Select");
    FormClass formClass = new FormClass(CuidAdapter.activityFormClass(activityId));
    formClass.setDatabaseId(1);
    formClass.setLabel("New Form");
    formClass.addElement(selectField);
    catalog.createOrUpdateFormSchema(formClass);
    System.out.println("Created activity " + activityId);
    // Now change the enum items
    EnumType updatedType = new EnumType(Cardinality.SINGLE, new EnumItem(EnumItem.generateId(), "C"), new EnumItem(EnumItem.generateId(), "D"));
    selectField.setType(updatedType);
    newRequest();
    catalog.createOrUpdateFormSchema(formClass);
    newRequest();
    // Now try to save a new instance with the value
    FieldValue valueC = new EnumValue(updatedType.getValues().get(0).getId());
    FormInstance newRecord = new FormInstance(CuidAdapter.generateSiteCuid(), formClass.getId());
    newRecord.set(selectField.getId(), new EnumValue(updatedType.getValues().get(0).getId()));
    newRecord.set(CuidAdapter.partnerField(activityId), CuidAdapter.partnerRef(1, 1));
    executeUpdate(newRecord);
    // Ensure that the select field has been saved
    FormRecord saved = catalog.getForm(formClass.getId()).get().get(newRecord.getId()).get();
    FormInstance savedInstance = FormInstance.toFormInstance(formClass, saved);
    assertThat(savedInstance.get(selectField.getId()), equalTo(valueC));
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) FormClass(org.activityinfo.model.form.FormClass) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) FieldValue(org.activityinfo.model.type.FieldValue) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormInstance(org.activityinfo.model.form.FormInstance) FormRecord(org.activityinfo.model.form.FormRecord) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) FormField(org.activityinfo.model.form.FormField) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) Test(org.junit.Test)

Example 23 with EnumValue

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

the class RadioGroupWidget method init.

@Override
public void init(FieldValue value) {
    EnumValue enumValue = (EnumValue) value;
    CheckBox checkBox = radios.get(enumValue.getValueId());
    checkBox.setValue(true);
}
Also used : EnumValue(org.activityinfo.model.type.enumerated.EnumValue) CheckBox(com.sencha.gxt.widget.core.client.form.CheckBox)

Example 24 with EnumValue

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

the class CheckBoxGroupWidget method init.

@Override
public void init(FieldValue value) {
    EnumValue enumValue = (EnumValue) value;
    for (ResourceId itemId : enumValue.getResourceIds()) {
        CheckBox checkBox = checkBoxes.get(itemId);
        checkBox.setValue(true);
    }
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) CheckBox(com.sencha.gxt.widget.core.client.form.CheckBox)

Example 25 with EnumValue

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

the class EnumFieldImporter method persistSingleValuedEnum.

private boolean persistSingleValuedEnum(SourceRow row, FormInstance instance) {
    if (validateSingleValuedEnum(row).isPersistable()) {
        final Set<ResourceId> result = Sets.newHashSet();
        String value = sources.get(0).getValue(row);
        for (EnumItem enumItem : enumType.getValues()) {
            if (enumItem.getLabel().equalsIgnoreCase(value)) {
                result.add(enumItem.getId());
                break;
            }
        }
        if (!result.isEmpty()) {
            instance.set(targets.get(0).getFormField().getId(), new EnumValue(result));
            return true;
        }
    }
    return false;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

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