dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33401
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17036: implement support for bulk user invites, adds new endpoint /api/users/invites
------------------------------------------------------------
revno: 17036
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-10-10 19:08:01 +0700
message:
implement support for bulk user invites, adds new endpoint /api/users/invites
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/Users.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.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/user/User.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2014-10-10 12:08:01 +0000
@@ -54,7 +54,7 @@
/**
* @author Nguyen Hong Duc
*/
-@JacksonXmlRootElement(localName = "user", namespace = DxfNamespaces.DXF_2_0)
+@JacksonXmlRootElement( localName = "user", namespace = DxfNamespaces.DXF_2_0 )
public class User
extends BaseIdentifiableObject
{
@@ -224,7 +224,7 @@
{
return hasDataViewOrganisationUnit() ? getDataViewOrganisationUnit() : getOrganisationUnit();
}
-
+
/**
* Returns the data view organisation units or organisation units if not exist.
*/
@@ -232,7 +232,7 @@
{
return hasDataViewOrganisationUnit() ? dataViewOrganisationUnits : organisationUnits;
}
-
+
public String getOrganisationUnitsName()
{
return IdentifiableObjectUtils.join( organisationUnits );
@@ -259,8 +259,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getFirstName()
{
return firstName;
@@ -272,8 +272,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getSurname()
{
return surname;
@@ -285,8 +285,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getEmail()
{
return email;
@@ -298,8 +298,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getJobTitle()
{
return jobTitle;
@@ -311,8 +311,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getPhoneNumber()
{
return phoneNumber;
@@ -324,8 +324,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getIntroduction()
{
return introduction;
@@ -337,8 +337,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getGender()
{
return gender;
@@ -350,8 +350,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public Date getBirthday()
{
return birthday;
@@ -363,8 +363,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getNationality()
{
return nationality;
@@ -376,8 +376,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getEmployer()
{
return employer;
@@ -389,8 +389,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getEducation()
{
return education;
@@ -402,8 +402,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getInterests()
{
return interests;
@@ -415,8 +415,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getLanguages()
{
return languages;
@@ -428,8 +428,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public Date getLastCheckedInterpretations()
{
return lastCheckedInterpretations;
@@ -441,8 +441,8 @@
}
@JsonProperty
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public UserCredentials getUserCredentials()
{
return userCredentials;
@@ -454,10 +454,10 @@
}
@JsonProperty
- @JsonSerialize(contentAs = BaseIdentifiableObject.class)
- @JsonView({ DetailedView.class })
- @JacksonXmlElementWrapper(localName = "userGroups", namespace = DxfNamespaces.DXF_2_0)
- @JacksonXmlProperty(localName = "userGroup", namespace = DxfNamespaces.DXF_2_0)
+ @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+ @JsonView( { DetailedView.class } )
+ @JacksonXmlElementWrapper( localName = "userGroups", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "userGroup", namespace = DxfNamespaces.DXF_2_0 )
public Set<UserGroup> getGroups()
{
return groups;
@@ -469,10 +469,10 @@
}
@JsonProperty
- @JsonSerialize(contentAs = BaseIdentifiableObject.class)
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlElementWrapper(localName = "organisationUnits", namespace = DxfNamespaces.DXF_2_0)
- @JacksonXmlProperty(localName = "organisationUnit", namespace = DxfNamespaces.DXF_2_0)
+ @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlElementWrapper( localName = "organisationUnits", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "organisationUnit", namespace = DxfNamespaces.DXF_2_0 )
public Set<OrganisationUnit> getOrganisationUnits()
{
return organisationUnits;
@@ -484,10 +484,10 @@
}
@JsonProperty
- @JsonSerialize(contentAs = BaseIdentifiableObject.class)
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlElementWrapper(localName = "dataViewOrganisationUnits", namespace = DxfNamespaces.DXF_2_0)
- @JacksonXmlProperty(localName = "dataViewOrganisationUnit", namespace = DxfNamespaces.DXF_2_0)
+ @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlElementWrapper( localName = "dataViewOrganisationUnits", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "dataViewOrganisationUnit", namespace = DxfNamespaces.DXF_2_0 )
public Set<OrganisationUnit> getDataViewOrganisationUnits()
{
return dataViewOrganisationUnits;
@@ -498,10 +498,10 @@
this.dataViewOrganisationUnits = dataViewOrganisationUnits;
}
- @JsonProperty(value = "attributeValues")
- @JsonView({ DetailedView.class, ExportView.class })
- @JacksonXmlElementWrapper(localName = "attributeValues", namespace = DxfNamespaces.DXF_2_0)
- @JacksonXmlProperty(localName = "attributeValue", namespace = DxfNamespaces.DXF_2_0)
+ @JsonProperty( value = "attributeValues" )
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlElementWrapper( localName = "attributeValues", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "attributeValue", namespace = DxfNamespaces.DXF_2_0 )
public Set<AttributeValue> getAttributeValues()
{
return attributeValues;
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/Users.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/Users.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/Users.java 2014-10-10 12:08:01 +0000
@@ -0,0 +1,66 @@
+package org.hisp.dhis.user;
+
+/*
+ * Copyright (c) 2004-2014, 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.DxfNamespaces;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * User collection wrapper. Mainly used for doing bulk invites.
+ *
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "users", namespace = DxfNamespaces.DXF_2_0 )
+public class Users
+{
+ private List<User> users = new ArrayList<>();
+
+ public Users()
+ {
+ }
+
+ @JsonProperty
+ @JacksonXmlElementWrapper( useWrapping = false, namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "users", namespace = DxfNamespaces.DXF_2_0 )
+ public List<User> getUsers()
+ {
+ return users;
+ }
+
+ public void setUsers( List<User> users )
+ {
+ this.users = users;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java 2014-10-10 10:55:35 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java 2014-10-10 12:08:01 +0000
@@ -45,6 +45,7 @@
import org.hisp.dhis.user.UserGroup;
import org.hisp.dhis.user.UserGroupService;
import org.hisp.dhis.user.UserService;
+import org.hisp.dhis.user.Users;
import org.hisp.dhis.webapi.controller.AbstractCrudController;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.hisp.dhis.webapi.webdomain.WebMetaData;
@@ -78,6 +79,8 @@
{
public static final String INVITE_PATH = "/invite";
+ public static final String BULK_INVITE_PATH = "/invites";
+
@Autowired
private UserService userService;
@@ -186,6 +189,28 @@
inviteUser( user, request, response );
}
+ @RequestMapping( value = BULK_INVITE_PATH, method = RequestMethod.POST, consumes = { "application/xml", "text/xml" } )
+ public void postXmlInvites( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
+ {
+ Users users = renderService.fromXml( request.getInputStream(), Users.class );
+
+ for ( User user : users.getUsers() )
+ {
+ inviteUser( user, request, response );
+ }
+ }
+
+ @RequestMapping( value = BULK_INVITE_PATH, method = RequestMethod.POST, consumes = "application/json" )
+ public void postJsonInvites( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
+ {
+ Users users = renderService.fromJson( request.getInputStream(), Users.class );
+
+ for ( User user : users.getUsers() )
+ {
+ inviteUser( user, request, response );
+ }
+ }
+
//--------------------------------------------------------------------------
// PUT
//--------------------------------------------------------------------------
@@ -211,7 +236,8 @@
User parsed = renderService.fromXml( request.getInputStream(), getEntityClass() );
parsed.setUid( uid );
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed, ImportStrategy.UPDATE );
+ ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
+ ImportStrategy.UPDATE );
renderService.toXml( response.getOutputStream(), summary );
}
@@ -236,7 +262,8 @@
User parsed = renderService.fromJson( request.getInputStream(), getEntityClass() );
parsed.setUid( uid );
- ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed, ImportStrategy.UPDATE );
+ ImportTypeSummary summary = importService.importObject( currentUserService.getCurrentUser().getUid(), parsed,
+ ImportStrategy.UPDATE );
renderService.toJson( response.getOutputStream(), summary );
}