Search in sources :

Example 16 with Expression

use of org.hisp.dhis.expression.Expression in project dhis2-core by dhis2.

the class PredictorObjectBundleHook method preCreate.

@Override
public void preCreate(IdentifiableObject object, ObjectBundle bundle) {
    if (!Predictor.class.isInstance(object)) {
        return;
    }
    Predictor predictor = (Predictor) object;
    Expression skipTest = predictor.getSampleSkipTest();
    preheatService.connectReferences(predictor.getGenerator(), bundle.getPreheat(), bundle.getPreheatIdentifier());
    if (skipTest != null) {
        preheatService.connectReferences(skipTest, bundle.getPreheat(), bundle.getPreheatIdentifier());
    }
    sessionFactory.getCurrentSession().save(predictor.getGenerator());
    if (skipTest != null) {
        sessionFactory.getCurrentSession().save(skipTest);
    }
    if (predictor.getPeriodType() != null) {
        PeriodType periodType = bundle.getPreheat().getPeriodTypeMap().get(predictor.getPeriodType().getName());
        predictor.setPeriodType(periodType);
    }
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Predictor(org.hisp.dhis.predictor.Predictor) Expression(org.hisp.dhis.expression.Expression)

Example 17 with Expression

use of org.hisp.dhis.expression.Expression in project dhis2-core by dhis2.

the class PredictorObjectBundleHook method preUpdate.

@Override
public void preUpdate(IdentifiableObject object, IdentifiableObject persistedObject, ObjectBundle bundle) {
    if (!Predictor.class.isInstance(object)) {
        return;
    }
    Predictor predictor = (Predictor) object;
    Expression skipTest = predictor.getSampleSkipTest();
    preheatService.connectReferences(predictor.getGenerator(), bundle.getPreheat(), bundle.getPreheatIdentifier());
    if (skipTest != null) {
        preheatService.connectReferences(skipTest, bundle.getPreheat(), bundle.getPreheatIdentifier());
    }
    sessionFactory.getCurrentSession().save(predictor.getGenerator());
    if (skipTest != null) {
        sessionFactory.getCurrentSession().save(skipTest);
    }
    if (predictor.getPeriodType() != null) {
        PeriodType periodType = bundle.getPreheat().getPeriodTypeMap().get(predictor.getPeriodType().getName());
        predictor.setPeriodType(periodType);
    }
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Predictor(org.hisp.dhis.predictor.Predictor) Expression(org.hisp.dhis.expression.Expression)

Example 18 with Expression

use of org.hisp.dhis.expression.Expression in project dhis2-core by dhis2.

the class ExpressionUpgrader method upgradeExpressions.

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);
        }
    }
}
Also used : Expression(org.hisp.dhis.expression.Expression)

Aggregations

Expression (org.hisp.dhis.expression.Expression)18 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)5 DataElement (org.hisp.dhis.dataelement.DataElement)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)2 DhisTest (org.hisp.dhis.DhisTest)2 IntegrationTest (org.hisp.dhis.IntegrationTest)2 MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)2 PeriodType (org.hisp.dhis.period.PeriodType)2 Predictor (org.hisp.dhis.predictor.Predictor)2 CurrentUserService (org.hisp.dhis.user.CurrentUserService)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 ArrayList (java.util.ArrayList)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)1 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)1 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)1