@Override public Double getExpressionValue( Expression expression, Map<? extends DimensionalItemObject, Double> valueMap, Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days ) { return getExpressionValue( expression, valueMap, constantMap, orgUnitCountMap, days, null ); }
@Override public String generateExpression( String expression, Map<? extends DimensionalItemObject, Double> valueMap, Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days, MissingValueStrategy missingValueStrategy ) { return generateExpression( expression, valueMap, constantMap, orgUnitCountMap, days, missingValueStrategy, null ); }
public static MissingValueStrategy safeValueOf( String value, MissingValueStrategy defaultValue ) { return value != null ? MissingValueStrategy.valueOf( value ) : defaultValue; } }
private void upgradeExpressions() { Collection<Expression> expressions = expressionService.getAllExpressions(); for ( Expression expression : expressions ) { String expr = upgradeExpression( expression.getExpression() ); if ( expr != null ) { expression.setExpression( expr ); expressionService.updateExpression( expression ); } } }
/** * @param uniqueCharacter A unique character to identify the object. * @param expressionString The expression string. */ public static Expression createExpression2( char uniqueCharacter, String expressionString ) { Expression expression = new Expression(); expression.setExpression( expressionString ); expression.setDescription( "Description" + uniqueCharacter ); return expression; }
@Override public SortedMap<ValidationRule, String> getInvalidValidationRuleRightSideExpressions() { SortedMap<ValidationRule, String> invalids = new TreeMap<>(); I18n i18n = i18nManager.getI18n(); for ( ValidationRule rule : validationRuleService.getAllValidationRules() ) { ExpressionValidationOutcome result = expressionService.expressionIsValid( rule.getRightSide().getExpression() ); if ( !result.isValid() ) { invalids.put( rule, i18n.getString(result.getKey()) ); } } return invalids; }
@Override public Double getExpressionValue( Expression expression, Map<? extends DimensionalItemObject, Double> valueMap, Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days, ListMap<String, Double> aggregateMap ) { String expressionString = generateExpression( expression.getExpression(), valueMap, constantMap, orgUnitCountMap, days, expression.getMissingValueStrategy(), aggregateMap ); return expressionString != null ? calculateExpression( expressionString ) : null; }
@Override public Set<DataElement> getDataElements( ValidationRule validationRule ) { Set<DataElement> elements = new HashSet<>(); elements.addAll( expressionService.getDataElementsInExpression( validationRule.getLeftSide().getExpression() ) ); elements.addAll( expressionService.getDataElementsInExpression( validationRule.getRightSide().getExpression() ) ); return elements; }
/** * Gets all DimensionalItemObjects from the expressions and skip test. * * @param expressions set of expressions. * @param skipTest the skip test expression (if any). * @return set of all dimensional item objects found in all expressions. */ private Set<DimensionalItemObject> getDimensionItems( Set<String> expressions, Expression skipTest ) { Set<DimensionalItemObject> operands = new HashSet<>(); for ( String expression : expressions ) { operands.addAll( expressionService.getDimensionalItemObjectsInExpression( expression ) ); } if ( skipTest != null ) { operands.addAll( expressionService.getDimensionalItemObjectsInExpression( skipTest.getExpression() ) ); } return operands; }
/** * Returns the instruction if it is not null or empty, if not returns the * left side description, operator and right side description if not null or * empty, if not returns null. */ public String getInstructionFallback() { if ( instruction != null && !instruction.isEmpty() ) { return instruction; } else if ( leftSide != null && rightSide != null ) { return leftSide.getDescription() + " " + operator.getMathematicalOperator() + " " + rightSide.getDescription(); } else { return null; } }
/** * Evaluates whether an expression is true or false. * * @param leftSide The left side of the expression. * @param operator The expression operator. * @param rightSide The right side of the expression. * @return True if the expression is true, false otherwise. */ public static boolean expressionIsTrue( double leftSide, Operator operator, double rightSide ) { final String expression = leftSide + operator.getMathematicalOperator() + rightSide; return expressionIsTrue( expression ); }
@Override public Set<DataElement> getDataElementsInExpression( String expression ) { return getIdObjectsInExpression( OPERAND_PATTERN, expression, ( m ) -> dataElementService.getDataElement( m.group( GROUP_DATA_ELEMENT ) ) ); }
public static Operator safeValueOf( String name ) { return name != null ? Operator.valueOf( name ) : null; } }
public static Operator fromValue( String value ) { for ( Operator operator : Operator.values() ) { if ( operator.mathematicalOperator.equalsIgnoreCase( value ) ) { return operator; } } return null; }
@Override public Double getIndicatorValue( Indicator indicator, Period period, Map<? extends DimensionalItemObject, Double> valueMap, Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap ) { IndicatorValue value = getIndicatorValueObject( indicator, period, valueMap, constantMap, orgUnitCountMap ); return value != null ? value.getValue() : null; }
@Override @Transactional public int addExpression( Expression expression ) { expressionStore.save( expression ); return expression.getId(); }
@Override public SortedMap<ValidationRule, String> getInvalidValidationRuleLeftSideExpressions() { SortedMap<ValidationRule, String> invalids = new TreeMap<>(); I18n i18n = i18nManager.getI18n(); for ( ValidationRule rule : validationRuleService.getAllValidationRules() ) { ExpressionValidationOutcome result = expressionService.expressionIsValid( rule.getLeftSide().getExpression() ); if ( !result.isValid() ) { invalids.put( rule, i18n.getString(result.getKey()) ); } } return invalids; }
@Override public Set<CategoryOptionCombo> getOptionCombosInExpression( String expression ) { return getIdObjectsInExpression( CATEGORY_OPTION_COMBO_OPERAND_PATTERN, expression, ( m ) -> categoryService.getCategoryOptionCombo( m.group( GROUP_CATEGORORY_OPTION_COMBO ) ) ); }
public static MissingValueStrategy safeValueOf( String value ) { return value != null ? MissingValueStrategy.valueOf( value ) : null; }
@Override public Set<OrganisationUnitGroup> getOrganisationUnitGroupsInExpression( String expression ) { return getIdObjectsInExpression( OU_GROUP_PATTERN, expression, ( m ) -> organisationUnitGroupService.getOrganisationUnitGroup( m.group( GROUP_ID ) ) ); }