dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #15590
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5683: Charts, improved error handling
------------------------------------------------------------
revno: 5683
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-01-09 21:22:01 +0100
message:
Charts, improved error handling
modified:
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/ChartResult.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-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2012-01-09 20:22:01 +0000
@@ -186,15 +186,15 @@
public JFreeChart getJFreeChart( String uid, I18nFormat format )
{
Chart chart = getChart( uid );
-
- return getJFreeChart( chart, format );
+
+ return chart != null ? getJFreeChart( chart, format ) : null;
}
public JFreeChart getJFreeChart( int id, I18nFormat format )
{
Chart chart = getChart( id );
- return getJFreeChart( chart, format );
+ return chart != null ? getJFreeChart( chart, format ) : null;
}
public JFreeChart getJFreeChart( Chart chart, I18nFormat format )
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/ChartResult.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/ChartResult.java 2011-05-05 21:15:45 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/ChartResult.java 2012-01-09 20:22:01 +0000
@@ -15,6 +15,8 @@
*/
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Result;
@@ -38,12 +40,11 @@
public class ChartResult
implements Result
{
- /**
- * Determines if a de-serialized file is compatible with this class.
- */
- private static final long serialVersionUID = -8364233242858237681L;
-
+ private static final Log log = LogFactory.getLog( ChartResult.class );
+
private static final String DEFAULT_FILENAME = "chart.png";
+ private static final int DEFAULT_WIDTH = 700;
+ private static final int DEFAULT_HEIGHT = 500;
private JFreeChart chart = null;
@@ -110,11 +111,11 @@
Integer stackHeight = (Integer) invocation.getStack().findValue( "height" );
- height = stackHeight != null && stackHeight > 0 ? stackHeight : height;
+ height = stackHeight != null && stackHeight > 0 ? stackHeight : height != null ? height: DEFAULT_HEIGHT;
Integer stackWidth = (Integer) invocation.getStack().findValue( "width" );
- width = stackWidth != null && stackWidth > 0 ? stackWidth : width;
+ width = stackWidth != null && stackWidth > 0 ? stackWidth : width != null ? width : DEFAULT_WIDTH;
String stackFilename = (String) invocation.getStack().findValue( "filename" );
@@ -122,19 +123,10 @@
if ( chart == null )
{
- throw new NullPointerException( "No chart found" );
- }
-
- if ( height == null )
- {
- throw new IllegalArgumentException( "Height not set" );
- }
-
- if ( width == null )
- {
- throw new IllegalArgumentException( "Width not set" );
- }
-
+ log.warn( "No chart found" );
+ return;
+ }
+
HttpServletResponse response = ServletActionContext.getResponse();
ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PNG, true, filename, false );