dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #15626
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5709: Impl class MessageConversationDeletionHandler
------------------------------------------------------------
revno: 5709
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-01-11 20:25:49 +0100
message:
Impl class MessageConversationDeletionHandler
added:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/MessageConversationDeletionHandler.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageConversationStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java
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/organisationunit/OrganisationUnitDeletionHandler.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.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-api/src/main/java/org/hisp/dhis/message/MessageConversationStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageConversationStore.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageConversationStore.java 2012-01-11 19:25:49 +0000
@@ -50,4 +50,10 @@
List<MessageConversation> getMessageConversations( User user, Integer first, Integer max );
long getUnreadUserMessageConversationCount( User user );
+
+ int deleteMessages( User sender );
+
+ int deleteUserMessages( User user );
+
+ int removeUserFromMessageConversations( User lastSender );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageService.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageService.java 2012-01-11 19:25:49 +0000
@@ -64,5 +64,7 @@
List<MessageConversation> getMessageConversations( int first, int max );
- List<MessageConversation> getAllMessageConversations();
+ List<MessageConversation> getAllMessageConversations();
+
+ void deleteMessages( User sender );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2012-01-11 19:25:49 +0000
@@ -221,6 +221,13 @@
return messageConversationStore.getMessageConversations( null, null, null );
}
+ public void deleteMessages( User user )
+ {
+ messageConversationStore.deleteMessages( user );
+ messageConversationStore.deleteUserMessages( user );
+ messageConversationStore.removeUserFromMessageConversations( user );
+ }
+
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/MessageConversationDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/MessageConversationDeletionHandler.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/MessageConversationDeletionHandler.java 2012-01-11 19:25:49 +0000
@@ -0,0 +1,65 @@
+package org.hisp.dhis.message;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.system.deletion.DeletionHandler;
+import org.hisp.dhis.user.User;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class MessageConversationDeletionHandler
+ extends DeletionHandler
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private MessageService messageService;
+
+ public void setMessageService( MessageService messageService )
+ {
+ this.messageService = messageService;
+ }
+
+ // -------------------------------------------------------------------------
+ // DeletionHandler implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public String getClassName()
+ {
+ return MessageConversation.class.getSimpleName();
+ }
+
+ @Override
+ public void deleteUser( User user )
+ {
+ messageService.deleteMessages( user );
+ }
+}
=== 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-01-03 03:50:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/hibernate/HibernateMessageConversationStore.java 2012-01-11 19:25:49 +0000
@@ -115,4 +115,31 @@
return (Long) query.uniqueResult();
}
+
+ public int deleteMessages( User sender )
+ {
+ String hql = "delete Message m where m.sender = :sender";
+
+ Query query = getQuery( hql );
+ query.setEntity( "sender", sender );
+ return query.executeUpdate();
+ }
+
+ public int deleteUserMessages( User user )
+ {
+ String hql = "delete UserMessage u where u.user = :user";
+
+ Query query = getQuery( hql );
+ query.setEntity( "user", user );
+ return query.executeUpdate();
+ }
+
+ public int removeUserFromMessageConversations( User lastSender )
+ {
+ String hql = "update MessageConversation m set m.lastSender = null where m.lastSender = :lastSender";
+
+ Query query = getQuery( hql );
+ query.setEntity( "lastSender", lastSender );
+ return query.executeUpdate();
+ }
}
\ No newline at end of file
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDeletionHandler.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDeletionHandler.java 2012-01-11 19:25:49 +0000
@@ -72,7 +72,6 @@
@Override
public void deleteOrganisationUnit( OrganisationUnit unit )
{
- // Delete attributeValues
Iterator<AttributeValue> iterator = unit.getAttributeValues().iterator();
while ( iterator.hasNext() )
=== 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 2012-01-05 20:39:23 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2012-01-11 19:25:49 +0000
@@ -1243,6 +1243,10 @@
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
+ <bean id="org.hisp.dhis.message.MessageConversationDeletionHandler" class="org.hisp.dhis.message.MessageConversationDeletionHandler">
+ <property name="messageService" ref="org.hisp.dhis.message.MessageService"/>
+ </bean>
+
<!-- DeletionManager -->
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
@@ -1279,6 +1283,7 @@
<ref local="org.hisp.dhis.dataelement.DataElementCategoryDeletionHandler" />
<ref local="org.hisp.dhis.dataelement.DataElementGroupSetDeletionHandler" />
<ref local="org.hisp.dhis.configuration.ConfigurationDeletionHandler" />
+ <ref local="org.hisp.dhis.message.MessageConversationDeletionHandler" />
</list>
</list>
</property>
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java 2012-01-11 19:25:49 +0000
@@ -65,6 +65,8 @@
assertFalse( coordinateIsValid( "192.56789,-45.34332" ) );
assertFalse( coordinateIsValid( "140.34,92.23323" ) );
assertFalse( coordinateIsValid( "123.34,-94.23323" ) );
+ assertFalse( coordinateIsValid( "000.34,-94.23323" ) );
+ assertFalse( coordinateIsValid( "123.34,-00.23323" ) );
}
@Test