1
package org.hisp.dhis.validationrule.action;
4
* Copyright (c) 2004-2007, University of Oslo
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
* * Neither the name of the HISP project nor the names of its contributors may
15
* be used to endorse or promote products derived from this software without
16
* specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
import java.util.ArrayList;
31
import java.util.Collection;
32
import java.util.Collections;
33
import java.util.HashSet;
34
import java.util.List;
36
import org.hisp.dhis.i18n.I18nFormat;
37
import org.hisp.dhis.organisationunit.OrganisationUnit;
38
import org.hisp.dhis.organisationunit.OrganisationUnitService;
39
import org.hisp.dhis.oust.manager.SelectionTreeManager;
40
import org.hisp.dhis.source.Source;
41
import org.hisp.dhis.util.SessionUtils;
42
import org.hisp.dhis.validation.ValidationResult;
43
import org.hisp.dhis.validation.ValidationRuleGroup;
44
import org.hisp.dhis.validation.ValidationRuleService;
45
import org.hisp.dhis.validation.comparator.ValidationResultComparator;
47
import com.opensymphony.xwork.ActionSupport;
50
* @author Margrethe Store
51
* @author Lars Helge Overland
52
* @version $Id: RunValidationAction.java 6059 2008-10-28 15:15:34Z larshelg $
54
public class RunValidationAction
57
private static final String KEY_VALIDATIONRESULT = "validationResult";
59
// -------------------------------------------------------------------------
61
// -------------------------------------------------------------------------
63
private ValidationRuleService validationRuleService;
65
public void setValidationRuleService( ValidationRuleService validationRuleService )
67
this.validationRuleService = validationRuleService;
70
private I18nFormat format;
72
public void setFormat( I18nFormat format )
77
private SelectionTreeManager selectionTreeManager;
79
public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
81
this.selectionTreeManager = selectionTreeManager;
84
private OrganisationUnitService organisationUnitService;
86
public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
88
this.organisationUnitService = organisationUnitService;
91
// -------------------------------------------------------------------------
93
// -------------------------------------------------------------------------
95
private String startDate;
97
public String getStartDate()
102
public void setStartDate( String startDate )
104
this.startDate = startDate;
107
private String endDate;
109
public String getEndDate()
114
public void setEndDate( String endDate )
116
this.endDate = endDate;
119
private Integer validationRuleGroupId;
121
public void setValidationRuleGroupId( Integer validationRuleGroupId )
123
this.validationRuleGroupId = validationRuleGroupId;
126
private Boolean includeChildren;
128
public void setIncludeChildren( Boolean includeChildren )
130
this.includeChildren = includeChildren;
133
private List<ValidationResult> validationResults;
135
public List<ValidationResult> getValidationResults()
137
return validationResults;
140
// -------------------------------------------------------------------------
142
// -------------------------------------------------------------------------
144
public String execute()
146
Collection<? extends Source> sources = selectionTreeManager.getSelectedOrganisationUnits();
148
if ( includeChildren )
150
Collection<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
152
for ( Source source : sources )
154
organisationUnits.addAll( organisationUnitService.getOrganisationUnitWithChildren( source.getId() ) );
157
sources = organisationUnits;
160
if ( validationRuleGroupId == -1 )
162
validationResults = new ArrayList<ValidationResult>( validationRuleService.validate(
163
format.parseDate( startDate ), format.parseDate( endDate ), sources ) );
167
ValidationRuleGroup group = validationRuleService.getValidationRuleGroup( validationRuleGroupId );
169
validationResults = new ArrayList<ValidationResult>( validationRuleService.validate(
170
format.parseDate( startDate ), format.parseDate( endDate ), sources, group ) );
173
Collections.sort( validationResults, new ValidationResultComparator() );
175
SessionUtils.setSessionVar( KEY_VALIDATIONRESULT, validationResults );