← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22115: DatIntegrityService, using java8 streams.

 

------------------------------------------------------------
revno: 22115
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-03-02 22:44:53 +0100
message:
  DatIntegrityService, using java8 streams.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitGroupWithoutGroupSetFilter.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/dataelement/DataElementCategoryOptionCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java	2016-03-02 07:56:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java	2016-03-02 21:44:53 +0000
@@ -231,14 +231,13 @@
             return uid;
         }
 
-        List<DataElementCategory> categories = this.categoryCombo.getCategories();
+        List<DataElementCategory> categories = categoryCombo.getCategories();
 
         for ( DataElementCategory category : categories )
         {
             List<DataElementCategoryOption> options = category.getCategoryOptions();
 
-            optionLoop:
-            for ( DataElementCategoryOption option : this.categoryOptions )
+            optionLoop: for ( DataElementCategoryOption option : categoryOptions )
             {
                 if ( options.contains( option ) )
                 {

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityService.java	2016-03-02 17:06:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityService.java	2016-03-02 21:44:53 +0000
@@ -30,6 +30,7 @@
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Set;
 import java.util.SortedMap;
 
 import org.hisp.dhis.common.SetMap;
@@ -64,12 +65,12 @@
     /**
      * Gets all data elements which are not assigned to any data set.
      */
-    Collection<DataElement> getDataElementsWithoutDataSet();
+    List<DataElement> getDataElementsWithoutDataSet();
 
     /**
      * Gets all data elements which are not members of any groups.
      */
-    Collection<DataElement> getDataElementsWithoutGroups();
+    List<DataElement> getDataElementsWithoutGroups();
     
     /**
      * Gets all data elements units which are members of more than one group
@@ -108,7 +109,7 @@
      * Gets all section with invalid category combinations. Invalid means that
      * the data elements in the sections don't have the same category combination.
      */
-    Collection<Section> getSectionsWithInvalidCategoryCombinations();
+    List<Section> getSectionsWithInvalidCategoryCombinations();
     
     // -------------------------------------------------------------------------
     // DataSet
@@ -117,7 +118,7 @@
     /**
      * Gets all data sets which are not assigned to any organisation units.
      */
-    Collection<DataSet> getDataSetsNotAssignedToOrganisationUnits();
+    List<DataSet> getDataSetsNotAssignedToOrganisationUnits();
     
     // -------------------------------------------------------------------------
     // Indicator
@@ -126,12 +127,12 @@
     /**
      * Gets all indicators with identical numerator and denominator.
      */
-    Collection<Collection<Indicator>> getIndicatorsWithIdenticalFormulas();
+    Set<Collection<Indicator>> getIndicatorsWithIdenticalFormulas();
 
     /**
      * Gets all indicators which are not assigned to any groups.
      */
-    Collection<Indicator> getIndicatorsWithoutGroups();
+    List<Indicator> getIndicatorsWithoutGroups();
 
     /**
      * Gets all indicators with invalid indicator numerators.
@@ -156,17 +157,17 @@
     /**
      * Gets all organisation units which are related to each other in a cyclic reference.
      */
-    Collection<OrganisationUnit> getOrganisationUnitsWithCyclicReferences();
+    Set<OrganisationUnit> getOrganisationUnitsWithCyclicReferences();
 
     /**
      * Gets all organisation units with no parents or children.
      */
-    Collection<OrganisationUnit> getOrphanedOrganisationUnits();
+    List<OrganisationUnit> getOrphanedOrganisationUnits();
 
     /**
      * Gets all organisation units which are not assigned to any groups.
      */
-    Collection<OrganisationUnit> getOrganisationUnitsWithoutGroups();
+    List<OrganisationUnit> getOrganisationUnitsWithoutGroups();
 
     /**
      * Gets all organisation units which are members of more than one group
@@ -191,7 +192,7 @@
     /**
      * Gets all organisation unit groups which are not assigned to any group set.
      */
-    Collection<OrganisationUnitGroup> getOrganisationUnitGroupsWithoutGroupSets();
+    List<OrganisationUnitGroup> getOrganisationUnitGroupsWithoutGroupSets();
 
     // -------------------------------------------------------------------------
     // ValidationRule
@@ -200,7 +201,7 @@
     /**
      * Gets all ValidationRules which are not members fo one or more groups.
      */
-    Collection<ValidationRule> getValidationRulesWithoutGroups();
+    List<ValidationRule> getValidationRulesWithoutGroups();
     
     /**
      * Gets all ValidationRules with invalid left side expressions.

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java	2016-03-02 17:06:15 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java	2016-03-02 21:44:53 +0000
@@ -33,8 +33,6 @@
 import org.hisp.dhis.common.ListMap;
 import org.hisp.dhis.common.SetMap;
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
-import org.hisp.dhis.commons.filter.Filter;
-import org.hisp.dhis.commons.filter.FilterUtils;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -62,17 +60,19 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.system.filter.OrganisationUnitGroupWithoutGroupSetFilter;
 import org.hisp.dhis.validation.ValidationRule;
 import org.hisp.dhis.validation.ValidationRuleService;
 import org.springframework.transaction.annotation.Transactional;
 
+import com.google.common.collect.Sets;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
@@ -181,13 +181,13 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public Collection<DataElement> getDataElementsWithoutDataSet()
+    public List<DataElement> getDataElementsWithoutDataSet()
     {
         return dataElementService.getDataElementsWithoutDataSets();
     }
 
     @Override
-    public Collection<DataElement> getDataElementsWithoutGroups()
+    public List<DataElement> getDataElementsWithoutGroups()
     {
         return dataElementService.getDataElementsWithoutGroups();
     }
@@ -334,18 +334,11 @@
     }
 
     @Override
-    public Collection<DataSet> getDataSetsNotAssignedToOrganisationUnits()
+    public List<DataSet> getDataSetsNotAssignedToOrganisationUnits()
     {
         Collection<DataSet> dataSets = dataSetService.getAllDataSets();
 
-        return FilterUtils.filter( dataSets, new Filter<DataSet>()
-        {
-            @Override
-            public boolean retain( DataSet object )
-            {
-                return object.getSources() == null || object.getSources().size() == 0;
-            }
-        } );
+        return dataSets.stream().filter( ds -> ds.getSources() == null || ds.getSources().isEmpty() ).collect( Collectors.toList() );
     }
 
     // -------------------------------------------------------------------------
@@ -353,9 +346,9 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public Collection<Section> getSectionsWithInvalidCategoryCombinations()
+    public List<Section> getSectionsWithInvalidCategoryCombinations()
     {
-        Collection<Section> sections = new HashSet<>();
+        List<Section> sections = new ArrayList<>();
 
         for ( Section section : sectionService.getAllSections() )
         {
@@ -373,13 +366,13 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public Collection<Collection<Indicator>> getIndicatorsWithIdenticalFormulas()
+    public Set<Collection<Indicator>> getIndicatorsWithIdenticalFormulas()
     {
-        Hashtable<String, Indicator> formulas = new Hashtable<>();
-
-        Hashtable<String, Collection<Indicator>> targets = new Hashtable<>();
-
-        Collection<Indicator> indicators = indicatorService.getAllIndicators();
+        Map<String, Indicator> formulas = new HashMap<>();
+
+        Map<String, Set<Indicator>> targets = new HashMap<>();
+
+        List<Indicator> indicators = indicatorService.getAllIndicators();
 
         for ( Indicator indicator : indicators )
         {
@@ -408,11 +401,11 @@
             }
         }
 
-        return targets.values();
+        return Sets.newHashSet( targets.values() );
     }
 
     @Override
-    public Collection<Indicator> getIndicatorsWithoutGroups()
+    public List<Indicator> getIndicatorsWithoutGroups()
     {
         return indicatorService.getIndicatorsWithoutGroups();
     }
@@ -514,9 +507,9 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public Collection<OrganisationUnit> getOrganisationUnitsWithCyclicReferences()
+    public Set<OrganisationUnit> getOrganisationUnitsWithCyclicReferences()
     {
-        Collection<OrganisationUnit> organisationUnits = organisationUnitService.getAllOrganisationUnits();
+        List<OrganisationUnit> organisationUnits = organisationUnitService.getAllOrganisationUnits();
 
         Set<OrganisationUnit> cyclic = new HashSet<>();
 
@@ -553,22 +546,15 @@
     }
 
     @Override
-    public Collection<OrganisationUnit> getOrphanedOrganisationUnits()
+    public List<OrganisationUnit> getOrphanedOrganisationUnits()
     {
-        Collection<OrganisationUnit> organisationUnits = organisationUnitService.getAllOrganisationUnits();
-
-        return FilterUtils.filter( organisationUnits, new Filter<OrganisationUnit>()
-        {
-            @Override
-            public boolean retain( OrganisationUnit object )
-            {
-                return object.getParent() == null && (object.getChildren() == null || object.getChildren().size() == 0);
-            }
-        } );
+        List<OrganisationUnit> units = organisationUnitService.getAllOrganisationUnits();
+        
+        return units.stream().filter( ou -> ou.getParent() == null && ( ou.getChildren() == null || ou.getChildren().size() == 0 ) ).collect( Collectors.toList() );
     }
 
     @Override
-    public Collection<OrganisationUnit> getOrganisationUnitsWithoutGroups()
+    public List<OrganisationUnit> getOrganisationUnitsWithoutGroups()
     {
         return organisationUnitService.getOrganisationUnitsWithoutGroups();
     }
@@ -596,11 +582,11 @@
     }
 
     @Override
-    public Collection<OrganisationUnitGroup> getOrganisationUnitGroupsWithoutGroupSets()
+    public List<OrganisationUnitGroup> getOrganisationUnitGroupsWithoutGroupSets()
     {
         Collection<OrganisationUnitGroup> groups = organisationUnitGroupService.getAllOrganisationUnitGroups();
-
-        return FilterUtils.filter( groups, new OrganisationUnitGroupWithoutGroupSetFilter() );
+        
+        return groups.stream().filter( g -> g == null || g.getGroupSet() == null ).collect( Collectors.toList() );
     }
 
     // -------------------------------------------------------------------------
@@ -608,18 +594,11 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public Collection<ValidationRule> getValidationRulesWithoutGroups()
+    public List<ValidationRule> getValidationRulesWithoutGroups()
     {
         Collection<ValidationRule> validationRules = validationRuleService.getAllValidationRules();
-
-        return FilterUtils.filter( validationRules, new Filter<ValidationRule>()
-        {
-            @Override
-            public boolean retain( ValidationRule object )
-            {
-                return object.getGroups() == null || object.getGroups().size() == 0;
-            }
-        } );
+        
+        return validationRules.stream().filter( r -> r.getGroups() == null || r.getGroups().isEmpty() ).collect( Collectors.toList() );
     }
 
     @Override

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitGroupWithoutGroupSetFilter.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitGroupWithoutGroupSetFilter.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitGroupWithoutGroupSetFilter.java	2016-03-02 21:44:53 +0000
@@ -32,6 +32,8 @@
 import org.hisp.dhis.commons.filter.Filter;
 
 /**
+ * TODO remove
+ * 
  * @author Lars Helge Overland
  */
 public class OrganisationUnitGroupWithoutGroupSetFilter