dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38482
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19598: Use WebMessage in Sharing/Event controller
------------------------------------------------------------
revno: 19598
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-07-09 13:53:00 +0700
message:
Use WebMessage in Sharing/Event controller
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SharingController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.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/webapi/controller/SharingController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SharingController.java 2015-07-08 05:42:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SharingController.java 2015-07-09 06:53:00 +0000
@@ -36,12 +36,14 @@
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dxf2.common.JacksonUtils;
+import org.hisp.dhis.dxf2.webmessage.WebMessageException;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.UserGroup;
import org.hisp.dhis.user.UserGroupAccess;
import org.hisp.dhis.user.UserGroupAccessService;
import org.hisp.dhis.user.UserGroupService;
import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.utils.WebMessageUtils;
import org.hisp.dhis.webapi.webdomain.sharing.Sharing;
import org.hisp.dhis.webapi.webdomain.sharing.SharingUserGroupAccess;
import org.hisp.dhis.webapi.webdomain.sharing.SharingUserGroups;
@@ -87,12 +89,11 @@
private AclService aclService;
@RequestMapping( method = RequestMethod.GET, produces = { "application/json" } )
- public void getSharing( @RequestParam String type, @RequestParam String id, HttpServletResponse response ) throws IOException
+ public void getSharing( @RequestParam String type, @RequestParam String id, HttpServletResponse response ) throws IOException, WebMessageException
{
if ( !aclService.isShareable( type ) )
{
- ContextUtils.notFoundResponse( response, "Type " + type + " is not supported." );
- return;
+ throw new WebMessageException( WebMessageUtils.conflict( "Type " + type + " is not supported." ) );
}
Class<? extends IdentifiableObject> klass = aclService.classForType( type );
@@ -100,8 +101,7 @@
if ( object == null )
{
- ContextUtils.notFoundResponse( response, "Object of type " + type + " with ID " + id + " was not found." );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Object of type " + type + " with ID " + id + " was not found." ) );
}
if ( !aclService.canManage( currentUserService.getCurrentUser(), object ) )
@@ -160,22 +160,20 @@
}
@RequestMapping( method = { RequestMethod.POST, RequestMethod.PUT }, consumes = "application/json" )
- public void setSharing( @RequestParam String type, @RequestParam String id, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ public void setSharing( @RequestParam String type, @RequestParam String id, HttpServletResponse response, HttpServletRequest request ) throws IOException, WebMessageException
{
Class<? extends IdentifiableObject> sharingClass = aclService.classForType( type );
if ( sharingClass == null || !aclService.isShareable( sharingClass ) )
{
- ContextUtils.notFoundResponse( response, "Type " + type + " is not supported." );
- return;
+ throw new WebMessageException( WebMessageUtils.conflict( "Type " + type + " is not supported." ) );
}
BaseIdentifiableObject object = (BaseIdentifiableObject) manager.get( sharingClass, id );
if ( object == null )
{
- ContextUtils.notFoundResponse( response, "Object of type " + type + " with ID " + id + " was not found." );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Object of type " + type + " with ID " + id + " was not found." ) );
}
if ( !aclService.canManage( currentUserService.getCurrentUser(), object ) )
@@ -257,12 +255,12 @@
}
@RequestMapping( value = "/search", method = RequestMethod.GET, produces = { "application/json" } )
- public void searchUserGroups( @RequestParam String key, @RequestParam( required = false ) Integer pageSize, HttpServletResponse response ) throws IOException
+ public void searchUserGroups( @RequestParam String key, @RequestParam( required = false ) Integer pageSize,
+ HttpServletResponse response ) throws IOException, WebMessageException
{
if ( key == null )
{
- ContextUtils.conflictResponse( response, "Search key not specified" );
- return;
+ throw new WebMessageException( WebMessageUtils.conflict( "Search key not specified" ) );
}
int max = pageSize != null ? pageSize : Integer.MAX_VALUE;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2015-07-08 04:33:58 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2015-07-09 06:53:00 +0000
@@ -260,8 +260,7 @@
if ( event == null )
{
- ContextUtils.notFoundResponse( response, "Event not found for uid: " + uid );
- return null;
+ throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
}
if ( options.hasLinks() )
@@ -470,8 +469,7 @@
if ( dataElement == null )
{
- ContextUtils.notFoundResponse( response, "DataElement not found for uid: " + dataElementUid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "DataElement not found for uid: " + dataElementUid ) );
}
Event updatedEvent = JacksonUtils.fromJson( request.getInputStream(), Event.class );