dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20396
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9289: [mobile] update last recipients list function for messaging on mobile browser
------------------------------------------------------------
revno: 9289
committer: Homg Em <em.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-12-13 15:06:31 +0700
message:
[mobile] update last recipients list function for messaging on mobile browser
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/Message.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageConversation.java
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-api/src/main/java/org/hisp/dhis/message/UserMessage.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/test/java/org/hisp/dhis/message/MessageServiceTest.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ResourceTableController.java
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/message/action/GetMessageAction.java
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/message/action/GetMessagesAction.java
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/messaging/action/SendMessagesAction.java
dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/messages.vm
--
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/Message.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/Message.java 2012-03-19 18:32:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/Message.java 2012-12-13 08:06:31 +0000
@@ -76,6 +76,7 @@
this.text = text;
this.metaData = metaData;
this.sender = sender;
+
}
@Override
@@ -85,7 +86,7 @@
}
@JsonProperty
- @JsonView( {DetailedView.class, ExportView.class} )
+ @JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlProperty
public String getText()
{
@@ -98,7 +99,7 @@
}
@JsonProperty
- @JsonView( {DetailedView.class, ExportView.class} )
+ @JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlProperty
public String getMetaData()
{
@@ -112,7 +113,7 @@
@JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
- @JsonView( {DetailedView.class, ExportView.class} )
+ @JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlProperty
public User getSender()
{
=== 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 2012-10-08 14:17:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageConversation.java 2012-12-13 08:06:31 +0000
@@ -50,9 +50,9 @@
public class MessageConversation
extends BaseIdentifiableObject
{
- //--------------------------------------------------------------------------
+ // --------------------------------------------------------------------------
// Persistent fields
- //--------------------------------------------------------------------------
+ // --------------------------------------------------------------------------
private String subject;
@@ -66,9 +66,9 @@
@Scanned
private List<Message> messages = new ArrayList<Message>();
- //--------------------------------------------------------------------------
+ // --------------------------------------------------------------------------
// Transient fields
- //--------------------------------------------------------------------------
+ // --------------------------------------------------------------------------
private transient boolean read;
@@ -80,9 +80,10 @@
private transient int messageCount;
- //--------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------
// Constructors
- //--------------------------------------------------------------------------
+ // --------------------------------------------------------------------------
public MessageConversation()
{
@@ -95,9 +96,9 @@
this.lastMessage = new Date();
}
- //--------------------------------------------------------------------------
+ // --------------------------------------------------------------------------
// Logic
- //--------------------------------------------------------------------------
+ // --------------------------------------------------------------------------
@Override
public int hashCode()
@@ -253,9 +254,9 @@
userMessages.clear();
}
- //-------------------------------------------------------------------------------------------------------
+ // -------------------------------------------------------------------------------------------------------
// Persistent fields
- //-------------------------------------------------------------------------------------------------------
+ // -------------------------------------------------------------------------------------------------------
@Override
public String getName()
@@ -264,7 +265,7 @@
}
@JsonProperty
- @JsonView( {DetailedView.class, ExportView.class} )
+ @JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public String getSubject()
{
@@ -278,7 +279,7 @@
@JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
- @JsonView( {DetailedView.class, ExportView.class} )
+ @JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public User getLastSender()
{
@@ -291,7 +292,7 @@
}
@JsonProperty
- @JsonView( {DetailedView.class, ExportView.class} )
+ @JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public Date getLastMessage()
{
@@ -304,7 +305,7 @@
}
@JsonProperty
- @JsonView( {DetailedView.class, ExportView.class} )
+ @JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlElementWrapper( localName = "userMessages", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "userMessage", namespace = Dxf2Namespace.NAMESPACE )
public Set<UserMessage> getUserMessages()
@@ -318,7 +319,7 @@
}
@JsonProperty
- @JsonView( {DetailedView.class, ExportView.class} )
+ @JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlElementWrapper( localName = "messages", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "message", namespace = Dxf2Namespace.NAMESPACE )
public List<Message> getMessages()
@@ -331,12 +332,12 @@
this.messages = messages;
}
- //-------------------------------------------------------------------------------------------------------
+ // -------------------------------------------------------------------------------------------------------
// Transient fields
- //-------------------------------------------------------------------------------------------------------
+ // -------------------------------------------------------------------------------------------------------
@JsonProperty
- @JacksonXmlProperty( isAttribute = true)
+ @JacksonXmlProperty( isAttribute = true )
public boolean isRead()
{
return read;
@@ -348,7 +349,7 @@
}
@JsonProperty
- @JacksonXmlProperty( isAttribute = true)
+ @JacksonXmlProperty( isAttribute = true )
public boolean isFollowUp()
{
return followUp;
@@ -405,7 +406,8 @@
subject = messageConversation.getSubject() == null ? subject : messageConversation.getSubject();
lastSender = messageConversation.getLastSender() == null ? lastSender : messageConversation.getLastSender();
- lastMessage = messageConversation.getLastMessage() == null ? lastMessage : messageConversation.getLastMessage();
+ lastMessage = messageConversation.getLastMessage() == null ? lastMessage : messageConversation
+ .getLastMessage();
removeAllUserMessages();
userMessages.addAll( messageConversation.getUserMessages() );
=== 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-05-30 08:41:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageConversationStore.java 2012-12-13 08:06:31 +0000
@@ -58,4 +58,8 @@
int deleteUserMessages( User user );
int removeUserFromMessageConversations( User lastSender );
+
+ List<UserMessage> getLastRecipients(User user, Integer first, Integer max, Integer currentUserId);
+
+
}
=== 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-12-04 08:35:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageService.java 2012-12-13 08:06:31 +0000
@@ -75,4 +75,6 @@
List<MessageConversation> getAllMessageConversations();
void deleteMessages( User sender );
+
+ List<UserMessage> getLastRecipients( int first, int max, Integer currentUserId );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/UserMessage.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/UserMessage.java 2012-06-14 18:50:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/UserMessage.java 2012-12-13 08:06:31 +0000
@@ -55,6 +55,37 @@
private boolean read;
private boolean followUp;
+
+ private transient String lastRecipientSurname;
+
+ private transient String lastRecipientFirstname;
+
+
+
+ public String getLastRecipientSurname()
+ {
+ return lastRecipientSurname;
+ }
+
+ public void setLastRecipientSurname( String lastRecipientSurname )
+ {
+ this.lastRecipientSurname = lastRecipientSurname;
+ }
+
+ public String getLastRecipientFirstname()
+ {
+ return lastRecipientFirstname;
+ }
+
+ public void setLastRecipientFirstname( String lastRecipientFirstname )
+ {
+ this.lastRecipientFirstname = lastRecipientFirstname;
+ }
+
+ public String getLastRecipientName()
+ {
+ return lastRecipientFirstname + " " + lastRecipientSurname;
+ }
public UserMessage()
{
=== 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-12-12 10:55:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2012-12-13 08:06:31 +0000
@@ -43,6 +43,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
+import com.sun.org.apache.regexp.internal.recompile;
+
/**
* @author Lars Helge Overland
*/
@@ -51,8 +53,9 @@
implements MessageService
{
private static final Log log = LogFactory.getLog( DefaultMessageService.class );
-
+
private static final String COMPLETE_SUBJECT = "Form registered as complete";
+
private static final String COMPLETE_TEMPLATE = "completeness_message";
// -------------------------------------------------------------------------
@@ -98,11 +101,12 @@
{
return sendMessage( subject, text, metaData, users, false );
}
-
- public int sendMessage( String subject, String text, String metaData, Set<User> users_, boolean includeFeedbackRecipients )
+
+ public int sendMessage( String subject, String text, String metaData, Set<User> users_,
+ boolean includeFeedbackRecipients )
{
Set<User> users = new HashSet<User>( users_ );
-
+
// ---------------------------------------------------------------------
// Add feedback recipients to users if they are not there
// ---------------------------------------------------------------------
@@ -110,13 +114,13 @@
if ( includeFeedbackRecipients )
{
UserGroup userGroup = configurationService.getConfiguration().getFeedbackRecipients();
-
+
if ( userGroup != null && userGroup.getMembers().size() > 0 )
{
users.addAll( userGroup.getMembers() );
}
}
-
+
User sender = currentUserService.getCurrentUser();
if ( sender != null )
@@ -124,6 +128,13 @@
users.add( sender );
}
+ User recipient = currentUserService.getCurrentUser();
+
+ if ( recipient != null )
+ {
+ users.add( recipient );
+ }
+
// ---------------------------------------------------------------------
// Instantiate message, content and user messages
// ---------------------------------------------------------------------
@@ -167,18 +178,18 @@
public int sendCompletenessMessage( CompleteDataSetRegistration registration )
{
DataSet dataSet = registration.getDataSet();
-
+
if ( dataSet == null )
{
return 0;
}
UserGroup userGroup = dataSet.getNotificationRecipients();
-
+
User sender = currentUserService.getCurrentUser();
Set<User> recipients = new HashSet<User>();
-
+
if ( userGroup != null )
{
recipients.addAll( new HashSet<User>( userGroup.getMembers() ) );
@@ -188,18 +199,18 @@
{
recipients.add( sender );
}
-
+
if ( recipients.isEmpty() )
{
return 0;
}
-
+
String text = new VelocityManager().render( registration, COMPLETE_TEMPLATE );
MessageConversation conversation = new MessageConversation( COMPLETE_SUBJECT, sender );
conversation.addMessage( new Message( text, null, sender ) );
-
+
for ( User user : recipients )
{
conversation.addUserMessage( new UserMessage( user ) );
@@ -208,12 +219,16 @@
if ( !conversation.getUserMessages().isEmpty() )
{
int id = saveMessageConversation( conversation );
+
+
+ invokeMessageSenders( COMPLETE_SUBJECT, text, sender, conversation.getUsers() );
+
invokeMessageSenders( COMPLETE_SUBJECT, text, sender, new HashSet<User>( conversation.getUsers() ) );
-
+
return id;
}
-
+
return 0;
}
@@ -249,14 +264,17 @@
public List<MessageConversation> getMessageConversations( int first, int max )
{
- return messageConversationStore.getMessageConversations( currentUserService.getCurrentUser(), false, false, first, max );
+ return messageConversationStore.getMessageConversations( currentUserService.getCurrentUser(), false, false,
+ first, max );
}
- public List<MessageConversation> getMessageConversations( boolean followUpOnly, boolean unreadOnly, int first, int max )
+ public List<MessageConversation> getMessageConversations( boolean followUpOnly, boolean unreadOnly, int first,
+ int max )
{
- return messageConversationStore.getMessageConversations( currentUserService.getCurrentUser(), followUpOnly, unreadOnly, first, max );
+ return messageConversationStore.getMessageConversations( currentUserService.getCurrentUser(), followUpOnly,
+ unreadOnly, first, max );
}
-
+
public int getMessageConversationCount()
{
return messageConversationStore.getMessageConversationCount( currentUserService.getCurrentUser(), false, false );
@@ -264,9 +282,10 @@
public int getMessageConversationCount( boolean followUpOnly, boolean unreadOnly )
{
- return messageConversationStore.getMessageConversationCount( currentUserService.getCurrentUser(), followUpOnly, unreadOnly );
+ return messageConversationStore.getMessageConversationCount( currentUserService.getCurrentUser(), followUpOnly,
+ unreadOnly );
}
-
+
public List<MessageConversation> getAllMessageConversations()
{
return messageConversationStore.getMessageConversations( null, false, false, null, null );
@@ -278,7 +297,7 @@
messageConversationStore.deleteUserMessages( user );
messageConversationStore.removeUserFromMessageConversations( user );
}
-
+
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
@@ -289,6 +308,12 @@
{
messageSender.sendMessage( subject, text, sender, users, false );
}
- }
-
+ }
+
+ @Override
+ public List<UserMessage> getLastRecipients( int first, int max, Integer currentUserId )
+ {
+ return messageConversationStore.getLastRecipients( currentUserService.getCurrentUser(), first, max, currentUserId );
+ }
+
}
=== 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-10-08 14:17:25 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/hibernate/HibernateMessageConversationStore.java 2012-12-13 08:06:31 +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.message.UserMessage;
import org.hisp.dhis.system.util.SqlHelper;
import org.hisp.dhis.user.User;
import org.springframework.jdbc.core.RowMapper;
@@ -44,14 +45,15 @@
* @author Lars Helge Overland
*/
public class HibernateMessageConversationStore
- extends HibernateIdentifiableObjectStore<MessageConversation> implements MessageConversationStore
+ extends HibernateIdentifiableObjectStore<MessageConversation>
+ implements MessageConversationStore
{
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
private StatementBuilder statementBuilder;
-
+
public void setStatementBuilder( StatementBuilder statementBuilder )
{
this.statementBuilder = statementBuilder;
@@ -61,123 +63,125 @@
// Implementation methods
// -------------------------------------------------------------------------
- public List<MessageConversation> getMessageConversations( User user, boolean followUpOnly, boolean unreadOnly, 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, (" +
- "select count(messageconversationid) from messageconversation_messages mcm where mcm.messageconversationid=mc.messageconversationid) as messagecount " +
- "from messageconversation mc " +
- "left join messageconversation_usermessages mu on mc.messageconversationid=mu.messageconversationid " +
- "left join usermessage um on mu.usermessageid=um.usermessageid " +
- "left join userinfo ui on mc.lastsenderid=ui.userinfoid ";
-
+
+ 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 "
+ + "left join messageconversation_usermessages mu on mc.messageconversationid=mu.messageconversationid "
+ + "left join usermessage um on mu.usermessageid=um.usermessageid "
+ + "left join userinfo ui on mc.lastsenderid=ui.userinfoid ";
+
if ( user != null )
{
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 ";
-
+
if ( first != null && max != null )
{
sql += statementBuilder.limitRecord( first, max );
}
-
+
final List<MessageConversation> conversations = jdbcTemplate.query( sql, new RowMapper<MessageConversation>()
{
- public MessageConversation mapRow( ResultSet resultSet, int count ) throws SQLException
+ public MessageConversation mapRow( ResultSet resultSet, int count )
+ throws SQLException
{
MessageConversation conversation = new MessageConversation();
-
+
conversation.setId( resultSet.getInt( 1 ) );
conversation.setUid( resultSet.getString( 2 ) );
conversation.setSubject( resultSet.getString( 3 ) );
conversation.setLastMessage( resultSet.getDate( 4 ) );
conversation.setLastSenderSurname( resultSet.getString( 5 ) );
- conversation.setLastSenderFirstname( resultSet.getString( 6 ) );
+ conversation.setLastSenderFirstname( resultSet.getString( 6 ) );
conversation.setRead( resultSet.getBoolean( 7 ) );
conversation.setFollowUp( resultSet.getBoolean( 8 ) );
conversation.setMessageCount( resultSet.getInt( 9 ) );
-
+
return conversation;
- }
+ }
} );
-
+
return conversations;
}
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() + " ";
+ 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()
+ + " ";
if ( followUpOnly )
{
sql += "and um.isfollowup=true ";
}
-
+
if ( unreadOnly )
{
sql += "and um.isread=false ";
}
-
+
return jdbcTemplate.queryForInt( sql );
}
-
+
public long getUnreadUserMessageConversationCount( User user )
{
String hql = "select count(*) from MessageConversation m join m.userMessages u where u.user = :user and u.read = false";
-
+
Query query = getQuery( hql );
query.setEntity( "user", user );
query.setCacheable( true );
-
+
return (Long) query.uniqueResult();
}
-
+
public int deleteMessages( User sender )
{
- String sql = "delete from messageconversation_messages where messageid in (" +
- "select messageid from message where userid = " + sender.getId() + ")";
-
+ 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 );
query.setEntity( "sender", sender );
return query.executeUpdate();
}
-
+
public int deleteUserMessages( User user )
{
- String sql = "delete from messageconversation_usermessages where usermessageid in (" +
- "select usermessageid from usermessage where userid = " + user.getId() + ")";
+ 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 );
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";
@@ -186,4 +190,38 @@
query.setEntity( "lastSender", lastSender );
return query.executeUpdate();
}
+
+ public List<UserMessage> getLastRecipients( User user, Integer first, Integer max, Integer currentUserId )
+ {
+ 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 = " + currentUserId;
+
+ 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
=== 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 2012-11-20 17:04:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/message/MessageServiceTest.java 2012-12-13 08:06:31 +0000
@@ -49,6 +49,7 @@
private User sender;
private User userA;
private User userB;
+
private Set<User> users;
@@ -65,10 +66,12 @@
sender = createUser( 'S' );
userA = createUser( 'A' );
userB = createUser( 'B' );
+
userService.addUser( sender );
userService.addUser( userA );
userService.addUser( userB );
+
users = new HashSet<User>();
users.add( userA );
@@ -106,7 +109,7 @@
conversation.addUserMessage( userMessageB );
Message contentA = new Message( "TextA", "MetaA", sender );
- Message contentB = new Message( "TextB", "MetaB", sender );
+ Message contentB = new Message( "TextB", "MetaB", sender);
conversation.addMessage( contentA );
conversation.addMessage( contentB );
@@ -128,7 +131,7 @@
@Test
public void testDeleteMessage()
{
- MessageConversation conversation = new MessageConversation( "Subject", sender );
+ MessageConversation conversation = new MessageConversation( "Subject", sender);
UserMessage userMessageA = new UserMessage( userA );
UserMessage userMessageB = new UserMessage( userB );
@@ -137,7 +140,7 @@
conversation.addUserMessage( userMessageB );
Message contentA = new Message( "TextA", "MetaA", sender );
- Message contentB = new Message( "TextB", "MetaB", sender );
+ Message contentB = new Message( "TextB", "MetaB", sender);
conversation.addMessage( contentA );
conversation.addMessage( contentB );
@@ -184,7 +187,7 @@
public void testSendReply()
{
MessageConversation message = new MessageConversation( "Subject", sender );
- message.addMessage( new Message( "TextA", "MetaA", sender ) );
+ message.addMessage( new Message( "TextA", "MetaA", sender) );
int id = messageService.saveMessageConversation( message );
messageService.sendReply( message, "TextB", "MetaB" );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ResourceTableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ResourceTableController.java 2012-12-04 18:31:02 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ResourceTableController.java 2012-12-13 08:06:31 +0000
@@ -29,7 +29,6 @@
import javax.servlet.http.HttpServletResponse;
-import org.hisp.dhis.analytics.AnalyticsTableService;
import org.hisp.dhis.api.utils.ContextUtils;
import org.hisp.dhis.resourcetable.ResourceTableService;
import org.springframework.beans.factory.annotation.Autowired;
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/message/action/GetMessageAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/message/action/GetMessageAction.java 2012-01-12 08:43:22 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/message/action/GetMessageAction.java 2012-12-13 08:06:31 +0000
@@ -31,12 +31,16 @@
import org.hisp.dhis.message.Message;
import org.hisp.dhis.message.MessageConversation;
import org.hisp.dhis.message.MessageService;
+import org.hisp.dhis.message.UserMessage;
import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
import org.springframework.util.Assert;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -97,16 +101,17 @@
// -------------------------------------------------------------------------
@Override
- public String execute() throws Exception
+ public String execute()
+ throws Exception
{
Assert.hasText( conversationId );
MessageConversation conversation = messageService.getMessageConversation( conversationId );
-
+
subject = conversation.getSubject();
+
messages = new ArrayList<Message>( conversation.getMessages() );
Collections.reverse( messages );
-
conversation.markRead( currentUserService.getCurrentUser() );
messageService.updateMessageConversation( conversation );
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/message/action/GetMessagesAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/message/action/GetMessagesAction.java 2012-01-09 14:29:43 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/message/action/GetMessagesAction.java 2012-12-13 08:06:31 +0000
@@ -27,12 +27,15 @@
package org.hisp.dhis.light.message.action;
-import com.opensymphony.xwork2.Action;
+import java.util.ArrayList;
+import java.util.List;
+
import org.hisp.dhis.message.MessageConversation;
import org.hisp.dhis.message.MessageService;
+import org.hisp.dhis.message.UserMessage;
+import org.hisp.dhis.user.CurrentUserService;
-import java.util.ArrayList;
-import java.util.List;
+import com.opensymphony.xwork2.Action;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -51,6 +54,13 @@
this.messageService = messageService;
}
+ private CurrentUserService currentUserService;
+
+ public void setCurrentUserService( CurrentUserService currentUserService )
+ {
+ this.currentUserService = currentUserService;
+ }
+
// -------------------------------------------------------------------------
// Input & Output
// -------------------------------------------------------------------------
@@ -62,15 +72,34 @@
return conversations;
}
+ private List<UserMessage> usermessages;
+
+ public List<UserMessage> getUsermessages()
+ {
+ return usermessages;
+ }
+
+ private Integer currentUserId;
+
+ public void setCurrentUserId( Integer currentUserId )
+ {
+ this.currentUserId = currentUserId;
+ }
+
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
- public String execute() throws Exception
+ public String execute()
+ throws Exception
{
conversations = new ArrayList<MessageConversation>( messageService.getMessageConversations( 0, 10 ) );
+ currentUserId = currentUserService.getCurrentUser().getId();
+
+ usermessages = new ArrayList<UserMessage>( messageService.getLastRecipients( 0, 5, currentUserId ) );
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/messaging/action/SendMessagesAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/messaging/action/SendMessagesAction.java 2012-12-04 08:35:56 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/messaging/action/SendMessagesAction.java 2012-12-13 08:06:31 +0000
@@ -48,7 +48,7 @@
@Autowired
private MessageService messageService;
-
+
@Autowired
private UserService userService;
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2012-12-04 08:35:56 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2012-12-13 08:06:31 +0000
@@ -509,6 +509,7 @@
<bean id="org.hisp.dhis.light.message.action.GetMessagesAction"
class="org.hisp.dhis.light.message.action.GetMessagesAction" scope="prototype">
<property name="messageService" ref="org.hisp.dhis.message.MessageService" />
+ <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
</bean>
<bean id="org.hisp.dhis.light.message.action.GetMessageAction"
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml 2012-12-04 08:35:56 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml 2012-12-13 08:06:31 +0000
@@ -479,6 +479,12 @@
class="org.hisp.dhis.light.messaging.action.SendMessagesAction">
<result name="success" type="redirect">/light/messages.action</result>
</action>
+
+ <action name="recipients"
+ class="org.hisp.dhis.light.messaging.action.GetLastRecipientsAction">
+ <result name="success" type="velocity">/dhis-web-light/main.vm</result>
+ <param name="page">/dhis-web-light/messages.vm</param>
+ </action>
<!-- Anonymous -->
<action name="anonymous"
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/messages.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/messages.vm 2012-12-04 08:35:56 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/messages.vm 2012-12-13 08:06:31 +0000
@@ -37,23 +37,27 @@
</ul>
</p>
-
+<ul>
+<li>
+<a href="feedback.action">$i18n.getString("feedback")</a>
+</li>
+</ul>
<h2>$i18n.getString( "last_recipients" )</h2>
-
-<form method="POST" action="sendFeedback.action">
-<div class="header-box" align="center">
- <h3 style="text-align: left;">$i18n.getString( "send_feedback" )</h3>
- <p style="text-align: left;">
- $i18n.getString( "subject" ) *<br />
- <input type="text" maxlength="255" size="24" name="subject" />
-
- $i18n.getString( "text" ) *<br />
- <input type="text" maxlength="255" size="24" name="text" />
- <input type="submit" style="width: 100%;" value="$i18n.getString("send")" />
- </p>
-</div>
-</form>
+<p>
+<ul>
+#set( $max = 1)
+ #foreach( $usermessage in $usermessages )
+
+ <li><a href="showUserList.action?userId=$usermessage.getId()">$usermessage.lastRecipientName</a></li>
+ #if ( $max == 5 )
+ #break
+ #end
+ #set( $max = $max+1 )
+
+ #end
+</ul>
+</p>
<div id="footer">