<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="createBarWS">
    <zip destfile="approval.bar">
      <fileset dir="." includes="approval/*.*"/>
      <fileset dir="." includes="common.wsdl"/>
    </zip>
    <zip destfile="riskAssessment.bar">
      <fileset dir="." includes="riskAssessment/*.*"/>
      <fileset dir="." includes="common.wsdl"/>
    </zip>
  </target>
    
  <target name="createBarVersions">
    <zip destfile="loanApproval-v1.bar">
      <fileset dir="." includes="approval/approval.wsdl"/>
      <fileset dir="." includes="common.wsdl"/>
      <fileset dir="." includes="loanService.wsdl"/>
      <fileset dir="." includes="loanService-v1.bpel"/>
    </zip>
    <zip destfile="loanApproval-v2.bar">
      <fileset dir="." includes="approval/approval.wsdl"/>
      <fileset dir="." includes="riskAssessment/riskAssessment.wsdl"/>
      <fileset dir="." includes="common.wsdl"/>
      <fileset dir="." includes="loanService.wsdl"/>
      <fileset dir="." includes="loanService-v2.bpel"/>
    </zip>
  </target>
  
  <target name="createBars" depends="createBarWS, createBarVersions"/>
  
  <target name="deployWS" depends="createBarWS">
    <java  classname="org.ow2.orchestra.jmxclient.JMXClient" classpathref="base.classpath" fork="true" error="error.txt"  failonerror="true">
      <arg value="--deploy" />
      <arg value="--bar" />
      <arg value="approval.bar" />
    </java>
    <java  classname="org.ow2.orchestra.jmxclient.JMXClient" classpathref="base.classpath" fork="true" error="error.txt"  failonerror="true">
      <arg value="--deploy" />
      <arg value="--bar" />
      <arg value="riskAssessment.bar" />
    </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>