~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/DefaultValidationRuleService.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:
51
51
import org.hisp.dhis.common.GenericIdentifiableObjectStore;
52
52
import org.hisp.dhis.constant.ConstantService;
53
53
import org.hisp.dhis.dataelement.DataElement;
 
54
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 
55
import org.hisp.dhis.dataelement.DataElementCategoryService;
54
56
import org.hisp.dhis.dataelement.DataElementOperand;
55
57
import org.hisp.dhis.dataentryform.DataEntryFormService;
56
58
import org.hisp.dhis.dataset.DataSet;
129
131
        this.dataValueService = dataValueService;
130
132
    }
131
133
 
 
134
    private DataElementCategoryService dataElementCategoryService;
 
135
 
 
136
    public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService )
 
137
    {
 
138
        this.dataElementCategoryService = dataElementCategoryService;
 
139
    }
 
140
 
132
141
    private ConstantService constantService;
133
142
 
134
143
    public void setConstantService( ConstantService constantService )
169
178
    // -------------------------------------------------------------------------
170
179
 
171
180
    @Override
172
 
    public Collection<ValidationResult> validate( Date startDate, Date endDate, Collection<OrganisationUnit> sources, boolean sendAlerts, I18nFormat format )
173
 
    {
174
 
        return validate( startDate, endDate, sources, null, sendAlerts, format );
175
 
    }
176
 
 
177
 
    @Override
178
181
    public Collection<ValidationResult> validate( Date startDate, Date endDate, Collection<OrganisationUnit> sources,
179
 
        ValidationRuleGroup group, boolean sendAlerts, I18nFormat format )
 
182
        DataElementCategoryOptionCombo attributeCombo, ValidationRuleGroup group, boolean sendAlerts, I18nFormat format )
180
183
    {
181
184
        log.info( "Validate start:" + startDate + " end: " + endDate + " sources: " + sources.size() + " group: " + group );
182
185
        
183
186
        Collection<Period> periods = periodService.getPeriodsBetweenDates( startDate, endDate );
184
187
        Collection<ValidationRule> rules = group != null ? group.getMembers() : getAllValidationRules();
185
188
        
186
 
        Collection<ValidationResult> results = Validator.validate( sources, periods, rules, null,
187
 
            constantService, expressionService, periodService, dataValueService );
 
189
        Collection<ValidationResult> results = Validator.validate( sources, periods, rules, attributeCombo, null,
 
190
            constantService, expressionService, periodService, dataValueService, dataElementCategoryService );
188
191
        
189
192
        formatPeriods( results, format );
190
193
        
207
210
        Collection<ValidationRule> rules = getAllValidationRules();
208
211
        Collection<OrganisationUnit> sources = new HashSet<OrganisationUnit>();
209
212
        sources.add( source );
210
 
        
211
 
        return Validator.validate( sources, periods, rules, null,
212
 
            constantService, expressionService, periodService, dataValueService );
 
213
 
 
214
        return Validator.validate( sources, periods, rules, null, null,
 
215
            constantService, expressionService, periodService, dataValueService, dataElementCategoryService );
213
216
    }
214
217
 
215
218
    @Override
216
 
    public Collection<ValidationResult> validate( DataSet dataSet, Period period, OrganisationUnit source )
 
219
    public Collection<ValidationResult> validate( DataSet dataSet, Period period, OrganisationUnit source,
 
220
        DataElementCategoryOptionCombo attributeCombo )
217
221
    {
218
222
        log.info( "Validate data set: " + dataSet.getName() + " period: " + period.getPeriodType().getName() + " "
219
 
            + period.getStartDate() + " " + period.getEndDate() + " source: " + source.getName() );
220
 
        
 
223
            + period.getStartDate() + " " + period.getEndDate() + " source: " + source.getName()
 
224
            + " attribute combo: " + ( attributeCombo == null ? "(null)" : attributeCombo.getName() ) );
 
225
 
221
226
        Collection<Period> periods = new ArrayList<Period>();
222
227
        periods.add( period );
223
228
 
237
242
        Collection<OrganisationUnit> sources = new HashSet<OrganisationUnit>();
238
243
        sources.add( source );
239
244
        
240
 
        return Validator.validate( sources, periods, rules, null,
241
 
            constantService, expressionService, periodService, dataValueService );
 
245
        return Validator.validate( sources, periods, rules, attributeCombo, null,
 
246
            constantService, expressionService, periodService, dataValueService, dataElementCategoryService );
242
247
    }
243
248
 
244
249
    @Override
263
268
        log.info( "Scheduled monitoring run sources: " + sources.size() + ", periods: " + periods.size() + ", rules:" + rules.size()
264
269
            + ", last run: " + ( lastScheduledRun == null ? "[none]" : lastScheduledRun ) );
265
270
        
266
 
        Collection<ValidationResult> results = Validator.validate( sources, periods, rules,
267
 
            lastScheduledRun, constantService, expressionService, periodService, dataValueService );
 
271
        Collection<ValidationResult> results = Validator.validate( sources, periods, rules, null, lastScheduledRun,
 
272
            constantService, expressionService, periodService, dataValueService, dataElementCategoryService );
268
273
        
269
274
        log.info( "Validation run result count: " + results.size() );
270
275
        
505
510
        {
506
511
            ValidationRule rule = result.getValidationRule();
507
512
            
508
 
            builder.append( result.getSource().getName() ).append( " " ).append( result.getPeriod().getName() ).append( LN ).
 
513
            builder.append( result.getSource().getName() ).append( " " ).append( result.getPeriod().getName() ).
 
514
            append( result.getAttributeOptionCombo().isDefault() ? "" : " " + result.getAttributeOptionCombo().getName() ).append( LN ).
509
515
            append( rule.getName() ).append( " (" ).append( rule.getImportance() ).append( ") " ).append( LN ).
510
516
            append( rule.getLeftSide().getDescription() ).append( ": " ).append( result.getLeftsideValue() ).append( LN ).
511
517
            append( rule.getRightSide().getDescription() ).append( ": " ).append( result.getRightsideValue() ).append( LN ).append( LN );