dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35576
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18209: Validation, check for comments for missing values, pushed down to service layer, fixed bug
------------------------------------------------------------
revno: 18209
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-02-09 18:46:40 +0100
message:
Validation, check for comments for missing values, pushed down to service layer, fixed bug
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java 2015-02-09 17:46:40 +0000
@@ -30,9 +30,11 @@
import java.util.Collection;
import java.util.Date;
+import java.util.List;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -94,6 +96,18 @@
*/
void scheduledRun();
+ /**
+ * Validate that missing data values have a corresponding comment, assuming
+ * that the given data set has the noValueRequiresComment property set to true.
+ *
+ * @param dataSet the data set.
+ * @param period the period.
+ * @param organisationUnit the organisation unit.
+ * @param attributeOptionCombo the attribute option combo.
+ * @return a list of operands representing missing comments.
+ */
+ List<DataElementOperand> validateRequiredComments( DataSet dataSet, Period period, OrganisationUnit organisationUnit, DataElementCategoryOptionCombo attributeOptionCombo );
+
// -------------------------------------------------------------------------
// ValidationRule
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2015-02-09 14:52:38 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2015-02-09 17:46:40 +0000
@@ -41,11 +41,13 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.common.GenericIdentifiableObjectStore;
@@ -53,7 +55,9 @@
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.datavalue.DataValue;
import org.hisp.dhis.datavalue.DataValueService;
import org.hisp.dhis.expression.ExpressionService;
import org.hisp.dhis.i18n.I18nFormat;
@@ -280,6 +284,32 @@
systemSettingManager.saveSystemSetting( SystemSettingManager.KEY_LAST_MONITORING_RUN, thisRun );
}
+
+ public List<DataElementOperand> validateRequiredComments( DataSet dataSet, Period period, OrganisationUnit organisationUnit, DataElementCategoryOptionCombo attributeOptionCombo )
+ {
+ List<DataElementOperand> violations = new ArrayList<>();
+
+ if ( dataSet.isNoValueRequiresComment() )
+ {
+ for ( DataElement de : dataSet.getDataElements() )
+ {
+ for ( DataElementCategoryOptionCombo co : de.getCategoryCombo().getOptionCombos() )
+ {
+ DataValue dv = dataValueService.getDataValue( de, period, organisationUnit, co, attributeOptionCombo );
+
+ boolean missingValue = dv == null || StringUtils.trimToNull( dv.getValue() ) == null;
+ boolean missingComment = dv == null || StringUtils.trimToNull( dv.getComment() ) == null;
+
+ if ( missingValue && missingComment )
+ {
+ violations.add( new DataElementOperand( de, co ) );
+ }
+ }
+ }
+ }
+
+ return violations;
+ }
// -------------------------------------------------------------------------
// Supportive methods - scheduled run
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java 2015-02-09 17:46:40 +0000
@@ -36,20 +36,14 @@
import java.util.Map;
import java.util.TreeMap;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
-import org.hisp.dhis.webapi.utils.InputUtils;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
import org.hisp.dhis.dataanalysis.DataAnalysisService;
-import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
-import org.hisp.dhis.datavalue.DataValue;
-import org.hisp.dhis.datavalue.DataValueService;
import org.hisp.dhis.datavalue.DeflatedDataValue;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -58,6 +52,7 @@
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.validation.ValidationResult;
import org.hisp.dhis.validation.ValidationRuleService;
+import org.hisp.dhis.webapi.utils.InputUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.opensymphony.xwork2.Action;
@@ -69,8 +64,6 @@
public class ValidationAction
implements Action
{
- private static final Log log = LogFactory.getLog( ValidationAction.class );
-
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -117,13 +110,6 @@
this.dataElementCategoryService = dataElementCategoryService;
}
- private DataValueService dataValueService;
-
- public void setDataValueService( DataValueService dataValueService )
- {
- this.dataValueService = dataValueService;
- }
-
@Autowired
private InputUtils inputUtils;
@@ -247,21 +233,22 @@
for ( OrganisationUnit organisationUnit : organisationUnits )
{
- List<DeflatedDataValue> values = outlierAnalysis( organisationUnit, dataSet, period );
+ List<DeflatedDataValue> values = new ArrayList<>( minMaxOutlierAnalysisService.analyse( getCollection( organisationUnit ),
+ dataSet.getDataElements(), getCollection( period ), null ) );
if ( !values.isEmpty() )
{
dataValues.put( organisationUnit, values );
}
- List<ValidationResult> results = validationRuleAnalysis( organisationUnit, dataSet, period, attributeOptionCombo );
+ List<ValidationResult> results = new ArrayList<>( validationRuleService.validate( dataSet, period, organisationUnit, attributeOptionCombo ) );
if ( !results.isEmpty() )
{
validationResults.put( organisationUnit, results );
}
- List<DataElementOperand> violations = noValueRequiresCommentAnalysis( organisationUnit, dataSet, period );
+ List<DataElementOperand> violations = validationRuleService.validateRequiredComments( dataSet, period, organisationUnit, attributeOptionCombo );
if ( !violations.isEmpty() )
{
@@ -271,62 +258,4 @@
return dataValues.isEmpty() && validationResults.isEmpty() && commentViolations.isEmpty() ? SUCCESS : INPUT;
}
-
- // -------------------------------------------------------------------------
- // Min-max and outlier analysis
- // -------------------------------------------------------------------------
-
- private List<DeflatedDataValue> outlierAnalysis( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
- {
- List<DeflatedDataValue> deflatedDataValues = new ArrayList<>( minMaxOutlierAnalysisService.analyse( getCollection( organisationUnit ),
- dataSet.getDataElements(), getCollection( period ), null ) );
-
- log.debug( "Number of outlier values: " + deflatedDataValues.size() );
-
- return deflatedDataValues;
- }
-
- // -------------------------------------------------------------------------
- // Validation rule analysis
- // -------------------------------------------------------------------------
-
- private List<ValidationResult> validationRuleAnalysis( OrganisationUnit organisationUnit, DataSet dataSet, Period period, DataElementCategoryOptionCombo attributeOptionCombo )
- {
- List<ValidationResult> validationResults = new ArrayList<>( validationRuleService.validate( dataSet, period, organisationUnit, attributeOptionCombo ) );
-
- log.debug( "Number of validation violations: " + validationResults.size() );
-
- return validationResults;
- }
-
- // -------------------------------------------------------------------------
- // No value requires comment analysis
- // -------------------------------------------------------------------------
-
- private List<DataElementOperand> noValueRequiresCommentAnalysis( OrganisationUnit organisationUnit, DataSet dataSet, Period period )
- {
- List<DataElementOperand> violations = new ArrayList<>();
-
- if ( !dataSet.isNoValueRequiresComment() )
- {
- return violations;
- }
-
- for ( DataElement de : dataSet.getDataElements() )
- {
- for ( DataElementCategoryOptionCombo co : de.getCategoryCombo().getOptionCombos() )
- {
- DataValue dv = dataValueService.getDataValue( de, period, organisationUnit, co );
-
- if ( dv == null || DataValue.FALSE.equals( dv.getValue() ) )
- {
- violations.add( new DataElementOperand( de, co ) );
- }
- }
- }
-
- log.info( "Number of missing comments: " + violations.size() );
-
- return violations;
- }
}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2014-12-04 06:39:46 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2015-02-09 17:46:40 +0000
@@ -63,7 +63,6 @@
<property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
<property name="dataElementCategoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
- <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
</bean>
</beans>