org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask Java Examples

The following examples show how to use org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BirtViewerReportService.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see org.eclipse.birt.report.service.api.IViewerReportService#getParameterDefinitions(org.eclipse.birt.report.service.api.IViewerReportDesignHandle,
 *      org.eclipse.birt.report.service.api.InputOptions, boolean)
 */
public Collection getParameterDefinitions(
		IViewerReportDesignHandle design, InputOptions runOptions,
		boolean includeGroups ) throws ReportServiceException
{
	IGetParameterDefinitionTask task = null;
	try
	{
		task = getParameterDefinitionTask( design, runOptions );
		if ( task != null )
		{
			Collection params = task.getParameterDefns( true );
			return convertEngineParameters( params, includeGroups );
		}
	}
	finally
	{
		if ( task != null )
			task.close( );
	}

	return null;
}
 
Example #2
Source File: ScalarParameter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public IGetParameterDefinitionTask createParameterDefinitionTask()
{
	IGetParameterDefinitionTask task = null;
	if (engineTask != null)
	{
		task = engineTask.getEngine( )
			.createGetParameterDefinitionTask( engineTask.getReportRunnable( ) );
	}
	if (taskContext != null)
	{
	
		Map context = new HashMap( );
		Iterator itor = taskContext.keySet( ).iterator( );
		while(itor.hasNext( ))
		{
			Object obj = itor.next( );
			context.put( obj, taskContext.get( obj ) );
		}
		// TODO replace with DtE constant
		context.put( "com.actuate.birt.data.linkeddatamodel.LinkedDataModelDataModeSize",
				ReportPlugin.getDefault( ).getPluginPreferences( ).getString( ReportPlugin.DATA_MODEL_MEMORY_LIMIT_PREFERENCE ) );
		task.setAppContext( context );
		
	}
	return task;
}
 
Example #3
Source File: GetParameterDefinitionTaskTest.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void testSortByOnDatasetColumn( ) throws EngineException,
		SemanticException
{
	IReportRunnable report = engine.openReportDesign( REPORT_DESIGN );
	IGetParameterDefinitionTask task = engine
			.createGetParameterDefinitionTask( report );

	Collection list = task.getSelectionListForCascadingGroup(
			"SortBysOfSingleDataSet", new Object[0] );
	Object[] content = list.toArray( );
	assertEquals( "USA", SelectionChoiceUtil.getValue( content[1] ) );

	list = task.getSelectionListForCascadingGroup(
			"SortBysOfSingleDataSet", new Object[]{"USA"} );
	content = list.toArray( );
	assertEquals( "MA", SelectionChoiceUtil.getValue( content[1] ) );
}
 
Example #4
Source File: BirtViewerReportService.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see org.eclipse.birt.report.service.api.IViewerReportService#getParameterDefaultValue(org.eclipse.birt.report.service.api.IViewerReportDesignHandle,
 *      java.lang.String, org.eclipse.birt.report.service.api.InputOptions)
 */
public Object getParameterDefaultValue( IViewerReportDesignHandle design,
		String parameterName, InputOptions options )
		throws ReportServiceException
{
	IGetParameterDefinitionTask task = null;
	Object defaultValue = null;
	try
	{
		task = getParameterDefinitionTask( design, options );
		if ( task != null )
			defaultValue = task.getDefaultValue( parameterName );
	}
	finally
	{
		if ( task != null )
			task.close( );
	}

	return defaultValue;
}
 
Example #5
Source File: GetParameterDefinitionTaskTest.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void testDynamicFilterParameters( ) throws EngineException
{
	copyResource( DYNAMIC_FILTER_DESIGN, REPORT_DESIGN );
	IReportRunnable runnable = engine.openReportDesign( REPORT_DESIGN );
	IGetParameterDefinitionTask task = engine
			.createGetParameterDefinitionTask( runnable );

	// get parameter defn
	IParameterDefnBase param = task.getParameterDefn( "Param_1" );
	if ( param instanceof IDynamicFilterParameterDefn )
	{
		IDynamicFilterParameterDefn dynParam = (IDynamicFilterParameterDefn) param;
		assertNotNull( dynParam.getColumn( ) );
	}
	else
		fail( );
}
 
Example #6
Source File: ReportEngineService.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * createGetParameterDefinitionTask.
 * 
 * @param runnable
 * @deprecated
 * @return the get parameter definition task
 */
public IGetParameterDefinitionTask createGetParameterDefinitionTask(
		IReportRunnable runnable )
{
	IGetParameterDefinitionTask task = null;

	try
	{
		task = engine.createGetParameterDefinitionTask( runnable );
	}
	catch ( Exception e )
	{
	}

	return task;
}
 
Example #7
Source File: AbstractViewer.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected List getInputParameters( String reportDesignFile )
{
	try
	{
		IGetParameterDefinitionTask task = engine.createGetParameterDefinitionTask( engine.openReportDesign( reportDesignFile ) );
		ParameterFactory factory = new ParameterFactory( task );
		List parameters = factory.getRootChildren( );
		task.close( );
		task = null;
		return parameters;
	}
	catch ( EngineException e )
	{
	}
	return null;
}
 
Example #8
Source File: ReportEngineService.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * createGetParameterDefinitionTask.
 * 
 * @param runnable
 * @return the get parameter definition task
 */
public IGetParameterDefinitionTask createGetParameterDefinitionTask(
		IReportRunnable runnable, InputOptions options )
{
	IGetParameterDefinitionTask task = null;

	try
	{
		HttpServletRequest request = (HttpServletRequest) options.getOption( InputOptions.OPT_REQUEST );
		Locale locale = (Locale) options.getOption( InputOptions.OPT_LOCALE );
		TimeZone timeZone = (TimeZone) options.getOption( InputOptions.OPT_TIMEZONE );

		task = engine.createGetParameterDefinitionTask( runnable );
		task.setLocale( locale );

		com.ibm.icu.util.TimeZone tz = BirtUtility.toICUTimeZone( timeZone );
		if ( tz != null )
		{
			task.setTimeZone( tz );
		}

		// set app context
		Map context = BirtUtility.getAppContext( request );
		task.setAppContext( context );
	}
	catch ( Exception e )
	{
	}

	return task;
}
 
Example #9
Source File: ParameterNodeFactory.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Builds parameter tree.
 * 
 * @param task
 * @return parameter tree.
 */

public static IParameterNode buildParamTree(
		IGetParameterDefinitionTask task )
{
	ParameterFactory factory = new ParameterFactory( task );
	List children = factory.getRootChildren( );

	CompositeParameterNode rootNode = new CompositeParameterNode( );

	Iterator iterator = children.iterator( );
	while ( iterator.hasNext( ) )
	{
		Object obj = iterator.next( );

		if ( obj instanceof IParameter )
		{
			IParameter param = (IParameter) obj;
			LeafParameterNode leaf = new LeafParameterNode( param );
			rootNode.add( leaf );

		}
		else if ( obj instanceof IParameterGroup )
		{
			IParameterGroup parameterGroup = (IParameterGroup) obj;
			CompositeParameterNode node = new CompositeParameterNode( );

			List childList = parameterGroup.getChildren( );
			rootNode.add( node );

			buildParamGroup( node, childList );
		}

	}
	return rootNode;
}
 
Example #10
Source File: BirtViewerReportService.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.birt.report.service.api.IViewerReportService#getParameterSelectionList(org.eclipse.birt.report.service.api.IViewerReportDesignHandle,
 *      org.eclipse.birt.report.service.api.InputOptions, java.lang.String)
 */
public Collection getParameterSelectionList(
		IViewerReportDesignHandle design, InputOptions runOptions,
		String paramName ) throws ReportServiceException
{
	IGetParameterDefinitionTask task = null;
	try
	{
		task = getParameterDefinitionTask( design, runOptions );
		if ( task != null )
		{
			ViewerAttributeBean bean = getViewerAttrBean( runOptions );
			if ( bean != null )
			{
				com.ibm.icu.util.TimeZone tz = BirtUtility.toICUTimeZone( bean.getTimeZone( ) );
				if ( tz != null )
				{
					task.setTimeZone( tz );
				}
				task.setLocale( bean.getLocale( ) );
				task.setParameterValues( bean.getParameters( ) );
			}

			Collection selectionList = task.getSelectionList( paramName );
			return convertEngineParameterSelectionChoice( selectionList );
		}
	}
	finally
	{
		if ( task != null )
			task.close( );
	}

	return null;
}
 
Example #11
Source File: ListingParameter.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public List getValueList( )
{
	List values = new ArrayList( );

	boolean isCascading = isCascadingParameter( );

	String name = handle.getName( );
	IGetParameterDefinitionTask task = createParameterDefinitionTask( );

	try 
	{
		if ( isCascading )
		{
			values = getCascadingValues( values, task );
		}
		else
		{
			List selectionList = (List) task.getSelectionList( name );
			/*
			 * Iterator iterator = selectionList.iterator( ); while (
			 * iterator.hasNext( ) ) { IParameterSelectionChoice choice =
			 * (IParameterSelectionChoice) iterator .next( ); values.add(
			 * choice.getValue( ) ); }
			 */

			// TODO change IParameterSelectionChoice to parameter choice.
			values.addAll( selectionList );
		}
		return values;
	} 
	finally 
	{
		if ( task != null )
			task.close();
	}
}
 
Example #12
Source File: BirtViewerReportService.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the GetParameterDefinitionTask
 * 
 * @param reportDesignName
 * @param options
 * @return
 * @throws EngineException
 */
private IGetParameterDefinitionTask getParameterDefinitionTask(
		String reportDesignName, InputOptions options )
		throws EngineException
{

	IReportRunnable runnable = ReportEngineService.getInstance( )
			.openReportDesign( reportDesignName, getModuleOptions( options ) );
	IGetParameterDefinitionTask paramTask = ReportEngineService.getInstance( )
			.createGetParameterDefinitionTask( runnable, options );
	return paramTask;
}
 
Example #13
Source File: ParamNodeFactory.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Builds parameter tree.
 * 
 * @param task
 * @return parameter tree.
 */

public static IParamNode buildParamTree( IGetParameterDefinitionTask task )
{
	ParameterFactory factory = new ParameterFactory( task );
	List children = factory.getRootChildren( );

	CompositeNode rootNode = new CompositeNode( );

	Iterator iterator = children.iterator( );
	while ( iterator.hasNext( ) )
	{
		Object obj = iterator.next( );

		if ( obj instanceof IParameter )
		{
			IParameter param = (IParameter) obj;
			ParamLeaf leaf = new ParamLeaf( param );
			rootNode.add( leaf );

		}
		else if ( obj instanceof IParamGroup )
		{
			IParamGroup paramGroup = (IParamGroup) obj;
			CompositeNode node = new CompositeNode( );

			List childList = paramGroup.getChildren( );
			rootNode.add( node );

			buildParamGroup( node, childList );
		}

	}
	return rootNode;
}
 
Example #14
Source File: ListingParam.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public List getValueList( )
{
	List values = new ArrayList( );

	boolean isCascading = isCascadingParameter( );

	String name = handle.getName( );
	IGetParameterDefinitionTask task = engineTask.getEngine( )
			.createGetParameterDefinitionTask(
					engineTask.getReportRunnable( ) );

	if ( isCascading )
	{
		values = getCascadingValues( values, task );
	}
	else
	{
		List selectionList = (List) task.getSelectionList( name );
		/*
		 * Iterator iterator = selectionList.iterator( ); while (
		 * iterator.hasNext( ) ) { IParameterSelectionChoice choice =
		 * (IParameterSelectionChoice) iterator .next( ); values.add(
		 * choice.getValue( ) ); }
		 */

		// TODO change IParameterSelectionChoice to parameter choice.
		values.addAll( selectionList );
	}

	return values;
}
 
Example #15
Source File: GetParameterDefinitionTaskTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void testMultipleValues( ) throws EngineException
{
	copyResource( REPORT_DESIGN_RESOURCE, REPORT_DESIGN );
	IReportRunnable runnable = engine.openReportDesign( REPORT_DESIGN );
	IGetParameterDefinitionTask task = engine
			.createGetParameterDefinitionTask( runnable );

	/** test the MultiValueSingleDatasetCPG
	 *  USA
	 *  		NV
	 *  				Las Vegas
	 *  		NY
	 *  				NYC
	 *  				White Plains
	 *  		PA
	 *  				Allentown
	 *  				Philadelphia
	 *  Japan
	 *  		Osaka
	 *  				Kita-ku
	 *  		Tokyo
	 *  				Minato-ku
	 */
	String cpg1 = "MultiValueSingleDatasetCPG";
	String[][] values = {{"USA"}, {"NV", "PA"}};
	Collection col = task.getSelectionListForCascadingGroup( cpg1, values );
	assertEquals( 3, col.size( ) );
	values = new String[][]{{"USA", "Japan"},
			{"NV", "NY", "PA", "Osaka", "Tokyo"}};
	col = task.getSelectionListForCascadingGroup( cpg1, values );
	assertEquals( 7, col.size( ) );
	values = new String[][]{{"USA", "Japan"}, {"PA"}};
	col = task.getSelectionListForCascadingGroup( cpg1, values );
	assertEquals( 2, col.size( ) );
}
 
Example #16
Source File: GetParameterDefinitionTaskTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void testParameterInfo( ) throws EngineException
{
	IReportRunnable report = engine.openReportDesign( REPORT_DESIGN );
	IGetParameterDefinitionTask task = engine
			.createGetParameterDefinitionTask( report );

	IScalarParameterDefn param = (IScalarParameterDefn) task
			.getParameterDefn( "NewParameter2" );
	assertTrue( param.getSelectionListType( ) == IScalarParameterDefn.LIST_BOX );
}
 
Example #17
Source File: GetParameterDefinitionTaskTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void testParameterWithDataSet( ) throws SemanticException,
		EngineException
{
	IReportRunnable report = engine.openReportDesign( REPORT_DESIGN );
	ReportDesignHandle design = (ReportDesignHandle) report
			.getDesignHandle( ).getModuleHandle( );
	ScalarParameterHandle parameter1 = (ScalarParameterHandle) design
			.findParameter( "NewParameter2" ); //$NON-NLS-1$
	parameter1.setDataSetName( "Data Set1" ); //$NON-NLS-1$
	ScalarParameterHandle parameter2 = (ScalarParameterHandle) design
			.findParameter( "NewParameter3" ); //$NON-NLS-1$
	parameter2.setDataSetName( "Data Set" ); //$NON-NLS-1$
	IGetParameterDefinitionTask task = engine
			.createGetParameterDefinitionTask( report );
	task.setLocale( ULocale.US );
	
	IParameterDefnBase defn = task.getParameterDefn( "ParamCountry" );
	String name = defn.getName( );
	assertEquals( name, "ParamCountry" );

	Collection list = task.getSelectionListForCascadingGroup(
			"NewCascadingParameterGroup", new Object[0] ); //$NON-NLS-1$
	Object[] content = list.toArray( );
	assertEquals( "1002", ( SelectionChoiceUtil.getValue( content[0] ) ) ); //$NON-NLS-1$
	list = task.getSelectionListForCascadingGroup(
			"NewCascadingParameterGroup", new Object[]{"1002"} ); //$NON-NLS-1$ //$NON-NLS-2$
	content = list.toArray( );
	assertEquals(
			"Atelier graphique", ( SelectionChoiceUtil.getValue( content[0] ) ) ); //$NON-NLS-1$
}
 
Example #18
Source File: ReportEngine.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * creates an engine task for obtaining report parameter definitions
 * 
 * @param reportRunnable
 *            the runnable report design object
 * @return a GetParameterDefinitionTask
 */
public IGetParameterDefinitionTask createGetParameterDefinitionTask(
		IReportRunnable reportRunnable )
{
	logger
			.log(
					Level.FINE,
					"ReportEngine.createGetParameterDefinitionTask: reportRunnable={0} ",
					reportRunnable );
	return helper
			.createGetParameterDefinitionTask( (ReportRunnable) reportRunnable );
}
 
Example #19
Source File: ReportEngine.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * creates an engine task for obtaining report parameter definitions
 * 
 * @param reportRunnable
 *            the runnable report design object
 * @return a run and render report task
 */
public IGetParameterDefinitionTask createGetParameterDefinitionTask(
		IRunnable reportRunnable )
{
	logger
			.log(
					Level.FINE,
					"ReportEngine.createGetParameterDefinitionTask: reportRunnable={0} ",
					reportRunnable );
	return helper
			.createGetParameterDefinitionTask( (ReportRunnable) reportRunnable );
}
 
Example #20
Source File: ReportEngineTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Test createGetParameterDefinitionTask()
 */
public void testCreateGetParameterDefinitionTask( )
{
	EngineConfig config = new EngineConfig( );
	IReportRunnable reportRunner;
	ReportEngine engine = new ReportEngine( config );
	/*
	 * String input =
	 * PLUGIN_PATH+System.getProperty("file.separator")+RESOURCE_BUNDLE
	 * .getString("CASE_INPUT"); input +=
	 * System.getProperty("file.separator") ; String
	 * designName=input+"parameter.rptdesign";
	 */
	String designName = this.genInputFile( "parameter.rptdesign" );

	try
	{
		reportRunner = engine.openReportDesign( designName );
		IGetParameterDefinitionTask getParamTask = engine
				.createGetParameterDefinitionTask( reportRunner );
		getParamTask.evaluateDefaults( );
		IParameterDefnBase paramDefn = getParamTask.getParameterDefn( "p1" );
		System.err.println( paramDefn.getTypeName( ) );
		System.err.println( paramDefn instanceof ScalarParameterDefn );
		assertEquals(
				"creatGetParameterDefinitionTask() fail",
				"abc",
				getParamTask.getDefaultValue( paramDefn ) );
	}
	catch ( EngineException ee )
	{
		ee.printStackTrace( );
	}

}
 
Example #21
Source File: ReportEngineService.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Check whether missing parameter or not.
 * 
 * @param task
 * @param parameters
 * @deprecated
 * @return true if all the parameter values are valid, otherwise false
 */
public boolean validateParameters( IGetParameterDefinitionTask task,
		Map parameters )
{
	assert task != null;
	assert parameters != null;

	boolean missingParameter = false;

	Collection parameterList = task.getParameterDefns( false );
	for ( Iterator iter = parameterList.iterator( ); iter.hasNext( ); )
	{
		IScalarParameterDefn parameterObj = (IScalarParameterDefn) iter.next( );
		// ScalarParameterHandle paramHandle = ( ScalarParameterHandle )
		// parameterObj
		// .getHandle( );

		String parameterName = parameterObj.getName( );
		Object parameterValue = parameters.get( parameterName );

		if ( parameterObj.isHidden( ) )
		{
			continue;
		}

		if ( parameterValue == null && !parameterObj.allowNull( ) )
		{
			missingParameter = true;
			break;
		}

		if ( IScalarParameterDefn.TYPE_STRING == parameterObj.getDataType( ) )
		{
			String parameterStringValue = (String) parameterValue;
			if ( parameterStringValue != null
					&& parameterStringValue.length( ) <= 0
					&& !parameterObj.allowBlank( ) )
			{
				missingParameter = true;
				break;
			}
		}
	}

	return missingParameter;
}
 
Example #22
Source File: ReportEngineService.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Prepare the report parameters.
 * 
 * @param request
 * @param task
 * @param configVars
 * @param locale
 * @deprecated
 * @return map of the request parameters
 */
public HashMap parseParameters( HttpServletRequest request,
		IGetParameterDefinitionTask task, Map configVars, Locale locale )
{
	assert task != null;
	HashMap params = new HashMap( );

	Collection parameterList = task.getParameterDefns( false );
	for ( Iterator iter = parameterList.iterator( ); iter.hasNext( ); )
	{
		IScalarParameterDefn parameterObj = (IScalarParameterDefn) iter.next( );

		String paramValue = null;
		Object paramValueObj = null;

		// ScalarParameterHandle paramHandle = ( ScalarParameterHandle )
		// parameterObj
		// .getHandle( );
		String paramName = parameterObj.getName( );
		String format = parameterObj.getDisplayFormat( );

		// Get default value from task
		ReportParameterConverter converter = new ReportParameterConverter( format,
				locale );

		if ( ParameterAccessor.isReportParameterExist( request, paramName ) )
		{
			// Get value from http request
			paramValue = ParameterAccessor.getReportParameter( request,
					paramName,
					paramValue );
			paramValueObj = converter.parse( paramValue,
					parameterObj.getDataType( ) );
		}
		else if ( ParameterAccessor.isDesigner( )
				&& configVars.containsKey( paramName ) )
		{
			// Get value from test config
			String configValue = (String) configVars.get( paramName );
			ReportParameterConverter cfgConverter = new ReportParameterConverter( format,
					Locale.US );
			paramValueObj = cfgConverter.parse( configValue,
					parameterObj.getDataType( ) );
		}
		else
		{
			paramValueObj = task.getDefaultValue( parameterObj.getName( ) );
		}

		params.put( paramName, paramValueObj );
	}

	return params;
}
 
Example #23
Source File: BirtViewerReportService.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the GetParameterDefinitionTask
 * 
 * @param design
 * @param options
 * @return
 * @throws ReportServiceException
 */
private IGetParameterDefinitionTask getParameterDefinitionTask(
		IViewerReportDesignHandle design, InputOptions options )
		throws ReportServiceException
{
	IGetParameterDefinitionTask task;
	if ( design.getContentType( ) == IViewerReportDesignHandle.RPT_RUNNABLE_OBJECT )
	{
		// IReportRunnable is specified in IViewerReportDesignHandle.
		IReportRunnable runnable = (IReportRunnable) design.getDesignObject( );
		task = ReportEngineService.getInstance( )
				.createGetParameterDefinitionTask( runnable, options );
	}
	else
	{
		// report design name is specified in IViewerReportDesignHandle.
		try
		{
			task = getParameterDefinitionTask( design.getFileName( ),
					options );
		}
		catch ( EngineException e )
		{
			throw new ReportServiceException( e.getLocalizedMessage( ),
					e.getCause( ) );
		}
	}

	// set AppConext
	if ( task != null )
	{
		HttpServletRequest request = (HttpServletRequest) options.getOption( InputOptions.OPT_REQUEST );
		HashMap context = new HashMap( );
		context.put( EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST,
				request );
		ParameterAccessor.pushAppContext( context, request );
		task.setAppContext( context );
	}

	return task;
}
 
Example #24
Source File: BirtReportServlet.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
protected Map findReportParams(HttpServletRequest request, IReportRunnable design) throws ConnectionDefinitionException {
	logger.debug("IN");
	String dateformat = request.getParameter("dateformat");
	if (dateformat != null) {
		dateformat = dateformat.replaceAll("D", "d");
		dateformat = dateformat.replaceAll("m", "M");
		dateformat = dateformat.replaceAll("Y", "y");
	}

	HashMap toReturn = new HashMap();
	IGetParameterDefinitionTask task = birtReportEngine.createGetParameterDefinitionTask(design);
	Collection paramsColl = task.getParameterDefns(false);
	Iterator it = paramsColl.iterator();
	while (it.hasNext()) {
		IScalarParameterDefn param = (IScalarParameterDefn) it.next();
		String paramName = param.getName();
		String paramValueString = request.getParameter(paramName);
		paramValueString = decodeParameter(paramValueString);

		if (paramValueString == null || paramValueString.trim().equals("")) {
			logger.debug(this.getClass().getName() + "findReportParams() The report parameter " + paramName + " has no values set.");
			continue;
			// logger.debug(this.getClass().getName() +
			// "findReportParams() The report parameter " + paramName
			// + " has no values set. Gets default value.");
			// paramValueString = param.getDefaultValue();
		}

		int paramType = param.getDataType();
		/*
		 * The ParameterConverter converts a single value. Multi-value parameters are assumed to contains values that are String type. If they are not
		 * Strings (list of dates, list of numbers, ...) the converter will not work.
		 */
		Object paramValue = ParameterConverter.convertParameter(paramType, paramValueString, dateformat);
		if (paramValue == null)
			paramValue = paramValueString;

		toReturn.put(paramName, paramValue);
		logger.debug("PUT " + paramName + "/" + paramValueString);

	}
	logger.debug("OUT");
	return toReturn;
}
 
Example #25
Source File: BirtViewerReportService.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.birt.report.service.api.IViewerReportService#getSelectionListForCascadingGroup(org.eclipse.birt.report.service.api.IViewerReportDesignHandle,
 *      java.lang.String, java.lang.Object[],
 *      org.eclipse.birt.report.service.api.InputOptions)
 */
public Collection getSelectionListForCascadingGroup(
		IViewerReportDesignHandle design, String groupName,
		Object[] groupKeys, InputOptions options )
		throws ReportServiceException
{
	IGetParameterDefinitionTask task = null;
	HttpServletRequest request = (HttpServletRequest) options.getOption( InputOptions.OPT_REQUEST );
	try
	{
		task = getParameterDefinitionTask( design, options );
		if ( task != null )
		{
			ViewerAttributeBean bean = getViewerAttrBean( options );
			if ( bean != null )
			{
				com.ibm.icu.util.TimeZone tz = BirtUtility.toICUTimeZone( bean.getTimeZone( ) );
				if ( tz != null )
				{
					task.setTimeZone( tz );
				}
				task.setLocale( bean.getLocale( ) );
				task.setParameterValues( bean.getParameters( ) );
			}

			// Add task into session
			BirtUtility.addTask( request, task );

			task.evaluateQuery( groupName );
			Collection selectionList = task.getSelectionListForCascadingGroup( groupName,
					groupKeys );
			return convertEngineParameterSelectionChoice( selectionList );
		}

	}
	finally
	{
		// Remove task from http session
		BirtUtility.removeTask( request );

		if ( task != null )
			task.close( );
	}

	return null;
}
 
Example #26
Source File: ReportLaunchHelper.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Gets the parameter
 * 
 * @param params
 * @return
 */
private static boolean getParameterValues( String reportDesignFile,
		int taskType, IReportEngine engine, Map paramValues )
{
	
	IGetParameterDefinitionTask task = null;
	IReportDocument document = null;
	boolean launch = false;
	
	try
	{
		if ( taskType == TASK_TYPE_RENDER )
		{
			document = engine.openReportDocument( reportDesignFile );
			task = engine.createGetParameterDefinitionTask( document
					.getReportRunnable( ) );
		}
		else
		{
			task = engine.createGetParameterDefinitionTask( engine.openReportDesign( reportDesignFile ) );
		}
		ParameterFactory factory = new ParameterFactory( task );
		List params = factory.getRootChildren( false );
		
		if ( params != null && params.size( ) > 0 )
		{
			InputParameterDialog dialog = new InputParameterDialog( DebugUI.getShell( ),
					params,
					paramValues );
			// InputParameterDailog uses reportrunnable set in
			// GetParameterDefinitionTask execution context.Close
			// GetParameterDefinitionTask after InputParameterDialog
			// completes reading the default values for the report
			// parameters.   
			if ( dialog.open( ) == Window.OK )
			{
				paramValues.clear( );
				paramValues.putAll( dialog.getParameters( ) );
				launch = true;
			}
		}
		else
		{
			launch = true;
		}
	}
	catch ( EngineException e )
	{
		logger.log( Level.SEVERE, e.getMessage( ), e);
	}finally{
		if ( task != null )
		{
			task.close( );
		}
		if (document != null)
		{
			document.close();
		}
	}
	
	return launch;
}
 
Example #27
Source File: ScalarParameter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public List getDefaultValues( )
{
	IGetParameterDefinitionTask task = createParameterDefinitionTask( );

	try
	{
		Object obj =  task.getDefaultValue( handle.getName( ) );
		List retValue = new ArrayList();
		if (obj == null)
		{
			return retValue;
		}
		if (obj instanceof Object[])
		{
			Object[] objs = (Object[])obj;
			for (int i=0; i<objs.length; i++)
			{
				retValue.add( objs[i] );
			}
		}
		else if (obj instanceof Collection)
		{
			Collection collection = (Collection)obj;
			Iterator itor = collection.iterator( );
			while(itor.hasNext( ))
			{
				retValue.add( itor.next( ) );
			}
		}
		else
		{
			retValue.add( obj );
		}
		return retValue;
	}
	finally
	{
		if ( task != null )
			task.close();
	}
}
 
Example #28
Source File: ScalarParameter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Gets default value.
 * 
 * @return default value
 */

public String getDefaultValue( )
{
	IGetParameterDefinitionTask task = createParameterDefinitionTask( );
	try
	{
		Object obj = task.getDefaultValue( handle.getName( ) );
		if (obj == null)
		{
			return null;
		}
		if (obj instanceof Object[] )
		{
			Object[] objs = (Object[])obj;
			if (objs.length > 0)
			{
				oriDefaultValue = objs[0];
				return objs[0] != null ? objs[0].toString( ) : null;
			}
			else
			{
				return null;
			}
		}
		oriDefaultValue = obj;
		if (obj instanceof Date)
		{
			try
			{
				return DataTypeUtil.toString( obj );
			}
			catch ( BirtException e )
			{
				//return toString
			}
		}
		return obj.toString( );
	}
	finally
	{
		if ( task != null )
			task.close();
	}
}
 
Example #29
Source File: ListingParameter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Gets cascading parameter values.
 * 
 * @param values
 * @param task
 * @return cascading parameter values. each item is
 *         <code>IParameterSelectionChoice</code>
 */

private List getCascadingValues( List values,
		IGetParameterDefinitionTask task )
{
	CascadingParameterGroupHandle container = (CascadingParameterGroupHandle) handle.getContainer( );
	List groupList = new ArrayList( );
	List children = group.getChildren( );

	Iterator iterator = children.iterator( );
	while ( iterator.hasNext( ) )
	{
		IParameter param = (IParameter) iterator.next( );

		if ( param == this )
			break;

		// groupList.add( value );
		try
		{
			groupList.add( param.converToDataType( param.getSelectionValue( ) ) );
		}
		catch ( BirtException e )
		{
			// do nothing
		}
	}
	Object[] groupKeys = new Object[groupList.size( )];
	for ( int i = 0; i < groupList.size( ); i++ )
	{
		groupKeys[i] = groupList.get( i );
	}
	List cascading = (List) task.getSelectionListForCascadingGroup( container.getName( ),
			groupKeys );

	if ( cascading != null )
	{
		iterator = cascading.iterator( );
		while ( iterator.hasNext( ) )
		{
			IParameterSelectionChoice choice = (IParameterSelectionChoice) iterator.next( );
			values.add( choice.getValue( ) );
		}
		return cascading;
	}
	else
	{
		return Collections.EMPTY_LIST;
	}
}
 
Example #30
Source File: IParameterAdapter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void setParameterDefinitionTask(
		IGetParameterDefinitionTask parameterDefinitionTask )
{
	this.parameterDefinitionTask = parameterDefinitionTask;
}