~dhis2-devs-core/dhis2/trunk

« back to all changes in this revision

Viewing changes to dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/Validator.java

  • Committer: jimgrace at gmail
  • Date: 2014-05-18 00:49:40 UTC
  • Revision ID: jimgrace@gmail.com-20140518004940-wbw1bxjhfdmf33yl
Support attribute categories in validation

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
import java.util.concurrent.TimeUnit;
36
36
 
37
37
import org.hisp.dhis.constant.ConstantService;
 
38
import org.hisp.dhis.dataelement.DataElementCategoryOption;
 
39
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 
40
import org.hisp.dhis.dataelement.DataElementCategoryService;
38
41
import org.hisp.dhis.datavalue.DataValueService;
39
42
import org.hisp.dhis.expression.ExpressionService;
40
43
import org.hisp.dhis.organisationunit.OrganisationUnit;
57
60
     * 
58
61
     * @param sources the organisation units in which to run the validation rules
59
62
     * @param periods the periods of data to check
 
63
     * @param attributeCombo the attribute combo to check (if restricted)
60
64
     * @param rules the ValidationRules to evaluate
61
 
     * @param runType whether this is an INTERACTIVE or SCHEDULED run
62
65
     * @param lastScheduledRun date/time of the most recent successful
63
66
     *        scheduled monitoring run (needed only for scheduled runs)
64
67
     * @param constantService Constant Service reference
65
68
     * @param expressionService Expression Service reference
66
69
     * @param periodService Period Service reference
67
70
     * @param dataValueService Data Value Service reference
 
71
     * @param dataElementCategoryService Data Element Category Service reference
68
72
     * @return a collection of any validations that were found
69
73
     */
70
 
    public static Collection<ValidationResult> validate( Collection<OrganisationUnit> sources,
71
 
        Collection<Period> periods, Collection<ValidationRule> rules, Date lastScheduledRun,
72
 
        ConstantService constantService, ExpressionService expressionService, PeriodService periodService, DataValueService dataValueService )
 
74
    public static Collection<ValidationResult> validate( Collection<OrganisationUnit> sources, Collection<Period> periods,
 
75
        Collection<ValidationRule> rules, DataElementCategoryOptionCombo attributeCombo, Date lastScheduledRun,
 
76
        ConstantService constantService, ExpressionService expressionService, PeriodService periodService,
 
77
        DataValueService dataValueService, DataElementCategoryService dataElementCategoryService )
73
78
    {
74
 
        ValidationRunContext context = ValidationRunContext.getNewValidationRunContext( sources, periods, rules,
75
 
            constantService.getConstantMap(), ValidationRunType.SCHEDULED, lastScheduledRun,
76
 
            expressionService, periodService, dataValueService );
 
79
        ValidationRunContext context = ValidationRunContext.getNewValidationRunContext( sources, periods,
 
80
            attributeCombo, rules, constantService.getConstantMap(), ValidationRunType.SCHEDULED, lastScheduledRun,
 
81
            expressionService, periodService, dataValueService, dataElementCategoryService );
77
82
 
78
83
        int threadPoolSize = getThreadPoolSize( context );
79
84
        ExecutorService executor = Executors.newFixedThreadPool( threadPoolSize );
97
102
        {
98
103
            executor.shutdownNow();
99
104
        }
100
 
        
 
105
 
 
106
        reloadAttributeOptionCombos( context.getValidationResults(), dataElementCategoryService );
 
107
 
101
108
        return context.getValidationResults();
102
109
    }
103
110
    
123
130
 
124
131
        return threadPoolSize;
125
132
    }
 
133
 
 
134
    /**
 
135
     * Reload attribute category option combos into this Hibernate context.
 
136
     *
 
137
     * @param results
 
138
     * @param dataElementCategoryService
 
139
     */
 
140
    private static void reloadAttributeOptionCombos( Collection<ValidationResult> results, DataElementCategoryService dataElementCategoryService )
 
141
    {
 
142
        for ( ValidationResult result : results )
 
143
        {
 
144
            result.setAttributeOptionCombo( dataElementCategoryService.getDataElementCategoryOptionCombo( result.getAttributeOptionCombo().getId() ) );
 
145
        }
 
146
    }
126
147
}