=== 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 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 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 );