testchart.jsp 5.63 KB
Newer Older
Thitichaipun Wutthisak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
<%@ page language="java" 
	import="java.util.ArrayList,
	org.pentaho.core.ui.SimpleUrlFactory,
    org.pentaho.messages.Messages,
	org.pentaho.core.system.PentahoSystem,
	org.pentaho.ui.component.charting.CategoryDatasetChartComponent,
	org.pentaho.plugin.jfreechart.JFreeChartEngine,
	org.pentaho.core.solution.HttpRequestParameterProvider,
	org.pentaho.core.solution.HttpSessionParameterProvider,
	org.pentaho.core.session.IPentahoSession,
	org.pentaho.core.util.UIUtil,
    org.pentaho.core.util.IUITemplater,
	org.pentaho.messages.util.LocaleHelper,
	org.pentaho.commons.connection.IPentahoConnection,
	org.pentaho.commons.connection.IPentahoResultSet,
	org.pentaho.data.PentahoConnectionFactory,
	org.pentaho.core.system.PentahoSystem,
	org.pentaho.core.system.PathBasedSystemSettings,
	org.pentaho.core.system.IApplicationContext,
	org.pentaho.core.system.WebApplicationContext,
	java.util.Enumeration,java.util.Properties,
	org.pentaho.core.system.StandaloneApplicationContext,
	org.apache.commons.lang.StringUtils"
	 %><%
	
/*
 * Copyright 2006 Pentaho Corporation.  All rights reserved. 
 * This software was developed by Pentaho Corporation and is provided under the terms 
 * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
 * this file except in compliance with the license. If you need a copy of the license, 
 * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
 * BI Platform.  The Initial Developer is Pentaho Corporation.
 *
 * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
 * the license for the specific language governing your rights and limitations.
*/

	response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
	String solutionPath="D:/EnterprisePT/JbossServices/server/default/deploy/HRPEAP.ear/hrAppWeb.war/DASHBOARD/";
	String baseUrl ="http://localhost:8080/hr/DASHBOARD/";
	ServletContext context  = pageContext.getServletContext();	

	IApplicationContext applicationContext = new WebApplicationContext(solutionPath, baseUrl, context.getRealPath(""), context);
    try{
	Properties props = new Properties();
    Enumeration initParmNames = context.getInitParameterNames();
    String initParmName;
    while (initParmNames.hasMoreElements()) {
      initParmName = (String) initParmNames.nextElement();
      props.setProperty(initParmName, context.getInitParameter(initParmName));
    }
   // ((WebApplicationContext) applicationContext).setProperties(props);
	WebApplicationContext wb=(WebApplicationContext)applicationContext;
	wb.setProperties(props);

	String jvmSpecifiedSysCfgPath = System.getProperty(PathBasedSystemSettings.SYSTEM_CFG_PATH_KEY);
    if (StringUtils.isBlank(jvmSpecifiedSysCfgPath)) {
      String webSpecifiedSysCfgPath = context.getInitParameter("pentaho-system-cfg"); //$NON-NLS-1$
      if (StringUtils.isNotBlank(webSpecifiedSysCfgPath)) {
        System.setProperty(PathBasedSystemSettings.SYSTEM_CFG_PATH_KEY, webSpecifiedSysCfgPath);
      }
    }

    boolean initOk = PentahoSystem.init(applicationContext);
	}catch(Exception ex){
	
	}

	
	
	IPentahoSession userSession = UIUtil.getPentahoSession( request );
	HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider( request );
	HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider( userSession );
	int chartType = (int)requestParameters.getLongParameter("ChartType", JFreeChartEngine.UNDEFINED_CHART_TYPE); //$NON-NLS-1$
	String chartDefinitionPath = requestParameters.getStringParameter("ChartDefinitionPath", null); //$NON-NLS-1$
	
	String thisUrl = baseUrl + "Chart?"; //$NON-NLS-1$
	String intro = ""; //$NON-NLS-1$
	String footer = ""; //$NON-NLS-1$
	String content = ""; //$NON-NLS-1$

	SimpleUrlFactory urlFactory = new SimpleUrlFactory( thisUrl );
	ArrayList messages = new ArrayList();
	CategoryDatasetChartComponent barChart = new CategoryDatasetChartComponent( chartType, chartDefinitionPath, 600, 400, urlFactory, messages );

    IPentahoConnection connection = PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, "SampleData", null); //$NON-NLS-1$
    try {
	    String query = "select department, actual, budget, variance from QUADRANT_ACTUALS"; //$NON-NLS-1$
	
	    IPentahoResultSet results = connection.executeQuery(query);
	    try {
		    
		    barChart.setValues(results);
			barChart.validate( userSession, null );
			
			barChart.setParameterProvider( HttpRequestParameterProvider.SCOPE_REQUEST, requestParameters ); //$NON-NLS-1$
			barChart.setParameterProvider( HttpSessionParameterProvider.SCOPE_SESSION, sessionParameters ); //$NON-NLS-1$
			
			content = barChart.getContent( "text/html" ); //$NON-NLS-1$
			if( content == null ) {
				StringBuffer buffer = new StringBuffer();		
				UIUtil.formatErrorMessage( "text/html", Messages.getErrorString( "CHART.DISPLAY_ERROR" ), messages, buffer ); //$NON-NLS-1$ //$NON-NLS-2$
				content = buffer.toString();
			}
		
			IUITemplater templater = PentahoSystem.getUITemplater( userSession );
			if( templater != null ) {
				String sections[] = templater.breakTemplate( "template-document.html", Messages.getString( "CHART.USER_SAMPLES" ), userSession ); //$NON-NLS-1$ //$NON-NLS-2$
				if( sections != null && sections.length > 0 ) {
					intro = sections[0];
				}
				if( sections != null && sections.length > 1 ) {
					footer = sections[1];
				}
			} else {
				intro = Messages.getString( "UI.ERROR_0002_BAD_TEMPLATE_OBJECT" ); //$NON-NLS-1$
			}
	    } finally {
	    	results.close();
	    }
    } finally {
    	connection.close();
    }
	
%><%//= intro %>
<%//= content %>
<%//= footer %>