~dhis2-devs-core/dhis2/trunk

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/RunValidationAction.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:
32
32
import org.apache.commons.logging.Log;
33
33
import org.apache.commons.logging.LogFactory;
34
34
import org.hisp.dhis.common.Grid;
 
35
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 
36
import org.hisp.dhis.dataelement.DataElementCategoryService;
35
37
import org.hisp.dhis.i18n.I18nFormat;
36
38
import org.hisp.dhis.organisationunit.OrganisationUnit;
37
39
import org.hisp.dhis.organisationunit.OrganisationUnitService;
82
84
    {
83
85
        this.organisationUnitService = organisationUnitService;
84
86
    }
85
 
    
 
87
 
 
88
    private DataElementCategoryService dataElementCategoryService;
 
89
 
 
90
    public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService )
 
91
    {
 
92
        this.dataElementCategoryService = dataElementCategoryService;
 
93
    }
 
94
 
86
95
    // -------------------------------------------------------------------------
87
96
    // Input/output
88
97
    // -------------------------------------------------------------------------
118
127
        this.endDate = endDate;
119
128
    }
120
129
 
 
130
    private Integer attributeOptionComboId;
 
131
 
 
132
    public void setAttributeOptionComboId( Integer attributeOptionComboId )
 
133
    {
 
134
        this.attributeOptionComboId = attributeOptionComboId;
 
135
    }
 
136
 
121
137
    private Integer validationRuleGroupId;
122
138
 
123
139
    public void setValidationRuleGroupId( Integer validationRuleGroupId )
124
140
    {
125
141
        this.validationRuleGroupId = validationRuleGroupId;
126
142
    }
127
 
    
 
143
 
128
144
    private boolean sendAlerts;
129
145
 
130
146
    public void setSendAlerts( boolean sendAlerts )
153
169
        return maxExceeded;
154
170
    }
155
171
 
 
172
    private boolean showAttributeCombos;
 
173
 
 
174
    public boolean isShowAttributeCombos()
 
175
    {
 
176
        return showAttributeCombos;
 
177
    }
 
178
 
156
179
    private OrganisationUnit organisationUnit;
157
180
 
158
181
    public OrganisationUnit getOrganisationUnit()
170
193
 
171
194
        Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitWithChildren( organisationUnit.getId() );
172
195
 
173
 
        if ( validationRuleGroupId == -1 )
174
 
        {
175
 
            log.info( "Validating captured data for all rules" );
176
 
 
177
 
            validationResults = new ArrayList<ValidationResult>( validationRuleService.validate( format
178
 
                .parseDate( startDate ), format.parseDate( endDate ), organisationUnits, sendAlerts, format ) );
179
 
        }
180
 
        else
181
 
        {
182
 
            ValidationRuleGroup group = validationRuleService.getValidationRuleGroup( validationRuleGroupId );
183
 
 
184
 
            log.info( "Validating captured data for rules for group: '" + group.getName() + "'" );
185
 
 
186
 
            validationResults = new ArrayList<ValidationResult>( validationRuleService.validate( format
187
 
                .parseDate( startDate ), format.parseDate( endDate ), organisationUnits, group, sendAlerts, format ) );
188
 
        }
 
196
        ValidationRuleGroup group = validationRuleGroupId == -1 ? null : validationRuleService.getValidationRuleGroup( validationRuleGroupId );
 
197
 
 
198
        DataElementCategoryOptionCombo attributeOptionCombo = attributeOptionComboId == null || attributeOptionComboId == -1 ? null : dataElementCategoryService.getDataElementCategoryOptionCombo( attributeOptionComboId );
 
199
 
 
200
        log.info( "Validating data for " + ( group == null ? "all rules" : "group: " + group.getName() ) );
 
201
 
 
202
        validationResults = new ArrayList<ValidationResult>( validationRuleService.validate( format
 
203
                .parseDate( startDate ), format.parseDate( endDate ), organisationUnits, attributeOptionCombo, group, sendAlerts, format ) );
189
204
 
190
205
        maxExceeded = validationResults.size() > ValidationRuleService.MAX_INTERACTIVE_ALERTS;
191
206
 
193
208
 
194
209
        SessionUtils.setSessionVar( KEY_VALIDATIONRESULT, validationResults );
195
210
 
 
211
        computeShowAttributeCombos();
 
212
 
196
213
        log.info( "Validation done" );
197
214
 
198
215
        return SUCCESS;
199
216
    }
 
217
 
 
218
    private void computeShowAttributeCombos()
 
219
    {
 
220
        showAttributeCombos = false;
 
221
 
 
222
        for ( ValidationResult result : validationResults )
 
223
        {
 
224
            if ( !result.getAttributeOptionCombo().isDefault() )
 
225
            {
 
226
                showAttributeCombos = true;
 
227
 
 
228
                break;
 
229
            }
 
230
        }
 
231
    }
200
232
}