dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #32082
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16396: add created, lastupdated to mc store
------------------------------------------------------------
revno: 16396
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-08-13 17:24:23 +0700
message:
add created, lastupdated to mc store
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageConversation.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/MessageConversation.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageConversation.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageConversation.java 2014-08-13 10:24:23 +0000
@@ -102,10 +102,22 @@
// Logic
// --------------------------------------------------------------------------
+
@Override
public String toString()
{
- return "[" + subject + "]";
+ return "MessageConversation{" +
+ "subject='" + subject + '\'' +
+ ", lastSender=" + lastSender +
+ ", lastMessage=" + lastMessage +
+ ", userMessages=" + userMessages +
+ ", messages=" + messages +
+ ", read=" + read +
+ ", followUp=" + followUp +
+ ", lastSenderSurname='" + lastSenderSurname + '\'' +
+ ", lastSenderFirstname='" + lastSenderFirstname + '\'' +
+ ", messageCount=" + messageCount +
+ "} " + super.toString();
}
public void addUserMessage( UserMessage userMessage )
=== 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 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/hibernate/HibernateMessageConversationStore.java 2014-08-13 10:24:23 +0000
@@ -28,10 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-
import org.hibernate.Query;
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
import org.hisp.dhis.jdbc.StatementBuilder;
@@ -42,6 +38,10 @@
import org.hisp.dhis.user.User;
import org.springframework.jdbc.core.RowMapper;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
/**
* @author Lars Helge Overland
*/
@@ -54,12 +54,12 @@
// -------------------------------------------------------------------------
private StatementBuilder statementBuilder;
-
+
public void setStatementBuilder( StatementBuilder statementBuilder )
{
this.statementBuilder = statementBuilder;
}
-
+
// -------------------------------------------------------------------------
// Implementation methods
// -------------------------------------------------------------------------
@@ -71,7 +71,7 @@
String sql = "select mc.messageconversationid, mc.uid, mc.subject, mc.lastmessage, ui.surname, ui.firstname, um.isread, um.isfollowup, (" +
"select count(messageconversationid) from messageconversation_messages mcm where mcm.messageconversationid=mc.messageconversationid) as messagecount " +
- "from messageconversation mc " +
+ ", mc.created, mc.lastupdated from messageconversation mc " +
"inner join messageconversation_usermessages mu on mc.messageconversationid=mu.messageconversationid " +
"inner join usermessage um on mu.usermessageid=um.usermessageid " +
"left join userinfo ui on mc.lastsenderid=ui.userinfoid ";
@@ -114,6 +114,8 @@
conversation.setRead( resultSet.getBoolean( 7 ) );
conversation.setFollowUp( resultSet.getBoolean( 8 ) );
conversation.setMessageCount( resultSet.getInt( 9 ) );
+ conversation.setCreated( resultSet.getDate( 10 ) );
+ conversation.setLastUpdated( resultSet.getDate( 11 ) );
return conversation;
}
@@ -148,7 +150,7 @@
{
return -1;
}
-
+
String hql = "select count(*) from MessageConversation m join m.userMessages u where u.user = :user and u.read = false";
Query query = getQuery( hql );
@@ -163,7 +165,7 @@
{
return -1;
}
-
+
String sql = "delete from messageconversation_messages where messageid in ("
+ "select messageid from message where userid = " + sender.getId() + ")";
@@ -182,7 +184,7 @@
{
return -1;
}
-
+
String sql = "delete from messageconversation_usermessages where usermessageid in ("
+ "select usermessageid from usermessage where userid = " + user.getId() + ")";
@@ -205,34 +207,34 @@
}
public List<UserMessage> getLastRecipients( User user, Integer first, Integer max )
- {
- String sql = " select distinct userinfoid, surname, firstname from userinfo uf"
- + " join usermessage um on (uf.userinfoid = um.userid)"
- + " join messageconversation_usermessages mu on (um.usermessageid = mu.usermessageid)"
- + " join messageconversation mc on (mu.messageconversationid = mc.messageconversationid)"
- + " where mc.lastsenderid = " + user.getId();
-
+ {
+ String sql = " select distinct userinfoid, surname, firstname from userinfo uf"
+ + " join usermessage um on (uf.userinfoid = um.userid)"
+ + " join messageconversation_usermessages mu on (um.usermessageid = mu.usermessageid)"
+ + " join messageconversation mc on (mu.messageconversationid = mc.messageconversationid)"
+ + " where mc.lastsenderid = " + user.getId();
+
sql += " order by userinfoid desc";
-
+
if ( first != null && max != null )
{
sql += " " + statementBuilder.limitRecord( first, max );
}
-
+
final List<UserMessage> recipients = jdbcTemplate.query( sql, new RowMapper<UserMessage>()
{
public UserMessage mapRow( ResultSet resultSet, int count ) throws SQLException
{
UserMessage recipient = new UserMessage();
-
+
recipient.setId( resultSet.getInt( 1 ) );
recipient.setLastRecipientSurname( resultSet.getString( 2 ) );
recipient.setLastRecipientFirstname( resultSet.getString( 3 ) );
-
+
return recipient;
- }
- } );
-
+ }
+ } );
+
return recipients;
}
}
\ No newline at end of file