← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15284: [mobile] update send message server side for mobile J2ME agg

 

------------------------------------------------------------
revno: 15284
committer: Hong Em <em.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-05-16 13:06:48 +0700
message:
  [mobile] update send message server side for mobile J2ME agg
modified:
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Message.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Recipient.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/User.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java
  dhis-2/dhis-services/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/api/model/OrgUnitTest.java
  dhis-2/dhis-services/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/api/model/OrgUnitsTest.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.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-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java	2014-05-09 10:07:18 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java	2014-05-16 06:06:48 +0000
@@ -110,4 +110,7 @@
     public Collection<User> findUser( String keyword )
         throws NotAllowedException;
 
+    public String sendMessage( Message message )
+        throws NotAllowedException;
+
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Message.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Message.java	2014-05-05 10:16:05 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Message.java	2014-05-16 06:06:48 +0000
@@ -44,11 +44,14 @@
 
     private String text;
 
-    public Message( String subject, String text )
+    private Recipient recipient;
+
+    public Message( String subject, String text, Recipient recipient )
     {
         super();
         this.subject = subject;
         this.text = text;
+        this.recipient = recipient;
     }
 
     public Message()
@@ -87,6 +90,16 @@
         this.text = text;
     }
 
+    public Recipient getRecipient()
+    {
+        return recipient;
+    }
+
+    public void setRecipient( Recipient recipient )
+    {
+        this.recipient = recipient;
+    }
+
     @Override
     public void serialize( DataOutputStream dout )
         throws IOException
@@ -94,6 +107,8 @@
         dout.writeUTF( this.subject );
         dout.writeUTF( this.text );
 
+        this.getRecipient().serialize( dout );
+
     }
 
     @Override
@@ -103,6 +118,14 @@
         subject = din.readUTF();
         text = din.readUTF();
 
+        int recipientSize = din.readInt();
+
+        if ( recipientSize > 0 )
+        {
+            recipient = new Recipient();
+            recipient.deSerialize( din );
+        }
+
     }
 
     @Override
@@ -130,6 +153,8 @@
         dataOutputStream.writeUTF( this.subject );
         dataOutputStream.writeUTF( this.text );
 
+        this.getRecipient().serialize( dataOutputStream );
+
     }
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java	2014-05-09 10:07:18 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java	2014-05-16 06:06:48 +0000
@@ -68,6 +68,8 @@
     private String sendFeedbackUrl;
 
     private String findUserUrl;
+    
+    private String sendMessageUrl;
 
     private String updateContactUrl;
 
@@ -238,6 +240,18 @@
     {
         this.findUserUrl = findUserUrl;
     }
+    
+    
+
+    public String getSendMessageUrl()
+    {
+        return sendMessageUrl;
+    }
+
+    public void setSendMessageUrl( String sendMessageUrl )
+    {
+        this.sendMessageUrl = sendMessageUrl;
+    }
 
     public String getUpdateContactUrl()
     {
@@ -395,6 +409,7 @@
         dataOutputStream.writeUTF( updateNewVersionUrl );
         dataOutputStream.writeUTF( sendFeedbackUrl );
         dataOutputStream.writeUTF( findUserUrl );
+        dataOutputStream.writeUTF( sendMessageUrl );
         dataOutputStream.writeUTF( updateContactUrl );
         dataOutputStream.writeUTF( findPatientUrl );
         dataOutputStream.writeUTF( registerPersonUrl );
@@ -428,6 +443,7 @@
         updateNewVersionUrl = dataInputStream.readUTF();
         sendFeedbackUrl = dataInputStream.readUTF();
         findUserUrl = dataInputStream.readUTF();
+        sendMessageUrl = dataInputStream.readUTF();
         updateContactUrl = dataInputStream.readUTF();
         findPatientUrl = dataInputStream.readUTF();
         registerPersonUrl = dataInputStream.readUTF();
@@ -478,6 +494,7 @@
         dataOutputStream.writeUTF( this.updateNewVersionUrl );
         dataOutputStream.writeUTF( this.sendFeedbackUrl );
         dataOutputStream.writeUTF( this.findUserUrl );
+        dataOutputStream.writeUTF( this.sendMessageUrl );
         // dataOutputStream.writeUTF( this.updateContactUrl );
     }
 
@@ -498,6 +515,7 @@
         dataOutputStream.writeUTF( updateNewVersionUrl );
         dataOutputStream.writeUTF( sendFeedbackUrl );
         dataOutputStream.writeUTF( findUserUrl );
+        dataOutputStream.writeUTF( sendMessageUrl );
         dataOutputStream.writeUTF( updateContactUrl );
         dataOutputStream.writeUTF( findPatientUrl );
         dataOutputStream.writeUTF( registerPersonUrl );

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Recipient.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Recipient.java	2014-05-09 10:07:18 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Recipient.java	2014-05-16 06:06:48 +0000
@@ -31,7 +31,9 @@
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 public class Recipient
     implements DataStreamSerializable
@@ -40,6 +42,8 @@
 
     private Collection<User> users;
 
+    private List<User> userList = new ArrayList<User>();
+
     public String getClientVersion()
     {
         return clientVersion;
@@ -60,6 +64,16 @@
         this.users = users;
     }
 
+    public List<User> getUserList()
+    {
+        return userList;
+    }
+
+    public void setUserList( List<User> userList )
+    {
+        this.userList = userList;
+    }
+
     @Override
     public void serialize( DataOutputStream dout )
         throws IOException
@@ -84,6 +98,14 @@
     public void deSerialize( DataInputStream dataInputStream )
         throws IOException
     {
+        int userSize = dataInputStream.readInt();
+
+        for ( int i = 0; i < userSize; i++ )
+        {
+            User user = new User();
+            user.deSerialize( dataInputStream );
+            userList.add( user );
+        }
 
     }
 
@@ -105,7 +127,7 @@
     public void serializeVersion2_10( DataOutputStream dout )
         throws IOException
     {
-       
+
         if ( users == null )
         {
             dout.writeInt( 0 );

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/User.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/User.java	2014-05-09 10:07:18 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/User.java	2014-05-16 06:06:48 +0000
@@ -39,6 +39,8 @@
 {
     private String clientVersion;
 
+    private int id;
+
     private String surname;
 
     private String firstName;
@@ -47,9 +49,10 @@
     {
     }
 
-    public User( String surname, String firstName )
+    public User( int id, String surname, String firstName )
     {
         super();
+        this.id = id;
         this.surname = surname;
         this.firstName = firstName;
     }
@@ -65,6 +68,17 @@
     }
 
     @XmlAttribute
+    public int getId()
+    {
+        return id;
+    }
+
+    public void setId( int id )
+    {
+        this.id = id;
+    }
+
+    @XmlAttribute
     public String getSurname()
     {
         return surname;
@@ -90,6 +104,7 @@
     public void serialize( DataOutputStream dout )
         throws IOException
     {
+        dout.writeInt( this.id );
         dout.writeUTF( this.surname );
         dout.writeUTF( this.firstName );
 
@@ -99,6 +114,7 @@
     public void deSerialize( DataInputStream din )
         throws IOException
     {
+        id = din.readInt();
         surname = din.readUTF();
         firstName = din.readUTF();
     }
@@ -107,6 +123,7 @@
     public void serializeVersion2_8( DataOutputStream dout )
         throws IOException
     {
+        dout.writeInt( this.id );
         dout.writeUTF( this.surname );
         dout.writeUTF( this.firstName );
     }
@@ -115,6 +132,7 @@
     public void serializeVersion2_9( DataOutputStream dout )
         throws IOException
     {
+        dout.writeInt( this.id );
         dout.writeUTF( this.surname );
         dout.writeUTF( this.firstName );
     }
@@ -123,6 +141,7 @@
     public void serializeVersion2_10( DataOutputStream dout )
         throws IOException
     {
+        dout.writeInt( this.id );
         dout.writeUTF( this.surname );
         dout.writeUTF( this.firstName );
 

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2014-05-14 13:41:06 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2014-05-16 06:06:48 +0000
@@ -115,6 +115,8 @@
 
     private static final String FEEDBACK_SENT = "feedback_sent";
 
+    private static final String MESSAGE_SENT = "message_sent";
+
     private ActivityComparator activityComparator = new ActivityComparator();
 
     // -------------------------------------------------------------------------
@@ -1608,12 +1610,12 @@
                 }
             }
         }
-        
-        //get tracked entity with no tracked entity name
+
+        // get tracked entity with no tracked entity name
         resultSet += "Others$";
         for ( TrackedEntityInstance patient : patients )
         {
-            if ( patient.getTrackedEntity() == null)
+            if ( patient.getTrackedEntity() == null )
             {
                 resultSet += patient.getId() + "/";
                 String attText = "";
@@ -1932,7 +1934,9 @@
 
         for ( User userCore : users )
         {
+
             org.hisp.dhis.api.mobile.model.User user = new org.hisp.dhis.api.mobile.model.User();
+            user.setId( userCore.getId() );
             user.setSurname( userCore.getSurname() );
             user.setFirstName( userCore.getFirstName() );
             userList.add( user );
@@ -1941,4 +1945,26 @@
 
         return userList;
     }
+
+    @Override
+    public String sendMessage( org.hisp.dhis.api.mobile.model.Message message )
+        throws NotAllowedException
+    {
+        String subject = message.getSubject();
+        String text = message.getText();
+        String metaData = MessageService.META_USER_AGENT;
+
+        Set<User> users = new HashSet<User>();
+
+        for ( org.hisp.dhis.api.mobile.model.User user : message.getRecipient().getUserList() )
+        {
+            User userWeb = userService.getUser( user.getId() );
+            users.add( userWeb );
+
+        }
+
+        messageService.sendMessage( subject, text, metaData, users );
+
+        return MESSAGE_SENT;
+    }
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/api/model/OrgUnitTest.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/api/model/OrgUnitTest.java	2014-05-09 10:07:18 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/api/model/OrgUnitTest.java	2014-05-16 06:06:48 +0000
@@ -61,6 +61,7 @@
         unit.setUpdateNewVersionUrl( "" );
         unit.setSendFeedbackUrl( "sendFeedbackUrl" );
         unit.setFindUserUrl( "findUserUrl" );
+        unit.setSendMessageUrl( "sendMessageUrl" );
         unit.setUpdateContactUrl( "updateContactUrl" );
         unit.setFindPatientUrl( "findPatientUrl" );
         unit.setUploadProgramStageUrl( "uploadProgramStageUrl" );

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/api/model/OrgUnitsTest.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/api/model/OrgUnitsTest.java	2014-05-09 10:07:18 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/api/model/OrgUnitsTest.java	2014-05-16 06:06:48 +0000
@@ -86,7 +86,8 @@
         orgUnit.setSearchUrl( "search" );
         orgUnit.setUpdateNewVersionUrl( "updateNewVersionUrl" );
         orgUnit.setSendFeedbackUrl( "sendFeedback" );
-        orgUnit.setFindUserUrl( "findUserUrl" );
+        orgUnit.setFindUserUrl( "findUser" );
+        orgUnit.setSendMessageUrl( "sendMessage" );
         orgUnit.setUpdateContactUrl( "updateContactForMobile" );
         orgUnit.setFindPatientUrl( "findPatient" );
         orgUnit.setRegisterPersonUrl( "registerPerson" );

=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java	2014-05-09 10:07:18 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java	2014-05-16 06:06:48 +0000
@@ -149,6 +149,7 @@
         orgUnit.setUpdateNewVersionUrl( getUrl( request, unit.getId(), "updateNewVersionUrl" ) );
         orgUnit.setSendFeedbackUrl( getUrl( request, unit.getId(), "sendFeedback" ) );
         orgUnit.setFindUserUrl( getUrl( request, unit.getId(), "findUser" ) );
+        orgUnit.setSendMessageUrl(getUrl( request, unit.getId(), "sendMessage" ));
         orgUnit.setUpdateContactUrl( getUrl( request, unit.getId(), "updateContactForMobile" ) );
         orgUnit.setFindPatientUrl( getUrl( request, unit.getId(), "findPatient" ) );
         orgUnit.setRegisterPersonUrl( getUrl( request, unit.getId(), "registerPerson" ) );

=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java	2014-05-09 10:07:18 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java	2014-05-16 06:06:48 +0000
@@ -574,4 +574,14 @@
         return recipient;
     }
 
+    @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/sendMessage" )
+    @ResponseBody
+    public String sendMessage( @PathVariable
+    int id, @RequestBody
+    Message message )
+        throws NotAllowedException
+    {
+        return activityReportingService.sendMessage(message);
+    }
+
 }