dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38433
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19571: use WebMessageException for notFound
------------------------------------------------------------
revno: 19571
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-07-08 11:02:09 +0700
message:
use WebMessageException for notFound
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SqlViewController.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/SqlViewController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SqlViewController.java 2015-07-04 16:43:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SqlViewController.java 2015-07-08 04:02:09 +0000
@@ -29,13 +29,15 @@
*/
import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.commons.util.CodecUtils;
+import org.hisp.dhis.dxf2.webmessage.WebMessageException;
import org.hisp.dhis.schema.descriptors.SqlViewSchemaDescriptor;
import org.hisp.dhis.sqlview.SqlView;
import org.hisp.dhis.sqlview.SqlViewService;
import org.hisp.dhis.system.grid.GridUtils;
-import org.hisp.dhis.commons.util.CodecUtils;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.hisp.dhis.webapi.utils.ContextUtils.CacheStrategy;
+import org.hisp.dhis.webapi.utils.WebMessageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -45,7 +47,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletResponse;
-
+import java.io.IOException;
import java.util.Set;
/**
@@ -64,17 +66,16 @@
@RequestMapping( value = "/{uid}/data", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON )
public String getViewJson( @PathVariable( "uid" ) String uid,
- @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
- Model model, HttpServletResponse response )
+ @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
+ Model model, HttpServletResponse response ) throws WebMessageException
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
if ( sqlView == null )
{
- ContextUtils.notFoundResponse( response, "SQL view does not exist: " + uid );
- return null;
+ throw new WebMessageException( WebMessageUtils.notFound( "SQL view does not exist: " + uid ) );
}
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ), SqlView.getCriteria( var ) );
model.addAttribute( "model", grid );
@@ -87,17 +88,16 @@
@RequestMapping( value = "/{uid}/data.xml", method = RequestMethod.GET )
public void getViewXml( @PathVariable( "uid" ) String uid,
- @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
- HttpServletResponse response ) throws Exception
+ @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
+ HttpServletResponse response ) throws WebMessageException, IOException
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
if ( sqlView == null )
{
- ContextUtils.notFoundResponse( response, "SQL view does not exist: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "SQL view does not exist: " + uid ) );
}
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ), SqlView.getCriteria( var ) );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING );
@@ -107,21 +107,20 @@
@RequestMapping( value = "/{uid}/data.csv", method = RequestMethod.GET )
public void getViewCsv( @PathVariable( "uid" ) String uid,
- @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
+ @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
HttpServletResponse response ) throws Exception
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
if ( sqlView == null )
{
- ContextUtils.notFoundResponse( response, "SQL view does not exist: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "SQL view does not exist: " + uid ) );
}
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ), SqlView.getCriteria( var ) );
-
+
String filename = CodecUtils.filenameEncode( grid.getTitle() ) + ".csv";
-
+
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, true );
GridUtils.toCsv( grid, response.getWriter() );
@@ -129,21 +128,20 @@
@RequestMapping( value = "/{uid}/data.xls", method = RequestMethod.GET )
public void getViewXls( @PathVariable( "uid" ) String uid,
- @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
+ @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
HttpServletResponse response ) throws Exception
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
if ( sqlView == null )
{
- ContextUtils.notFoundResponse( response, "SQL view does not exist: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "SQL view does not exist: " + uid ) );
}
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ), SqlView.getCriteria( var ) );
String filename = CodecUtils.filenameEncode( grid.getTitle() ) + ".xls";
-
+
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, true );
GridUtils.toXls( grid, response.getOutputStream() );
@@ -151,17 +149,16 @@
@RequestMapping( value = "/{uid}/data.html", method = RequestMethod.GET )
public void getViewHtml( @PathVariable( "uid" ) String uid,
- @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
+ @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
HttpServletResponse response ) throws Exception
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
if ( sqlView == null )
{
- ContextUtils.notFoundResponse( response, "SQL view does not exist: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "SQL view does not exist: " + uid ) );
}
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ), SqlView.getCriteria( var ) );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING );
@@ -171,17 +168,16 @@
@RequestMapping( value = "/{uid}/data.html+css", method = RequestMethod.GET )
public void getViewHtmlCss( @PathVariable( "uid" ) String uid,
- @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
+ @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
HttpServletResponse response ) throws Exception
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
if ( sqlView == null )
{
- ContextUtils.notFoundResponse( response, "SQL view does not exist: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "SQL view does not exist: " + uid ) );
}
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ), SqlView.getCriteria( var ) );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING );
@@ -191,17 +187,16 @@
@RequestMapping( value = "/{uid}/data.pdf", method = RequestMethod.GET )
public void getViewPdf( @PathVariable( "uid" ) String uid,
- @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
+ @RequestParam( required = false ) Set<String> criteria, @RequestParam( required = false ) Set<String> var,
HttpServletResponse response ) throws Exception
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
if ( sqlView == null )
{
- ContextUtils.notFoundResponse( response, "SQL view does not exist: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "SQL view does not exist: " + uid ) );
}
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ), SqlView.getCriteria( var ) );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PDF, CacheStrategy.RESPECT_SYSTEM_SETTING );
@@ -210,15 +205,14 @@
}
@RequestMapping( value = "/{uid}/execute", method = RequestMethod.POST )
- public void executeView( @PathVariable( "uid" ) String uid, @RequestParam( required = false ) Set<String> var,
- HttpServletResponse response )
+ public void executeView( @PathVariable( "uid" ) String uid, @RequestParam( required = false ) Set<String> var,
+ HttpServletResponse response ) throws WebMessageException
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
if ( sqlView == null )
{
- ContextUtils.notFoundResponse( response, "SQL view not found" );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "SQL view not found" ) );
}
String result = sqlViewService.createViewTable( sqlView );
=== 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-06-24 06:56:16 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2015-07-08 04:02:09 +0000
@@ -28,8 +28,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.OrganisationUnitSelectionMode;
+import org.hisp.dhis.commons.util.StreamUtils;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dxf2.common.IdSchemes;
@@ -44,21 +44,21 @@
import org.hisp.dhis.dxf2.events.event.csv.CsvEventService;
import org.hisp.dhis.dxf2.events.report.EventRowService;
import org.hisp.dhis.dxf2.events.report.EventRows;
-import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService;
import org.hisp.dhis.dxf2.importsummary.ImportStatus;
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.dxf2.webmessage.WebMessageException;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.importexport.ImportStrategy;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramStatus;
import org.hisp.dhis.scheduling.TaskCategory;
import org.hisp.dhis.scheduling.TaskId;
import org.hisp.dhis.system.scheduling.Scheduler;
-import org.hisp.dhis.commons.util.StreamUtils;
import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.webapi.service.WebMessageService;
import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.utils.WebMessageUtils;
import org.hisp.dhis.webapi.webdomain.WebOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -96,8 +96,6 @@
// Dependencies
//--------------------------------------------------------------------------
- @Autowired
- private IdentifiableObjectManager manager;
@Autowired
private CurrentUserService currentUserService;
@@ -115,14 +113,11 @@
private EventRowService eventRowService;
@Autowired
- private TrackedEntityInstanceService trackedEntityInstanceService;
-
- @Autowired
- private OrganisationUnitService organisationUnitService;
-
- @Autowired
private DataElementService dataElementService;
+ @Autowired
+ private WebMessageService webMessageService;
+
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@@ -426,52 +421,49 @@
@RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { "application/xml", "text/xml" } )
@PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')" )
- public void putXmlEvent( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, ImportOptions importOptions ) throws IOException
+ public void putXmlEvent( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, ImportOptions importOptions ) throws IOException, WebMessageException
{
Event event = eventService.getEvent( uid );
if ( event == null )
{
- ContextUtils.notFoundResponse( response, "Event not found for uid: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
}
Event updatedEvent = JacksonUtils.fromXml( request.getInputStream(), Event.class );
updatedEvent.setEvent( uid );
eventService.updateEvent( updatedEvent, false, importOptions );
- ContextUtils.okResponse( response, "Event updated: " + uid );
+ webMessageService.send( WebMessageUtils.ok( "Event updated: " + uid ), response, request );
}
@RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" )
@PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')" )
- public void putJsonEvent( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, ImportOptions importOptions ) throws IOException
+ public void putJsonEvent( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, ImportOptions importOptions ) throws IOException, WebMessageException
{
Event event = eventService.getEvent( uid );
if ( event == null )
{
- ContextUtils.notFoundResponse( response, "Event not found for uid: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
}
Event updatedEvent = JacksonUtils.fromJson( request.getInputStream(), Event.class );
updatedEvent.setEvent( uid );
eventService.updateEvent( updatedEvent, false, importOptions );
- ContextUtils.okResponse( response, "Event updated: " + uid );
+ webMessageService.send( WebMessageUtils.ok( "Event updated: " + uid ), response, request );
}
@RequestMapping( value = "/{uid}/{dataElementUid}", method = RequestMethod.PUT, consumes = "application/json" )
@PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')" )
- public void putJsonEventSingleValue( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, @PathVariable( "dataElementUid" ) String dataElementUid ) throws IOException
+ public void putJsonEventSingleValue( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, @PathVariable( "dataElementUid" ) String dataElementUid ) throws IOException, WebMessageException
{
Event event = eventService.getEvent( uid );
if ( event == null )
{
- ContextUtils.notFoundResponse( response, "Event not found for uid: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
}
DataElement dataElement = dataElementService.getDataElement( dataElementUid );
@@ -486,46 +478,43 @@
updatedEvent.setEvent( uid );
eventService.updateEvent( updatedEvent, true );
- ContextUtils.okResponse( response, "Event updated: " + uid );
-
+ webMessageService.send( WebMessageUtils.ok( "Event updated: " + uid ), response, request );
}
@RequestMapping( value = "/{uid}/addNote", method = RequestMethod.PUT, consumes = "application/json" )
@PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')" )
- public void putJsonEventForNote( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, ImportOptions importOptions ) throws IOException
+ public void putJsonEventForNote( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, ImportOptions importOptions ) throws IOException, WebMessageException
{
Event event = eventService.getEvent( uid );
if ( event == null )
{
- ContextUtils.notFoundResponse( response, "Event not found for uid: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
}
Event updatedEvent = JacksonUtils.fromJson( request.getInputStream(), Event.class );
updatedEvent.setEvent( uid );
eventService.updateEventForNote( updatedEvent );
- ContextUtils.okResponse( response, "Event updated: " + uid );
+ webMessageService.send( WebMessageUtils.ok( "Event updated: " + uid ), response, request );
}
@RequestMapping( value = "/{uid}/updateEventDate", method = RequestMethod.PUT, consumes = "application/json" )
@PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')" )
- public void putJsonEventForEventDate( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, ImportOptions importOptions ) throws IOException
+ public void putJsonEventForEventDate( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, ImportOptions importOptions ) throws IOException, WebMessageException
{
Event event = eventService.getEvent( uid );
if ( event == null )
{
- ContextUtils.notFoundResponse( response, "Event not found for uid: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
}
Event updatedEvent = JacksonUtils.fromJson( request.getInputStream(), Event.class );
updatedEvent.setEvent( uid );
eventService.updateEventForEventDate( updatedEvent );
- ContextUtils.okResponse( response, "Event updated: " + uid );
+ webMessageService.send( WebMessageUtils.ok( "Event updated: " + uid ), response, request );
}
// -------------------------------------------------------------------------
@@ -534,14 +523,13 @@
@RequestMapping( value = "/{uid}", method = RequestMethod.DELETE )
@PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_DELETE')" )
- public void deleteEvent( HttpServletResponse response, @PathVariable( "uid" ) String uid )
+ public void deleteEvent( HttpServletResponse response, @PathVariable( "uid" ) String uid ) throws WebMessageException
{
Event event = eventService.getEvent( uid );
if ( event == null )
{
- ContextUtils.notFoundResponse( response, "Event not found for uid: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Event not found for uid: " + uid ) );
}
response.setStatus( HttpServletResponse.SC_NO_CONTENT );