<project name="orchestra-producer" default="usage">

	<description>Orchestra ordering service example</description>

	<!-- properties files -->
  <property file="../../conf/orchestra.properties" />

  <path id="base.classpath">
    <pathelement location="../../conf"/>
    <fileset dir="../../lib">
      <include name="orchestra-jmxclient*.jar" />
    </fileset>
  </path>
  
	<target name="usage" description="usage for this example build file">
		<echo>Producer example</echo>
		<echo>To deploy the process: ant deploy</echo>
		<echo>To undeploy the process: ant undeploy</echo>
		<echo>Please make sure Orchestra is started before executing this example.</echo>
	</target>

	<target name="createBar" description="create the bar file">
		<propertyfile file="bar.properties">
			<entry key="bpel" value="orderingService.bpel" />
			<entry key="wsdl" value="orderingService.wsdl" />
		</propertyfile>
		<zip destfile="order.bar">
			<fileset dir="." includes="*.bpel" />
			<fileset dir="." includes="*.wsdl" />
			<fileset dir="." includes="bar.properties" />
		</zip>
	</target>


	<target name="deploy" description="deploy this example">
		<java classpathref="base.classpath" classname="org.ow2.orchestra.jmxclient.JMXClient" fork="yes" failonerror="true">
			<arg value="--deploy" />
			<arg value="--bpel" />
			<arg value="${basedir}/orderingService.bpel" />
			<arg value="--wsdls" />
			<arg value="${basedir}/orderingService.wsdl" />
		</java>
	</target>

	<target name="undeploy" description="undeploy this example">
		<java classpathref="base.classpath" classname="org.ow2.orchestra.jmxclient.JMXClient" fork="yes" failonerror="true">
			<arg value="--undeploy" />
			<arg value="--process" />
			<arg value="{http://orchestra.ow2.org/demos/orderingService}orderingService" />
		</java>
	</target>

	<target name="create-deadline">
		<tstamp>
			<format property="deadline.date" pattern="yyyy-MM-dd" offset="10" unit="minute" />
		</tstamp>
		<tstamp>
			<format property="deadline.time" pattern="HH:mm:ss" offset="10" unit="minute" />
		</tstamp>
		<property name="deadline.value" value="${deadline.date}T${deadline.time}" />
		<echo>Session will be valid until ${deadline.value} (GMT)</echo>
	</target>

	<target name="id">
      <input message="Session id :" addproperty="id" defaultvalue="1" />
    <property name="session.id" value="&lt;id&gt;${id}&lt;/id&gt;" />
	</target>


	<target name="init" depends="id,create-deadline" description="initiate a session">
		<input message="Client name :" addproperty="init.clientName" defaultvalue="I" />
		<property name="init.name" value="&lt;clientName&gt;${init.clientName}&lt;/clientName&gt;" />
		<property name="init.deadline" value="&lt;sessionExpiration&gt;${deadline.value}&lt;/sessionExpiration&gt;" />
		<property name="init.open" value="&lt;initInfo xmlns='http://orchestra.ow2.org/demos/orderingService'&gt;" />
		<property name="init.close" value="&lt;/initInfo&gt;" />
		
		<java classpathref="base.classpath" classname="org.ow2.orchestra.jmxclient.JMXClient" fork="yes" failonerror="true">
			<arg value="--call" />
			<arg value="--endpoint" />
			<arg value="http://${orchestra.servlet.host}:${orchestra.servlet.port}/${orchestra.servlet.path}/initPort" />
			<arg value="--soapAction" />
			<arg value="http://orchestra.ow2.org/demos/orderingService/init" />
			<arg value="--soapMessage" />
			<arg value="${init.open}${session.id}${init.name}${init.deadline}${init.close}" />
		</java>
	</target>

	<target name="order" depends="id" description="order a product for a given session">
		<input message="Product name :" addproperty="order.productName" defaultvalue="Orchestra" />
		<property name="order.name" value="&lt;productName&gt;${order.productName}&lt;/productName&gt;" />
		<property name="order.open" value="&lt;orderInfo xmlns='http://orchestra.ow2.org/demos/orderingService'&gt;" />
		<property name="order.close" value="&lt;/orderInfo&gt;" />

		<java classpathref="base.classpath" classname="org.ow2.orchestra.jmxclient.JMXClient" fork="yes" failonerror="true">
			<arg value="--call" />
			<arg value="--endpoint" />
			<arg value="http://${orchestra.servlet.host}:${orchestra.servlet.port}/${orchestra.servlet.path}/orderPort" />
			<arg value="--soapAction" />
			<arg value="http://orchestra.ow2.org/demos/orderingService/order" />
			<arg value="--soapMessage" />
			<arg value="${order.open}${session.id}${order.name}${order.close}" />
		</java>
	</target>

	<target name="validate" depends="id" description="end a session">
		<property name="validate.open" value="&lt;validateInfo xmlns='http://orchestra.ow2.org/demos/orderingService'&gt;" />
		<property name="validate.close" value="&lt;/validateInfo&gt;" />

		<java classpathref="base.classpath" classname="org.ow2.orchestra.jmxclient.JMXClient" fork="yes" failonerror="true">
			<arg value="--call" />
			<arg value="--endpoint" />
			<arg value="http://${orchestra.servlet.host}:${orchestra.servlet.port}/${orchestra.servlet.path}/validatePort" />
			<arg value="--soapAction" />
			<arg value="http://orchestra.ow2.org/demos/orderingService/validate" />
			<arg value="--soapMessage" />
			<arg value="${validate.open}${session.id}${validate.close}" />
		</java>
	</target>

</project>