use of org.hisp.dhis.expression.ExpressionParams in project dhis2-core by dhis2.
the class VectorFunction method visitSampledPeriods.
/**
* Visits each of the sample periods and compiles a list of the double
* values produced.
*/
private List<Double> visitSampledPeriods(ExprContext ctx, CommonExpressionVisitor visitor) {
ExpressionParams params = visitor.getParams();
ExpressionState state = visitor.getState();
List<Double> values = new ArrayList<>();
for (Period p : params.getSamplePeriods()) {
state.setItemsFound(0);
state.setItemValuesFound(0);
Map<DimensionalItemObject, Object> valueMap = firstNonNull(params.getPeriodValueMap().get(p), Collections.emptyMap());
Double value = visitWithValueMap(ctx, visitor, valueMap);
if ((params.getMissingValueStrategy() == SKIP_IF_ANY_VALUE_MISSING && state.getItemValuesFound() < state.getItemsFound()) || (params.getMissingValueStrategy() == SKIP_IF_ALL_VALUES_MISSING && state.getItemsFound() != 0 && state.getItemValuesFound() == 0)) {
value = null;
}
if (value != null) {
values.add(value);
}
}
return values;
}
use of org.hisp.dhis.expression.ExpressionParams in project dhis2-core by dhis2.
the class DataValidationTaskTest method mockExpressionService.
private void mockExpressionService(Expression expression, Map<DimensionalItemObject, Object> vals, Double val) {
ExpressionParams params = ExpressionParams.builder().expression(expression.getExpression()).parseType(VALIDATION_RULE_EXPRESSION).valueMap(vals).missingValueStrategy(expression.getMissingValueStrategy()).orgUnit(ouA).build();
when(expressionService.getExpressionValue(params.toBuilder().days(p1.getDaysInPeriod()).build())).thenReturn(val);
when(expressionService.getExpressionValue(params.toBuilder().days(p2.getDaysInPeriod()).build())).thenReturn(val);
when(expressionService.getExpressionValue(params.toBuilder().days(p3.getDaysInPeriod()).build())).thenReturn(val);
}
use of org.hisp.dhis.expression.ExpressionParams in project dhis2-core by dhis2.
the class VectorFunction method visitWithValueMap.
/**
* Visits a subtree with an explicit valueMap.
*/
private Double visitWithValueMap(ExprContext ctx, CommonExpressionVisitor visitor, Map<DimensionalItemObject, Object> valueMap) {
ExpressionParams savedParams = visitor.getParams();
ExpressionParams params = visitor.getParams().toBuilder().valueMap(valueMap).build();
visitor.setParams(params);
Double value = castDouble(visitor.visit(ctx));
visitor.setParams(savedParams);
return value;
}
Aggregations