← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17455: Approval, simplified code for getting periods

 

------------------------------------------------------------
revno: 17455
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-11-12 18:42:04 +0100
message:
  Approval, simplified code for getting periods
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.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-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java	2014-11-12 17:27:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java	2014-11-12 17:42:04 +0000
@@ -34,12 +34,11 @@
 import static org.hisp.dhis.dataapproval.DataApprovalState.UNAPPROVED_READY;
 import static org.hisp.dhis.dataapproval.DataApprovalState.UNAPPROVED_WAITING;
 import static org.hisp.dhis.setting.SystemSettingManager.KEY_ACCEPTANCE_REQUIRED_FOR_APPROVAL;
-import static org.hisp.dhis.system.util.CollectionUtils.asSet;
+import static org.hisp.dhis.system.util.CollectionUtils.asList;
 import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
 import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -48,10 +47,12 @@
 import java.util.concurrent.ExecutionException;
 
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.Criteria;
 import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.common.IdentifiableObjectUtils;
 import org.hisp.dhis.dataapproval.DataApproval;
 import org.hisp.dhis.dataapproval.DataApprovalLevel;
 import org.hisp.dhis.dataapproval.DataApprovalLevelService;
@@ -204,18 +205,16 @@
 
         PeriodType dataSetPeriodType = dataSets.iterator().next().getPeriodType();
 
-        Collection<Period> periods;
+        List<Period> periods;
 
         if ( period.getPeriodType().equals( dataSetPeriodType ) )
         {
-            periods = asSet( period );
+            periods = asList( period );
         }
         else if ( period.getPeriodType().getFrequencyOrder() > dataSetPeriodType.getFrequencyOrder() )
         {
-            periods = periodService.getPeriodsBetweenDates(
-                    dataSetPeriodType,
-                    period.getStartDate(),
-                    period.getEndDate() );
+            periods = new ArrayList<>( periodService.getPeriodsBetweenDates( dataSetPeriodType,
+                    period.getStartDate(), period.getEndDate() ) );
         }
         else
         {
@@ -229,13 +228,6 @@
         final String minDate = DateUtils.getMediumDateString( period.getStartDate() );
         final String maxDate = DateUtils.getMediumDateString( period.getEndDate() );
 
-        String periodIds = "";
-
-        for ( Period p : periods )
-        {
-            periodIds += ( periodIds.isEmpty() ? "" : ", " ) + periodService.reloadPeriod( p ).getId();
-        }
-
         boolean maySeeDefaultCategoryCombo = user == null || user.getUserCredentials() == null ||
                 ( CollectionUtils.isEmpty( user.getUserCredentials().getCogsDimensionConstraints() )
                 && CollectionUtils.isEmpty( user.getUserCredentials().getCatDimensionConstraints() ) );
@@ -281,6 +273,10 @@
             orgUnitJoinOn = "o.level = " + orgUnitLevel;
         }
 
+        periods = periodService.reloadPeriods( periods );
+        
+        String periodIds = StringUtils.join( IdentifiableObjectUtils.getIdentifiers( periods ), "," );
+
         boolean isSuperUser = currentUserService.currentUserIsSuper();
 
         DataApprovalLevel lowestApprovalLevelForOrgUnit = null;