← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19089: For sending a message, check if the combined user count is more than 200 (ou + u + ug)

 

------------------------------------------------------------
revno: 19089
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-05-05 13:31:31 +0600
message:
  For sending a message, check if the combined user count is more than 200 (ou + u + ug)
added:
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/UserCountAction.java
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/jsonUserCount.vm
modified:
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/message.js
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/sendMessage.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
=== added file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/UserCountAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/UserCountAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/UserCountAction.java	2015-05-05 07:31:31 +0000
@@ -0,0 +1,138 @@
+package org.hisp.dhis.dashboard.message.action;
+
+/*
+ * Copyright (c) 2004-2015, 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 com.opensymphony.xwork2.Action;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.oust.manager.SelectionTreeManager;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserGroup;
+import org.hisp.dhis.user.UserGroupService;
+import org.hisp.dhis.user.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class UserCountAction
+    implements Action
+{
+    private static final String PREFIX_USER = "u:";
+    private static final String PREFIX_USERGROUP = "ug:";
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    @Autowired
+    private SelectionTreeManager selectionTreeManager;
+
+    @Autowired
+    private UserService userService;
+
+    @Autowired
+    private UserGroupService userGroupService;
+
+    // -------------------------------------------------------------------------
+    // Input & Output
+    // -------------------------------------------------------------------------
+
+    private Set<User> users = new HashSet<>();
+
+    public Set<User> getUsers()
+    {
+        return users;
+    }
+
+    private String recipients;
+
+    public void setRecipients( String recipients )
+    {
+        this.recipients = recipients;
+    }
+
+    private boolean ignoreTree;
+
+    public void setIgnoreTree( boolean ignoreTree )
+    {
+        this.ignoreTree = ignoreTree;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute() throws Exception
+    {
+        if ( !ignoreTree )
+        {
+            for ( OrganisationUnit unit : selectionTreeManager.getReloadedSelectedOrganisationUnits() )
+            {
+                users.addAll( unit.getUsers() );
+            }
+        }
+
+        if ( StringUtils.isEmpty( recipients ) )
+        {
+            return SUCCESS;
+        }
+
+        String[] recipientsArray = recipients.split( "," );
+
+        for ( String recipient : recipientsArray )
+        {
+            if ( recipient.startsWith( PREFIX_USER ) )
+            {
+                User user = userService.getUser( recipient.substring( 2 ) );
+
+                if ( user != null )
+                {
+                    users.add( user );
+                }
+            }
+            else if ( recipient.startsWith( PREFIX_USERGROUP ) )
+            {
+                UserGroup userGroup = userGroupService.getUserGroup( recipient.substring( 3 ) );
+
+                if ( userGroup != null )
+                {
+                    users.addAll( userGroup.getMembers() );
+                }
+            }
+        }
+
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml	2014-12-18 11:41:20 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml	2015-05-05 07:31:31 +0000
@@ -5,11 +5,11 @@
   <!-- Dashboard -->
 
   <bean id="org.hisp.dhis.dashboard.action.InitAction" class="org.hisp.dhis.dashboard.action.InitAction"
-	scope="prototype">
+    scope="prototype">
     <property name="messageService" ref="org.hisp.dhis.message.MessageService" />
-	<property name="interpretationService" ref="org.hisp.dhis.interpretation.InterpretationService" />	
+    <property name="interpretationService" ref="org.hisp.dhis.interpretation.InterpretationService" />
   </bean>
-  
+
   <!-- Message -->
 
   <bean id="org.hisp.dhis.dashboard.message.action.GetMessagesAction" class="org.hisp.dhis.dashboard.message.action.GetMessagesAction"
@@ -18,7 +18,7 @@
   </bean>
 
   <bean id="org.hisp.dhis.dashboard.message.action.GetMessageOptionsAction" class="org.hisp.dhis.dashboard.message.action.GetMessageOptionsAction"
-    scope="prototype"/>
+    scope="prototype" />
 
   <bean id="org.hisp.dhis.dashboard.message.action.SendMessageAction" class="org.hisp.dhis.dashboard.message.action.SendMessageAction"
     scope="prototype">
@@ -37,13 +37,13 @@
   <bean id="org.hisp.dhis.dashboard.message.action.ReadMessageAction" class="org.hisp.dhis.dashboard.message.action.ReadMessageAction"
     scope="prototype">
     <property name="messageService" ref="org.hisp.dhis.message.MessageService" />
-	<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+    <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
   </bean>
 
   <bean id="org.hisp.dhis.dashboard.message.action.UnreadMessageAction" class="org.hisp.dhis.dashboard.message.action.UnreadMessageAction"
     scope="prototype">
     <property name="messageService" ref="org.hisp.dhis.message.MessageService" />
-	<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+    <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
   </bean>
 
   <bean id="org.hisp.dhis.dashboard.message.action.RemoveMessageAction" class="org.hisp.dhis.dashboard.message.action.RemoveMessageAction"
@@ -51,21 +51,23 @@
     <property name="messageService" ref="org.hisp.dhis.message.MessageService" />
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
   </bean>
-  
+
   <bean id="org.hisp.dhis.dashboard.message.action.ToggleFollowUpAction" class="org.hisp.dhis.dashboard.message.action.ToggleFollowUpAction"
-	scope="prototype">
+    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.dashboard.message.action.UserCountAction" class="org.hisp.dhis.dashboard.message.action.UserCountAction" scope="prototype" />
+
   <!-- Interpretations -->
-  
+
   <bean id="org.hisp.dhis.dashboard.interpretation.action.GetInterpretationsAction" class="org.hisp.dhis.dashboard.interpretation.action.GetInterpretationsAction"
-	scope="prototype"/>
+    scope="prototype" />
 
   <!-- Profile -->
 
   <bean id="org.hisp.dhis.dashboard.profile.action.GetUserAction" class="org.hisp.dhis.dashboard.profile.action.GetUserAction"
-    scope="prototype"/>
+    scope="prototype" />
 
 </beans>

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml	2014-12-30 14:04:26 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml	2015-05-05 07:31:31 +0000
@@ -110,6 +110,11 @@
       <param name="onExceptionReturn">plainTextError</param>
     </action>
 
+    <action name="userCount" class="org.hisp.dhis.dashboard.message.action.UserCountAction">
+      <result name="success" type="velocity-json">/dhis-web-dashboard-integration/jsonUserCount.vm</result>
+      <param name="onExceptionReturn">plainTextError</param>
+    </action>
+
     <!-- Interpretation -->
 
     <action name="interpretation" class="org.hisp.dhis.dashboard.action.NoAction">

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/message.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/message.js	2015-05-05 04:26:17 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/message.js	2015-05-05 07:31:31 +0000
@@ -25,8 +25,17 @@
 }
 
 function userCount() {
+    var ignoreTree = $("#ignoreTree").val();
+    var recipients = $("#recipients").val();
+
     return $.ajax({
-        url: '../dhis-web-commons/oust/usercount.action'
+        url: 'userCount.action',
+        type: 'POST',
+        method: 'POST',
+        data: {
+            ignoreTree: ignoreTree,
+            recipients: recipients
+        }
     });
 }
 

=== added file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/jsonUserCount.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/jsonUserCount.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/jsonUserCount.vm	2015-05-05 07:31:31 +0000
@@ -0,0 +1,3 @@
+{
+  "userCount": $users.size()
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/sendMessage.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/sendMessage.vm	2015-05-05 04:23:07 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/sendMessage.vm	2015-05-05 07:31:31 +0000
@@ -40,45 +40,47 @@
 
 <table>
 
-#if( !${recipient} )
-<tr>
-<td style="width:80px">$i18n.getString( "to_org_unit" )</td>
-<td>
-#organisationUnitSelectionTree( true true false false )
-</td>
-</tr>
-#else
-<input type="hidden" name="ignoreTree" value="true">
-#end
-
-<tr>
-<td style="width:80px"><label id="toUser" style="display:none">$i18n.getString( "to_user" )</label></td>
-<td>
-<input type="hidden" name="recipients" id="recipients" style="width:545px; padding:4px; border:1px solid grey;"/>
-</td>
-</tr>
-
-<tr><td colspan="2" style="height:1px"></td></tr>
-
-<tr>
-<td><label>$i18n.getString( "subject" )</label></td>
-<td><input type="text" id="subject" name="subject" style="width:619px;"></td>
-</tr>
-
-<tr>
-<td><label>$i18n.getString( "text" )</label></td>
-<td><textarea id="text" name="text" style="width:619px; height:220px;"></textarea></td>
-</tr>
-
-<tr>
-<td colspan="2" style="height:10px"></td>
-</tr>
-
-<tr>
-<td></td>
-<td><a class="blueButtonLink" href="javascript:submitMessage()">$i18n.getString( 'send' )</a>
-<a class="greyButtonLink" href="message.action">$i18n.getString( 'discard' )</a></td>
-</tr>
+  #if( !${recipient} )
+    <tr>
+      <td style="width:80px">$i18n.getString( "to_org_unit" )</td>
+      <td>
+        #organisationUnitSelectionTree( true true false false )
+      </td>
+    </tr>
+  #else
+    <input type="hidden" id="ignoreTree" name="ignoreTree" value="true">
+  #end
+
+  <tr>
+    <td style="width:80px"><label id="toUser" style="display:none">$i18n.getString( "to_user" )</label></td>
+    <td>
+      <input type="hidden" name="recipients" id="recipients" style="width:545px; padding:4px; border:1px solid grey;"/>
+    </td>
+  </tr>
+
+  <tr>
+    <td colspan="2" style="height:1px"></td>
+  </tr>
+
+  <tr>
+    <td><label>$i18n.getString( "subject" )</label></td>
+    <td><input type="text" id="subject" name="subject" style="width:619px;"></td>
+  </tr>
+
+  <tr>
+    <td><label>$i18n.getString( "text" )</label></td>
+    <td><textarea id="text" name="text" style="width:619px; height:220px;"></textarea></td>
+  </tr>
+
+  <tr>
+    <td colspan="2" style="height:10px"></td>
+  </tr>
+
+  <tr>
+    <td></td>
+    <td><a class="blueButtonLink" href="javascript:submitMessage()">$i18n.getString( 'send' )</a>
+      <a class="greyButtonLink" href="message.action">$i18n.getString( 'discard' )</a></td>
+  </tr>
 
 </table>