------------------------------------------------------------
revno: 11909
committer: Lai <lai.hispviet...@gmail.com>
branch nick: dhis2
timestamp: Wed 2013-09-04 16:44:07 +0700
message:
  simplify the get sent SMS by status method
modified:
  
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/resources/META-INF/dhis/beans.xml
  
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-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-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/hibernate/HibernateOutboundSmsStore.java	2013-09-04 09:44:07 +0000
@@ -28,17 +28,17 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.sql.ResultSet;
-import java.sql.SQLException;
 import java.util.Date;
 import java.util.List;
+
+import org.hibernate.Criteria;
+import org.hibernate.Session;
 import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.hibernate.HibernateGenericStore;
 import org.hisp.dhis.sms.outbound.OutboundSms;
 import org.hisp.dhis.sms.outbound.OutboundSmsStatus;
 import org.hisp.dhis.sms.outbound.OutboundSmsStore;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.RowMapper;
 
 public class HibernateOutboundSmsStore
     extends HibernateGenericStore<OutboundSms>
@@ -48,13 +48,6 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private JdbcTemplate jdbcTemplate;
-
-    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
-    {
-        this.jdbcTemplate = jdbcTemplate;
-    }
-
     // -------------------------------------------------------------------------
     // Implementation
     // -------------------------------------------------------------------------
@@ -87,49 +80,19 @@
         return getCriteria().addOrder( Order.desc( "date" ) ).list();
     }
 
+    @SuppressWarnings( "unchecked" )
     @Override
     public List<OutboundSms> get( OutboundSmsStatus status )
     {
-        int realStatus = 0;
-
-        if ( status.equals( OutboundSmsStatus.OUTBOUND ) )
-        {
-            realStatus = OutboundSmsStatus.OUTBOUND.ordinal();
-        }
-        else if ( status.equals( OutboundSmsStatus.SENT ) )
-        {
-            realStatus = OutboundSmsStatus.SENT.ordinal();
-        }
-        else
-        {
-            realStatus = OutboundSmsStatus.ERROR.ordinal();
-        }
-
-        String sql = "select osm.id as outboundsmsid, message, ore.elt as phonenumber, date "
-            + "from outbound_sms osm inner join outbound_sms_recipients ore "
-            + "on osm.id=ore.outbound_sms_id where status = " + realStatus;
-
-        try
-        {
-            List<OutboundSms> OutboundSmsList = jdbcTemplate.query( sql, new RowMapper<OutboundSms>()
-            {
-                public OutboundSms mapRow( ResultSet rs, int rowNum )
-                    throws SQLException
-                {
-                    OutboundSms outboundSms = new OutboundSms( rs.getString( 2 ), rs.getString( 3 ) );
-                    outboundSms.setId( rs.getInt( 1 ) );
-                    outboundSms.setDate( rs.getDate( 4 ) );
-                    return outboundSms;
-                }
-            } );
-
-            return OutboundSmsList;
-        }
-        catch ( Exception ex )
-        {
-            ex.printStackTrace();
-            return null;
-        }
+        Session session = sessionFactory.getCurrentSession();
+        
+        Criteria criteria = session.createCriteria( OutboundSms.class ).addOrder( Order.desc( "date" ) );
+        
+        if ( status != null )
+        {
+            criteria.add( Restrictions.eq( "status", status ) );
+        }
+        return criteria.list();
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2013-09-03 14:53:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2013-09-04 09:44:07 +0000
@@ -345,7 +345,6 @@
     class="org.hisp.dhis.sms.hibernate.HibernateOutboundSmsStore">
      <property name="clazz" value="org.hisp.dhis.sms.outbound.OutboundSms" />	
      <property name="sessionFactory" ref="sessionFactory" />
-    <property name="jdbcTemplate" ref="jdbcTemplate" />
   </bean>
   
   <!-- Service definitions -->

=== 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-03 15:04:30 +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 09:44:07 +0000
@@ -33,6 +33,7 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.hisp.dhis.paging.ActionPagingSupport;
 import org.hisp.dhis.program.ProgramStageInstanceService;
 import org.hisp.dhis.program.SchedulingProgramObject;
 import org.hisp.dhis.sms.outbound.OutboundSms;
@@ -41,10 +42,8 @@
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserService;
 
-import com.opensymphony.xwork2.Action;
-
 public class ShowSentSMSAction
-    implements Action
+    extends ActionPagingSupport<OutboundSms>
 {
 
     // -------------------------------------------------------------------------
@@ -114,6 +113,13 @@
         return recipientNames;
     }
 
+    private Integer total;
+
+    public Integer getTotal()
+    {
+        return total;
+    }
+
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
@@ -122,36 +128,23 @@
     public String execute()
         throws Exception
     {
-        List<OutboundSms> tempListOutboundSMS = outboundSmsService.getAllOutboundSms();
-
         listOutboundSMS = new ArrayList<OutboundSms>();
-        
+
         if ( filterStatusType != null && filterStatusType == 0 )
         {
-            for ( OutboundSms each : tempListOutboundSMS )
-            {
-                if ( each.getStatus().equals( OutboundSmsStatus.OUTBOUND ) )
-                {
-                    this.listOutboundSMS.add( each );
-                }
-            }
+            listOutboundSMS = outboundSmsService.getOutboundSms( OutboundSmsStatus.OUTBOUND );
         }
         if ( filterStatusType != null && filterStatusType == 1 )
         {
-            for ( OutboundSms each : tempListOutboundSMS )
-            {
-                if ( each.getStatus().equals( OutboundSmsStatus.SENT ) )
-                {
-                    this.listOutboundSMS.add( each );
-                }
-            }
-        }
-        if ( filterStatusType != null && filterStatusType == 2 || filterStatusType == null )
-        {
-            for ( OutboundSms each : tempListOutboundSMS )
-            {
-                this.listOutboundSMS.add( each );
-            }
+            listOutboundSMS = outboundSmsService.getOutboundSms( OutboundSmsStatus.SENT );
+        }
+        if ( filterStatusType != null && filterStatusType == 2 )
+        {
+            listOutboundSMS = outboundSmsService.getOutboundSms( OutboundSmsStatus.ERROR );
+        }
+        if ( filterStatusType != null && filterStatusType == 3 || filterStatusType == null )
+        {
+            listOutboundSMS = outboundSmsService.getAllOutboundSms();
         }
 
         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-08-28 07:52:09 +0000
+++ 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
@@ -72,7 +72,8 @@
 				<select id="statusType" onchange="filterByStatus(this.value)">
 					<option value="0" #if ( $!filterStatusType == 0 ) selected='selected' #end>$i18n.getString('outbound')</option>
 					<option value="1" #if ( $!filterStatusType == 1 ) selected='selected' #end>$i18n.getString('sent')</option>
-					<option value="2" #if ( $!filterStatusType == 2 ) selected='selected' #end>$i18n.getString('all')</option>
+					<option value="2" #if ( $!filterStatusType == 2 ) selected='selected' #end>$i18n.getString('error')</option>
+					<option value="3" #if ( $!filterStatusType == 3 ) selected='selected' #end>$i18n.getString('all')</option>
 				</select>
 			</td>
 			<td style="text-align:right">

_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : dhis2-devs@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp

Reply via email to