dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17644
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7097: WIP messaging
------------------------------------------------------------
revno: 7097
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-05-30 10:41:20 +0200
message:
WIP messaging
added:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SqlHelper.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
--
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 2012-02-14 19:19:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageConversationStore.java 2012-05-30 08:41:20 +0000
@@ -47,9 +47,9 @@
* @param max the max number of records to return, or all if null.
* @return a list of MessageConversations.
*/
- List<MessageConversation> getMessageConversations( User user, Integer first, Integer max );
+ List<MessageConversation> getMessageConversations( User user, boolean followUpOnly, boolean unreadOnly, Integer first, Integer max );
- int getMessageConversationCount( User user );
+ int getMessageConversationCount( User user, boolean followUpOnly, boolean unreadOnly );
long getUnreadUserMessageConversationCount( User user );
=== 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 2012-02-14 19:19:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageService.java 2012-05-30 08:41:20 +0000
@@ -64,8 +64,12 @@
List<MessageConversation> getMessageConversations( int first, int max );
+ List<MessageConversation> getMessageConversations( boolean followUpOnly, boolean unreadOnly, int first, int max );
+
int getMessageConversationCount();
+ int getMessageConversationCount( boolean followUpOnly, boolean unreadOnly );
+
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 2012-04-25 14:26:13 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2012-05-30 08:41:20 +0000
@@ -223,17 +223,27 @@
public List<MessageConversation> getMessageConversations( int first, int max )
{
- return messageConversationStore.getMessageConversations( currentUserService.getCurrentUser(), first, max );
+ return messageConversationStore.getMessageConversations( currentUserService.getCurrentUser(), false, false, first, max );
+ }
+
+ public List<MessageConversation> getMessageConversations( boolean followUpOnly, boolean unreadOnly, int first, int max )
+ {
+ return messageConversationStore.getMessageConversations( currentUserService.getCurrentUser(), followUpOnly, unreadOnly, first, max );
}
public int getMessageConversationCount()
{
- return messageConversationStore.getMessageConversationCount( currentUserService.getCurrentUser() );
+ return messageConversationStore.getMessageConversationCount( currentUserService.getCurrentUser(), false, false );
+ }
+
+ public int getMessageConversationCount( boolean followUpOnly, boolean unreadOnly )
+ {
+ return messageConversationStore.getMessageConversationCount( currentUserService.getCurrentUser(), followUpOnly, unreadOnly );
}
public List<MessageConversation> getAllMessageConversations()
{
- return messageConversationStore.getMessageConversations( null, null, null );
+ return messageConversationStore.getMessageConversations( null, false, false, null, null );
}
public void deleteMessages( User 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-05-30 07:54:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/hibernate/HibernateMessageConversationStore.java 2012-05-30 08:41:20 +0000
@@ -36,6 +36,7 @@
import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.message.MessageConversation;
import org.hisp.dhis.message.MessageConversationStore;
+import org.hisp.dhis.system.util.SqlHelper;
import org.hisp.dhis.user.User;
import org.springframework.jdbc.core.RowMapper;
@@ -60,8 +61,10 @@
// Implementation methods
// -------------------------------------------------------------------------
- public List<MessageConversation> getMessageConversations( User user, Integer first, Integer max )
+ public List<MessageConversation> getMessageConversations( User user, boolean followUpOnly, boolean unreadOnly, Integer first, Integer max )
{
+ SqlHelper sh = new SqlHelper();
+
String sql =
"select mc.messageconversationid, mc.uid, mc.subject, mc.lastmessage, ui.surname, ui.firstname, um.isread, um.isfollowup " +
"from messageconversation mc " +
@@ -71,7 +74,17 @@
if ( user != null )
{
- sql += "where um.userid=" + user.getId() + " ";
+ sql += sh.whereAnd() + " um.userid=" + user.getId() + " ";
+ }
+
+ if ( followUpOnly )
+ {
+ sql += sh.whereAnd() + " um.isfollowup=true ";
+ }
+
+ if ( unreadOnly )
+ {
+ sql += sh.whereAnd() + " um.isread=false ";
}
sql += "order by mc.lastmessage desc ";
@@ -103,14 +116,24 @@
return conversations;
}
- public int getMessageConversationCount( User user )
+ public int getMessageConversationCount( User user, boolean followUpOnly, boolean unreadOnly )
{
String sql =
"select count(*) from messageconversation mc " +
"left join messageconversation_usermessages mu on mc.messageconversationid=mu.messageconversationid " +
"left join usermessage um on mu.usermessageid=um.usermessageid " +
- "where um.userid=" + user.getId();
+ "where um.userid=" + user.getId() + " ";
+ if ( followUpOnly )
+ {
+ sql += "and um.isfollowup=true ";
+ }
+
+ if ( unreadOnly )
+ {
+ sql += "and um.isread=false ";
+ }
+
return jdbcTemplate.queryForInt( sql );
}
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SqlHelper.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SqlHelper.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SqlHelper.java 2012-05-30 08:41:20 +0000
@@ -0,0 +1,48 @@
+package org.hisp.dhis.system.util;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author Lars Helge Overland
+ */
+public class SqlHelper
+{
+ private boolean whereAndInvoked = false;
+
+ /**
+ * Returns "where" the first time it is invoked, then "and" for subsequent invocations.
+ */
+ public String whereAnd()
+ {
+ String str = whereAndInvoked ? "and" : "where";
+
+ whereAndInvoked = true;
+
+ return str;
+ }
+}