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

  <description>Orchestra Loan Approval example</description>

  <!-- properties files -->
  <property environment="env" />
  <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">
    <echo>Loan Approval example</echo>
    <echo>To deploy the processes: ant deploy</echo>
    <echo>To invoke the process: ant launch</echo>
    <echo>To undeploy the process: ant undeploy</echo>
    <echo>Please make sure Orchestra is started before executing this example.</echo>
  </target>

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

  <target name="undeployWS">
    <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/loanApproval/approval}approval" />
    </java>
    <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/loanApproval/riskAssessment}riskAssessment" />
    </java>
  </target>

  <target name="deploy" depends="deployWS">
    <java classpathref="base.classpath" classname="org.ow2.orchestra.jmxclient.JMXClient" fork="yes" failonerror="true">
      <arg value="--deploy" />
      <arg value="--bpel" />
      <arg value="${basedir}/loanService.bpel" />
      <arg value="--wsdls" />
      <arg value="${basedir}/loanService.wsdl,${basedir}/approval/approval.wsdl,${basedir}/riskAssessment/riskAssessment.wsdl" />
    </java>
  </target>

  <target name="undeploy" depends="undeployWS">
    <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/loanApproval/loanService}loanService" />
    </java>
  </target>

  <target name="launch">
    <input message="First name" addproperty="loanApproval.firstname" defaultvalue="John" />
    <input message="Last name" addproperty="loanApproval.name" defaultvalue="Doe" />
    <input message="Amount" addproperty="loanApproval.amount" defaultvalue="9999" />

    <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}/loanServicePort"/>
      <arg value="--soapAction" />
      <arg value="http://orchestra.ow2.org/loanApproval/loanService" />
      <arg value="--soapMessage" />
      <arg value="
        &lt;loan:request xmlns:loan='http://orchestra.ow2.org/loanApproval/loanService'&gt;
          &lt;firstName&gt;${loanApproval.firstname}&lt;/firstName&gt;
          &lt;name&gt;${loanApproval.name}&lt;/name&gt;
          &lt;amount&gt;${loanApproval.amount}&lt;/amount&gt;
        &lt;/loan:request&gt;
      "/>
    </java>
  </target>
</project>