http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/06fe487d/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityFactory.java ---------------------------------------------------------------------- diff --git a/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityFactory.java b/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityFactory.java new file mode 100644 index 0000000..0f43ab0 --- /dev/null +++ b/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityFactory.java @@ -0,0 +1,114 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.taverna.gis; + +import static org.apache.taverna.gis.GisActivity.*; + +import java.io.IOException; +import java.net.URI; +import java.util.HashSet; +import java.util.Set; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.apache.taverna.workflowmodel.Edits; +import org.apache.taverna.workflowmodel.processor.activity.ActivityFactory; +import org.apache.taverna.workflowmodel.processor.activity.ActivityInputPort; +import org.apache.taverna.workflowmodel.processor.activity.ActivityOutputPort; + +/** + * Gis <code>ActivityFactory<code>. + */ +public class GisActivityFactory implements ActivityFactory { + + private Edits edits; + + @Override + public GisActivity createActivity() { + return new GisActivity(); + } + + @Override + public URI getActivityType() { + return URI.create(GisActivity.ACTIVITY_TYPE); + } + + @Override + public JsonNode getActivityConfigurationSchema() { + ObjectMapper objectMapper = new ObjectMapper(); + try { + return objectMapper.readTree(getClass().getResource("/schema.json")); + } catch (IOException e) { + return objectMapper.createObjectNode(); + } + } + + @Override + public Set<ActivityInputPort> getInputPorts(JsonNode configuration) { + Set<ActivityInputPort> inputPorts = new HashSet<>(); + + // FIXME: Replace with your input port definitions + + // Hard coded input port, expecting a single String + inputPorts.add(edits.createActivityInputPort(IN_FIRST_INPUT, 0, true, null, String.class)); + + // Optional ports depending on configuration + if (configuration.get("exampleString").asText().equals("specialCase")) { + // depth 1, ie. list of binary byte[] arrays + inputPorts.add(edits.createActivityInputPort(IN_EXTRA_DATA, 1, true, null, byte[].class)); + } + + return inputPorts; + } + + @Override + public Set<ActivityOutputPort> getOutputPorts(JsonNode configuration) { + Set<ActivityOutputPort> outputPorts = new HashSet<>(); + + // FIXME: Replace with your output port definitions + + // Optional ports depending on configuration + if (configuration.get("exampleString").asText().equals("specialCase")) { + outputPorts.add(edits.createActivityOutputPort(OUT_REPORT, 0, 0)); + } + + // Single value output port (depth 0) + outputPorts.add(edits.createActivityOutputPort(OUT_SIMPLE_OUTPUT, 0, 0)); + // Output port with list of values (depth 1) + outputPorts.add(edits.createActivityOutputPort(OUT_MORE_OUTPUTS, 1, 1)); + + return outputPorts; + } + + /** + * Sets the edits property. + * <p> + * This method is used by Spring. The property name must match the property specified + * in the Spring context file. + * + * @param edits the <code>Edits</code> used to create input/output ports + */ + public void setEdits(Edits edits) { + this.edits = edits; + } + +}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/06fe487d/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityHealthChecker.java ---------------------------------------------------------------------- diff --git a/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityHealthChecker.java b/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityHealthChecker.java new file mode 100644 index 0000000..b1e3093 --- /dev/null +++ b/taverna-gis-activity/src/main/java/org/apache/taverna/gis/GisActivityHealthChecker.java @@ -0,0 +1,83 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.taverna.gis; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.databind.JsonNode; + +import org.apache.taverna.visit.VisitReport; +import org.apache.taverna.visit.VisitReport.Status; +import org.apache.taverna.workflowmodel.health.HealthCheck; +import org.apache.taverna.workflowmodel.health.HealthChecker; + +/** + * Gis <code>HealthChecker</code>. + */ +public class GisActivityHealthChecker implements + HealthChecker<GisActivity> { + + public boolean canVisit(Object o) { + // Return True if we can visit the object. We could do + // deeper (but not time consuming) checks here, for instance + // if the health checker only deals with GisActivity where + // a certain configuration option is enabled. + return o instanceof GisActivity; + } + + public boolean isTimeConsuming() { + // Return true if the health checker does a network lookup + // or similar time consuming checks, in which case + // it would only be performed when using File->Validate workflow + // or File->Run. + return false; + } + + public VisitReport visit(GisActivity activity, List<Object> ancestry) { + JsonNode config = activity.getConfiguration(); + + // We'll build a list of subreports + List<VisitReport> subReports = new ArrayList<>(); + + if (!URI.create(config.get("exampleUri").asText()).isAbsolute()) { + // Report Severe problems we know won't work + VisitReport report = new VisitReport(HealthCheck.getInstance(), + activity, "Example URI must be absolute", HealthCheck.INVALID_URL, + Status.SEVERE); + subReports.add(report); + } + + if (config.get("exampleString").asText().equals("")) { + // Warning on possible problems + subReports.add(new VisitReport(HealthCheck.getInstance(), activity, + "Example string empty", HealthCheck.NO_CONFIGURATION, + Status.WARNING)); + } + + // The default explanation here will be used if the subreports list is + // empty + return new VisitReport(HealthCheck.getInstance(), activity, + "Gis service OK", HealthCheck.NO_PROBLEM, subReports); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/06fe487d/taverna-gis-activity/src/main/resources/schema.json ---------------------------------------------------------------------- diff --git a/taverna-gis-activity/src/main/resources/schema.json b/taverna-gis-activity/src/main/resources/schema.json new file mode 100644 index 0000000..1e396b3 --- /dev/null +++ b/taverna-gis-activity/src/main/resources/schema.json @@ -0,0 +1,25 @@ +{ + "$schema": "http://json-schema.org/draft-03/schema#", + "id": "http://example.com/2013/activity/apache-taverna-activity-gis.schema.json", + "title": "Gis activity configuration", + "type": "object", + "properties": { + "@context": { + "description": "JSON-LD context for interpreting the configuration as RDF", + "required": true, + "enum": ["http://example.com/2013/activity/apache-taverna-activity-gis.context.json"] + }, + "exampleString": { + "title": "Example String", + "description": "An example string property", + "type": "string", + "required": true + }, + "exampleUri": { + "title": "Example URI", + "description": "An example uri property", + "type": "string", + "required": true + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/06fe487d/taverna-gis-activity/src/main/resources/spring/context-osgi.xml ---------------------------------------------------------------------- diff --git a/taverna-gis-activity/src/main/resources/spring/context-osgi.xml b/taverna-gis-activity/src/main/resources/spring/context-osgi.xml new file mode 100644 index 0000000..98809c2 --- /dev/null +++ b/taverna-gis-activity/src/main/resources/spring/context-osgi.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:beans="http://www.springframework.org/schema/beans" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/osgi + http://www.springframework.org/schema/osgi/spring-osgi.xsd"> + + <!-- Services to be registered with the OSGi service register --> + <service ref="GisActivityHealthChecker" interface="org.apache.taverna.workflowmodel.health.HealthChecker" /> + + <service ref="GisActivityFactory" interface="org.apache.taverna.workflowmodel.processor.activity.ActivityFactory" /> + + <!-- References to services required from the OSGi service register --> + <reference id="edits" interface="org.apache.taverna.workflowmodel.Edits" /> + +</beans:beans> http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/06fe487d/taverna-gis-activity/src/main/resources/spring/context.xml ---------------------------------------------------------------------- diff --git a/taverna-gis-activity/src/main/resources/spring/context.xml b/taverna-gis-activity/src/main/resources/spring/context.xml new file mode 100644 index 0000000..c42932d --- /dev/null +++ b/taverna-gis-activity/src/main/resources/spring/context.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd"> + + <bean id="GisActivityHealthChecker" class="org.apache.taverna.gis.GisActivityHealthChecker" /> + + <bean id="GisActivityFactory" class="org.apache.taverna.gis.GisActivityFactory"> + <property name="edits" ref="edits" /> + </bean> + +</beans> http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/06fe487d/taverna-gis-activity/src/main/resources/wps_config.xml ---------------------------------------------------------------------- diff --git a/taverna-gis-activity/src/main/resources/wps_config.xml b/taverna-gis-activity/src/main/resources/wps_config.xml new file mode 100644 index 0000000..cd73904 --- /dev/null +++ b/taverna-gis-activity/src/main/resources/wps_config.xml @@ -0,0 +1,212 @@ +<?xml version="1.0" encoding="UTF-8"?> +<WPSConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://n52.org/wps https://raw.githubusercontent.com/52North/wps-config/52n-wps-config-1.2.1/src/main/xsd/schema_v2.xsd" xmlns="http://n52.org/wps"> + <Datahandlers> + <ParserList> + <Parser name="WCPSQueryParser" + className="org.n52.wps.io.datahandler.parser.WCPSQueryParser" + active="true"> + <Format mimetype="text/plain" + schema="http://schemas.opengis.net/wcps/1.0/wcpsAll.xsd" /> + </Parser> + <Parser name="WKTParser" + className="org.n52.wps.io.datahandler.parser.WKTParser" + active="true"> + <Format mimetype="application/wkt"/> + </Parser> + <Parser name="GenericXMLDataParser" + className="org.n52.wps.io.datahandler.parser.GenericXMLDataParser" + active="true"> + <Format mimetype="text/xml" /> + <Format mimetype="text/xml; subtype=gml/2.1.2" + schema="http://schemas.opengis.net/gml/2.1.2/feature.xsd" /> + </Parser> + <Parser name="GenericFileParser" + className="org.n52.wps.io.datahandler.parser.GenericFileParser" + active="true"> + <Format mimetype="application/x-zipped-shp" /> + <Format mimetype="application/img" /> + <Format mimetype="image/tiff" /> + <Format mimetype="image/geotiff" /> + <Format mimetype="application/geotiff" /> + <Format mimetype="application/dbase" /> + <Format mimetype="application/remap" /> + <Format mimetype="application/x-erdas-hfa" /> + <Format mimetype="application/x-netcdf" /> + <Format mimetype="application/dgn" /> + <Format mimetype="image/jpeg" /> + <Format mimetype="image/png" /> + <Format mimetype="application/x-geotiff" /> + <Format mimetype="application/hdf4-eos" /> + <Format mimetype="text/plain" /> + <Format mimetype="application/rData" /> + <Format mimetype="application/rData+Spatial" /> + <Format mimetype="application/rData+SpatialPoints" /> + <Format mimetype="application/rData+SpatialPolygons" /> + <Format mimetype="text/html" /> + + <Format mimetype="application/rData" encoding="base64" /> + <Format mimetype="application/rData+Spatial" encoding="base64" /> + <Format mimetype="application/rData+SpatialPoints" encoding="base64" /> + <Format mimetype="application/rData+SpatialPolygons" encoding="base64" /> + <Format mimetype="application/x-zipped-shp" encoding="base64" /> + <Format mimetype="application/img" encoding="base64" /> + <Format mimetype="image/tiff" encoding="base64" /> + <Format mimetype="application/geotiff" encoding="base64" /> + <Format mimetype="application/dbase" encoding="base64" /> + <Format mimetype="application/remap" encoding="base64" /> + <Format mimetype="application/x-erdas-hfa" encoding="base64" /> + <Format mimetype="application/x-netcdf" encoding="base64" /> + <Format mimetype="application/dgn" encoding="base64" /> + <Format mimetype="image/jpeg" encoding="base64" /> + <Format mimetype="image/png" encoding="base64" /> + <Format mimetype="application/x-geotiff" encoding="base64" /> + <Format mimetype="application/hdf4-eos" encoding="base64" /> + <Format mimetype="text/plain" encoding="base64" /> + </Parser> + </ParserList> + <GeneratorList> + <Generator name="WKTGenerator" + className="org.n52.wps.io.datahandler.generator.WKTGenerator" + active="true"> + <Format mimetype="application/wkt"/> + </Generator> + <Generator name="GenericXMLDataGenerator" + className="org.n52.wps.io.datahandler.generator.GenericXMLDataGenerator" + active="true"> + <Format mimetype="text/xml" /> + <Format mimetype="text/xml; subtype=gml/2.1.2" + schema="http://schemas.opengis.net/gml/2.1.2/feature.xsd" /> + </Generator> + <Generator name="GenericFileGenerator" + className="org.n52.wps.io.datahandler.generator.GenericFileGenerator" + active="true"> + <Format mimetype="application/x-zipped-shp" encoding="base64" /> + <Format mimetype="application/shp" encoding="base64" /> + <Format mimetype="application/img" encoding="base64" /> + <Format mimetype="image/tiff" encoding="base64" /> + <Format mimetype="image/geotiff" encoding="base64" /> + <Format mimetype="application/geotiff" encoding="base64" /> + <Format mimetype="application/dbase" encoding="base64" /> + <Format mimetype="application/remap" encoding="base64" /> + <Format mimetype="application/x-erdas-hfa" encoding="base64" /> + <Format mimetype="application/x-netcdf" encoding="base64" /> + <Format mimetype="application/netcdf" encoding="base64" /> + <Format mimetype="application/dgn" encoding="base64" /> + <Format mimetype="image/jpeg" encoding="base64" /> + <Format mimetype="image/png" encoding="base64" /> + <Format mimetype="application/x-geotiff" encoding="base64" /> + <Format mimetype="text/plain" encoding="base64" /> + <Format mimetype="application/x-zipped-shp" encoding="base64" /> + <Format mimetype="application/rData" encoding="base64" /> + <Format mimetype="application/rData+Spatial" encoding="base64" /> + <Format mimetype="application/rData+SpatialPoints" encoding="base64" /> + <Format mimetype="application/rData+SpatialPolygons" encoding="base64" /> + + <Format mimetype="application/rData" /> + <Format mimetype="application/rData+Spatial" /> + <Format mimetype="application/rData+SpatialPoints" /> + <Format mimetype="application/rData+SpatialPolygons" /> + <Format mimetype="application/x-zipped-shp" /> + <Format mimetype="application/shp" /> + <Format mimetype="application/img" /> + <Format mimetype="image/tiff" /> + <Format mimetype="image/geotiff" /> + <Format mimetype="application/geotiff" /> + <Format mimetype="application/dbase" /> + <Format mimetype="application/remap" /> + <Format mimetype="application/x-erdas-hfa" /> + <Format mimetype="application/x-netcdf" /> + <Format mimetype="application/netcdf" /> + <Format mimetype="application/dgn" /> + <Format mimetype="image/jpeg" /> + <Format mimetype="image/png" /> + <Format mimetype="application/x-geotiff" /> + <Format mimetype="text/plain" /> + <Format mimetype="application/pdf" /> + <Format mimetype="application/zip" /> + <Format mimetype="text/html" /> + </Generator> + </GeneratorList> + </Datahandlers> + <AlgorithmRepositoryList> + <Repository name="LocalAlgorithmRepository" + className="org.n52.wps.server.LocalAlgorithmRepository" active="true"> + <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.JTSConvexHullAlgorithm</Property> + <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.DummyTestClass</Property> + <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.LongRunningDummyTestClass</Property> + <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.MultipleComplexInAndOutputsDummyTestClass</Property> + <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.MultiReferenceInputAlgorithm</Property> + <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.MultiReferenceBinaryInputAlgorithm</Property> + <Property name="Algorithm" active="true">org.n52.wps.server.algorithm.test.EchoProcess</Property> + </Repository> + <Repository name="UploadedAlgorithmRepository" + className="org.n52.wps.server.UploadedAlgorithmRepository" active="false"> + </Repository> + <Repository name="ServiceLoaderAlgorithmRepository" + className="org.n52.wps.server.ServiceLoaderAlgorithmRepository" active="true"> + </Repository> + <!-- + <Repository name="MCProcessRepository" className="org.n52.wps.mc.MCProcessRepository" active="true"> + <Property name="REMOTE_REPOSITORY" active="false">http://141.30.100.178/gpfeed2/gpfeed.xml</Property> + <Property name="LOCAL_REPOSITORY" active="true">D:\MCpackages</Property> + </Repository> + --> + </AlgorithmRepositoryList> + <RemoteRepositoryList /> + + <Server protocol="http" hostname="localhost" hostport="8080" + includeDataInputsInResponse="false" computationTimeoutMilliSeconds="5" + cacheCapabilites="false" webappPath="wps" repoReloadInterval="0" maxPoolSize="20" keepAliveSeconds="1000" maxQueuedTasks="100" minPoolSize="10" > + <!-- Setting to 'true' will enable filtering of responses documents. Any server URL in + the response document will be replaced with the server URL used in the HTTP request. --> + <Property name="responseURLFilterEnabled" active="true">false</Property> + <Database> + <!-- NOTE: database wipe is only implemented for the FlatFileDatabase (the default) --> + <!-- enable database wiping base on values below --> + <Property name="wipe.enabled" active="true">true</Property> + <!-- scans database every 1 hour --> + <Property name="wipe.period" active="true">PT1H</Property> + <!-- deletes files older than 7 days --> + <Property name="wipe.threshold" active="true">P7D</Property> + </Database> + + <!-- + POSTGRES Connector + ================== + Ensure that the postgres driver is available to the server during + launch. The server will fail to start if Postgres is active but the + driver is missing. However, if the driver exists and the database + cannot be connected to (unavailable, username/pass issue, etc), the + framework will fail-over to the Flatfile Database + jndiName or username/password: If jndiName exists, username + and password are not used. + saveResultsToDb: Setting to false will save results output to file + and put the URI link to the file in the database. Setting to true + stores the actual result output in the database (You probably don't + want this if you have large results). + JNDI Configuration: + <Database> + <Property active="true" name="databaseClass">org.n52.wps.server.database.PostgresDatabase</Property> + <Property active="true" name="jndiName">jndiname</Property> + <Property active="true" name="saveResultsToDb">false</Property> + <Property name="wipe.enabled" active="true">true</Property> + <Property name="wipe.period" active="true">PT1H</Property> + <Property name="wipe.threshold" active="true">P7D</Property> + </Database> + Direct connection configuration: + <Database> + Alternative connection method + <Property active="true" name="databaseName">postgres</Property> + <Property active="true" name="databasePath">//localhost:5432</Property> + <Property active="true" name="username">username</Property> + <Property active="true" name="password">password</Property> + <Property active="true" name="saveResultsToDb">false</Property> + <Property name="wipe.enabled" active="true">true</Property> + <Property name="wipe.period" active="true">PT1H</Property> + <Property name="wipe.threshold" active="true">P7D</Property> + </Database> +--> + + </Server> +</WPSConfiguration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/06fe487d/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityFactoryTest.java ---------------------------------------------------------------------- diff --git a/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityFactoryTest.java b/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityFactoryTest.java new file mode 100644 index 0000000..9468849 --- /dev/null +++ b/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityFactoryTest.java @@ -0,0 +1,120 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.taverna.gis; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + +import java.net.URI; +import java.util.HashSet; +import java.util.Set; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import org.apache.taverna.workflowmodel.impl.EditsImpl; +import org.apache.taverna.workflowmodel.processor.activity.ActivityInputPort; +import org.apache.taverna.workflowmodel.processor.activity.ActivityOutputPort; + +import org.junit.Before; +import org.junit.Test; + +public class GisActivityFactoryTest { + + private ObjectNode configuration; + + private GisActivityFactory activityFactory; + + @Before + public void setUp() throws Exception { + configuration = JsonNodeFactory.instance.objectNode(); + configuration.put("exampleString", "something"); + configuration.put("exampleUri", "http://localhost:8080/myEndPoint"); + + activityFactory = new GisActivityFactory(); + activityFactory.setEdits(new EditsImpl()); + } + + @Test + public void testCreateActivity() { + GisActivity activity = activityFactory.createActivity(); + assertNotNull(activity); + assertNotSame(activity, activityFactory.createActivity()); + } + + @Test + public void testGetActivityURI() { + assertEquals(URI.create(GisActivity.ACTIVITY_TYPE), activityFactory.getActivityType()); + } + + @Test + public void testGetActivityConfigurationSchema() { + JsonNode configurationSchema = activityFactory.getActivityConfigurationSchema(); + assertNotNull(configurationSchema); + assertTrue(configurationSchema.has("properties")); + JsonNode propertiesNode = configurationSchema.get("properties"); + assertTrue(propertiesNode.has("exampleString")); + assertTrue(propertiesNode.has("exampleUri")); + } + + @Test + public void testGetInputPorts() { + Set<String> expectedInputs = new HashSet<String>(); + expectedInputs.add("firstInput"); + + Set<ActivityInputPort> inputPorts = activityFactory.getInputPorts(configuration); + assertEquals("Unexpected inputs", expectedInputs.size(), inputPorts.size()); + for (ActivityInputPort inputPort : inputPorts) { + assertTrue("Wrong input : " + inputPort.getName(), expectedInputs + .remove(inputPort.getName())); + } + + ObjectNode specialConfiguration = JsonNodeFactory.instance.objectNode(); + specialConfiguration.put("exampleString", "specialCase"); + specialConfiguration.put("exampleUri", "http://localhost:8080/myEndPoint"); + + assertEquals("Unexpected inputs", 2, activityFactory.getInputPorts(specialConfiguration).size()); + } + + @Test + public void testGetOutputPorts() { + Set<String> expectedOutputs = new HashSet<String>(); + expectedOutputs.add("simpleOutput"); + expectedOutputs.add("moreOutputs"); + + Set<ActivityOutputPort> outputPorts = activityFactory.getOutputPorts(configuration); + assertEquals("Unexpected outputs", expectedOutputs.size(), outputPorts.size()); + for (ActivityOutputPort outputPort : outputPorts) { + assertTrue("Wrong output : " + outputPort.getName(), + expectedOutputs.remove(outputPort.getName())); + } + + ObjectNode specialConfiguration = JsonNodeFactory.instance.objectNode(); + specialConfiguration.put("exampleString", "specialCase"); + specialConfiguration.put("exampleUri", "http://localhost:8080/myEndPoint"); + + assertEquals("Unexpected outputs", 3, activityFactory.getOutputPorts(specialConfiguration).size()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/06fe487d/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityTest.java ---------------------------------------------------------------------- diff --git a/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityTest.java b/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityTest.java new file mode 100644 index 0000000..6faea0d --- /dev/null +++ b/taverna-gis-activity/src/test/java/org/apache/taverna/gis/GisActivityTest.java @@ -0,0 +1,93 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.taverna.gis; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.net.URI; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import org.apache.taverna.activities.testutils.ActivityInvoker; +import org.apache.taverna.workflowmodel.processor.activity.ActivityConfigurationException; +import org.apache.taverna.workflowmodel.processor.activity.ActivityInputPort; +import org.apache.taverna.workflowmodel.processor.activity.ActivityOutputPort; + +import org.junit.Before; +import org.junit.Test; + +public class GisActivityTest { + + private ObjectNode configuration; + + private GisActivity activity = new GisActivity(); + + @Before + public void makeConfiguration() throws Exception { + configuration = JsonNodeFactory.instance.objectNode(); + configuration.put("exampleString", "something"); + configuration.put("exampleUri", "http://localhost:8080/myEndPoint"); + } + + @Test + public void configureActivity() throws Exception { + activity.configure(configuration); + assertTrue(configuration.equals(activity.getConfiguration())); + } + + @Test(expected = ActivityConfigurationException.class) + public void invalidConfiguration() throws ActivityConfigurationException { + ObjectNode invalidBean = JsonNodeFactory.instance.objectNode(); + invalidBean.put("exampleString", "invalidExample"); + // Should throw ActivityConfigurationException + activity.configure(invalidBean); + } + + @Test + public void executeAsynch() throws Exception { + activity.configure(configuration); + + Map<String, Object> inputs = new HashMap<String, Object>(); + inputs.put("firstInput", "hello"); + + Map<String, Class<?>> expectedOutputTypes = new HashMap<String, Class<?>>(); + expectedOutputTypes.put("simpleOutput", String.class); + expectedOutputTypes.put("moreOutputs", String.class); + + Map<String, Object> outputs = ActivityInvoker.invokeAsyncActivity( + activity, inputs, expectedOutputTypes); + + assertEquals("Unexpected outputs", 2, outputs.size()); + assertEquals("simple", outputs.get("simpleOutput")); + assertEquals(Arrays.asList("Value 1", "Value 2"), outputs + .get("moreOutputs")); + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-gis/blob/06fe487d/taverna-gis-plugin/pom.xml ---------------------------------------------------------------------- diff --git a/taverna-gis-plugin/pom.xml b/taverna-gis-plugin/pom.xml new file mode 100644 index 0000000..4a19ebb --- /dev/null +++ b/taverna-gis-plugin/pom.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<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.gis</groupId> + <artifactId>apache-taverna-plugin-gis</artifactId> + <version>0.0.1-incubating-SNAPSHOT</version> + </parent> + <artifactId>taverna-gis-plugin</artifactId> + <packaging>taverna-plugin</packaging> + <name>Apache Taverna GIS plugin</name> + <description>Activity and workbench integration for invoking GIS services</description> + <dependencies> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>taverna-gis-activity</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>taverna-gis-client</artifactId> + <version>${project.version}</version> + </dependency> + <!-- Enable for Workbench integration --> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>taverna-gis-activity-ui</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> +</project>
