use of org.hisp.dhis.validation.ValidationRule in project dhis2-core by dhis2.
the class DefaultCsvImportService method validationRulesFromCsv.
private List<ValidationRule> validationRulesFromCsv(CsvReader reader) throws IOException {
List<ValidationRule> list = new ArrayList<>();
while (reader.readRecord()) {
String[] values = reader.getValues();
if (values != null && values.length > 0) {
Expression leftSide = new Expression();
Expression rightSide = new Expression();
ValidationRule object = new ValidationRule();
setIdentifiableObject(object, values);
object.setDescription(getSafe(values, 3, null, 255));
object.setInstruction(getSafe(values, 4, null, 255));
object.setImportance(Importance.valueOf(getSafe(values, 5, Importance.MEDIUM.toString(), 255)));
// Left here so nobody wonders what field 6 is for
// object.setRuleType( RuleType.valueOf( getSafe( values, 6, RuleType.VALIDATION.toString(), 255 ) ) );
object.setOperator(Operator.safeValueOf(getSafe(values, 7, Operator.equal_to.toString(), 255)));
object.setPeriodType(PeriodType.getByNameIgnoreCase(getSafe(values, 8, MonthlyPeriodType.NAME, 255)));
leftSide.setExpression(getSafe(values, 9, null, 255));
leftSide.setDescription(getSafe(values, 10, null, 255));
leftSide.setMissingValueStrategy(MissingValueStrategy.safeValueOf(getSafe(values, 11, MissingValueStrategy.NEVER_SKIP.toString(), 50)));
rightSide.setExpression(getSafe(values, 12, null, 255));
rightSide.setDescription(getSafe(values, 13, null, 255));
rightSide.setMissingValueStrategy(MissingValueStrategy.safeValueOf(getSafe(values, 14, MissingValueStrategy.NEVER_SKIP.toString(), 50)));
object.setLeftSide(leftSide);
object.setRightSide(rightSide);
object.setAutoFields();
list.add(object);
}
}
return list;
}
use of org.hisp.dhis.validation.ValidationRule in project dhis2-core by dhis2.
the class ValidationRuleObjectBundleHook method preCreate.
@Override
public void preCreate(IdentifiableObject object, ObjectBundle bundle) {
if (!ValidationRule.class.isInstance(object)) {
return;
}
ValidationRule validationRule = (ValidationRule) object;
if (validationRule.getPeriodType() != null) {
PeriodType periodType = bundle.getPreheat().getPeriodTypeMap().get(validationRule.getPeriodType().getName());
validationRule.setPeriodType(periodType);
}
}
use of org.hisp.dhis.validation.ValidationRule in project dhis2-core by dhis2.
the class FormUtilsImpl method getValidationRuleViolations.
@Override
public List<String> getValidationRuleViolations(OrganisationUnit organisationUnit, DataSet dataSet, Period period) {
List<ValidationResult> validationRuleResults = new ArrayList<>(validationService.startInteractiveValidationAnalysis(dataSet, period, organisationUnit, null));
List<String> validationRuleViolations = new ArrayList<>(validationRuleResults.size());
for (ValidationResult result : validationRuleResults) {
ValidationRule rule = result.getValidationRule();
StringBuilder sb = new StringBuilder();
sb.append(expressionService.getExpressionDescription(rule.getLeftSide().getExpression()));
sb.append(" ").append(rule.getOperator().getMathematicalOperator()).append(" ");
sb.append(expressionService.getExpressionDescription(rule.getRightSide().getExpression()));
validationRuleViolations.add(sb.toString());
}
return validationRuleViolations;
}
use of org.hisp.dhis.validation.ValidationRule in project dhis2-core by dhis2.
the class DhisConvenienceTest method createValidationRule.
/**
* @param uniqueCharacter A unique character to identify the object.
* @param operator The operator.
* @param leftSide The left side expression.
* @param rightSide The right side expression.
* @param periodType The period-type.
*/
public static ValidationRule createValidationRule(String uniqueCharacter, Operator operator, Expression leftSide, Expression rightSide, PeriodType periodType) {
Assert.notNull(leftSide, "Left side expression must be specified");
Assert.notNull(rightSide, "Rigth side expression must be specified");
ValidationRule validationRule = new ValidationRule();
validationRule.setAutoFields();
validationRule.setName("ValidationRule" + uniqueCharacter);
validationRule.setDescription("Description" + uniqueCharacter);
validationRule.setOperator(operator);
validationRule.setLeftSide(leftSide);
validationRule.setRightSide(rightSide);
validationRule.setPeriodType(periodType);
return validationRule;
}
Aggregations