use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.
the class SimpleFormPanel method setValue.
public Promise<Void> setValue(FormInstance instance) {
model.setWorkingRootInstance(instance);
List<Promise<Void>> tasks = Lists.newArrayList();
for (FieldContainer container : widgetCreator.getContainers().values()) {
FormField field = container.getField();
FieldValue value = model.getWorkingRootInstance().get(field.getId(), field.getType());
if (value != null && value.getTypeClass() == field.getType().getTypeClass()) {
tasks.add(container.getFieldWidget().setValue(value));
} else {
container.getFieldWidget().clearValue();
}
container.setValid();
}
return Promise.waitAll(tasks).then(new Function<Void, Void>() {
@Override
public Void apply(Void input) {
// invoke relevance handler once values are set
relevanceHandler.onValueChange();
return null;
}
});
}
use of org.activityinfo.model.type.FieldValue 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);
}
}
use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.
the class DateComponentFunction method apply.
@Override
public final FieldValue apply(List<FieldValue> arguments) {
checkArity(arguments, 1);
FieldValue argument = arguments.get(0);
if (!(argument instanceof LocalDate)) {
throw new FormulaSyntaxException("Expected date argument");
}
LocalDate date = (LocalDate) argument;
return new Quantity(apply(date));
}
use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.
the class SimpleConditionParser method parseBinary.
private static SimpleCondition parseBinary(FunctionCallNode call) {
ResourceId fieldId = parseFieldId(call.getArgument(0));
SimpleOperator op = parseOp(call.getFunction());
FieldValue fieldValue = parseFieldValue(call.getArgument(1));
return new SimpleCondition(fieldId, op, fieldValue);
}
use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.
the class StatFunction method apply.
@Override
public final FieldValue apply(List<FieldValue> arguments) {
double[] argumentValues = new double[arguments.size()];
for (int i = 0; i < arguments.size(); i++) {
FieldValue argument = arguments.get(i);
if (argument instanceof Quantity) {
Quantity quantity = (Quantity) argument;
argumentValues[i] = quantity.getValue();
} else {
argumentValues[i] = Double.NaN;
}
}
double result = compute(argumentValues, 0, argumentValues.length);
return new Quantity(result);
}
Aggregations