=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-09-27 09:58:06 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-10-01 13:21:22 +0000 @@ -32,17 +32,15 @@ import org.hisp.dhis.api.utils.WebUtils; import org.hisp.dhis.api.webdomain.user.Dashboard; import org.hisp.dhis.api.webdomain.user.Inbox; +import org.hisp.dhis.api.webdomain.user.Recipients; import org.hisp.dhis.api.webdomain.user.Settings; import org.hisp.dhis.dxf2.utils.JacksonUtils; -import org.hisp.dhis.i18n.locale.LocaleManager; -import org.hisp.dhis.i18n.resourcebundle.ResourceBundleManager; import org.hisp.dhis.interpretation.Interpretation; import org.hisp.dhis.interpretation.InterpretationService; import org.hisp.dhis.message.MessageConversation; import org.hisp.dhis.message.MessageService; -import org.hisp.dhis.user.CurrentUserService; -import org.hisp.dhis.user.User; -import org.hisp.dhis.user.UserService; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.user.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -53,7 +51,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.*; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; /** * @author Morten Olav Hansen @@ -71,6 +73,9 @@ private UserService userService; @Autowired + private UserGroupService userGroupService; + + @Autowired private MessageService messageService; @Autowired @@ -78,7 +83,7 @@ @RequestMapping public String getCurrentUser( @RequestParam Map parameters, - Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception + Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception { WebOptions options = new WebOptions( parameters ); User currentUser = currentUserService.getCurrentUser(); @@ -102,7 +107,7 @@ @RequestMapping( value = "/inbox" ) public String getInbox( @RequestParam Map parameters, - Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception + Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception { WebOptions options = new WebOptions( parameters ); User currentUser = currentUserService.getCurrentUser(); @@ -130,7 +135,7 @@ @RequestMapping( value = "/dashboard" ) public String getDashboard( @RequestParam Map parameters, - Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception + Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception { WebOptions options = new WebOptions( parameters ); User currentUser = currentUserService.getCurrentUser(); @@ -158,7 +163,7 @@ @RequestMapping( value = "/settings" ) public String getSettings( @RequestParam Map parameters, - Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception + Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception { WebOptions options = new WebOptions( parameters ); User currentUser = currentUserService.getCurrentUser(); @@ -187,7 +192,7 @@ } @RequestMapping( value = "/settings", method = RequestMethod.POST, consumes = "application/xml" ) - public void postSettingsXml(HttpServletResponse response, HttpServletRequest request) throws Exception + public void postSettingsXml( HttpServletResponse response, HttpServletRequest request ) throws Exception { Settings settings = JacksonUtils.fromXml( request.getInputStream(), Settings.class ); User currentUser = currentUserService.getCurrentUser(); @@ -208,7 +213,7 @@ } @RequestMapping( value = "/settings", method = RequestMethod.POST, consumes = "application/json" ) - public void postSettingsJson(HttpServletResponse response, HttpServletRequest request) throws Exception + public void postSettingsJson( HttpServletResponse response, HttpServletRequest request ) throws Exception { Settings settings = JacksonUtils.fromJson( request.getInputStream(), Settings.class ); User currentUser = currentUserService.getCurrentUser(); @@ -227,4 +232,31 @@ userService.updateUser( currentUser ); } + + @RequestMapping( value = "/recipients", produces = "application/json" ) + public void recipientsJson( HttpServletResponse response, @RequestParam( value = "filter", required = false ) String filter ) throws IOException + { + User currentUser = currentUserService.getCurrentUser(); + + if ( currentUser == null ) + { + ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." ); + return; + } + + Recipients recipients = new Recipients(); + + if ( filter == null || filter.isEmpty() ) + { + recipients.setUsers( new HashSet( userService.getAllUsers() ) ); + recipients.setUserGroups( new HashSet( userGroupService.getAllUserGroups() ) ); + } + else + { + recipients.setUsers( new HashSet( userService.getUsersByName( filter ) ) ); + recipients.setUserGroups( new HashSet( userGroupService.getUserGroupsBetweenByName( filter, 0, Integer.MAX_VALUE ) ) ); + } + + JacksonUtils.toJson( response.getOutputStream(), recipients ); + } } === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Recipients.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Recipients.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Recipients.java 2012-10-01 13:21:22 +0000 @@ -0,0 +1,103 @@ +package org.hisp.dhis.api.webdomain.user; + +/* + * Copyright (c) 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. + */ + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonView; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.view.DetailedView; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.user.User; +import org.hisp.dhis.user.UserGroup; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author Morten Olav Hansen + */ +@JacksonXmlRootElement( localName = "recipients", namespace = Dxf2Namespace.NAMESPACE ) +public class Recipients +{ + private Set organisationUnits = new HashSet(); + + private Set users = new HashSet(); + + private Set userGroups = new HashSet(); + + public Recipients() + { + } + + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + @JacksonXmlElementWrapper( localName = "organisationUnits", namespace = Dxf2Namespace.NAMESPACE ) + @JacksonXmlProperty( localName = "organisationUnit", namespace = Dxf2Namespace.NAMESPACE ) + public Set getOrganisationUnits() + { + return organisationUnits; + } + + public void setOrganisationUnits( Set organisationUnits ) + { + this.organisationUnits = organisationUnits; + } + + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + @JacksonXmlElementWrapper( localName = "users", namespace = Dxf2Namespace.NAMESPACE ) + @JacksonXmlProperty( localName = "user", namespace = Dxf2Namespace.NAMESPACE ) + public Set getUsers() + { + return users; + } + + public void setUsers( Set users ) + { + this.users = users; + } + + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + @JacksonXmlElementWrapper( localName = "userGroups", namespace = Dxf2Namespace.NAMESPACE ) + @JacksonXmlProperty( localName = "userGroup", namespace = Dxf2Namespace.NAMESPACE ) + public Set getUserGroups() + { + return userGroups; + } + + public void setUserGroups( Set userGroups ) + { + this.userGroups = userGroups; + } +} === modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm' --- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm 2012-10-01 04:01:22 +0000 +++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm 2012-10-01 13:21:22 +0000 @@ -1,17 +1,110 @@
@@ -27,13 +120,13 @@
- - + +
-
  • Manage recipients 1
  • +
  • Manage recipients 0
  • @@ -52,15 +145,7 @@
    -
      -
    • Organisation Units
    • -
    • Not implemented.
    • - -
    • Users
    • -
    • Not implemented.
    • - -
    • User groups
    • -
    • Not implemented.
    • +