Search in sources :

Example 1 with EnumValue

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

the class DropDownEnumWidget method init.

@Override
public void init(FieldValue value) {
    EnumValue enumValue = (EnumValue) value;
    String label = labels.get(enumValue.getValueId());
    comboBox.setText(label);
}
Also used : EnumValue(org.activityinfo.model.type.enumerated.EnumValue)

Example 2 with EnumValue

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

the class FormInputViewModelTest method testPersistence.

@Test
public void testPersistence() {
    Survey survey = setup.getCatalog().getSurvey();
    FormInputViewModelBuilder builder = builderFor(survey);
    // Start with no input
    FormInputModel inputModel = new FormInputModel(new RecordRef(survey.getFormId(), ResourceId.generateId())).update(survey.getGenderFieldId(), new FieldInput(new EnumValue(survey.getMaleId()))).update(survey.getNameFieldId(), new FieldInput(TextValue.valueOf("BOB"))).update(survey.getDobFieldId(), new FieldInput(new LocalDate(1982, 1, 16))).update(survey.getAgeFieldId(), new FieldInput(new Quantity(35)));
    // Verify that it's valid
    FormInputViewModel viewModel = builder.build(inputModel);
    assertThat(viewModel.isValid(), equalTo(true));
    // Now build the update transaction and save!
    Promise<Void> completed = setup.getFormStore().updateRecords(viewModel.buildTransaction());
    assertThat(completed.getState(), equalTo(Promise.State.FULFILLED));
}
Also used : EnumValue(org.activityinfo.model.type.enumerated.EnumValue) RecordRef(org.activityinfo.model.type.RecordRef) Quantity(org.activityinfo.model.type.number.Quantity) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) FieldInput(org.activityinfo.ui.client.input.model.FieldInput) LocalDate(org.activityinfo.model.type.time.LocalDate) Test(org.junit.Test)

Example 3 with EnumValue

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

the class FormInputViewModelTest method testMultipleSelectPersistence.

@Test
public void testMultipleSelectPersistence() {
    IntakeForm intakeForm = setup.getCatalog().getIntakeForm();
    FormInputViewModelBuilder builder = builderFor(intakeForm);
    FormInputModel inputModel = new FormInputModel(new RecordRef(intakeForm.getFormId(), ResourceId.generateId())).update(intakeForm.getOpenDateFieldId(), new LocalDate(2017, 1, 1)).update(intakeForm.getNationalityFieldId(), new EnumValue(intakeForm.getPalestinianId(), intakeForm.getJordanianId()));
    FormInputViewModel viewModel = builder.build(inputModel);
    assertThat(viewModel.isValid(), equalTo(true));
    Promise<Void> completed = setup.getFormStore().updateRecords(viewModel.buildTransaction());
    assertThat(completed.getState(), equalTo(Promise.State.FULFILLED));
}
Also used : EnumValue(org.activityinfo.model.type.enumerated.EnumValue) RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) LocalDate(org.activityinfo.model.type.time.LocalDate) Test(org.junit.Test)

Example 4 with EnumValue

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

the class EnumCheckboxWidget method fireValueChanged.

public void fireValueChanged() {
    EnumValue value = updatedValue();
    valueUpdater.update(value);
    setClearButtonState(value);
}
Also used : EnumValue(org.activityinfo.model.type.enumerated.EnumValue)

Example 5 with EnumValue

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

the class XPathBuilder method appendTo.

private void appendTo(FormulaNode formulaNode, StringBuilder xpath) {
    if (formulaNode instanceof ConstantNode) {
        ConstantNode constantNode = (ConstantNode) formulaNode;
        FieldValue value = constantNode.getValue();
        if (value instanceof BooleanFieldValue) {
            BooleanFieldValue booleanFieldValue = (BooleanFieldValue) value;
            xpath.append(booleanFieldValue.asBoolean() ? TRUE : FALSE);
        } else if (value instanceof EnumValue) {
            String xpathExpr = resolveSymbol(formulaNode);
            xpath.append(xpathExpr);
        } else {
            xpath.append(constantNode.asExpression());
        }
    } else if (formulaNode instanceof FunctionCallNode) {
        FunctionCallNode functionCallNode = (FunctionCallNode) formulaNode;
        List<FormulaNode> arguments = functionCallNode.getArguments();
        FormulaFunction function = functionCallNode.getFunction();
        switch(function.getId()) {
            case "&&":
                appendBinaryInfixTo("and", arguments, xpath);
                break;
            case "==":
                appendBinaryInfixTo("=", arguments, xpath);
                break;
            case "||":
                appendBinaryInfixTo("or", arguments, xpath);
                break;
            case "containsAny":
            case "containsAll":
            case "notContainsAny":
            case "notContainsAll":
                appendFunction(function.getId(), arguments, xpath);
                break;
            case "!=":
            case ">":
            case ">=":
            case "<":
            case "<=":
                appendBinaryInfixTo(function.getId(), arguments, xpath);
                break;
            case "!":
                appendUnaryFunction("not", arguments.get(0), xpath);
                break;
            default:
                throw new XPathBuilderException("Unsupported function " + function.getId());
        }
    } else if (formulaNode instanceof GroupNode) {
        GroupNode groupNode = (GroupNode) formulaNode;
        FormulaNode expr = groupNode.getExpr();
        xpath.append("(");
        appendTo(expr, xpath);
        xpath.append(")");
    } else if (formulaNode instanceof SymbolNode) {
        SymbolNode symbolNode = (SymbolNode) formulaNode;
        String xpathExpr = resolveSymbol(symbolNode);
        xpath.append(xpathExpr);
    } else if (formulaNode instanceof CompoundExpr) {
        CompoundExpr compoundExpr = (CompoundExpr) formulaNode;
        List<FormulaNode> arguments = new ArrayList<>();
        arguments.add(compoundExpr.getValue());
        arguments.add(compoundExpr.getField());
        appendBinaryInfixTo("=", arguments, xpath);
    } else {
        throw new XPathBuilderException("Unknown expr node " + formulaNode);
    }
}
Also used : FormulaFunction(org.activityinfo.model.formula.functions.FormulaFunction) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) ArrayList(java.util.ArrayList) BooleanFieldValue(org.activityinfo.model.type.primitive.BooleanFieldValue) ArrayList(java.util.ArrayList) List(java.util.List) FieldValue(org.activityinfo.model.type.FieldValue) BooleanFieldValue(org.activityinfo.model.type.primitive.BooleanFieldValue)

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