dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38480
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19596: WebMessage usage in web-api controllers
------------------------------------------------------------
revno: 19596
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-07-09 13:44:02 +0700
message:
WebMessage usage in web-api controllers
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardItemController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DocumentController.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/DashboardItemController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardItemController.java 2015-02-20 09:14:02 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardItemController.java 2015-07-09 06:44:02 +0000
@@ -28,17 +28,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import com.google.common.collect.Lists;
import org.hisp.dhis.common.Pager;
import org.hisp.dhis.dashboard.DashboardItem;
import org.hisp.dhis.dashboard.DashboardService;
+import org.hisp.dhis.dxf2.webmessage.WebMessageException;
import org.hisp.dhis.query.Order;
import org.hisp.dhis.schema.descriptors.DashboardItemSchemaDescriptor;
-import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.utils.WebMessageUtils;
import org.hisp.dhis.webapi.webdomain.WebMetaData;
import org.hisp.dhis.webapi.webdomain.WebOptions;
import org.springframework.beans.factory.annotation.Autowired;
@@ -47,7 +44,9 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import com.google.common.collect.Lists;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -59,7 +58,7 @@
{
@Autowired
private DashboardService dashboardService;
-
+
@Override
protected List<DashboardItem> getEntityList( WebMetaData metaData, WebOptions options, List<String> filters, List<Order> orders )
{
@@ -81,7 +80,7 @@
return entityList;
}
-
+
@RequestMapping( value = "/{uid}/shape/{shape}", method = RequestMethod.PUT )
public void putDashboardItemShape( @PathVariable String uid, @PathVariable String shape,
HttpServletRequest request, HttpServletResponse response ) throws Exception
@@ -90,12 +89,11 @@
if ( item == null )
{
- ContextUtils.notFoundResponse( response, "Dashboard item does not exist: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Dashboard item does not exist: " + uid ) );
}
-
+
item.setShape( shape );
-
+
dashboardService.updateDashboardItem( item );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java 2015-06-16 10:36:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataSetController.java 2015-07-09 06:44:02 +0000
@@ -28,20 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletResponse;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
import org.hisp.dhis.common.view.ExportView;
import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataentryform.DataEntryFormService;
@@ -49,10 +35,11 @@
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.datavalue.DataValue;
import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.dxf2.common.JacksonUtils;
import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
import org.hisp.dhis.dxf2.metadata.ExportService;
import org.hisp.dhis.dxf2.metadata.MetaData;
-import org.hisp.dhis.dxf2.common.JacksonUtils;
+import org.hisp.dhis.dxf2.webmessage.WebMessageException;
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.node.types.RootNode;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -60,8 +47,8 @@
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.schema.descriptors.DataSetSchemaDescriptor;
-import org.hisp.dhis.webapi.utils.ContextUtils;
import org.hisp.dhis.webapi.utils.FormUtils;
+import org.hisp.dhis.webapi.utils.WebMessageUtils;
import org.hisp.dhis.webapi.view.ClassPathUriResolver;
import org.hisp.dhis.webapi.webdomain.WebOptions;
import org.hisp.dhis.webapi.webdomain.form.Form;
@@ -76,6 +63,19 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -152,14 +152,13 @@
@RequestParam( value = "period", defaultValue = "", required = false ) String period,
@RequestParam( value = "orgUnit", defaultValue = "", required = false ) List<String> orgUnits,
@RequestParam( value = "comment", defaultValue = "true", required = false ) boolean comment,
- HttpServletResponse response ) throws IOException
+ HttpServletResponse response ) throws IOException, WebMessageException
{
List<DataSet> dataSets = getEntity( uid );
if ( dataSets.isEmpty() )
{
- ContextUtils.notFoundResponse( response, "Object not found for uid: " + uid );
- return null;
+ throw new WebMessageException( WebMessageUtils.notFound( "DataSet not found for uid: " + uid ) );
}
Period pe = periodService.getPeriod( period );
@@ -167,26 +166,24 @@
}
@RequestMapping( value = "/{uid}/form", method = RequestMethod.GET, produces = "application/json" )
- public void getFormJson(
- @PathVariable( "uid" ) String uid,
+ public void getFormJson(
+ @PathVariable( "uid" ) String uid,
@RequestParam( value = "ou", required = false ) String orgUnit,
- @RequestParam( value = "pe", required = false ) String period,
- @RequestParam( required = false ) boolean metaData, HttpServletResponse response ) throws IOException
+ @RequestParam( value = "pe", required = false ) String period,
+ @RequestParam( required = false ) boolean metaData, HttpServletResponse response ) throws IOException, WebMessageException
{
List<DataSet> dataSets = getEntity( uid );
if ( dataSets.isEmpty() )
{
- ContextUtils.notFoundResponse( response, "Data set does not exist: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "DataSet not found for uid: " + uid ) );
}
-
+
OrganisationUnit ou = null;
-
- if ( orgUnit != null && ( ou = manager.get( OrganisationUnit.class, orgUnit ) ) == null )
+
+ if ( orgUnit != null && (ou = manager.get( OrganisationUnit.class, orgUnit )) == null )
{
- ContextUtils.notFoundResponse( response, "Organisation unit does not exist: " + orgUnit );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Organisation unit does not exist: " + orgUnit ) );
}
Period pe = PeriodType.getPeriodFromIsoString( period );
@@ -197,26 +194,24 @@
}
@RequestMapping( value = "/{uid}/form", method = RequestMethod.GET, produces = { "application/xml", "text/xml" } )
- public void getFormXml(
- @PathVariable( "uid" ) String uid,
+ public void getFormXml(
+ @PathVariable( "uid" ) String uid,
@RequestParam( value = "ou", required = false ) String orgUnit,
- @RequestParam( value = "pe", required = false ) String period,
- @RequestParam( required = false ) boolean metaData, HttpServletResponse response ) throws IOException
+ @RequestParam( value = "pe", required = false ) String period,
+ @RequestParam( required = false ) boolean metaData, HttpServletResponse response ) throws IOException, WebMessageException
{
List<DataSet> dataSets = getEntity( uid );
if ( dataSets.isEmpty() )
{
- ContextUtils.notFoundResponse( response, "Object not found for uid: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "DataSet not found for uid: " + uid ) );
}
OrganisationUnit ou = null;
-
- if ( orgUnit != null && ( ou = manager.get( OrganisationUnit.class, orgUnit ) ) == null )
+
+ if ( orgUnit != null && (ou = manager.get( OrganisationUnit.class, orgUnit )) == null )
{
- ContextUtils.notFoundResponse( response, "Organisation unit does not exist: " + orgUnit );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Organisation unit does not exist: " + orgUnit ) );
}
Period pe = PeriodType.getPeriodFromIsoString( period );
@@ -225,11 +220,11 @@
JacksonUtils.toXml( response.getOutputStream(), form );
}
-
+
private Form getForm( List<DataSet> dataSets, OrganisationUnit ou, Period pe, boolean metaData )
{
DataSet dataSet = dataSets.get( 0 );
-
+
i18nService.internationalise( dataSet );
i18nService.internationalise( dataSet.getDataElements() );
i18nService.internationalise( dataSet.getSections() );
@@ -244,7 +239,7 @@
FormUtils.fillWithDataValues( form, dataValues );
}
-
+
return form;
}
@@ -258,8 +253,7 @@
if ( dataSet == null )
{
- ContextUtils.notFoundResponse( response, "Data set not found for identifier: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "DataSet not found for uid: " + uid ) );
}
DataEntryForm form = dataSet.getDataEntryForm();
@@ -276,8 +270,8 @@
dataEntryFormService.updateDataEntryForm( form );
}
- dataSet.increaseVersion();
- dataSetService.updateDataSet( dataSet );
+ dataSet.increaseVersion();
+ dataSetService.updateDataSet( dataSet );
}
/**
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java 2015-06-11 08:29:55 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java 2015-07-09 06:44:02 +0000
@@ -28,14 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import com.google.common.collect.Lists;
import org.hisp.dhis.common.DimensionService;
import org.hisp.dhis.common.DimensionalObject;
import org.hisp.dhis.common.IdentifiableObjectManager;
@@ -43,13 +36,14 @@
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dxf2.common.TranslateOptions;
+import org.hisp.dhis.dxf2.webmessage.WebMessageException;
import org.hisp.dhis.node.AbstractNode;
import org.hisp.dhis.node.Node;
import org.hisp.dhis.node.NodeUtils;
import org.hisp.dhis.node.types.CollectionNode;
import org.hisp.dhis.node.types.RootNode;
import org.hisp.dhis.query.Order;
-import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.utils.WebMessageUtils;
import org.hisp.dhis.webapi.webdomain.WebMetaData;
import org.hisp.dhis.webapi.webdomain.WebOptions;
import org.springframework.beans.factory.annotation.Autowired;
@@ -61,7 +55,12 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
-import com.google.common.collect.Lists;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
/**
* @author Lars Helge Overland
@@ -151,7 +150,7 @@
@RequestMapping( value = "/dataSet/{uid}", method = RequestMethod.GET )
public String getDimensionsForDataSet( @PathVariable String uid,
@RequestParam( value = "links", defaultValue = "true", required = false ) Boolean links,
- Model model, HttpServletResponse response )
+ Model model, HttpServletResponse response ) throws WebMessageException
{
WebMetaData metaData = new WebMetaData();
@@ -159,14 +158,12 @@
if ( dataSet == null )
{
- ContextUtils.notFoundResponse( response, "Data set does not exist: " + uid );
- return null;
+ throw new WebMessageException( WebMessageUtils.notFound( "DataSet not found for uid: " + uid ) );
}
if ( !dataSet.hasCategoryCombo() )
{
- ContextUtils.conflictResponse( response, "Data set does not have a category combination: " + uid );
- return null;
+ throw new WebMessageException( WebMessageUtils.conflict( "Data set does not have a category combination: " + uid ) );
}
List<DimensionalObject> dimensions = new ArrayList<>();
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DocumentController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DocumentController.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DocumentController.java 2015-07-09 06:44:02 +0000
@@ -31,11 +31,13 @@
import org.apache.commons.io.IOUtils;
import org.hisp.dhis.document.Document;
import org.hisp.dhis.document.DocumentService;
+import org.hisp.dhis.dxf2.webmessage.WebMessageException;
import org.hisp.dhis.external.location.LocationManager;
import org.hisp.dhis.external.location.LocationManagerException;
import org.hisp.dhis.schema.descriptors.DocumentSchemaDescriptor;
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.web.bind.annotation.PathVariable;
@@ -70,8 +72,7 @@
if ( document == null )
{
- ContextUtils.notFoundResponse( response, "Resource not found for identifier: " + uid );
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Document not found for uid: " + uid ) );
}
if ( document.isExternal() )
@@ -93,9 +94,7 @@
}
catch ( LocationManagerException ex )
{
- ContextUtils.conflictResponse( response, "Document could not be found: " + document.getUrl() );
-
- return;
+ throw new WebMessageException( WebMessageUtils.notFound( "Document could not be found: " + document.getUrl() ) );
}
finally
{