use of org.hisp.dhis.expression.Expression in project dhis2-core by dhis2.
the class PredictorDeletionHandler method deleteExpression.
@Override
public void deleteExpression(Expression expression) {
Iterator<Predictor> iterator = predictorService.getAllPredictors().iterator();
while (iterator.hasNext()) {
Predictor predictor = iterator.next();
Expression generator = predictor.getGenerator();
Expression skipTest = predictor.getSampleSkipTest();
if (generator != null && generator.equals(expression) || skipTest != null && skipTest.equals(expression)) {
iterator.remove();
predictorService.deletePredictor(predictor);
}
}
}
use of org.hisp.dhis.expression.Expression in project dhis2-core by dhis2.
the class ValidationRuleServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
periodTypeWeekly = new WeeklyPeriodType();
periodTypeMonthly = new MonthlyPeriodType();
periodTypeYearly = new YearlyPeriodType();
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementC = createDataElement('C');
dataElementD = createDataElement('D');
dataElementE = createDataElement('E');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataElementService.addDataElement(dataElementC);
dataElementService.addDataElement(dataElementD);
dataElementService.addDataElement(dataElementE);
optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
String suffix = SEPARATOR + optionCombo.getUid();
optionCombos = new HashSet<>();
optionCombos.add(optionCombo);
expressionA = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA");
expressionB = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB");
expressionC = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC");
expressionService.addExpression(expressionA);
expressionService.addExpression(expressionB);
expressionService.addExpression(expressionC);
dataSetWeekly = createDataSet('W', periodTypeWeekly);
dataSetMonthly = createDataSet('M', periodTypeMonthly);
dataSetYearly = createDataSet('Y', periodTypeYearly);
sourceA = createOrganisationUnit('A');
sourceB = createOrganisationUnit('B');
sourceC = createOrganisationUnit('C', sourceB);
sourceD = createOrganisationUnit('D', sourceB);
sourceE = createOrganisationUnit('E', sourceD);
sourceF = createOrganisationUnit('F', sourceD);
sourceG = createOrganisationUnit('G');
sourcesA.add(sourceA);
sourcesA.add(sourceB);
allSources.add(sourceA);
allSources.add(sourceB);
allSources.add(sourceC);
allSources.add(sourceD);
allSources.add(sourceE);
allSources.add(sourceF);
allSources.add(sourceG);
dataSetMonthly.addOrganisationUnit(sourceA);
dataSetMonthly.addOrganisationUnit(sourceB);
dataSetMonthly.addOrganisationUnit(sourceC);
dataSetMonthly.addOrganisationUnit(sourceD);
dataSetMonthly.addOrganisationUnit(sourceE);
dataSetMonthly.addOrganisationUnit(sourceF);
dataSetWeekly.addOrganisationUnit(sourceB);
dataSetWeekly.addOrganisationUnit(sourceC);
dataSetWeekly.addOrganisationUnit(sourceD);
dataSetWeekly.addOrganisationUnit(sourceE);
dataSetWeekly.addOrganisationUnit(sourceF);
dataSetWeekly.addOrganisationUnit(sourceG);
dataSetYearly.addOrganisationUnit(sourceB);
dataSetYearly.addOrganisationUnit(sourceC);
dataSetYearly.addOrganisationUnit(sourceD);
dataSetYearly.addOrganisationUnit(sourceE);
dataSetYearly.addOrganisationUnit(sourceF);
organisationUnitService.addOrganisationUnit(sourceA);
organisationUnitService.addOrganisationUnit(sourceB);
organisationUnitService.addOrganisationUnit(sourceC);
organisationUnitService.addOrganisationUnit(sourceD);
organisationUnitService.addOrganisationUnit(sourceE);
organisationUnitService.addOrganisationUnit(sourceF);
organisationUnitService.addOrganisationUnit(sourceG);
dataSetMonthly.addDataSetElement(dataElementA);
dataSetMonthly.addDataSetElement(dataElementB);
dataSetMonthly.addDataSetElement(dataElementC);
dataSetMonthly.addDataSetElement(dataElementD);
dataSetWeekly.addDataSetElement(dataElementE);
dataSetYearly.addDataSetElement(dataElementE);
dataSetService.addDataSet(dataSetWeekly);
dataSetService.addDataSet(dataSetMonthly);
dataSetService.addDataSet(dataSetYearly);
dataElementService.updateDataElement(dataElementA);
dataElementService.updateDataElement(dataElementB);
dataElementService.updateDataElement(dataElementC);
dataElementService.updateDataElement(dataElementD);
dataElementService.updateDataElement(dataElementE);
// deA + deB = deC - deD
validationRuleA = createValidationRule("A", equal_to, expressionA, expressionB, periodTypeMonthly);
// deC - deD > deB * 2
validationRuleB = createValidationRule("B", greater_than, expressionB, expressionC, periodTypeMonthly);
}
use of org.hisp.dhis.expression.Expression in project dhis2-core by dhis2.
the class ValidationRuleStoreTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementC = createDataElement('C');
dataElementD = createDataElement('D');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataElementService.addDataElement(dataElementC);
dataElementService.addDataElement(dataElementD);
dataElements = new HashSet<>();
dataElements.add(dataElementA);
dataElements.add(dataElementB);
dataElements.add(dataElementC);
dataElements.add(dataElementD);
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
optionCombos = new HashSet<>();
optionCombos.add(categoryOptionCombo);
expressionA = new Expression("expressionA", "descriptionA");
expressionB = new Expression("expressionB", "descriptionB");
expressionService.addExpression(expressionB);
expressionService.addExpression(expressionA);
periodType = PeriodType.getAvailablePeriodTypes().iterator().next();
}
use of org.hisp.dhis.expression.Expression 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.expression.Expression in project dhis2-core by dhis2.
the class ValidationRuleGroupStoreTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementC = createDataElement('C');
dataElementD = createDataElement('D');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataElementService.addDataElement(dataElementC);
dataElementService.addDataElement(dataElementD);
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
optionCombos = new HashSet<>();
optionCombos.add(categoryOptionCombo);
expressionA = new Expression("expressionA", "descriptionA");
expressionB = new Expression("expressionB", "descriptionB");
expressionService.addExpression(expressionB);
expressionService.addExpression(expressionA);
periodType = PeriodType.getAvailablePeriodTypes().iterator().next();
}
Aggregations