Merge list of errors to string
Created: 2011-09-13 14:04:50
Last updated: 2011-09-13 14:16:05
<meta />Based on http://myexperiment.elda.org/workflows/27/ (but myExperiment does not allow multi-myExperiment citations)
Also see http://taverna-users.markmail.org/search/?q=#query:+page:1+mid:cnfl53jbczhpf66b+state:results
<meta />
This example shows how to
<meta />Summary:
1) Make a temporary file
2) Receive the list item by item - write line to file
3) Any failed items will simply fail writing (so errors are stripped)
4) Read/use file in next step of workflow
Now you won't be able to insert placeholders with this solution, but
it should work.
This a modified version. This uses the file-encoding "utf-8"
and so should work well also with international characters. It also
returns the value as a File reference, which mean that this merge
should consume less memory than Merge_string_list_to_a_String.
Note that I was not able to use this as a nested workflow shim, as the
processor for the nested workflow has the "error bounce" layer,
preventing executions of the nested workflow when there are errors in
the incoming list. Manually editing the .t2flow to disable this error
handling for the nested workflow unfortunately brought out an error in
provenance capture that meant that the nested workflow would "never
finish".
Note that Taverna does not make any guarantees as to the execution
order when iterating over a list. It depends on the pipelining from
the upstream source if these will occur out of order or not. In this
example, the Write_text_file_append was however called in order.
So if anyone else wants to use this clever workaround, use "Merge
workflow" and manually delete the local workers before connecting to
the real service.
Preview
Run
Run this Workflow in the Taverna Workbench...
Workflow Components
Authors (1)
Titles (2)
Echo_with_occasional_failure-1 |
Sometimes Fails |
Descriptions (2)
The echo_with_occasional_failure service mostly echoes the string 'hello' to
the out port. Sometimes, it throws a service failure. |
The Sometimes_Fails service mostly echoes the string 'hello' to the out port.
Sometimes, it throws a service failure. |
Dependencies (0)
Processors (7)
Name |
Type |
Description |
Sometimes_Fails |
localworker |
Scriptimport java.util.Random; Random r = new Random(); if ((r.nextInt() % 4) ==
0) { throw new RuntimeException("Fails every four runs!"); } out = in; |
Create_Lots_Of_Strings |
localworker |
ScriptList strings = new ArrayList(); for (int i = 0; i < 40; i++) {
strings.add("String" + i); } |
Merge_String_List_to_a_String |
localworker |
ScriptString seperatorString = "\n";
if (seperator != void) {
seperatorString = seperator;
}
StringBuffer sb = new StringBuffer();
for (Iterator i = stringlist.iterator(); i.hasNext();) {
String item = (String) i.next();
sb.append(item);
if (i.hasNext()) {
sb.append(seperatorString);
}
}
concatenated = sb.toString();
|
Create_temporary_file |
beanshell |
Scriptif ("true".equals(active)) {
File temp = File.createTempFile("taverna", "txt");
temp.deleteOnExit();
out = temp.getCanonicalPath();
}else{
out = "empty";
}
|
Read_Text_File |
localworker |
ScriptBufferedReader getReader (String fileUrl) throws IOException {
InputStreamReader reader;
try {
reader = new FileReader(fileUrl);
}
catch (FileNotFoundException e) {
// try a real URL instead
URL url = new URL(fileUrl);
reader = new InputStreamReader (url.openStream());
}
return new BufferedReader(reader);
}
StringBuffer sb = new StringBuffer(4000);
BufferedReader in = getReader(fileurl);
String str;
String lineEnding = System.getProperty("line.separator");
while ((str = in.readLine()) != null) {
sb.append(str);
sb.append(lineEnding);
}
in.close();
filecontents = sb.toString();
|
active_value |
stringconstant |
Valuetrue |
Write_text_file_append |
beanshell |
ScriptString separatorString = "\n";
if (separator != void) {
separatorString = separator;
}
BufferedWriter out = new BufferedWriter(new FileWriter(outputFile, true));
out.write(filecontents + separatorString);
out.close();
outputFile = filecontents;
|
Beanshells (2)
Name |
Description |
Inputs |
Outputs |
Create_temporary_file |
|
active
|
out
|
Write_text_file_append |
|
outputFile
filecontents
separator
|
outputFile
|
Outputs (3)
Name |
Description |
out |
|
merged_output |
|
merged_output2 |
|
Datalinks (9)
Source |
Sink |
Create_Lots_Of_Strings:strings |
Sometimes_Fails:in |
Sometimes_Fails:out |
Merge_String_List_to_a_String:stringlist |
active_value:value |
Create_temporary_file:active |
Create_temporary_file:out |
Read_Text_File:fileurl |
Create_temporary_file:out |
Write_text_file_append:outputFile |
Sometimes_Fails:out |
Write_text_file_append:filecontents |
Sometimes_Fails:out |
out |
Merge_String_List_to_a_String:concatenated |
merged_output |
Read_Text_File:filecontents |
merged_output2 |
Coordinations (1)
Controller |
Target |
Merge_String_List_to_a_String |
Read_Text_File |
Uploader
License
All versions of this Workflow are
licensed under:
Version 1 (earliest)
(of 2)
Credits (0)
(People/Groups)
None
Attributions (0)
(Workflows/Files)
None
Shared with Groups (1)
Featured In Packs (0)
None
Log in to add to one of your Packs
Attributed By (0)
(Workflows/Files)
None
Favourited By (0)
No one
Statistics
Other workflows that use similar services
(0)
There are no workflows in myExperiment that use similar services to this Workflow.
Comments (0)
No comments yet
Log in to make a comment