← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11912: improve performance of view sent SMS form, paging

 

------------------------------------------------------------
revno: 11912
committer: Lai <lai.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-09-04 18:44:03 +0700
message:
  improve performance of view sent SMS form, paging
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/hibernate/HibernateOutboundSmsStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowSentSMSAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/showSentSMSPage.vm


--
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/sms/outbound/OutboundSmsService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsService.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsService.java	2013-09-04 11:44:03 +0000
@@ -38,6 +38,8 @@
     String ID = OutboundSmsService.class.getName();
 
     List<OutboundSms> getAllOutboundSms();
+    
+    List<OutboundSms> getAllOutboundSms( Integer min, Integer max );
 
     int saveOutboundSms( OutboundSms sms );
 
@@ -47,5 +49,7 @@
 
     List<OutboundSms> getOutboundSms( OutboundSmsStatus status );
     
+    List<OutboundSms> getOutboundSms( OutboundSmsStatus status, Integer min, Integer max );
+    
     OutboundSms getOutboundSms( int id );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsStore.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsStore.java	2013-09-04 11:44:03 +0000
@@ -35,11 +35,15 @@
     int saveOutboundSms( OutboundSms sms );
     
     List<OutboundSms> getAllOutboundSms();
+    
+    List<OutboundSms> getAllOutboundSms( Integer min, Integer max );
 
     OutboundSms getOutboundSmsbyId( int id );
     
     List<OutboundSms> get( OutboundSmsStatus status );
     
+    List<OutboundSms> get( OutboundSmsStatus status, Integer min, Integer max );
+    
     void updateOutboundSms( OutboundSms sms );
     
     void deleteOutboundSms( OutboundSms sms );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/hibernate/HibernateOutboundSmsStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/hibernate/HibernateOutboundSmsStore.java	2013-09-04 09:44:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/hibernate/HibernateOutboundSmsStore.java	2013-09-04 11:44:03 +0000
@@ -106,4 +106,39 @@
     {
         delete( sms );
     }
+
+    @SuppressWarnings( "unchecked" )
+    @Override
+    public List<OutboundSms> get( OutboundSmsStatus status, Integer min, Integer max )
+    {
+        Session session = sessionFactory.getCurrentSession();
+        
+        Criteria criteria = session.createCriteria( OutboundSms.class ).addOrder( Order.desc( "date" ) );
+        
+        if ( status != null )
+        {
+            criteria.add( Restrictions.eq( "status", status ) );
+        }
+        
+        if ( min != null && max != null)
+        {
+            criteria.setFirstResult( min ).setMaxResults( max );
+        }
+        return criteria.list();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    @Override
+    public List<OutboundSms> getAllOutboundSms( Integer min, Integer max )
+    {
+        Session session = sessionFactory.getCurrentSession();
+        
+        Criteria criteria = session.createCriteria( OutboundSms.class ).addOrder( Order.desc( "date" ) );
+        
+        if ( min != null && max != null)
+        {
+            criteria.setFirstResult( min ).setMaxResults( max );
+        }
+        return criteria.list();
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsService.java	2013-08-26 03:41:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsService.java	2013-09-04 11:44:03 +0000
@@ -93,4 +93,16 @@
     {
         return outboundSmsStore.getOutboundSmsbyId( id );
     }
+
+    @Override
+    public List<OutboundSms> getOutboundSms( OutboundSmsStatus status, Integer min, Integer max )
+    {
+        return outboundSmsStore.get( status, min, max );
+    }
+
+    @Override
+    public List<OutboundSms> getAllOutboundSms( Integer min, Integer max )
+    {
+        return outboundSmsStore.getAllOutboundSms( min, max );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowSentSMSAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowSentSMSAction.java	2013-09-04 09:44:07 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowSentSMSAction.java	2013-09-04 11:44:03 +0000
@@ -129,22 +129,31 @@
         throws Exception
     {
         listOutboundSMS = new ArrayList<OutboundSms>();
-
+        
         if ( filterStatusType != null && filterStatusType == 0 )
         {
-            listOutboundSMS = outboundSmsService.getOutboundSms( OutboundSmsStatus.OUTBOUND );
+            total = outboundSmsService.getOutboundSms( OutboundSmsStatus.OUTBOUND ).size();
+            paging = createPaging( total );
+            listOutboundSMS = outboundSmsService.getOutboundSms( OutboundSmsStatus.OUTBOUND, paging.getStartPos(), paging.getPageSize() );
         }
         if ( filterStatusType != null && filterStatusType == 1 )
         {
-            listOutboundSMS = outboundSmsService.getOutboundSms( OutboundSmsStatus.SENT );
+            total = outboundSmsService.getOutboundSms( OutboundSmsStatus.SENT ).size();
+            paging = createPaging( total );
+            listOutboundSMS = outboundSmsService.getOutboundSms( OutboundSmsStatus.SENT, paging.getStartPos(), paging.getPageSize() );
         }
         if ( filterStatusType != null && filterStatusType == 2 )
         {
-            listOutboundSMS = outboundSmsService.getOutboundSms( OutboundSmsStatus.ERROR );
+            total = outboundSmsService.getOutboundSms( OutboundSmsStatus.ERROR ).size();
+            paging = createPaging( total );
+            listOutboundSMS = outboundSmsService.getOutboundSms( OutboundSmsStatus.ERROR, paging.getStartPos(), paging.getPageSize() );
         }
         if ( filterStatusType != null && filterStatusType == 3 || filterStatusType == null )
         {
-            listOutboundSMS = outboundSmsService.getAllOutboundSms();
+            filterStatusType = 3;
+            total = outboundSmsService.getAllOutboundSms().size();
+            paging = createPaging( total );
+            listOutboundSMS = outboundSmsService.getAllOutboundSms( paging.getStartPos(), paging.getPageSize() );
         }
 
         recipientNames = new ArrayList<String>();

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/showSentSMSPage.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/showSentSMSPage.vm	2013-09-04 09:44:07 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/showSentSMSPage.vm	2013-09-04 11:44:03 +0000
@@ -80,6 +80,10 @@
 				<input type="button" name="btnDelete" value="$i18n.getString( 'delete_checked_option' )" onclick="deleteChecked()"/>
 			</td>
 		</tr>
+		<tr>
+			<td style="width:130px">$i18n.getString( "total_number_of_result" ):</td>
+			<td style="text-align:left" colspan="2">$total</td>
+		</tr>
 	</table>
 	<br/>
 	<table id="detailsSentSMSList" class="listTable" style="width:100%" border="0px">
@@ -107,6 +111,14 @@
 				<td style="text-align:center"><a href="javascript:removeSingleItem( '$outboundSms.id', '$outboundSms.message' )" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"/></td>
 			</tr>
 			#end
+			<tr>
+				<td colspan="8">
+					<p></p>
+					<div class="paging-container">
+						#parse( "/dhis-web-commons/paging/paging.vm" )
+					</div>
+				</td>
+			</tr>
 		</tbody>
 	</table>
 </form>
\ No newline at end of file