/*************************************************************************************
 * Copyright (c) 2004 Actuate Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Actuate Corporation - Initial implementation.
 ************************************************************************************/

package org.eclipse.birt.report.service.actionhandler;

import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Map;

import org.apache.axis.AxisFault;
import org.eclipse.birt.report.context.IContext;
import org.eclipse.birt.report.context.ViewerAttributeBean;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;
import org.eclipse.birt.report.model.api.util.ParameterValidationUtil;
import org.eclipse.birt.report.service.BirtReportServiceFactory;
import org.eclipse.birt.report.service.api.IViewerReportDesignHandle;
import org.eclipse.birt.report.service.api.IViewerReportService;
import org.eclipse.birt.report.service.api.InputOptions;
import org.eclipse.birt.report.service.api.ReportServiceException;
import org.eclipse.birt.report.soapengine.api.GetUpdatedObjectsResponse;
import org.eclipse.birt.report.soapengine.api.Operation;
import org.eclipse.birt.report.soapengine.api.Oprand;

public class BirtRunReportActionHandler extends AbstractBaseActionHandler
{

	/**
	 * Constructor.
	 * 
	 * @param context
	 * @param operation
	 */
	public BirtRunReportActionHandler( IContext context, Operation operation,
			GetUpdatedObjectsResponse response )
	{
		super( context, operation, response );
	}

	/**
	 * Local execution.
	 * 
	 * @exception ReportServiceException
	 * @return
	 */
	protected void __execute( ) throws RemoteException
	{
		ViewerAttributeBean attrBean = (ViewerAttributeBean) context.getBean( );
		assert attrBean != null;

		Map parameterMap = new HashMap( );

		String docName = attrBean.getReportDocumentName( );
		IViewerReportDesignHandle designHandle = attrBean
				.getReportDesignHandle( context.getRequest( ) );

		try
		{
			InputOptions options = new InputOptions( );
			options.setOption( InputOptions.OPT_REQUEST, context.getRequest( ) );
			options.setOption( InputOptions.OPT_LOCALE, attrBean.getLocale( ) );
			options.setOption( InputOptions.OPT_RTL, new Boolean( attrBean
					.isRtl( ) ) );
			options.setOption( InputOptions.OPT_IS_DESIGNER, new Boolean(
					attrBean.isDesigner( ) ) );

			// convert parameter
			if ( operation != null )
			{
				Oprand[] oprands = operation.getOprand( );
				for ( int i = 0; i < oprands.length; i++ )
				{
					String paramName = oprands[i].getName( );
					Object paramValue = oprands[i].getValue( );

					// find the parameter
					ScalarParameterHandle parameter = (ScalarParameterHandle) attrBean
							.findParameter( paramName );

					if ( parameter != null && paramValue != null )
					{
						// use current locale to parse parameter
						paramValue = ParameterValidationUtil.validate(
								parameter.getDataType( ), parameter
										.getPattern( ), paramValue.toString( ),
								attrBean.getLocale( ) );
					}

					if ( parameter != null )
					{
						parameterMap.put( paramName, paramValue );
					}
				}
			}

			getReportService( ).runReport( designHandle, docName, options,
					parameterMap );
		}
		catch ( Exception e )
		{
			AxisFault fault = new AxisFault( e.getLocalizedMessage( ) );
			fault.setFaultReason( e.getMessage( ) );
			throw fault;
		}
	}

	protected IViewerReportService getReportService( )
	{
		return BirtReportServiceFactory.getReportService( );
	}
}

@@ -1466,16 +1466,74 @@
 .Oprand;
+%0Aimport org.eclipse.birt.report.utility.ParameterAccessor;
 %0A%0Apublic
@@ -2917,24 +2917,492 @@
 tValue( );%0A%0A
+%09%09%09%09%09// Check if parameter set to null%0A%09%09%09%09%09if ( ParameterAccessor.PARAM_ISNULL%0A%09%09%09%09%09%09%09.equalsIgnoreCase( paramName )%0A%09%09%09%09%09%09%09&& paramValue != null )%0A%09%09%09%09%09%7B%0A%09%09%09%09%09%09// find the parameter%0A%09%09%09%09%09%09ScalarParameterHandle parameter = (ScalarParameterHandle) attrBean%0A%09%09%09%09%09%09%09%09.findParameter( paramValue.toString( ) );%0A%09%09%09%09%09%09%0A%09%09%09%09%09%09if ( parameter != null)%0A%09%09%09%09%09%09%7B%0A%09%09%09%09%09%09%09// set parametet to null value%0A%09%09%09%09%09%09%09parameterMap.put( paramValue, null );%0A%09%09%09%09%09%09%09continue;%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%0A
 %09%09%09%09%09// find

Set Null Parameter.Fix Bugzilla Bug 141201,125971