dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11431
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3256: Pushed code from message action class to service layer
------------------------------------------------------------
revno: 3256
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-04-01 13:33:40 +0200
message:
Pushed code from message action class to service layer
modified:
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-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/SendMessageAction.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/MessageService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageService.java 2011-03-31 11:45:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageService.java 2011-04-01 11:33:40 +0000
@@ -28,6 +28,7 @@
*/
import java.util.List;
+import java.util.Set;
import org.hisp.dhis.user.User;
@@ -38,6 +39,8 @@
{
final String ID = MessageService.class.getName();
+ int sendMessage( Message message, Set<User> users );
+
int saveMessage( Message message );
Message getMessage( int id );
=== 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-03-31 11:45:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2011-04-01 11:33:40 +0000
@@ -27,9 +27,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.hisp.dhis.common.GenericStore;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
import org.springframework.transaction.annotation.Transactional;
@@ -70,6 +73,20 @@
// MessageService implementation
// -------------------------------------------------------------------------
+ public int sendMessage( Message message, Set<User> users )
+ {
+ Set<UserMessage> userMessages = new HashSet<UserMessage>();
+
+ for ( User user : users )
+ {
+ userMessages.add( new UserMessage( user, message ) );
+ }
+
+ message.setUserMessages( userMessages );
+
+ return saveMessage( message );
+ }
+
public int saveMessage( Message message )
{
return messageStore.save( message );
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/SendMessageAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/SendMessageAction.java 2011-03-31 16:28:24 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/SendMessageAction.java 2011-04-01 11:33:40 +0000
@@ -99,27 +99,15 @@
Message message = new Message( subject, text, sender );
- Set<UserMessage> userMessages = getUserMessages( message );
-
- message.setUserMessages( userMessages );
-
- messageService.saveMessage( message );
-
- return SUCCESS;
- }
-
- private Set<UserMessage> getUserMessages( Message message )
- {
- Set<UserMessage> userMessages = new HashSet<UserMessage>();
+ Set<User> users = new HashSet<User>();
for ( OrganisationUnit unit : selectionTreeManager.getSelectedOrganisationUnits() )
{
- for ( User user : unit.getUsers() )
- {
- userMessages.add( new UserMessage( user, message ) );
- }
+ users.addAll( unit.getUsers() );
}
+
+ messageService.sendMessage( message, users );
- return userMessages;
+ return SUCCESS;
}
}