← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7464: Fixed bug, message for a user were not removed when the user is deleted

 

------------------------------------------------------------
revno: 7464
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-06-30 14:58:55 +0200
message:
  Fixed bug, message for a user were not removed when the user is deleted
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/hibernate/HibernateMessageConversationStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/message/MessageServiceTest.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/message/hibernate/HibernateMessageConversationStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/hibernate/HibernateMessageConversationStore.java	2012-05-30 08:41:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/hibernate/HibernateMessageConversationStore.java	2012-06-30 12:58:55 +0000
@@ -150,6 +150,11 @@
     
     public int deleteMessages( User sender )
     {
+        String sql = "delete from messageconversation_messages where messageid in (" +
+            "select messageid from message where userid = " + sender.getId() + ")";
+        
+        getSqlQuery( sql ).executeUpdate();
+        
         String hql = "delete Message m where m.sender = :sender";
 
         Query query = getQuery( hql );
@@ -159,6 +164,11 @@
     
     public int deleteUserMessages( User user )
     {
+        String sql = "delete from messageconversation_usermessages where usermessageid in (" +
+            "select usermessageid from usermessage where userid = " + user.getId() + ")";
+
+        getSqlQuery( sql ).executeUpdate();
+        
         String hql = "delete UserMessage u where u.user = :user";
 
         Query query = getQuery( hql );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/message/MessageServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/message/MessageServiceTest.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/message/MessageServiceTest.java	2012-06-30 12:58:55 +0000
@@ -126,6 +126,34 @@
     }
 
     @Test
+    public void testDeleteMessage()
+    {
+        MessageConversation conversation = new MessageConversation( "Subject", sender );
+        
+        UserMessage userMessageA = new UserMessage( userA );
+        UserMessage userMessageB = new UserMessage( userB );
+        
+        conversation.addUserMessage( userMessageA );
+        conversation.addUserMessage( userMessageB );
+        
+        Message contentA = new Message( "TextA", "MetaA", sender );
+        Message contentB = new Message( "TextB", "MetaB", sender );
+        
+        conversation.addMessage( contentA );
+        conversation.addMessage( contentB );
+        
+        int id = messageService.saveMessageConversation( conversation );
+        
+        conversation = messageService.getMessageConversation( id );
+        
+        assertNotNull( conversation );
+        
+        messageService.deleteMessages( userA );
+        messageService.deleteMessages( userB );
+        messageService.deleteMessages( sender );
+    }
+
+    @Test
     public void testSendMessage()
     {
         int id = messageService.sendMessage( "Subject", "Text", "Meta", users );