You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2015/02/23 11:16:59 UTC
[18/28] incubator-taverna-common-activities git commit: Revert
"temporarily empty repository"
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetImportActivityTest.java
----------------------------------------------------------------------
diff --git a/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetImportActivityTest.java b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetImportActivityTest.java
new file mode 100644
index 0000000..2cd2a2a
--- /dev/null
+++ b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetImportActivityTest.java
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * Copyright (C) 2009 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.spreadsheet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import net.sf.taverna.t2.activities.testutils.ActivityInvoker;
+import net.sf.taverna.t2.workflowmodel.EditException;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.Port;
+import net.sf.taverna.t2.workflowmodel.impl.EditsImpl;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityOutputPort;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+/**
+ * Unit tests for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportActivityTest}.
+ *
+ * @author David Withers
+ */
+public class SpreadsheetImportActivityTest {
+
+ private SpreadsheetImportActivity activity;
+ private SpreadsheetImportActivityFactory activityFactory;
+ private Edits edits;
+ private ObjectNode configuration;
+
+ @Before
+ public void setUp() throws Exception {
+ activity = new SpreadsheetImportActivity();
+ activityFactory = new SpreadsheetImportActivityFactory();
+ edits = new EditsImpl();
+ activityFactory.setEdits(edits);
+ configuration = JsonNodeFactory.instance.objectNode();
+ configuration.put("columnRange", configuration.objectNode().put("start", 0).put("end", 1));
+ configuration.put("rowRange", configuration.objectNode().put("start", 0).put("end", -1));
+ configuration.put("emptyCellValue", "");
+ configuration.put("allRows", true);
+ configuration.put("excludeFirstRow", false);
+ configuration.put("ignoreBlankRows", false);
+ configuration.put("emptyCellPolicy", "EMPTY_STRING");
+ configuration.put("outputFormat", "PORT_PER_COLUMN");
+ configuration.put("csvDelimiter", ",");
+ }
+
+ @Test
+ public void testSpreadsheetImportActivity() {
+ assertNotNull(activity);
+ assertNull(activity.getConfiguration());
+ }
+
+ @Test
+ public void testConfigureSpreadsheetImportConfiguration() throws Exception {
+ assertEquals(0, activity.getInputPorts().size());
+ assertEquals(0, activity.getOutputPorts().size());
+ configuration.put("columnRange", configuration.objectNode().put("start", 0).put("end", 10));
+ ArrayNode columnNames = configuration.arrayNode();
+ columnNames.addObject().put("column", "C").put("port", "test");
+ configuration.put("columnNames", columnNames);
+ activity.configure(configuration);
+ for (ActivityInputPort activityInputPort : activityFactory.getInputPorts(configuration)) {
+ edits.getAddActivityInputPortEdit(activity, activityInputPort).doEdit();
+ }
+ for (ActivityOutputPort activityOutputPort : activityFactory.getOutputPorts(configuration)) {
+ edits.getAddActivityOutputPortEdit(activity, activityOutputPort).doEdit();
+ }
+ assertEquals(configuration, activity.getConfiguration());
+ assertEquals(1, activity.getInputPorts().size());
+ Set<ActivityOutputPort> outputPorts = activity.getOutputPorts();
+ int[] rangeValues = SpreadsheetUtils.getRange(configuration.get("columnRange")).getRangeValues();
+ assertEquals(rangeValues.length, outputPorts.size());
+ for (int i = 0; i < rangeValues.length; i++) {
+ String portName = SpreadsheetUtils.getPortName(rangeValues[i], configuration);
+ Port port = null;
+ for (Port outputPort : outputPorts) {
+ if (outputPort.getName().equals(portName)) {
+ port = outputPort;
+ break;
+ }
+ }
+ assertNotNull(port);
+ outputPorts.remove(port);
+ }
+ assertEquals(0, outputPorts.size());
+
+ configuration.put("outputFormat", SpreadsheetOutputFormat.SINGLE_PORT.name());
+ activity.configure(configuration);
+ assertEquals(1, activityFactory.getOutputPorts(configuration).size());
+ }
+
+ @Test
+ public void testGetConfiguration() throws ActivityConfigurationException {
+ assertNull(activity.getConfiguration());
+ activity.configure(configuration);
+ assertNotNull(activity.getConfiguration());
+ assertEquals(configuration, activity.getConfiguration());
+ }
+
+ @Test
+ public void testExecuteAsynchMapOfStringT2ReferenceAsynchronousActivityCallback() throws Exception {
+ configuration.put("columnRange", configuration.objectNode().put("start", 0).put("end", 3));
+ activity.configure(configuration);
+ for (ActivityInputPort activityInputPort : activityFactory.getInputPorts(configuration)) {
+ edits.getAddActivityInputPortEdit(activity, activityInputPort).doEdit();
+ }
+ for (ActivityOutputPort activityOutputPort : activityFactory.getOutputPorts(configuration)) {
+ edits.getAddActivityOutputPortEdit(activity, activityOutputPort).doEdit();
+ }
+ Map<String, Class<?>> outputs = new HashMap<String, Class<?>>();
+ outputs.put("A", String.class);
+ outputs.put("B", String.class);
+ outputs.put("C", String.class);
+ outputs.put("D", String.class);
+ Map<String, Object> results = ActivityInvoker.invokeAsyncActivity(activity, Collections.singletonMap("fileurl",
+ (Object) "src/test/resources/test-spreadsheet.xls"), outputs);
+ assertEquals(4, results.size());
+ assertTrue(results.get("A") instanceof List<?>);
+ assertEquals(15, ((List<?>) results.get("A")).size());
+ results = ActivityInvoker.invokeAsyncActivity(activity, Collections.singletonMap("fileurl",
+ (Object) "src/test/resources/test-spreadsheet.ods"), outputs);
+ assertEquals(4, results.size());
+ assertTrue(results.get("A") instanceof List<?>);
+ assertEquals(15, ((List<?>) results.get("A")).size());
+ results = ActivityInvoker.invokeAsyncActivity(activity, Collections.singletonMap("fileurl",
+ (Object) "src/test/resources/test-spreadsheet.csv"), outputs);
+ assertEquals(4, results.size());
+ assertTrue(results.get("A") instanceof List<?>);
+ assertEquals(15, ((List<?>) results.get("A")).size());
+
+ // CSV output
+ configuration.put("outputFormat", SpreadsheetOutputFormat.SINGLE_PORT.name());
+ activity.configure(configuration);
+ outputs = new HashMap<String, Class<?>>();
+ outputs.put("output", String.class);
+ results = ActivityInvoker.invokeAsyncActivity(activity, Collections.singletonMap("fileurl",
+ (Object) "src/test/resources/test-spreadsheet.xls"), outputs);
+ assertEquals(1, results.size());
+ assertTrue(results.get("output") instanceof String);
+ assertEquals(15, ((String) results.get("output")).split(System.getProperty("line.separator")).length);
+
+ // TSV output
+ configuration.put("csvDelimiter", "\t");
+ activity.configure(configuration);
+ results = ActivityInvoker.invokeAsyncActivity(activity, Collections.singletonMap("fileurl",
+ (Object) "src/test/resources/test-spreadsheet.csv"), outputs);
+ assertEquals(1, results.size());
+ assertTrue(results.get("output") instanceof String);
+ assertEquals(15, ((String) results.get("output")).split(System.getProperty("line.separator")).length);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetImportConfigurationTest.java
----------------------------------------------------------------------
diff --git a/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetImportConfigurationTest.java b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetImportConfigurationTest.java
new file mode 100644
index 0000000..918f6f7
--- /dev/null
+++ b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetImportConfigurationTest.java
@@ -0,0 +1,265 @@
+/*******************************************************************************
+ * Copyright (C) 2009 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.spreadsheet;
+
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit tests for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration}.
+ *
+ * @author David Withers
+ */
+public class SpreadsheetImportConfigurationTest {
+
+ private SpreadsheetImportConfiguration configuration;
+
+ @Before
+ public void setUp() throws Exception {
+ configuration = new SpreadsheetImportConfiguration();
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#SpreadsheetImportConfiguration()}.
+ */
+ @Test
+ public void testSpreadsheetImportConfiguration() {
+ assertNotNull(configuration);
+ assertEquals(new Range(0, 1), configuration.getColumnRange());
+ assertEquals(new Range(0, -1), configuration.getRowRange());
+ assertEquals("", configuration.getEmptyCellValue());
+ assertEquals(SpreadsheetEmptyCellPolicy.EMPTY_STRING, configuration.getEmptyCellPolicy());
+ assertEquals(SpreadsheetOutputFormat.PORT_PER_COLUMN, configuration.getOutputFormat());
+ assertEquals(Collections.EMPTY_MAP, configuration.getColumnNames());
+ assertEquals(true, configuration.isAllRows());
+ assertEquals(false, configuration.isExcludeFirstRow());
+ assertEquals(false, configuration.isIgnoreBlankRows());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#SpreadsheetImportConfiguration(net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration)}.
+ */
+ @Test
+ public void testSpreadsheetImportConfigurationSpreadsheetImportConfiguration() {
+ configuration.setColumnRange(new Range(3, 22));
+ configuration.setColumnRange(new Range(2, 53));
+ configuration.setAllRows(false);
+ configuration.setExcludeFirstRow(true);
+ configuration.setIgnoreBlankRows(true);
+ configuration.setEmptyCellPolicy(SpreadsheetEmptyCellPolicy.GENERATE_ERROR);
+ configuration.setEmptyCellValue("NO VALUE");
+ configuration.setColumnNames(Collections.singletonMap("D", "delta"));
+ configuration.setOutputFormat(SpreadsheetOutputFormat.SINGLE_PORT);
+ configuration.setCsvDelimiter(" ");
+ SpreadsheetImportConfiguration newConfiguration = new SpreadsheetImportConfiguration(configuration);
+ assertEquals(configuration, newConfiguration);
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#getEmptyCellValue()}.
+ */
+ @Test
+ public void testGetEmptyCellValue() {
+ assertEquals("", configuration.getEmptyCellValue());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#setEmptyCellValue(java.lang.String)}.
+ */
+ @Test
+ public void testSetEmptyCellValue() {
+ configuration.setEmptyCellValue("XXXX");
+ assertEquals("XXXX", configuration.getEmptyCellValue());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#getColumnRange()}.
+ */
+ @Test
+ public void testGetColumnRange() {
+ assertEquals(new Range(0, 1), configuration.getColumnRange());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#setColumnRange(net.sf.taverna.t2.activities.spreadsheet.Range)}.
+ */
+ @Test
+ public void testSetColumnRange() {
+ configuration.setColumnRange(new Range(5, 89));
+ assertEquals(new Range(5, 89), configuration.getColumnRange());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#getRowRange()}.
+ */
+ @Test
+ public void testGetRowRange() {
+ assertEquals(new Range(0, -1), configuration.getRowRange());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#setRowRange(net.sf.taverna.t2.activities.spreadsheet.Range)}.
+ */
+ @Test
+ public void testSetRowRange() {
+ configuration.setRowRange(new Range(41, 67));
+ assertEquals(new Range(41, 67), configuration.getRowRange());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#getColumnNames()}.
+ */
+ @Test
+ public void testGetColumnNames() {
+ assertEquals(Collections.EMPTY_MAP, configuration.getColumnNames());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#setColumnNames(java.util.Map)}.
+ */
+ @Test
+ public void testSetColumnNames() {
+ configuration.setColumnNames(Collections.singletonMap("A", "alpha"));
+ assertEquals(Collections.singletonMap("A", "alpha"), configuration.getColumnNames());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#isAllRows()}.
+ */
+ @Test
+ public void testIsAllRows() {
+ assertEquals(true, configuration.isAllRows());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#setAllRows(boolean)}.
+ */
+ @Test
+ public void testSetAllRows() {
+ configuration.setAllRows(false);
+ assertEquals(false, configuration.isAllRows());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#isExcludeFirstRow()}.
+ */
+ @Test
+ public void testIsExcludeFirstRow() {
+ assertEquals(false, configuration.isExcludeFirstRow());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#setExcludeFirstRow(boolean)}.
+ */
+ @Test
+ public void testSetExcludeFirstRow() {
+ configuration.setExcludeFirstRow(true);
+ assertEquals(true, configuration.isExcludeFirstRow());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#isIgnoreBlankRows()}.
+ */
+ @Test
+ public void testIsIgnoreBlankRows() {
+ assertEquals(false, configuration.isIgnoreBlankRows());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#setIgnoreBlankRows(boolean)}.
+ */
+ @Test
+ public void testSetIgnoreBlankRows() {
+ configuration.setIgnoreBlankRows(true);
+ assertEquals(true, configuration.isIgnoreBlankRows());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#getEmptyCellPolicy()}.
+ */
+ @Test
+ public void testGetEmptyCellPolicy() {
+ assertEquals(SpreadsheetEmptyCellPolicy.EMPTY_STRING, configuration.getEmptyCellPolicy());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#setEmptyCellPolicy(net.sf.taverna.t2.activities.spreadsheet.SpreadsheetEmptyCellPolicy)}.
+ */
+ @Test
+ public void testSetEmptyCellPolicy() {
+ configuration.setEmptyCellPolicy(SpreadsheetEmptyCellPolicy.GENERATE_ERROR);
+ assertEquals(SpreadsheetEmptyCellPolicy.GENERATE_ERROR, configuration.getEmptyCellPolicy());
+ configuration.setEmptyCellPolicy(SpreadsheetEmptyCellPolicy.USER_DEFINED);
+ assertEquals(SpreadsheetEmptyCellPolicy.USER_DEFINED, configuration.getEmptyCellPolicy());
+ configuration.setEmptyCellPolicy(SpreadsheetEmptyCellPolicy.EMPTY_STRING);
+ assertEquals(SpreadsheetEmptyCellPolicy.EMPTY_STRING, configuration.getEmptyCellPolicy());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#equals(java.lang.Object)}.
+ */
+ @Test
+ public void testEqualsObject() {
+ assertTrue(configuration.equals(configuration));
+ assertTrue(configuration.equals(new SpreadsheetImportConfiguration()));
+ assertFalse(configuration.equals(null));
+ configuration.setEmptyCellValue("NIL");
+ assertFalse(configuration.equals(new SpreadsheetImportConfiguration()));
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportConfiguration#hashCode()}.
+ */
+ @Test
+ public void testHashCode() {
+ assertEquals(configuration.hashCode(), configuration.hashCode());
+ assertEquals(configuration.hashCode(), new SpreadsheetImportConfiguration().hashCode());
+ }
+
+ @Test
+ public void testGetOutputFormat() {
+ assertEquals(SpreadsheetOutputFormat.PORT_PER_COLUMN, configuration.getOutputFormat());
+ }
+
+ @Test
+ public void testSetOutputFormat() {
+ configuration.setOutputFormat(SpreadsheetOutputFormat.PORT_PER_COLUMN);
+ assertEquals(SpreadsheetOutputFormat.PORT_PER_COLUMN, configuration.getOutputFormat());
+ configuration.setOutputFormat(SpreadsheetOutputFormat.SINGLE_PORT);
+ assertEquals(SpreadsheetOutputFormat.SINGLE_PORT, configuration.getOutputFormat());
+ }
+
+ @Test
+ public void testGetCsvDelimiter() {
+ assertEquals(",", configuration.getCsvDelimiter());
+ }
+
+ @Test
+ public void testSetCsvDelimiter() {
+ configuration.setCsvDelimiter("'");
+ assertEquals("'", configuration.getCsvDelimiter());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetImportHealthCheckerTest.java
----------------------------------------------------------------------
diff --git a/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetImportHealthCheckerTest.java b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetImportHealthCheckerTest.java
new file mode 100644
index 0000000..dbf6711
--- /dev/null
+++ b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetImportHealthCheckerTest.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (C) 2009 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.spreadsheet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+
+import net.sf.taverna.t2.visit.VisitReport.Status;
+import net.sf.taverna.t2.workflowmodel.impl.EditsImpl;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+/**
+ * Unit tests for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportHealthChecker}.
+ *
+ * @author David Withers
+ */
+public class SpreadsheetImportHealthCheckerTest {
+
+ private SpreadsheetImportHealthChecker healthChecker;
+
+ private SpreadsheetImportActivity activity;
+ private ArrayList ancestors;
+
+ @Before
+ public void setUp() throws Exception {
+ EditsImpl ei = new EditsImpl();
+ healthChecker = new SpreadsheetImportHealthChecker();
+ activity = new SpreadsheetImportActivity();
+ activity.setEdits(new EditsImpl());
+ ancestors = new ArrayList();
+ ancestors.add(ei.createProcessor("fred"));
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportHealthChecker#canHandle(java.lang.Object)}.
+ */
+ @Test
+ public void testCanHandle() {
+ assertTrue(healthChecker.canVisit(activity));
+ assertFalse(healthChecker.canVisit(null));
+ assertFalse(healthChecker.canVisit(""));
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportHealthChecker#checkHealth(net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportActivity)}.
+ * @throws Exception
+ */
+ @Test
+ public void testCheckHealth() throws Exception {
+ assertEquals(Status.SEVERE, healthChecker.visit(activity, ancestors).getStatus());
+ ObjectNode configuration = JsonNodeFactory.instance.objectNode();
+ configuration.put("columnRange", configuration.objectNode().put("start", 0).put("end", 1));
+ configuration.put("rowRange", configuration.objectNode().put("start", 0).put("end", -1));
+ configuration.put("emptyCellValue", "");
+ configuration.put("allRows", true);
+ configuration.put("excludeFirstRow", false);
+ configuration.put("ignoreBlankRows", false);
+ configuration.put("emptyCellPolicy", "EMPTY_STRING");
+ configuration.put("outputFormat", "PORT_PER_COLUMN");
+ configuration.put("csvDelimiter", ",");
+ activity.configure(configuration);
+ assertEquals(Status.OK, healthChecker.visit(activity, ancestors).getStatus());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetReadExceptionTest.java
----------------------------------------------------------------------
diff --git a/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetReadExceptionTest.java b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetReadExceptionTest.java
new file mode 100644
index 0000000..ef3445f
--- /dev/null
+++ b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetReadExceptionTest.java
@@ -0,0 +1,38 @@
+package net.sf.taverna.t2.activities.spreadsheet;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class SpreadsheetReadExceptionTest {
+
+ @Test
+ public void testSpreadsheetReadException() {
+ SpreadsheetReadException spreadsheetReadException = new SpreadsheetReadException();
+ assertNull(spreadsheetReadException.getMessage());
+ assertNull(spreadsheetReadException.getCause());
+ }
+
+ @Test
+ public void testSpreadsheetReadExceptionString() {
+ SpreadsheetReadException spreadsheetReadException = new SpreadsheetReadException("test exception");
+ assertEquals("test exception", spreadsheetReadException.getMessage());
+ assertNull(spreadsheetReadException.getCause());
+ }
+
+ @Test
+ public void testSpreadsheetReadExceptionThrowable() {
+ Exception exception = new Exception();
+ SpreadsheetReadException spreadsheetReadException = new SpreadsheetReadException(exception);
+ assertEquals(exception, spreadsheetReadException.getCause());
+ }
+
+ @Test
+ public void testSpreadsheetReadExceptionStringThrowable() {
+ Exception exception = new Exception();
+ SpreadsheetReadException spreadsheetReadException = new SpreadsheetReadException("test exception", exception);
+ assertEquals("test exception", spreadsheetReadException.getMessage());
+ assertEquals(exception, spreadsheetReadException.getCause());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetUtilsTest.java
----------------------------------------------------------------------
diff --git a/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetUtilsTest.java b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetUtilsTest.java
new file mode 100644
index 0000000..1c3a8f5
--- /dev/null
+++ b/taverna-spreadsheet-import-activity/src/test/java/net/sf/taverna/t2/activities/spreadsheet/SpreadsheetUtilsTest.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (C) 2009 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.spreadsheet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+/**
+ * Unit tests for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtils}.
+ *
+ * @author David Withers
+ */
+public class SpreadsheetUtilsTest {
+
+ @Test
+ public void testSpreadsheetUtils() {
+ assertNotNull(new SpreadsheetUtils());
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtils#getColumnIndex(java.lang.String)}.
+ */
+ @Test
+ public void testGetColumnIndex() {
+ assertEquals(0, SpreadsheetUtils.getColumnIndex("A"));
+ assertEquals(4, SpreadsheetUtils.getColumnIndex("E"));
+ assertEquals(25, SpreadsheetUtils.getColumnIndex("Z"));
+ assertEquals(26, SpreadsheetUtils.getColumnIndex("AA"));
+ assertEquals(457833, SpreadsheetUtils.getColumnIndex("ZAFZ"));
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtils#getColumnLabel(int)}.
+ */
+ @Test
+ public void testGetColumnLabel() {
+ assertEquals("A", SpreadsheetUtils.getColumnLabel(0));
+ assertEquals("E", SpreadsheetUtils.getColumnLabel(4));
+ assertEquals("Z", SpreadsheetUtils.getColumnLabel(25));
+ assertEquals("AA", SpreadsheetUtils.getColumnLabel(26));
+ assertEquals("ZAFZ", SpreadsheetUtils.getColumnLabel(457833));
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtils#getPortName(java.lang.String, java.util.Map)}.
+ */
+ @Test
+ public void testGetPortNameStringMapOfStringString() {
+ assertEquals("A", SpreadsheetUtils.getPortName("A", null));
+ assertEquals("AABR", SpreadsheetUtils.getPortName("AABR", null));
+ ObjectNode configuration = JsonNodeFactory.instance.objectNode();
+ ArrayNode columnNames = configuration.arrayNode();
+ columnNames.addObject().put("column", "B").put("port", "beta");
+ configuration.put("columnNames", columnNames);
+ assertEquals("beta", SpreadsheetUtils.getPortName("B", configuration));
+ assertEquals("T", SpreadsheetUtils.getPortName("T", configuration));
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtils#getPortName(int, java.util.Map)}.
+ */
+ @Test
+ public void testGetPortNameIntMapOfStringString() {
+ assertEquals("A", SpreadsheetUtils.getPortName(0, null));
+ assertEquals("AA", SpreadsheetUtils.getPortName(26, null));
+ ObjectNode configuration = JsonNodeFactory.instance.objectNode();
+ ArrayNode columnNames = configuration.arrayNode();
+ columnNames.addObject().put("column", "D").put("port", "delta");
+ configuration.put("columnNames", columnNames);
+ assertEquals("delta", SpreadsheetUtils.getPortName(3, configuration));
+ assertEquals("AB", SpreadsheetUtils.getPortName(27, configuration));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.csv
----------------------------------------------------------------------
diff --git a/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.csv b/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.csv
new file mode 100644
index 0000000..bbbc3f3
--- /dev/null
+++ b/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.csv
@@ -0,0 +1 @@
+A,5,C,1
A,5,C,1
TRUE,15/06/09,,2
X,X,X,X
X,X,X,X
y,y,y,y
y,y,y,y
y,y,y,y
y,y,y,y
y,y,y,y
y,y,y,y
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.ods
----------------------------------------------------------------------
diff --git a/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.ods b/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.ods
new file mode 100644
index 0000000..e4dbd98
Binary files /dev/null and b/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.ods differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.xls
----------------------------------------------------------------------
diff --git a/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.xls b/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.xls
new file mode 100644
index 0000000..12a2536
Binary files /dev/null and b/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.xls differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.xlsx
----------------------------------------------------------------------
diff --git a/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.xlsx b/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.xlsx
new file mode 100644
index 0000000..2accc38
Binary files /dev/null and b/taverna-spreadsheet-import-activity/src/test/resources/test-spreadsheet.xlsx differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-wsdl-activity/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/pom.xml b/taverna-wsdl-activity/pom.xml
new file mode 100644
index 0000000..d92b618
--- /dev/null
+++ b/taverna-wsdl-activity/pom.xml
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.taverna.commonactivities</groupId>
+ <artifactId>taverna-common-activities</artifactId>
+ <version>2.1.0-incubating-SNAPSHOT</version>
+ </parent>
+ <artifactId>taverna-wsdl-activity</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Taverna WSDL Activity</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <!-- Use the java version instead of xmlcommons for javax.* packages -->
+ <Import-Package>javax.xml.namespace;version="0.0.0",javax.xml.parsers;version="0.0.0",org.w3c.dom;version="0.0.0",org.xml.sax;version="0.0.0",*</Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.taverna.engine</groupId>
+ <artifactId>taverna-workflowmodel-api</artifactId>
+ <version>${taverna.engine.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.taverna.engine</groupId>
+ <artifactId>taverna-reference-api</artifactId>
+ <version>${taverna.engine.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>taverna-wsdl-generic</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.taverna.engine</groupId>
+ <artifactId>taverna-credential-manager</artifactId>
+ <version>${taverna.engine.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jdom</groupId>
+ <artifactId>com.springsource.org.jdom</artifactId>
+ <version>${jdom.version}</version>
+ </dependency>
+<!--
+ <dependency>
+ <groupId>org.apache.ws</groupId>
+ <artifactId>com.springsource.org.apache.ws.security</artifactId>
+ <version>${ws.security.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xml</groupId>
+ <artifactId>com.springsource.org.apache.xml.security</artifactId>
+ <version>${xml.security.version}</version>
+ </dependency>
+-->
+<!--
+<dependency>
+ <groupId>org.apache.axis</groupId>
+ <artifactId>com.springsource.org.apache.axis</artifactId>
+ <version>1.4.0</version>
+</dependency>
+-->
+<dependency>
+ <groupId>org.apache.ws.security</groupId>
+ <artifactId>wss4j</artifactId>
+ <version>${wss4j.version}</version>
+ <!-- NOTE: wss4j 1.6 removes org.apache.ws.axis.security.WSDoAllSender
+ Do we still need this? I can't see how it's used.. -->
+</dependency>
+<dependency>
+ <groupId>org.apache.santuario</groupId>
+ <artifactId>xmlsec</artifactId>
+ <version>${santuario.xmlsec.version}</version>
+</dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.2.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.taverna.engine</groupId>
+ <artifactId>taverna-activity-test-utils</artifactId>
+ <version>${taverna.engine.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.taverna.engine</groupId>
+ <artifactId>taverna-workflowmodel-impl</artifactId>
+ <version>${taverna.engine.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/InputPortTypeDescriptorActivity.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/InputPortTypeDescriptorActivity.java b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/InputPortTypeDescriptorActivity.java
new file mode 100644
index 0000000..c153722
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/InputPortTypeDescriptorActivity.java
@@ -0,0 +1,57 @@
+package net.sf.taverna.t2.activities.wsdl;
+
+import java.io.IOException;
+import java.util.Map;
+
+import net.sf.taverna.t2.activities.wsdl.xmlsplitter.XMLInputSplitterActivity;
+import net.sf.taverna.wsdl.parser.TypeDescriptor;
+import net.sf.taverna.wsdl.parser.UnknownOperationException;
+
+/**
+ * Interface for an activity such as {@link WSDLActivity} and
+ * {@link XMLInputSplitterActivity} that can provide {@link TypeDescriptor}s for
+ * its inputs.
+ *
+ * @author Stian Soiland-Reyes
+ *
+ * @param <ActivityBeanType> The configuration bean type of the activity
+ */
+public interface InputPortTypeDescriptorActivity {
+
+ /**
+ * Provides access to the TypeDescriptor for a given input port name.
+ * <br>
+ * This TypeDescriptor represents the Type defined in the schema for this Activities
+ * WSDL.
+ *
+ * @param portName
+ * @return the TypeDescriptor, or null if the portName is not recognised.
+ * @throws UnknownOperationException if the operation this Activity is associated with doesn't exist.
+ * @throws IOException
+ *
+ * @see TypeDescriptor
+ * @see #getTypeDescriptorsForInputPorts()
+ * @see #getTypeDescriptorForOutputPort(String)
+ */
+ public abstract TypeDescriptor getTypeDescriptorForInputPort(String portName)
+ throws UnknownOperationException, IOException;
+
+ /**
+ * Return TypeDescriptor for a all input ports.
+ * <p>
+ * This TypeDescriptor represents the Type defined in the schema for this Activities
+ * WSDL.
+ *
+ * @param portName
+ * @return A {@link Map} from portname to {@link TypeDescriptor}
+ * @throws UnknownOperationException if the operation this Activity is associated with doesn't exist.
+ * @throws IOException If the WSDL or some of its dependencies could not be read
+ *
+ * @see TypeDescriptor
+ * @see #getTypeDescriptorForInputPort(String)
+ * @see #getTypeDescriptorsForOutputPorts()
+ */
+ public abstract Map<String, TypeDescriptor> getTypeDescriptorsForInputPorts()
+ throws UnknownOperationException, IOException;
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/OutputPortTypeDescriptorActivity.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/OutputPortTypeDescriptorActivity.java b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/OutputPortTypeDescriptorActivity.java
new file mode 100644
index 0000000..23a235c
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/OutputPortTypeDescriptorActivity.java
@@ -0,0 +1,57 @@
+package net.sf.taverna.t2.activities.wsdl;
+
+import java.io.IOException;
+import java.util.Map;
+
+import net.sf.taverna.t2.activities.wsdl.xmlsplitter.XMLOutputSplitterActivity;
+import net.sf.taverna.wsdl.parser.TypeDescriptor;
+import net.sf.taverna.wsdl.parser.UnknownOperationException;
+
+/**
+ * Interface for an activity such as {@link WSDLActivity} and
+ * {@link XMLOutputSplitterActivity} that can provide {@link TypeDescriptor}s for
+ * it's outputs.
+ *
+ * @author Stian Soiland-Reyes
+ *
+ * @param <ActivityBeanType> The configuration bean type of the activity
+ */
+public interface OutputPortTypeDescriptorActivity {
+
+ /**
+ * Provides access to the TypeDescriptor for a given output port name.
+ * <br>
+ * This TypeDescriptor represents the Type defined in the schema for this Activities
+ * WSDL.
+ *
+ * @param portName
+ * @return the TypeDescriptor, or null if the portName is not recognised.
+ * @throws UnknownOperationException if the operation this Activity is associated with doesn't exist.
+ * @throws IOException
+ *
+ * @see TypeDescriptor
+ * @see #getTypeDescriptorsForOutputPorts()
+ * @see #getTypeDescriptorForInputPort(String)
+ */
+ public abstract TypeDescriptor getTypeDescriptorForOutputPort(
+ String portName) throws UnknownOperationException, IOException;
+
+ /**
+ * Return TypeDescriptor for a all output ports.
+ * <p>
+ * This TypeDescriptor represents the Type defined in the schema for this Activities
+ * WSDL.
+ *
+ * @param portName
+ * @return A {@link Map} from portname to {@link TypeDescriptor}
+ * @throws UnknownOperationException if the operation this Activity is associated with doesn't exist.
+ * @throws IOException If the WSDL or some of its dependencies could not be read
+ *
+ * @see TypeDescriptor
+ * @see #getTypeDescriptorForOutputPort(String)
+ * @see #getTypeDescriptorsForInputPorts()
+ */
+ public abstract Map<String, TypeDescriptor> getTypeDescriptorsForOutputPorts()
+ throws UnknownOperationException, IOException;
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/T2WSDLSOAPInvoker.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/T2WSDLSOAPInvoker.java b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/T2WSDLSOAPInvoker.java
new file mode 100644
index 0000000..1e9d1a5
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/T2WSDLSOAPInvoker.java
@@ -0,0 +1,282 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+
+package net.sf.taverna.t2.activities.wsdl;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import net.sf.taverna.t2.activities.wsdl.security.SecurityProfiles;
+import net.sf.taverna.t2.security.credentialmanager.CMException;
+import net.sf.taverna.t2.security.credentialmanager.CredentialManager;
+import net.sf.taverna.t2.security.credentialmanager.UsernamePassword;
+import net.sf.taverna.wsdl.parser.WSDLParser;
+import net.sf.taverna.wsdl.soap.WSDLSOAPInvoker;
+
+import org.apache.axis.AxisProperties;
+import org.apache.axis.EngineConfiguration;
+import org.apache.axis.MessageContext;
+import org.apache.axis.client.Call;
+import org.apache.axis.configuration.XMLStringProvider;
+import org.apache.axis.message.SOAPHeaderElement;
+import org.apache.log4j.Logger;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.DOMOutputter;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * Invokes SOAP based Web Services from T2.
+ *
+ * Subclasses WSDLSOAPInvoker used for invoking Web Services from Taverna 1.x
+ * and extends it to provide support for invoking secure Web services.
+ *
+ * @author Stuart Owen
+ * @author Alex Nenadic
+ * @author Stian Soiland-Reyes
+ *
+ */
+public class T2WSDLSOAPInvoker extends WSDLSOAPInvoker {
+
+ private static final String REFERENCE_PROPERTIES = "ReferenceProperties";
+ private static final String ENDPOINT_REFERENCE = "EndpointReference";
+ private static Logger logger = Logger.getLogger(T2WSDLSOAPInvoker.class);
+ private static final Namespace wsaNS = Namespace.getNamespace("wsa",
+ "http://schemas.xmlsoap.org/ws/2004/03/addressing");
+
+ private String wsrfEndpointReference = null;
+
+ private CredentialManager credentialManager;
+
+ public T2WSDLSOAPInvoker(WSDLParser parser, String operationName,
+ List<String> outputNames, CredentialManager credentialManager) {
+ super(parser, operationName, outputNames);
+ this.credentialManager = credentialManager;
+ }
+
+ public T2WSDLSOAPInvoker(WSDLParser parser, String operationName,
+ List<String> outputNames, String wsrfEndpointReference, CredentialManager credentialManager) {
+ this(parser, operationName, outputNames, credentialManager);
+ this.wsrfEndpointReference = wsrfEndpointReference;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void addEndpointReferenceHeaders(
+ List<SOAPHeaderElement> soapHeaders) {
+ // Extract elements
+ // Add WSA-stuff
+ // Add elements
+
+ Document wsrfDoc;
+ try {
+ wsrfDoc = parseWsrfEndpointReference(wsrfEndpointReference);
+ } catch (JDOMException e) {
+ logger.warn("Could not parse endpoint reference, ignoring:\n"
+ + wsrfEndpointReference, e);
+ return;
+ } catch (IOException e) {
+ logger.error("Could not read endpoint reference, ignoring:\n"
+ + wsrfEndpointReference, e);
+ return;
+ }
+
+ Element endpointRefElem = null;
+ Element wsrfRoot = wsrfDoc.getRootElement();
+ if (wsrfRoot.getNamespace().equals(wsaNS)
+ && wsrfRoot.getName().equals(ENDPOINT_REFERENCE)) {
+ endpointRefElem = wsrfRoot;
+ } else {
+ // Only look for child if the parent is not an EPR
+ Element childEndpoint = wsrfRoot
+ .getChild(ENDPOINT_REFERENCE, wsaNS);
+ if (childEndpoint != null) {
+ // Support wrapped endpoint reference for backward compatibility
+ // and convenience (T2-677)
+ endpointRefElem = childEndpoint;
+ } else {
+ logger
+ .warn("Unexpected element name for endpoint reference, but inserting anyway: "
+ + wsrfRoot.getQualifiedName());
+ endpointRefElem = wsrfRoot;
+ }
+ }
+
+ Element refPropsElem = endpointRefElem.getChild(REFERENCE_PROPERTIES,
+ wsaNS);
+ if (refPropsElem == null) {
+ logger.warn("Could not find " + REFERENCE_PROPERTIES);
+ return;
+ }
+
+ List<Element> refProps = refPropsElem.getChildren();
+ // Make a copy of the list as it would be modified by
+ // prop.detach();
+ for (Element prop : new ArrayList<Element>(refProps)) {
+ DOMOutputter domOutputter = new DOMOutputter();
+ SOAPHeaderElement soapElem;
+ prop.detach();
+ try {
+ org.w3c.dom.Document domDoc = domOutputter.output(new Document(
+ prop));
+ soapElem = new SOAPHeaderElement(domDoc.getDocumentElement());
+ } catch (JDOMException e) {
+ logger.warn(
+ "Could not translate wsrf element to DOM:\n" + prop, e);
+ continue;
+ }
+ soapElem.setMustUnderstand(false);
+ soapElem.setActor(null);
+ soapHeaders.add(soapElem);
+ }
+
+ // soapHeaders.add(new SOAPHeaderElement((Element) wsrfDoc
+ // .getDocumentElement()));
+ }
+
+ protected void configureSecurity(Call call, JsonNode bean) throws Exception {
+
+ // If security settings require WS-Security - configure the axis call
+ // with appropriate properties
+ URI securityProfile = new URI(bean.get("securityProfile").textValue());
+ if (securityProfile
+ .equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_PLAINTEXTPASSWORD)
+ || securityProfile
+ .equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_DIGESTPASSWORD)
+ || securityProfile
+ .equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD)
+ || securityProfile
+ .equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD)) {
+
+ UsernamePassword usernamePassword = getUsernameAndPasswordForService(bean, false);
+ call.setProperty(Call.USERNAME_PROPERTY, usernamePassword.getUsername());
+ call.setProperty(Call.PASSWORD_PROPERTY, usernamePassword.getPasswordAsString());
+ usernamePassword.resetPassword();
+ } else if (securityProfile.equals(SecurityProfiles.HTTP_BASIC_AUTHN)){
+ // Basic HTTP AuthN - set HTTP headers
+ // pathrecursion allowed
+ UsernamePassword usernamePassword = getUsernameAndPasswordForService(bean, true);
+ MessageContext context = call.getMessageContext();
+ context.setUsername(usernamePassword.getUsername());
+ context.setPassword(usernamePassword.getPasswordAsString());
+ usernamePassword.resetPassword();
+ } else {
+ logger.error("Unknown security profile " + securityProfile);
+ }
+ }
+
+ /**
+ * Get username and password from Credential Manager or ask user to supply
+ * one. Username is the first element of the returned array, and the
+ * password is the second.
+ */
+ protected UsernamePassword getUsernameAndPasswordForService(
+ JsonNode bean, boolean usePathRecursion) throws CMException {
+
+ // Try to get username and password for this service from Credential
+ // Manager (which should pop up UI if needed)
+ URI serviceUri = URI.create(bean.get("operation").get("wsdl").textValue());
+ UsernamePassword username_password = credentialManager.getUsernameAndPasswordForService(serviceUri, usePathRecursion, null);
+ if (username_password == null) {
+ throw new CMException("No username/password provided for service " + serviceUri);
+ }
+ return username_password;
+ }
+
+ @Override
+ protected List<SOAPHeaderElement> makeSoapHeaders() {
+ List<SOAPHeaderElement> soapHeaders = new ArrayList<SOAPHeaderElement>(
+ super.makeSoapHeaders());
+ if (wsrfEndpointReference != null && getParser().isWsrfService()) {
+ addEndpointReferenceHeaders(soapHeaders);
+ }
+ return soapHeaders;
+ }
+
+ protected org.jdom.Document parseWsrfEndpointReference(
+ String wsrfEndpointReference) throws JDOMException, IOException {
+ SAXBuilder builder = new SAXBuilder();
+ return builder.build(new StringReader(wsrfEndpointReference));
+ }
+
+ public Map<String, Object> invoke(Map<String, Object> inputMap,
+ JsonNode bean) throws Exception {
+
+ EngineConfiguration wssEngineConfiguration = null;
+ if (bean.has("securityProfile")) {
+ URI securityProfile = new URI(bean.get("securityProfile").textValue());
+
+ // If security settings require WS-Security and not just e.g. Basic HTTP
+ // AuthN - configure the axis engine from the appropriate config strings
+ if (securityProfile
+ .equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_PLAINTEXTPASSWORD)) {
+ wssEngineConfiguration = new XMLStringProvider(
+ SecurityProfiles.WSSECURITY_USERNAMETOKEN_PLAINTEXTPASSWORD_CONFIG);
+ } else if (securityProfile
+ .equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_DIGESTPASSWORD)) {
+ wssEngineConfiguration = new XMLStringProvider(
+ SecurityProfiles.WSSECURITY_USERNAMETOKEN_DIGESTPASSWORD_CONFIG);
+ } else if (securityProfile
+ .equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD)) {
+ wssEngineConfiguration = new XMLStringProvider(
+ SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTETPASSWORD_CONFIG);
+ } else if (securityProfile
+ .equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD)) {
+ wssEngineConfiguration = new XMLStringProvider(
+ SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD_CONFIG);
+ }
+ }
+
+ // This does not work
+// ClassUtils.setClassLoader("net.sf.taverna.t2.activities.wsdl.security.TavernaAxisCustomSSLSocketFactory",TavernaAxisCustomSSLSocketFactory.class.getClassLoader());
+
+ // Setting Axis property only works when we also set the Thread's classloader as below
+ // (we do it from the net.sf.taverna.t2.workflowmodel.processor.dispatch.layers.Invoke.requestRun())
+// Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ if (AxisProperties.getProperty("axis.socketSecureFactory")== null || !AxisProperties.getProperty("axis.socketSecureFactory").equals("net.sf.taverna.t2.activities.wsdl.security.TavernaAxisCustomSSLSocketFactory")){
+ AxisProperties.setProperty("axis.socketSecureFactory", "net.sf.taverna.t2.activities.wsdl.security.TavernaAxisCustomSSLSocketFactory");
+ logger.info("Setting axis.socketSecureFactory property to " + AxisProperties.getProperty("axis.socketSecureFactory"));
+ }
+
+ // This also does not work
+ //AxisProperties.setClassDefault(SecureSocketFactory.class, "net.sf.taverna.t2.activities.wsdl.security.TavernaAxisCustomSSLSocketFactory");
+
+ Call call = super.getCall(wssEngineConfiguration);
+
+ // Now that we have an axis Call object, configure any additional
+ // security properties on it (or its message context or its Transport
+ // handler),
+ // such as WS-Security UsernameToken or HTTP Basic AuthN
+ if (bean.has("securityProfile")) {
+ configureSecurity(call, bean);
+ }
+
+ return invoke(inputMap, call);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivity.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivity.java b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivity.java
new file mode 100644
index 0000000..763cbee
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivity.java
@@ -0,0 +1,328 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.wsdl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.SocketTimeoutException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.wsdl.WSDLException;
+import javax.xml.parsers.ParserConfigurationException;
+
+import net.sf.taverna.t2.reference.ReferenceService;
+import net.sf.taverna.t2.reference.ReferenceServiceException;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.security.credentialmanager.CredentialManager;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.health.RemoteHealthChecker;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractAsynchronousActivity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityOutputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
+import net.sf.taverna.wsdl.parser.TypeDescriptor;
+import net.sf.taverna.wsdl.parser.UnknownOperationException;
+import net.sf.taverna.wsdl.parser.WSDLParser;
+
+import org.apache.log4j.Logger;
+import org.xml.sax.SAXException;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * An asynchronous Activity that is concerned with WSDL based web-services.
+ * <p>
+ * The activity is configured according to the WSDL location and the operation.<br>
+ * The ports are defined dynamically according to the WSDL specification, and in
+ * addition an output<br>
+ * port <em>attachmentList</em> is added to represent any attachements that are
+ * returned by the webservice.
+ * </p>
+ *
+ * @author Stuart Owen
+ * @author Stian Soiland-Reyes
+ */
+public class WSDLActivity extends
+ AbstractAsynchronousActivity<JsonNode> implements
+ InputPortTypeDescriptorActivity, OutputPortTypeDescriptorActivity {
+
+ public static final String URI = "http://ns.taverna.org.uk/2010/activity/wsdl";
+
+ public static final String ENDPOINT_REFERENCE = "EndpointReference";
+ private JsonNode configurationBean;
+ private WSDLParser parser;
+// private Map<String, Integer> outputDepth = new HashMap<String, Integer>();
+ private boolean isWsrfService = false;
+// private String endpointReferenceInputPortName;
+ private CredentialManager credentialManager;
+
+ public WSDLActivity(CredentialManager credentialManager) {
+ this.credentialManager = credentialManager;
+ }
+
+ public boolean isWsrfService() {
+ return isWsrfService;
+ }
+
+ private static Logger logger = Logger.getLogger(WSDLActivity.class);
+
+ /**
+ * Configures the activity according to the information passed by the
+ * configuration bean.<br>
+ * During this process the WSDL is parsed to determine the input and output
+ * ports.
+ *
+ * @param bean
+ * the {@link WSDLActivityConfigurationBean} configuration bean
+ */
+ @Override
+ public void configure(JsonNode bean)
+ throws ActivityConfigurationException {
+ this.configurationBean = bean;
+ try {
+ parseWSDL();
+ } catch (Exception ex) {
+ throw new ActivityConfigurationException(
+ "Unable to parse the WSDL " + bean.get("operation").get("wsdl").textValue(), ex);
+ }
+ }
+
+ @Override
+ public JsonNode getConfiguration() {
+ return configurationBean;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.sf.taverna.t2.activities.wsdl.InputPortTypeDescriptorActivity#
+ * getTypeDescriptorForInputPort(java.lang.String)
+ */
+ public TypeDescriptor getTypeDescriptorForInputPort(String portName)
+ throws UnknownOperationException, IOException {
+ List<TypeDescriptor> inputDescriptors = parser
+ .getOperationInputParameters(configurationBean.get("operation").get("name").textValue());
+ TypeDescriptor result = null;
+ for (TypeDescriptor descriptor : inputDescriptors) {
+ if (descriptor.getName().equals(portName)) {
+ result = descriptor;
+ break;
+ }
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.sf.taverna.t2.activities.wsdl.InputPortTypeDescriptorActivity#
+ * getTypeDescriptorsForInputPorts()
+ */
+ public Map<String, TypeDescriptor> getTypeDescriptorsForInputPorts()
+ throws UnknownOperationException, IOException {
+ Map<String, TypeDescriptor> descriptors = new HashMap<String, TypeDescriptor>();
+ List<TypeDescriptor> inputDescriptors = parser
+ .getOperationInputParameters(configurationBean.get("operation").get("name").textValue());
+ for (TypeDescriptor descriptor : inputDescriptors) {
+ descriptors.put(descriptor.getName(), descriptor);
+ }
+ return descriptors;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.sf.taverna.t2.activities.wsdl.OutputPortTypeDescriptorActivity#
+ * getTypeDescriptorForOutputPort(java.lang.String)
+ */
+ public TypeDescriptor getTypeDescriptorForOutputPort(String portName)
+ throws UnknownOperationException, IOException {
+ TypeDescriptor result = null;
+ List<TypeDescriptor> outputDescriptors = parser
+ .getOperationOutputParameters(configurationBean.get("operation").get("name").textValue());
+ for (TypeDescriptor descriptor : outputDescriptors) {
+ if (descriptor.getName().equals(portName)) {
+ result = descriptor;
+ break;
+ }
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seenet.sf.taverna.t2.activities.wsdl.OutputPortTypeDescriptorActivity#
+ * getTypeDescriptorsForOutputPorts()
+ */
+ public Map<String, TypeDescriptor> getTypeDescriptorsForOutputPorts()
+ throws UnknownOperationException, IOException {
+ Map<String, TypeDescriptor> descriptors = new HashMap<String, TypeDescriptor>();
+ List<TypeDescriptor> inputDescriptors = parser
+ .getOperationOutputParameters(configurationBean.get("operation").get("name").textValue());
+ for (TypeDescriptor descriptor : inputDescriptors) {
+ descriptors.put(descriptor.getName(), descriptor);
+ }
+ return descriptors;
+ }
+
+ private void parseWSDL() throws ParserConfigurationException,
+ WSDLException, IOException, SAXException, UnknownOperationException {
+ String wsdlLocation = configurationBean.get("operation").get("wsdl").textValue();
+ URLConnection connection = null;
+ try {
+ URL wsdlURL = new URL(wsdlLocation);
+ connection = wsdlURL.openConnection();
+ connection.setConnectTimeout(RemoteHealthChecker.getTimeoutInSeconds() * 1000);
+ connection.connect();
+ } catch (MalformedURLException e) {
+ throw new IOException("Malformed URL", e);
+ } catch (SocketTimeoutException e) {
+ throw new IOException("Timeout", e);
+ } catch (IOException e) {
+ throw e;
+ } finally {
+ if ((connection != null) && (connection.getInputStream() != null)) {
+ connection.getInputStream().close();
+ }
+ }
+ parser = new WSDLParser(wsdlLocation);
+ isWsrfService = parser.isWsrfService();
+ }
+
+ @Override
+ public void executeAsynch(final Map<String, T2Reference> data,
+ final AsynchronousActivityCallback callback) {
+
+ callback.requestRun(new Runnable() {
+
+ public void run() {
+
+ ReferenceService referenceService = callback.getContext()
+ .getReferenceService();
+
+ Map<String, T2Reference> outputData = new HashMap<String, T2Reference>();
+ Map<String, Object> invokerInputMap = new HashMap<String, Object>();
+ String endpointReferenceInputPortName = getEndpointReferenceInputPortName();
+
+ try {
+ String endpointReference = null;
+ for (String key : data.keySet()) {
+ Object renderIdentifier = referenceService
+ .renderIdentifier(data.get(key), String.class,
+ callback.getContext());
+ if (isWsrfService()
+ && key.equals(endpointReferenceInputPortName)) {
+ endpointReference = (String) renderIdentifier;
+ } else {
+ invokerInputMap.put(key, renderIdentifier);
+ }
+ }
+ List<String> outputNames = new ArrayList<String>();
+ for (OutputPort port : getOutputPorts()) {
+ outputNames.add(port.getName());
+ }
+
+ T2WSDLSOAPInvoker invoker = new T2WSDLSOAPInvoker(parser,
+ configurationBean.get("operation").get("name").textValue(), outputNames,
+ endpointReference, credentialManager);
+
+ Map<String, Object> invokerOutputMap = invoker.invoke(
+ invokerInputMap, configurationBean);
+
+ for (String outputName : invokerOutputMap.keySet()) {
+ Object value = invokerOutputMap.get(outputName);
+
+ if (value != null) {
+ Integer depth = getOutputPortDepth(outputName);
+ if (depth != null) {
+ outputData.put(outputName, referenceService
+ .register(value, depth, true, callback
+ .getContext()));
+ } else {
+ logger.info("Skipping unknown output port :"
+ + outputName);
+// // TODO what should the depth be in this case?
+// outputData.put(outputName, referenceService
+// .register(value, 0, true, callback
+// .getContext()));
+ }
+ }
+ }
+ callback.receiveResult(outputData, new int[0]);
+ } catch (ReferenceServiceException e) {
+ logger.error("Error finding the input data for "
+ + getConfiguration().get("operation"), e);
+ callback.fail("Unable to find input data", e);
+ return;
+ } catch (Exception e) {
+ logger.error("Error invoking WSDL service "
+ + getConfiguration().get("operation"), e);
+ callback.fail(
+ "An error occurred invoking the WSDL service", e);
+ return;
+ }
+
+ }
+
+ });
+
+ }
+
+ private Integer getOutputPortDepth(String portName) {
+ for (ActivityOutputPort outputPort : getOutputPorts()) {
+ if (outputPort.getName().equals(portName)) {
+ return outputPort.getDepth();
+ }
+ }
+ return null;
+ }
+
+ private String getEndpointReferenceInputPortName() {
+ String endpointReferenceInputPortName = null;
+ if (parser.isWsrfService()) {
+ Set<String> inputPorts = new HashSet<>();
+ try {
+ List<TypeDescriptor> inputDescriptors = parser.getOperationInputParameters(configurationBean
+ .get("operation").get("name").textValue());
+ for (TypeDescriptor descriptor : inputDescriptors) {
+ inputPorts.add(descriptor.getName());
+ }
+ } catch (UnknownOperationException | IOException e) {
+ }
+ // Make sure the port name is unique
+ endpointReferenceInputPortName = WSDLActivity.ENDPOINT_REFERENCE;
+ int counter = 0;
+ while (inputPorts.contains(endpointReferenceInputPortName)) {
+ endpointReferenceInputPortName = WSDLActivity.ENDPOINT_REFERENCE + counter++;
+ }
+ }
+ return endpointReferenceInputPortName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityConfigurationBean.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityConfigurationBean.java b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityConfigurationBean.java
new file mode 100644
index 0000000..80b0bd5
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityConfigurationBean.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.wsdl;
+
+import java.net.URI;
+
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationBean;
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationProperty;
+
+/**
+ * A standard Java Bean that provides the details required to configure a WSDLActivity.
+ * <p>
+ * This contains details about the WSDL and the Operation that the WSDLActivity is intended to invoke.
+ * </p>
+ * @author Stuart Owen
+ */
+@ConfigurationBean(uri = WSDLActivity.URI + "#Config")
+public class WSDLActivityConfigurationBean {
+ private WSDLOperationConfigurationBean operation;
+ private URI securityProfile;
+
+ // In the case service requires username and password for authentication,
+ // but do not serialise these variables to file
+ //transient private String username;
+ //transient private String password;
+
+ /** Creates a new instance of WSDLActivityConfigurationBean */
+ public WSDLActivityConfigurationBean() {
+ }
+
+ public WSDLOperationConfigurationBean getOperation() {
+ return operation;
+ }
+
+ @ConfigurationProperty(name = "operation", label = "WSDL Operation", description = "The WSDL operation")
+ public void setOperation(WSDLOperationConfigurationBean operation) {
+ this.operation = operation;
+ }
+
+ public URI getSecurityProfile() {
+ return securityProfile;
+ }
+
+ @ConfigurationProperty(name = "securityProfile", label = "Security Profile", description = "WS-Security settings required by the web service", required = false)
+ public void setSecurityProfile(URI securityProfile) {
+ this.securityProfile = securityProfile;
+ }
+
+// public void setUsername(String username) {
+// this.username = username;
+// }
+//
+// public String getUsername() {
+// return username;
+// }
+//
+// public void setPassword(String password) {
+// this.password = password;
+// }
+//
+// public String getPassword() {
+// return password;
+// }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityDescriptorChecker.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityDescriptorChecker.java b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityDescriptorChecker.java
new file mode 100644
index 0000000..5a41cde
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityDescriptorChecker.java
@@ -0,0 +1,147 @@
+/**
+ *
+ */
+package net.sf.taverna.t2.activities.wsdl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import net.sf.taverna.t2.visit.VisitReport;
+import net.sf.taverna.t2.visit.VisitReport.Status;
+import net.sf.taverna.t2.workflowmodel.Dataflow;
+import net.sf.taverna.t2.workflowmodel.Datalink;
+import net.sf.taverna.t2.workflowmodel.Merge;
+import net.sf.taverna.t2.workflowmodel.MergeInputPort;
+import net.sf.taverna.t2.workflowmodel.MergeOutputPort;
+import net.sf.taverna.t2.workflowmodel.MergePort;
+import net.sf.taverna.t2.workflowmodel.Port;
+import net.sf.taverna.t2.workflowmodel.Processor;
+import net.sf.taverna.t2.workflowmodel.ProcessorInputPort;
+import net.sf.taverna.t2.workflowmodel.ProcessorPort;
+import net.sf.taverna.t2.workflowmodel.health.HealthCheck;
+import net.sf.taverna.t2.workflowmodel.health.HealthChecker;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.utils.Tools;
+import net.sf.taverna.wsdl.parser.ArrayTypeDescriptor;
+import net.sf.taverna.wsdl.parser.ComplexTypeDescriptor;
+import net.sf.taverna.wsdl.parser.TypeDescriptor;
+import net.sf.taverna.wsdl.parser.UnknownOperationException;
+
+import org.apache.log4j.Logger;
+
+/**
+ * @author alanrw
+ *
+ */
+public final class WSDLActivityDescriptorChecker implements HealthChecker<InputPortTypeDescriptorActivity> {
+
+ private static Logger logger = Logger.getLogger(WSDLActivityDescriptorChecker.class);
+
+ public boolean canVisit(Object o) {
+ return ((o != null) && (o instanceof InputPortTypeDescriptorActivity));
+ }
+
+ public boolean isTimeConsuming() {
+ return false;
+ }
+
+ public VisitReport visit(InputPortTypeDescriptorActivity o,
+ List<Object> ancestry) {
+ List<VisitReport> reports = new ArrayList<VisitReport>();
+ try {
+ Map<String, TypeDescriptor> typeMap = o.getTypeDescriptorsForInputPorts();
+ Processor p = (Processor) VisitReport.findAncestor(ancestry, Processor.class);
+ Dataflow d = (Dataflow) VisitReport.findAncestor(ancestry, Dataflow.class);
+
+
+ for (Entry<String, TypeDescriptor> entry : typeMap.entrySet()) {
+ TypeDescriptor descriptor = entry.getValue();
+ if (!descriptor.getMimeType().contains("'text/xml'")) {
+ continue;
+ }
+ if (!((descriptor instanceof ArrayTypeDescriptor) || (descriptor instanceof ComplexTypeDescriptor))) {
+ continue;
+ }
+ // Find the processor port, if any that corresponds to the activity port
+ ActivityInputPort aip = Tools.getActivityInputPort((Activity<?>) o, entry.getKey());
+ if (aip == null) {
+ continue;
+ }
+ ProcessorInputPort pip = Tools.getProcessorInputPort(p, (Activity<?>) o, aip);
+
+ if (pip == null) {
+ continue;
+ }
+
+ for (Datalink dl : d.getLinks()) {
+
+ if (dl.getSink().equals(pip)) {
+ Port source = dl.getSource();
+ Set<VisitReport> subReports = checkSource(source, d, (Activity<?>) o, aip);
+ for (VisitReport vr : subReports) {
+ vr.setProperty("activity", o);
+ vr.setProperty("sinkPort", pip);
+ }
+ reports.addAll(subReports);
+ }
+ }
+
+ }
+ } catch (UnknownOperationException e) {
+ logger.error("Problem getting type descriptors for activity", e);
+ } catch (IOException e) {
+ logger.error("Problem getting type descriptors for activity", e);
+ } catch (NullPointerException e) {
+ logger.error("Problem getting type desciptors for activity", e);
+ }
+ if (reports.isEmpty()) {
+ return null;
+ }
+ if (reports.size() == 1) {
+ return reports.get(0);
+ }
+ else {
+ return new VisitReport(HealthCheck.getInstance(), o, "Collation", HealthCheck.DEFAULT_VALUE, reports);
+ }
+ }
+
+ private Set<VisitReport> checkSource(Port source, Dataflow d, Activity<?> o, ActivityInputPort aip) {
+ Set<VisitReport> reports = new HashSet<VisitReport>();
+ if (source instanceof ProcessorPort) {
+ ProcessorPort processorPort = (ProcessorPort) source;
+ Processor sourceProcessor = processorPort.getProcessor();
+ Activity<?> sourceActivity = sourceProcessor.getActivityList().get(0);
+ if (!(sourceActivity instanceof InputPortTypeDescriptorActivity)) {
+ VisitReport newReport = new VisitReport(HealthCheck.getInstance(), o, "Source of " + aip.getName(), HealthCheck.DATATYPE_SOURCE, Status.WARNING);
+ newReport.setProperty("sinkPortName", aip.getName());
+ newReport.setProperty("sourceName", sourceProcessor.getLocalName());
+ newReport.setProperty("isProcessorSource", "true");
+ reports.add(newReport);
+ }
+ } else if (source instanceof MergeOutputPort) {
+ Merge merge = ((MergePort) source).getMerge();
+ for (MergeInputPort mip : merge.getInputPorts()) {
+ for (Datalink dl : d.getLinks()) {
+ if (dl.getSink().equals(mip)) {
+ reports.addAll(checkSource(dl.getSource(), d, o, aip));
+ }
+ }
+
+ }
+ } else /* if (source instanceof DataflowInputPort) */ {
+ VisitReport newReport = new VisitReport(HealthCheck.getInstance(), o, "Source of " + aip.getName(), HealthCheck.DATATYPE_SOURCE, Status.WARNING);
+ newReport.setProperty("sinkPortName", aip.getName());
+ newReport.setProperty("sourceName", source.getName());
+ newReport.setProperty("isProcessorSource", "false");
+ reports.add(newReport);
+ }
+ return reports;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/390c286b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityFactory.java
----------------------------------------------------------------------
diff --git a/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityFactory.java b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityFactory.java
new file mode 100644
index 0000000..eeb7c5a
--- /dev/null
+++ b/taverna-wsdl-activity/src/main/java/net/sf/taverna/t2/activities/wsdl/WSDLActivityFactory.java
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * Copyright (C) 2010 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.wsdl;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.wsdl.WSDLException;
+import javax.xml.parsers.ParserConfigurationException;
+
+import net.sf.taverna.t2.security.credentialmanager.CredentialManager;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityOutputPort;
+import net.sf.taverna.wsdl.parser.TypeDescriptor;
+import net.sf.taverna.wsdl.parser.UnknownOperationException;
+import net.sf.taverna.wsdl.parser.WSDLParser;
+
+import org.apache.log4j.Logger;
+import org.xml.sax.SAXException;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * An {@link ActivityFactory} for creating <code>WSDLActivity</code>.
+ *
+ * @author David Withers
+ */
+public class WSDLActivityFactory implements ActivityFactory {
+
+ private static Logger logger = Logger.getLogger(WSDLActivityFactory.class);
+
+ private CredentialManager credentialManager;
+ private Edits edits;
+
+ @Override
+ public WSDLActivity createActivity() {
+ return new WSDLActivity(credentialManager);
+ }
+
+ @Override
+ public URI getActivityType() {
+ return URI.create(WSDLActivity.URI);
+ }
+
+ @Override
+ public JsonNode getActivityConfigurationSchema() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ try {
+ return objectMapper.readTree(getClass().getResource("/schema.json"));
+ } catch (IOException e) {
+ return objectMapper.createObjectNode();
+ }
+ }
+
+ public void setCredentialManager(CredentialManager credentialManager) {
+ this.credentialManager = credentialManager;
+ }
+
+ @Override
+ public Set<ActivityInputPort> getInputPorts(JsonNode configuration) {
+ Map<String, ActivityInputPort> inputPorts = new HashMap<>();
+ try {
+ WSDLParser parser = new WSDLParser(configuration.get("operation").get("wsdl").textValue());
+ List<TypeDescriptor> inputDescriptors = parser.getOperationInputParameters(configuration
+ .get("operation").get("name").textValue());
+ for (TypeDescriptor descriptor : inputDescriptors) {
+ inputPorts.put(descriptor.getName(), edits.createActivityInputPort(
+ descriptor.getName(), descriptor.getDepth(), true, null, String.class));
+ }
+ if (parser.isWsrfService()) {
+ // Make sure the port name is unique
+ String endpointReferenceInputPortName = WSDLActivity.ENDPOINT_REFERENCE;
+ int counter = 0;
+ while (inputPorts.containsKey(endpointReferenceInputPortName)) {
+ endpointReferenceInputPortName = WSDLActivity.ENDPOINT_REFERENCE + counter++;
+ }
+ inputPorts.put(endpointReferenceInputPortName, edits.createActivityInputPort(
+ endpointReferenceInputPortName, 0, true, null, String.class));
+ }
+ } catch (ParserConfigurationException | WSDLException | IOException | SAXException | UnknownOperationException e) {
+ logger.warn(
+ "Unable to parse the WSDL " + configuration.get("operation").get("wsdl").textValue(), e);
+ }
+
+ return new HashSet<>(inputPorts.values());
+ }
+
+ @Override
+ public Set<ActivityOutputPort> getOutputPorts(JsonNode configuration) {
+ Set<ActivityOutputPort> outputPorts = new HashSet<>();
+ try {
+ WSDLParser parser = new WSDLParser(configuration.get("operation").get("wsdl")
+ .textValue());
+ List<TypeDescriptor> outputDescriptors = parser
+ .getOperationOutputParameters(configuration.get("operation").get("name")
+ .textValue());
+ for (TypeDescriptor descriptor : outputDescriptors) {
+ outputPorts.add(edits.createActivityOutputPort(descriptor.getName(),
+ descriptor.getDepth(), descriptor.getDepth()));
+ }
+ // add output for attachment list
+ outputPorts.add(edits.createActivityOutputPort("attachmentList", 1, 1));
+ } catch (ParserConfigurationException | WSDLException | IOException | SAXException | UnknownOperationException e) {
+ logger.warn(
+ "Unable to parse the WSDL " + configuration.get("operation").get("wsdl").textValue(), e);
+ }
+
+ return outputPorts;
+ }
+
+ public void setEdits(Edits edits) {
+ this.edits = edits;
+ }
+
+}