dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18896
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8034: Added /api/currentUser/settings, allows getting basic user settings (and posting updates), xml an...
------------------------------------------------------------
revno: 8034
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-09-11 14:54:11 +0700
message:
Added /api/currentUser/settings, allows getting basic user settings (and posting updates), xml and json is supported.
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Settings.java
modified:
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/webdomain/user/Inbox.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-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-11 06:48:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-09-11 07:54:11 +0000
@@ -32,12 +32,17 @@
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.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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -48,8 +53,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.Map;
+import java.util.*;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -64,19 +68,28 @@
private CurrentUserService currentUserService;
@Autowired
+ private UserService userService;
+
+ @Autowired
private MessageService messageService;
@Autowired
private InterpretationService interpretationService;
+ @Autowired
+ private ResourceBundleManager resourceBundleManager;
+
+ @Autowired
+ private LocaleManager localeManager;
+
@RequestMapping
public String getCurrentUser( @RequestParam Map<String, String> parameters,
Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
WebOptions options = new WebOptions( parameters );
- User user = currentUserService.getCurrentUser();
+ User currentUser = currentUserService.getCurrentUser();
- if ( user == null )
+ if ( currentUser == null )
{
ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
return null;
@@ -84,10 +97,10 @@
if ( options.hasLinks() )
{
- WebUtils.generateLinks( user );
+ WebUtils.generateLinks( currentUser );
}
- model.addAttribute( "model", user );
+ model.addAttribute( "model", currentUser );
model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );
return StringUtils.uncapitalize( "user" );
@@ -95,12 +108,12 @@
@RequestMapping( value = "/inbox" )
public String getInbox( @RequestParam Map<String, String> parameters,
- Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+ Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
WebOptions options = new WebOptions( parameters );
- User user = currentUserService.getCurrentUser();
+ User currentUser = currentUserService.getCurrentUser();
- if ( user == null )
+ if ( currentUser == null )
{
ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
return null;
@@ -123,12 +136,12 @@
@RequestMapping( value = "/dashboard" )
public String getDashboard( @RequestParam Map<String, String> parameters,
- Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+ Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
WebOptions options = new WebOptions( parameters );
- User user = currentUserService.getCurrentUser();
+ User currentUser = currentUserService.getCurrentUser();
- if ( user == null )
+ if ( currentUser == null )
{
ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
return null;
@@ -146,6 +159,76 @@
model.addAttribute( "model", dashboard );
model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
- return StringUtils.uncapitalize( "inbox" );
+ return StringUtils.uncapitalize( "dashboard" );
+ }
+
+ @RequestMapping( value = "/settings" )
+ public String getSettings( @RequestParam Map<String, String> parameters,
+ Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+ {
+ WebOptions options = new WebOptions( parameters );
+ User currentUser = currentUserService.getCurrentUser();
+
+ if ( currentUser == null )
+ {
+ ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
+ return null;
+ }
+
+ Settings settings = new Settings();
+ settings.setFirstName( currentUser.getFirstName() );
+ settings.setSurname( currentUser.getSurname() );
+ settings.setEmail( currentUser.getEmail() );
+ settings.setPhoneNumber( currentUser.getPhoneNumber() );
+
+ if ( options.hasLinks() )
+ {
+ WebUtils.generateLinks( settings );
+ }
+
+ model.addAttribute( "model", settings );
+ model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
+
+ return StringUtils.uncapitalize( "settings" );
+ }
+
+ @RequestMapping( value = "/settings", method = RequestMethod.POST, consumes = "application/xml" )
+ public void postSettingsXml(HttpServletResponse response, HttpServletRequest request) throws Exception
+ {
+ Settings settings = JacksonUtils.fromXml( request.getInputStream(), Settings.class );
+ User currentUser = currentUserService.getCurrentUser();
+
+ if ( currentUser == null )
+ {
+ ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
+ return;
+ }
+
+ currentUser.setFirstName( settings.getFirstName() );
+ currentUser.setSurname( settings.getSurname() );
+ currentUser.setEmail( settings.getEmail() );
+ currentUser.setPhoneNumber( settings.getPhoneNumber() );
+
+ userService.updateUser( currentUser );
+ }
+
+ @RequestMapping( value = "/settings", method = RequestMethod.POST, consumes = "application/json" )
+ public void postSettingsJson(HttpServletResponse response, HttpServletRequest request) throws Exception
+ {
+ Settings settings = JacksonUtils.fromJson( request.getInputStream(), Settings.class );
+ User currentUser = currentUserService.getCurrentUser();
+
+ if ( currentUser == null )
+ {
+ ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
+ return;
+ }
+
+ currentUser.setFirstName( settings.getFirstName() );
+ currentUser.setSurname( settings.getSurname() );
+ currentUser.setEmail( settings.getEmail() );
+ currentUser.setPhoneNumber( settings.getPhoneNumber() );
+
+ userService.updateUser( currentUser );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Inbox.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Inbox.java 2012-09-11 06:48:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Inbox.java 2012-09-11 07:54:11 +0000
@@ -28,13 +28,10 @@
*/
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
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.Dxf2Namespace;
-import org.hisp.dhis.common.view.DetailedView;
-import org.hisp.dhis.common.view.ExportView;
import org.hisp.dhis.interpretation.Interpretation;
import org.hisp.dhis.message.MessageConversation;
@@ -47,9 +44,9 @@
@JacksonXmlRootElement( localName = "inbox", namespace = Dxf2Namespace.NAMESPACE )
public class Inbox
{
- private List<MessageConversation> messageConversations = new ArrayList<MessageConversation>( );
+ private List<MessageConversation> messageConversations = new ArrayList<MessageConversation>();
- private List<Interpretation> interpretations = new ArrayList<Interpretation>( );
+ private List<Interpretation> interpretations = new ArrayList<Interpretation>();
public Inbox()
{
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Settings.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Settings.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Settings.java 2012-09-11 07:54:11 +0000
@@ -0,0 +1,104 @@
+package org.hisp.dhis.api.webdomain.user;
+
+/*
+ * Copyright (c) 2004-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.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.Dxf2Namespace;
+
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "settings", namespace = Dxf2Namespace.NAMESPACE )
+public class Settings
+{
+ private String firstName;
+
+ private String surname;
+
+ private String email;
+
+ private String phoneNumber;
+
+ public Settings()
+ {
+ }
+
+ @JsonProperty(required = true)
+ @JacksonXmlProperty(namespace = Dxf2Namespace.NAMESPACE)
+ public String getFirstName()
+ {
+ return firstName;
+ }
+
+ public void setFirstName( String firstName )
+ {
+ this.firstName = firstName;
+ }
+
+ @JsonProperty(required = true)
+ @JacksonXmlProperty(namespace = Dxf2Namespace.NAMESPACE)
+ public String getSurname()
+ {
+ return surname;
+ }
+
+ public void setSurname( String surname )
+ {
+ this.surname = surname;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty(namespace = Dxf2Namespace.NAMESPACE)
+ public String getEmail()
+ {
+ return email;
+ }
+
+ public void setEmail( String email )
+ {
+ this.email = email;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty(namespace = Dxf2Namespace.NAMESPACE)
+ public String getPhoneNumber()
+ {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber( String phoneNumber )
+ {
+ this.phoneNumber = phoneNumber;
+ }
+}