<?xml version="1.0" encoding="UTF-8"?>
<s:scufl xmlns:s="http://org.embl.ebi.escience/xscufl/0.1alpha" version="0.2" log="0">
  <s:workflowdescription lsid="urn:lsid:net.sf.taverna:wfDefinition:eb93ba99-c971-4208-9d43-aaddb63a5516" author="Pekka Järveläinen" title="sesameMASTwesix">Parametrized wesix execution with MAST SIAP-service images. Note that only URL sent over Atlantic,
parameter is a reference, not the actual data, which goes directly from SIAP server to WESIX server.
Selection of the image using VOTableviewer. Viewing of everything by plastic.</s:workflowdescription>
  <s:processor name="Xpath_Sesame_Resolver_jdedeg" boring="true">
    <s:stringconstant>/Sesame/Resolver/jdedeg</s:stringconstant>
  </s:processor>
  <s:processor name="SExtractorConfigFileReader">
    <s:beanshell>
      <s:scriptvalue>private static final String PROPERTY_FILE_NAME = System.getProperty("user.home")+
        System.getProperty("file.separator")+".reflex"+System.getProperty("file.separator")+"wesixProperties.xml";
    private static final String COMMENT = "wesix properties for java client";
    Properties  wesixProperties = new Properties();
    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
    String line;
    while((line = br.readLine())!= null) {
        int sharp = line.indexOf("#");
        String data;
        if (sharp &lt; 0) {
            data = line;
        } else {
            data = line.substring(0, sharp); //remove comments
        }
        if (data.trim().length() &gt; 1) { // remove empty lines
            String[] keyvalue = data.split("[ \t]+", 2);
            System.out.println(keyvalue[0] +" "+ keyvalue[1]);
            wesixProperties.setProperty(keyvalue[0].toLowerCase(), keyvalue[1].trim());
        }
    }
    try {
        File wp = new File(PROPERTY_FILE_NAME);
        if (!wp.renameTo( new File(PROPERTY_FILE_NAME+".old"))) {
            System.err.println("Cann't rename " + PROPERTY_FILE_NAME + " to " +
                               PROPERTY_FILE_NAME+".old");
        }
        wesixProperties.storeToXML(new FileOutputStream(wp), COMMENT); 
    } catch (FileNotFoundException e) {
        System.err.println("Cann't write to " + PROPERTY_FILE_NAME);
    }</s:scriptvalue>
      <s:beanshellinputlist>
        <s:beanshellinput s:syntactictype="'text/plain'">filename</s:beanshellinput>
      </s:beanshellinputlist>
      <s:beanshelloutputlist />
    </s:beanshell>
  </s:processor>
  <s:processor name="XPath_Sesame_Resolver_jradeg" boring="true">
    <s:stringconstant>/Sesame/Resolver/jradeg</s:stringconstant>
  </s:processor>
  <s:processor name="Resultype_x" boring="true">
    <s:stringconstant>x</s:stringconstant>
  </s:processor>
  <s:processor name="WESIX">
    <s:beanshell>
      <s:scriptvalue>org.eso.sampo.erda.taverna.scuflui.CPLOutputViewerPanel outputViewer = org.eso.sampo.erda.taverna.scuflui.CPLOutputViewerPanel.getCPLOutputViewerPanel();
outputViewer.outMessage("Sending "+url+" to wesix, please wait\n");
catalog = org.eso.sampo.reflex.WESIX_client3VO.wsextractorURL3VO(url);
org.eso.sampo.erda.taverna.util.TaverdaProperties tp = org.eso.sampo.erda.taverna.util.TaverdaProperties.getTaverdaProperties();
String tmp = url.substring( url.lastIndexOf('=') + 1);
int las = tmp.lastIndexOf('/');
if ( las &lt; 0 ) {
   tmp = tp.getString("resultsDirectory")+ "/cat" + tmp;
} else { //remove '/'
   tmp = url.substring(las + 1);
   int dot = tmp.indexOf(".");
   if (dot &gt; 0) {
        tmp = tmp.substring(0, dot); // remove extensions
   }
  tmp = tp.getString("resultsDirectory")+ "/cat"+ tmp ;
}
outputViewer.outMessage("Got catalog "+tmp+" from wesix\n");
filename = tmp;</s:scriptvalue>
      <s:beanshellinputlist>
        <s:beanshellinput s:syntactictype="'text/plain'">url</s:beanshellinput>
      </s:beanshellinputlist>
      <s:beanshelloutputlist>
        <s:beanshelloutput s:syntactictype="'text/plain'">catalog</s:beanshelloutput>
        <s:beanshelloutput s:syntactictype="'text/plain'">filename</s:beanshelloutput>
      </s:beanshelloutputlist>
    </s:beanshell>
  </s:processor>
  <s:processor name="urlviaplastictoAladin">
    <s:sampo>org.eso.sampo.erda.taverna.external.worker.PlasticWorker</s:sampo>
  </s:processor>
  <s:processor name="Plastic_fits_viewer">
    <s:sampo>org.eso.sampo.erda.taverna.external.worker.PlasticWorker</s:sampo>
  </s:processor>
  <s:processor name="XPath_ra">
    <s:local>net.sourceforge.taverna.scuflworkers.xml.XPathTextWorker</s:local>
  </s:processor>
  <s:processor name="Write_tmp_cat_File">
    <s:local>net.sourceforge.taverna.scuflworkers.io.TextFileWriter</s:local>
  </s:processor>
  <s:processor name="XPath_dec">
    <s:local>net.sourceforge.taverna.scuflworkers.xml.XPathTextWorker</s:local>
  </s:processor>
  <s:processor name="MASTSIAP">
    <s:description>MAST SIAP</s:description>
    <s:workflow>
      <s:scufl version="0.2" log="0">
        <s:workflowdescription lsid="" author="Pekka Jarvelainen" title="MAST SIAP" />
        <s:processor name="Get_web_page_from_URL">
          <s:local>org.embl.ebi.escience.scuflworkers.java.WebPageFetcher</s:local>
        </s:processor>
        <s:processor name="Beanshell_scripting_host">
          <s:beanshell>
            <s:scriptvalue>org.eso.sampo.erda.taverna.scuflui.CPLOutputViewerPanel outputViewer = org.eso.sampo.erda.taverna.scuflui.CPLOutputViewerPanel.getCPLOutputViewerPanel();
StringBuffer temp = new StringBuffer();
temp.append("http://archive.stsci.edu/siap/search.php?POS=");
temp.append(ra);
temp.append(",");
temp.append(dec);
temp.append("&amp;SIZE=0.05");
String MASTURL = temp.toString();
outputViewer.outMessage("Starting " + MASTURL + ", please wait\n");</s:scriptvalue>
            <s:beanshellinputlist>
              <s:beanshellinput s:syntactictype="'text/plain'">ra</s:beanshellinput>
              <s:beanshellinput s:syntactictype="'text/plain'">dec</s:beanshellinput>
            </s:beanshellinputlist>
            <s:beanshelloutputlist>
              <s:beanshelloutput s:syntactictype="'text/plain'">MASTURL</s:beanshelloutput>
            </s:beanshelloutputlist>
          </s:beanshell>
        </s:processor>
        <s:processor name="tmpfilename" boring="true">
          <s:stringconstant>/tmp/siapresults.xml</s:stringconstant>
        </s:processor>
        <s:processor name="Write_Text_File">
          <s:defaults>
            <s:default name="outputFile">/tmp/siapresult</s:default>
          </s:defaults>
          <s:local>net.sourceforge.taverna.scuflworkers.io.TextFileWriter</s:local>
        </s:processor>
        <s:processor name="VOTableviewer">
          <s:sampo>org.eso.sampo.erda.taverna.scuflworkers.VOTableviewer.VOTableWorker</s:sampo>
        </s:processor>
        <s:link source="Beanshell_scripting_host:MASTURL" sink="Get_web_page_from_URL:url" />
        <s:link source="dec" sink="Beanshell_scripting_host:dec" />
        <s:link source="ra" sink="Beanshell_scripting_host:ra" />
        <s:link source="Get_web_page_from_URL:contents" sink="Write_Text_File:filecontents" />
        <s:link source="VOTableviewer:selectedURLs" sink="url" />
        <s:link source="tmpfilename:value" sink="VOTableviewer:URLtoVOTable" />
        <s:link source="tmpfilename:value" sink="Write_Text_File:outputFile" />
        <s:source name="ra" />
        <s:source name="dec" />
        <s:sink name="url" />
        <s:coordination name="VOTableviewer_BLOCKON_Write_Text_File">
          <s:condition>
            <s:state>Completed</s:state>
            <s:target>Write_Text_File</s:target>
          </s:condition>
          <s:action>
            <s:target>VOTableviewer</s:target>
            <s:statechange>
              <s:from>Scheduled</s:from>
              <s:to>Running</s:to>
            </s:statechange>
          </s:action>
        </s:coordination>
      </s:scufl>
    </s:workflow>
  </s:processor>
  <s:processor name="sesame">
    <s:arbitrarywsdl>
      <s:wsdl>http://www.eso.org/sampo/reflex/instructions/workflows/Sesame.wsdl</s:wsdl>
      <s:operation>sesame</s:operation>
    </s:arbitrarywsdl>
  </s:processor>
  <s:link source="Name" sink="sesame:name" />
  <s:link source="MASTSIAP:url" sink="WESIX:url" />
  <s:link source="MASTSIAP:url" sink="urlviaplastictoAladin:file" />
  <s:link source="Resultype_x:value" sink="sesame:resultType" />
  <s:link source="SExtractorConfigFile" sink="SExtractorConfigFileReader:filename" />
  <s:link source="WESIX:catalog" sink="Write_tmp_cat_File:filecontents" />
  <s:link source="WESIX:filename" sink="Plastic_fits_viewer:file" />
  <s:link source="WESIX:filename" sink="Write_tmp_cat_File:outputFile" />
  <s:link source="XPath_Sesame_Resolver_jradeg:value" sink="XPath_ra:xpath" />
  <s:link source="XPath_dec:nodelist" sink="MASTSIAP:dec" />
  <s:link source="XPath_ra:nodelist" sink="MASTSIAP:ra" />
  <s:link source="Xpath_Sesame_Resolver_jdedeg:value" sink="XPath_dec:xpath" />
  <s:link source="sesame:return" sink="XPath_dec:xml-text" />
  <s:link source="sesame:return" sink="XPath_ra:xml-text" />
  <s:source name="Name" />
  <s:source name="SExtractorConfigFile" />
  <s:coordination name="Plastic_fits_viewer_BLOCKON_Write_tmp_cat_File">
    <s:condition>
      <s:state>Completed</s:state>
      <s:target>Write_tmp_cat_File</s:target>
    </s:condition>
    <s:action>
      <s:target>Plastic_fits_viewer</s:target>
      <s:statechange>
        <s:from>Scheduled</s:from>
        <s:to>Running</s:to>
      </s:statechange>
    </s:action>
  </s:coordination>
  <s:coordination name="WESIX_BLOCKON_SExtractorConfigFileReader">
    <s:condition>
      <s:state>Completed</s:state>
      <s:target>SExtractorConfigFileReader</s:target>
    </s:condition>
    <s:action>
      <s:target>WESIX</s:target>
      <s:statechange>
        <s:from>Scheduled</s:from>
        <s:to>Running</s:to>
      </s:statechange>
    </s:action>
  </s:coordination>
</s:scufl>

