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);
}
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));
}
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));
}
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);
}
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);
}
}
Aggregations