dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35633
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18227: Web api, added support for getting validation rules related to a data set at /api/validationRules...
------------------------------------------------------------
revno: 18227
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-02-11 20:41:55 +0100
message:
Web api, added support for getting validation rules related to a data set at /api/validationRules?dataSet=uid
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-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IndexController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/validation/ValidationRuleController.java
--
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-02-09 17:46:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java 2015-02-11 19:41:55 +0000
@@ -31,6 +31,7 @@
import java.util.Collection;
import java.util.Date;
import java.util.List;
+import java.util.Set;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -108,6 +109,16 @@
*/
List<DataElementOperand> validateRequiredComments( DataSet dataSet, Period period, OrganisationUnit organisationUnit, DataElementCategoryOptionCombo attributeOptionCombo );
+
+ /**
+ * Returns all validation-type rules which have specified data elements
+ * assigned to them.
+ *
+ * @param dataElements the data elements to look for.
+ * @return all validation rules which have the data elements assigned.
+ */
+ Collection<ValidationRule> getValidationTypeRulesForDataElements( Set<DataElement> dataElements );
+
// -------------------------------------------------------------------------
// 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 17:46:40 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2015-02-11 19:41:55 +0000
@@ -284,7 +284,8 @@
systemSettingManager.saveSystemSetting( SystemSettingManager.KEY_LAST_MONITORING_RUN, thisRun );
}
-
+
+ @Override
public List<DataElementOperand> validateRequiredComments( DataSet dataSet, Period period, OrganisationUnit organisationUnit, DataElementCategoryOptionCombo attributeOptionCombo )
{
List<DataElementOperand> violations = new ArrayList<>();
@@ -311,6 +312,29 @@
return violations;
}
+ @Override
+ public Collection<ValidationRule> getValidationTypeRulesForDataElements( Set<DataElement> dataElements )
+ {
+ Set<ValidationRule> rulesForDataElements = new HashSet<>();
+
+ for ( ValidationRule validationRule : getAllValidationRules() )
+ {
+ if ( validationRule.getRuleType().equals( ValidationRule.RULE_TYPE_VALIDATION ) )
+ {
+ Set<DataElement> validationRuleElements = new HashSet<>();
+ validationRuleElements.addAll( validationRule.getLeftSide().getDataElementsInExpression() );
+ validationRuleElements.addAll( validationRule.getRightSide().getDataElementsInExpression() );
+
+ if ( dataElements.containsAll( validationRuleElements ) )
+ {
+ rulesForDataElements.add( validationRule );
+ }
+ }
+ }
+
+ return rulesForDataElements;
+ }
+
// -------------------------------------------------------------------------
// Supportive methods - scheduled run
// -------------------------------------------------------------------------
@@ -580,40 +604,9 @@
}
/**
- * Returns all validation-type rules which have specified data elements
- * assigned to them.
- *
- * @param dataElements the data elements to look for
- * @return all validation rules which have the data elements assigned.
- */
- private Collection<ValidationRule> getValidationTypeRulesForDataElements( Set<DataElement> dataElements )
- {
- Set<ValidationRule> rulesForDataElements = new HashSet<>();
-
- Set<DataElement> validationRuleElements = new HashSet<>();
-
- for ( ValidationRule validationRule : getAllValidationRules() )
- {
- if ( validationRule.getRuleType().equals( ValidationRule.RULE_TYPE_VALIDATION ) )
- {
- validationRuleElements.clear();
- validationRuleElements.addAll( validationRule.getLeftSide().getDataElementsInExpression() );
- validationRuleElements.addAll( validationRule.getRightSide().getDataElementsInExpression() );
-
- if ( dataElements.containsAll( validationRuleElements ) )
- {
- rulesForDataElements.add( validationRule );
- }
- }
- }
-
- return rulesForDataElements;
- }
-
- /**
* Formats and sets name on the period of each result.
*
- * @param results the collecion of validation results.
+ * @param results the collection of validation results.
* @param format the i18n format.
*/
private void formatPeriods( Collection<ValidationResult> results, I18nFormat format )
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java 2015-02-10 09:04:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java 2015-02-11 19:41:55 +0000
@@ -28,10 +28,16 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.hisp.dhis.common.DimensionService;
import org.hisp.dhis.common.DimensionalObject;
-import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
@@ -53,12 +59,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
+import com.google.common.collect.Lists;
@Controller
@RequestMapping( value = DimensionController.RESOURCE_PATH )
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IndexController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IndexController.java 2015-02-10 09:04:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/IndexController.java 2015-02-11 19:41:55 +0000
@@ -28,8 +28,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.commons.lang.StringUtils;
-import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.node.NodeUtils;
import org.hisp.dhis.node.types.CollectionNode;
import org.hisp.dhis.node.types.ComplexNode;
@@ -45,10 +49,6 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/validation/ValidationRuleController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/validation/ValidationRuleController.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/validation/ValidationRuleController.java 2015-02-11 19:41:55 +0000
@@ -28,12 +28,22 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.List;
+
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.schema.descriptors.ValidationRuleSchemaDescriptor;
import org.hisp.dhis.validation.ValidationRule;
+import org.hisp.dhis.validation.ValidationRuleService;
import org.hisp.dhis.webapi.controller.AbstractCrudController;
+import org.hisp.dhis.webapi.webdomain.WebMetaData;
+import org.hisp.dhis.webapi.webdomain.WebOptions;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
+import com.google.common.collect.Lists;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -42,4 +52,27 @@
public class ValidationRuleController
extends AbstractCrudController<ValidationRule>
{
+ @Autowired
+ private DataSetService dataSetService;
+
+ @Autowired
+ private ValidationRuleService validationRuleService;
+
+ @Override
+ protected List<ValidationRule> getEntityList( WebMetaData metaData, WebOptions options, List<String> filters )
+ {
+ if ( options.contains( "dataSet" ) )
+ {
+ DataSet ds = dataSetService.getDataSet( options.get( "dataSet" ) );
+
+ if ( ds == null )
+ {
+ return null;
+ }
+
+ return Lists.newArrayList( validationRuleService.getValidationRulesByDataElements( ds.getDataElements() ) );
+ }
+
+ return super.getEntityList( metaData, options, filters );
+ }
}