http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/io/github/taverna_extras/component/registry/standard/annotations/package-info.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/io/github/taverna_extras/component/registry/standard/annotations/package-info.java b/taverna-component-activity/src/main/java/io/github/taverna_extras/component/registry/standard/annotations/package-info.java new file mode 100644 index 0000000..6a89454 --- /dev/null +++ b/taverna-component-activity/src/main/java/io/github/taverna_extras/component/registry/standard/annotations/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +/** + * Miscellaneous annotations on other parts of the component engine. + * + * @author Donal Fellows + */ +package io.github.taverna_extras.component.registry.standard.annotations; \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/io/github/taverna_extras/component/registry/standard/package-info.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/io/github/taverna_extras/component/registry/standard/package-info.java b/taverna-component-activity/src/main/java/io/github/taverna_extras/component/registry/standard/package-info.java new file mode 100644 index 0000000..89df01a --- /dev/null +++ b/taverna-component-activity/src/main/java/io/github/taverna_extras/component/registry/standard/package-info.java @@ -0,0 +1,23 @@ +/* + * 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. + */ +/** + * This is the new interface to the myExperiment registry, a.k.a. μExperiment. + * @author Donal Fellows + */ +package io.github.taverna_extras.component.registry.standard; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/io/github/taverna_extras/component/utils/AnnotationUtils.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/io/github/taverna_extras/component/utils/AnnotationUtils.java b/taverna-component-activity/src/main/java/io/github/taverna_extras/component/utils/AnnotationUtils.java new file mode 100644 index 0000000..a3ac463 --- /dev/null +++ b/taverna-component-activity/src/main/java/io/github/taverna_extras/component/utils/AnnotationUtils.java @@ -0,0 +1,109 @@ +package io.github.taverna_extras.component.utils; +/* + * 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. + */ + +import java.io.IOException; +import java.io.StringReader; +import java.util.WeakHashMap; + +import org.apache.taverna.scufl2.api.annotation.Annotation; +import org.apache.taverna.scufl2.api.common.Child; +import org.apache.taverna.scufl2.api.common.Scufl2Tools; +import org.apache.taverna.scufl2.api.common.URITools; +import org.apache.taverna.scufl2.api.container.WorkflowBundle; +import org.apache.taverna.scufl2.ucfpackage.UCFPackage.ResourceEntry; + +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.rdf.model.Property; +import org.apache.jena.rdf.model.Statement; + +public class AnnotationUtils { + private static final String TITLE_ANNOTATION = "http://purl.org/dc/terms/title"; + private static final String DESCRIPTION_ANNOTATION = "http://purl.org/dc/terms/description"; + private Scufl2Tools tools = new Scufl2Tools(); + private URITools uris = new URITools(); + + public Model getAnnotationModel(Child<WorkflowBundle> subject) throws IOException { + return ModelFactory.createDefaultModel().add(getModel(subject)); + } + + private WeakHashMap<Child<?>, Model> cache = new WeakHashMap<>(); + + private static void readParse(Model model, WorkflowBundle bundle, String path) + throws IOException { + model.read( + new StringReader(bundle.getResources() + .getResourceAsString(path)), bundle.getGlobalBaseURI() + .resolve(path).toString(), "TTL"); + } + + public Model getModel(Child<WorkflowBundle> subject) throws IOException { + WorkflowBundle bundle = subject.getParent(); + Model m = cache.get(subject); + if (m == null) { + m = ModelFactory.createDefaultModel(); + long initialSize = m.size(); + for (Annotation a : tools.annotationsFor(subject, + subject.getParent())) + if (!a.getBody().isAbsolute()) + readParse(m, bundle, a.getBody().getPath()); + if (m.size() == initialSize) + for (ResourceEntry o : bundle.getResources() + .listResources("annotation").values()) + readParse(m, bundle, o.getPath()); + cache.put(subject, m); + } + return m; + } + + public Statement getAnnotation(Child<WorkflowBundle> subject, + String uriForAnnotation) throws IOException { + Model m = getModel(subject); + Property p = m.getProperty(uriForAnnotation); + return m.getResource(uris.uriForBean(subject).toString()).getProperty( + p); + } + + /** Get the title of the main workflow in a workflow bundle. */ + public String getTitle(WorkflowBundle bundle, String defaultTitle) { + try { + Statement s = getAnnotation(bundle.getMainWorkflow(), + TITLE_ANNOTATION); + if (s != null && s.getObject().isLiteral()) + return s.getObject().asLiteral().getString(); + } catch (IOException e) { + // TODO log this error? + } + return defaultTitle; + } + + /** Get the description of the main workflow in a workflow bundle. */ + public String getDescription(WorkflowBundle bundle, String defaultDescription) { + try { + Statement s = getAnnotation(bundle.getMainWorkflow(), + DESCRIPTION_ANNOTATION); + if (s != null && s.getObject().isLiteral()) + return s.getObject().asLiteral().getString(); + } catch (IOException e) { + // TODO log this error? + } + return defaultDescription; + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/io/github/taverna_extras/component/utils/SystemUtils.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/io/github/taverna_extras/component/utils/SystemUtils.java b/taverna-component-activity/src/main/java/io/github/taverna_extras/component/utils/SystemUtils.java new file mode 100644 index 0000000..9a57122 --- /dev/null +++ b/taverna-component-activity/src/main/java/io/github/taverna_extras/component/utils/SystemUtils.java @@ -0,0 +1,135 @@ +package io.github.taverna_extras.component.utils; +/* + * 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. + */ + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.JAXBElement; + +import io.github.taverna_extras.component.api.ComponentException; +import io.github.taverna_extras.component.registry.api.Description; +import org.apache.taverna.configuration.app.ApplicationConfiguration; +import org.apache.taverna.platform.execution.api.InvalidWorkflowException; +import org.apache.taverna.platform.execution.api.WorkflowCompiler; +import org.apache.taverna.scufl2.api.container.WorkflowBundle; +import org.apache.taverna.scufl2.api.io.WorkflowBundleIO; +import org.apache.taverna.workflowmodel.Dataflow; + +public class SystemUtils { + private static final String T2FLOW_TYPE = "application/vnd.taverna.t2flow+xml"; + private static final String SCUFL2_TYPE = "application/vnd.taverna.scufl2.workflow-bundle"; + private ApplicationConfiguration appConfig; + private WorkflowBundleIO workflowBundleIO; + private List<WorkflowCompiler> compilers; + + public byte[] serializeBundle(WorkflowBundle bundle) throws ComponentException { + try { + ByteArrayOutputStream dataflowStream = new ByteArrayOutputStream(); + workflowBundleIO.writeBundle(bundle, dataflowStream, SCUFL2_TYPE); + return dataflowStream.toByteArray(); + } catch (Exception e) { + throw new ComponentException( + "failed to serialize component implementation", e); + } + } + + private String determineMediaTypeForFilename(File file) { + String[] pieces = file.getName().split("\\."); + switch (pieces[pieces.length - 1]) { + case "t2flow": + return T2FLOW_TYPE; + default: + return SCUFL2_TYPE; + } + } + + public void saveBundle(WorkflowBundle bundle, File file) throws Exception { + workflowBundleIO.writeBundle(bundle, file, + determineMediaTypeForFilename(file)); + } + + public WorkflowBundle getBundleFromUri(String uri) throws Exception { + return workflowBundleIO.readBundle(new URL(uri), null); + } + + public WorkflowBundle getBundle(File file) throws Exception { + return workflowBundleIO.readBundle(file, null); + } + + public static JAXBElement<?> getElement(Description d, String name) + throws ComponentException { + for (Object o : d.getContent()) + if (o instanceof JAXBElement) { + JAXBElement<?> el = (JAXBElement<?>) o; + if (el.getName().getLocalPart().equals(name)) + return el; + } + throw new ComponentException("no " + name + " element"); + } + + public static String getElementString(Description d, String name) + throws ComponentException { + return getElement(d, name).getValue().toString().trim(); + } + + public static String getValue(Description d) { + StringBuilder sb = new StringBuilder(); + for (Object o : d.getContent()) + if (!(o instanceof JAXBElement)) + sb.append(o); + return sb.toString(); + } + + public File getApplicationHomeDir() { + return appConfig.getApplicationHomeDir().toFile(); + } + + public void setAppConfig(ApplicationConfiguration appConfig) { + this.appConfig = appConfig; + } + + public void setWorkflowBundler(WorkflowBundleIO workflowBundler) { + this.workflowBundleIO = workflowBundler; + } + + public void setCompilers(List<WorkflowCompiler> compilers) { + this.compilers = compilers; + } + + public Dataflow compile(WorkflowBundle implementation) + throws InvalidWorkflowException { + InvalidWorkflowException exn = null; + if (compilers != null) + for (WorkflowCompiler c : new ArrayList<>(compilers)) + try { + return c.getDataflow(implementation); + } catch (InvalidWorkflowException e) { + if (exn == null) + exn = e; + continue; + } + if (exn != null) + throw exn; + throw new InvalidWorkflowException("no compiler available"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivity.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivity.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivity.java deleted file mode 100644 index 9619297..0000000 --- a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivity.java +++ /dev/null @@ -1,167 +0,0 @@ -package io.github.taverna_extras.component.activity; -/* - * 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. - */ - -import static org.apache.log4j.Logger.getLogger; - -import java.net.MalformedURLException; -import java.util.Map; - -import org.apache.log4j.Logger; -import io.github.taverna_extras.component.api.ComponentException; -import io.github.taverna_extras.component.api.profile.ExceptionHandling; -import io.github.taverna_extras.component.registry.ComponentImplementationCache; -import io.github.taverna_extras.component.registry.ComponentUtil; -import io.github.taverna_extras.component.utils.AnnotationUtils; -import io.github.taverna_extras.component.utils.SystemUtils; - -import com.fasterxml.jackson.databind.JsonNode; -import org.apache.taverna.activities.dataflow.DataflowActivity; -import org.apache.taverna.annotation.annotationbeans.SemanticAnnotation; -import org.apache.taverna.invocation.InvocationContext; -import org.apache.taverna.invocation.impl.InvocationContextImpl; -import org.apache.taverna.platform.execution.api.InvalidWorkflowException; -import org.apache.taverna.reference.ReferenceService; -import org.apache.taverna.reference.T2Reference; -import org.apache.taverna.workflowmodel.Dataflow; -import org.apache.taverna.workflowmodel.EditException; -import org.apache.taverna.workflowmodel.Edits; -import org.apache.taverna.workflowmodel.processor.activity.AbstractAsynchronousActivity; -import org.apache.taverna.workflowmodel.processor.activity.ActivityConfigurationException; -import org.apache.taverna.workflowmodel.processor.activity.AsynchronousActivityCallback; -import org.apache.taverna.workflowmodel.utils.AnnotationTools; - -public class ComponentActivity extends - AbstractAsynchronousActivity<JsonNode> { - public static final String URI = "http://ns.taverna.org.uk/2010/activity/component"; - private Logger logger = getLogger(ComponentActivity.class); - - private ComponentUtil util; - private ComponentImplementationCache cache; - private volatile DataflowActivity componentRealization; - private JsonNode json; - private ComponentActivityConfigurationBean bean; - private SystemUtils system; - private AnnotationUtils annUtils; - private ComponentExceptionFactory cef; - - private Dataflow realizingDataflow = null; - - ComponentActivity(ComponentUtil util, ComponentImplementationCache cache, - Edits edits, SystemUtils system, AnnotationUtils annUtils, ComponentExceptionFactory exnFactory) { - this.util = util; - this.cache = cache; - this.system = system; - this.annUtils = annUtils; - setEdits(edits); - this.componentRealization = new DataflowActivity(); - this.cef = exnFactory; - } - - @Override - public void configure(JsonNode json) throws ActivityConfigurationException { - this.json = json; - try { - bean = new ComponentActivityConfigurationBean(json, util, cache); - } catch (MalformedURLException e) { - throw new ActivityConfigurationException( - "failed to understand configuration", e); - } - try { - configurePorts(bean.getPorts()); - } catch (ComponentException e) { - throw new ActivityConfigurationException( - "failed to get component realization", e); - } - } - - @Override - public void executeAsynch(Map<String, T2Reference> inputs, - AsynchronousActivityCallback callback) { - try { - ExceptionHandling exceptionHandling = bean.getExceptionHandling(); - // InvocationContextImpl newContext = copyInvocationContext(callback); - - getComponentRealization().executeAsynch(inputs, new ProxyCallback( - callback, callback.getContext(), exceptionHandling, cef)); - } catch (ActivityConfigurationException e) { - callback.fail("Unable to execute component", e); - } - } - - @SuppressWarnings("unused") - private InvocationContextImpl copyInvocationContext( - AsynchronousActivityCallback callback) { - InvocationContext originalContext = callback.getContext(); - ReferenceService rs = originalContext.getReferenceService(); - InvocationContextImpl newContext = new InvocationContextImpl(rs, null); - // for (Object o : originalContext.getEntities(Object.class)) { - // newContext.addEntity(o); - // } - return newContext; - } - - @Override - public JsonNode getConfiguration() { - return json; - } - - ComponentActivityConfigurationBean getConfigBean() { - return bean; - } - - private DataflowActivity getComponentRealization() - throws ActivityConfigurationException { - synchronized (componentRealization) { - try { - if (componentRealization.getNestedDataflow() == null) { - if (realizingDataflow == null) - realizingDataflow = system.compile(util - .getVersion(bean).getImplementation()); - componentRealization.setNestedDataflow(realizingDataflow); - copyAnnotations(); - } - } catch (ComponentException e) { - logger.error("unable to read workflow", e); - throw new ActivityConfigurationException( - "unable to read workflow", e); - } catch (InvalidWorkflowException e) { - logger.error("unable to compile workflow", e); - throw new ActivityConfigurationException( - "unable to compile workflow", e); - } - } - - return componentRealization; - } - - private void copyAnnotations() { - // FIXME Completely wrong way of doing this! - try { - //annUtils.getAnnotation(subject, uriForAnnotation) - String annotationValue = AnnotationTools.getAnnotationString(realizingDataflow, - SemanticAnnotation.class, null); - if (annotationValue != null) - AnnotationTools.setAnnotationString(this, SemanticAnnotation.class, - annotationValue, getEdits()).doEdit(); - } catch (EditException e) { - logger.error("failed to set annotation string", e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityConfigurationBean.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityConfigurationBean.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityConfigurationBean.java deleted file mode 100644 index 6819b3f..0000000 --- a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityConfigurationBean.java +++ /dev/null @@ -1,168 +0,0 @@ -package io.github.taverna_extras.component.activity; -/* - * 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. - */ - -import static org.apache.log4j.Logger.getLogger; -import static io.github.taverna_extras.component.api.config.ComponentPropertyNames.COMPONENT_NAME; -import static io.github.taverna_extras.component.api.config.ComponentPropertyNames.COMPONENT_VERSION; -import static io.github.taverna_extras.component.api.config.ComponentPropertyNames.FAMILY_NAME; -import static io.github.taverna_extras.component.api.config.ComponentPropertyNames.REGISTRY_BASE; - -import java.io.Serializable; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -//import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityInputPortDefinitionBean; -//import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityOutputPortDefinitionBean; -//import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityPortsDefinitionBean; - -import org.apache.log4j.Logger; -import io.github.taverna_extras.component.api.Version; -import io.github.taverna_extras.component.api.profile.ExceptionHandling; -import io.github.taverna_extras.component.registry.ComponentImplementationCache; -import io.github.taverna_extras.component.registry.ComponentUtil; -import io.github.taverna_extras.component.registry.ComponentVersionIdentification; - -import org.apache.taverna.scufl2.api.container.WorkflowBundle; -import org.apache.taverna.scufl2.api.port.InputWorkflowPort; -import org.apache.taverna.scufl2.api.port.OutputWorkflowPort; - -import com.fasterxml.jackson.databind.JsonNode; -import org.apache.taverna.workflowmodel.processor.activity.config.ActivityInputPortDefinitionBean; -import org.apache.taverna.workflowmodel.processor.activity.config.ActivityOutputPortDefinitionBean; -import org.apache.taverna.workflowmodel.processor.activity.config.ActivityPortsDefinitionBean; - -/** - * Component activity configuration bean. - */ -public class ComponentActivityConfigurationBean extends - ComponentVersionIdentification implements Serializable { - public static final String ERROR_CHANNEL = "error_channel"; - public static final List<String> ignorableNames = Arrays - .asList(ERROR_CHANNEL); - private static final long serialVersionUID = 5774901665863468058L; - private static final Logger logger = getLogger(ComponentActivity.class); - - private transient ActivityPortsDefinitionBean ports = null; - private transient ExceptionHandling eh; - private transient ComponentUtil util; - private transient ComponentImplementationCache cache; - - public ComponentActivityConfigurationBean(Version.ID toBeCopied, - ComponentUtil util, ComponentImplementationCache cache) { - super(toBeCopied); - this.util = util; - this.cache = cache; - try { - getPorts(); - } catch (io.github.taverna_extras.component.api.ComponentException e) { - logger.error("failed to get component realization", e); - } - } - - public ComponentActivityConfigurationBean(JsonNode json, - ComponentUtil util, ComponentImplementationCache cache) throws MalformedURLException { - super(getUrl(json), getFamily(json), getComponent(json), - getVersion(json)); - this.util = util; - this.cache = cache; - } - - private static URL getUrl(JsonNode json) throws MalformedURLException { - return new URL(json.get(REGISTRY_BASE).textValue()); - } - - private static String getFamily(JsonNode json) { - return json.get(FAMILY_NAME).textValue(); - } - - private static String getComponent(JsonNode json) { - return json.get(COMPONENT_NAME).textValue(); - } - - private static Integer getVersion(JsonNode json) { - JsonNode node = json.get(COMPONENT_VERSION); - if (node == null || !node.isInt()) - return null; - return node.intValue(); - } - - private ActivityPortsDefinitionBean getPortsDefinition(WorkflowBundle w) { - ActivityPortsDefinitionBean result = new ActivityPortsDefinitionBean(); - List<ActivityInputPortDefinitionBean> inputs = result - .getInputPortDefinitions(); - List<ActivityOutputPortDefinitionBean> outputs = result - .getOutputPortDefinitions(); - - for (InputWorkflowPort iwp : w.getMainWorkflow().getInputPorts()) - inputs.add(makeInputDefinition(iwp)); - // FIXME: Get the ValidatorState (so we can get getPortResolvedDepth() - ValidatorState vs = ... ; - for (OutputWorkflowPort owp : w.getMainWorkflow().getOutputPorts()) - outputs.add(makeOutputDefinition(vs.getPortResolvedDepth(owp), owp.getName())); - - try { - eh = util.getFamily(getRegistryBase(), getFamilyName()) - .getComponentProfile().getExceptionHandling(); - if (eh != null) - outputs.add(makeOutputDefinition(1, ERROR_CHANNEL)); - } catch (io.github.taverna_extras.component.api.ComponentException e) { - logger.error("failed to get exception handling for family", e); - } - return result; - } - - private ActivityInputPortDefinitionBean makeInputDefinition( - InputWorkflowPort dip) { - ActivityInputPortDefinitionBean activityInputPortDefinitionBean = new ActivityInputPortDefinitionBean(); - activityInputPortDefinitionBean.setHandledReferenceSchemes(null); - activityInputPortDefinitionBean.setMimeTypes((List<String>) null); - activityInputPortDefinitionBean.setTranslatedElementType(String.class); - activityInputPortDefinitionBean.setAllowsLiteralValues(true); - activityInputPortDefinitionBean.setDepth(dip.getDepth()); - activityInputPortDefinitionBean.setName(dip.getName()); - return activityInputPortDefinitionBean; - } - - private ActivityOutputPortDefinitionBean makeOutputDefinition(int depth, - String name) { - ActivityOutputPortDefinitionBean activityOutputPortDefinitionBean = new ActivityOutputPortDefinitionBean(); - activityOutputPortDefinitionBean.setMimeTypes(new ArrayList<String>()); - activityOutputPortDefinitionBean.setDepth(depth); - activityOutputPortDefinitionBean.setGranularDepth(depth); - activityOutputPortDefinitionBean.setName(name); - return activityOutputPortDefinitionBean; - } - - /** - * @return the ports - */ - public ActivityPortsDefinitionBean getPorts() throws io.github.taverna_extras.component.api.ComponentException{ - if (ports == null) - ports = getPortsDefinition(cache.getImplementation(this)); - return ports; - } - - public ExceptionHandling getExceptionHandling() { - return eh; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityFactory.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityFactory.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityFactory.java deleted file mode 100644 index c90ea1a..0000000 --- a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityFactory.java +++ /dev/null @@ -1,142 +0,0 @@ -package io.github.taverna_extras.component.activity; -/* - * 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. - */ - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URI; -import java.util.HashSet; -import java.util.Set; - -import io.github.taverna_extras.component.api.ComponentException; -import io.github.taverna_extras.component.api.Version.ID; -import io.github.taverna_extras.component.registry.ComponentImplementationCache; -import io.github.taverna_extras.component.registry.ComponentUtil; -import io.github.taverna_extras.component.utils.AnnotationUtils; -import io.github.taverna_extras.component.utils.SystemUtils; -import org.springframework.beans.factory.annotation.Required; - -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.ActivityConfigurationException; -import org.apache.taverna.workflowmodel.processor.activity.ActivityFactory; -import org.apache.taverna.workflowmodel.processor.activity.ActivityInputPort; -import org.apache.taverna.workflowmodel.processor.activity.ActivityOutputPort; -import org.apache.taverna.workflowmodel.processor.activity.config.ActivityInputPortDefinitionBean; -import org.apache.taverna.workflowmodel.processor.activity.config.ActivityOutputPortDefinitionBean; - -public class ComponentActivityFactory extends ComponentExceptionFactory - implements ActivityFactory { - private ComponentUtil util; - private ComponentImplementationCache cache; - private Edits edits; - private SystemUtils system; - private AnnotationUtils annUtils; - - @Override - public ComponentActivity createActivity() { - return new ComponentActivity(util, cache, edits, system, annUtils, this); - } - - @Override - public URI getActivityType() { - return URI.create(ComponentActivity.URI); - } - - @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) - throws ActivityConfigurationException { - try { - Set<ActivityInputPort> activityInputPorts = new HashSet<>(); - for (ActivityInputPortDefinitionBean ipd : createConfiguration( - configuration).getPorts().getInputPortDefinitions()) - activityInputPorts.add(edits.createActivityInputPort( - ipd.getName(), ipd.getDepth(), true, null, - ipd.getTranslatedElementType())); - return activityInputPorts; - } catch (MalformedURLException | ComponentException | RuntimeException e) { - throw new ActivityConfigurationException( - "failed to get implementation for configuration of inputs", - e); - } - } - - @Override - public Set<ActivityOutputPort> getOutputPorts(JsonNode configuration) - throws ActivityConfigurationException { - try { - Set<ActivityOutputPort> activityOutputPorts = new HashSet<>(); - for (ActivityOutputPortDefinitionBean opd : createConfiguration( - configuration).getPorts().getOutputPortDefinitions()) - activityOutputPorts.add(edits.createActivityOutputPort( - opd.getName(), opd.getDepth(), opd.getGranularDepth())); - return activityOutputPorts; - } catch (MalformedURLException | ComponentException | RuntimeException e) { - throw new ActivityConfigurationException( - "failed to get implementation for configuration of outputs", - e); - } - } - - public ComponentActivityConfigurationBean createConfiguration(ID id) { - return new ComponentActivityConfigurationBean(id, util, cache); - } - - public ComponentActivityConfigurationBean createConfiguration(JsonNode json) - throws MalformedURLException { - return new ComponentActivityConfigurationBean(json, util, cache); - } - - @Required - public void setComponentUtil(ComponentUtil util) { - this.util = util; - } - - @Required - public void setDataflowCache(ComponentImplementationCache cache) { - this.cache = cache; - } - - @Required - public void setEdits(Edits edits) { - this.edits = edits; - } - - @Required - public void setSystemUtil(SystemUtils system) { - this.system = system; - } - - @Required - public void setAnnotationUtils(AnnotationUtils annUtils) { - this.annUtils = annUtils; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityLocalChecker.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityLocalChecker.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityLocalChecker.java deleted file mode 100644 index d874241..0000000 --- a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityLocalChecker.java +++ /dev/null @@ -1,69 +0,0 @@ -package io.github.taverna_extras.component.activity; -/* - * 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. - */ - -import static io.github.taverna_extras.component.activity.ComponentHealthCheck.NON_SHAREABLE; - -import java.util.List; -import org.apache.taverna.visit.VisitKind; -import org.apache.taverna.visit.VisitReport; -import static org.apache.taverna.visit.VisitReport.Status.WARNING; -import org.apache.taverna.workflowmodel.health.HealthChecker; - -/** - * Component health checker - * - */ -public class ComponentActivityLocalChecker implements - HealthChecker<ComponentActivity> { - private static final VisitKind visitKind = ComponentHealthCheck - .getInstance(); - - @Override - 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 ComponentActivity where a certain configuration option is - * enabled. - */ - return o instanceof ComponentActivity; - } - - @Override - 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; - } - - @Override - public VisitReport visit(ComponentActivity activity, List<Object> ancestry) { - if (!activity.getConfigBean().getRegistryBase().getProtocol() - .startsWith("http")) - return new VisitReport(visitKind, activity, - "Local component makes workflow non-shareable", - NON_SHAREABLE, WARNING); - return null; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityUpgradeChecker.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityUpgradeChecker.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityUpgradeChecker.java deleted file mode 100644 index 4d45b60..0000000 --- a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentActivityUpgradeChecker.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.github.taverna_extras.component.activity; -/* - * 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. - */ - -import static org.apache.log4j.Logger.getLogger; -import static io.github.taverna_extras.component.activity.ComponentHealthCheck.OUT_OF_DATE; - -import java.util.List; - -import org.apache.log4j.Logger; -import io.github.taverna_extras.component.api.ComponentException; -import io.github.taverna_extras.component.registry.ComponentUtil; -import org.apache.taverna.visit.VisitKind; -import org.apache.taverna.visit.VisitReport; -import static org.apache.taverna.visit.VisitReport.Status.WARNING; -import org.apache.taverna.workflowmodel.health.HealthChecker; -import org.springframework.beans.factory.annotation.Required; - -/** - * @author alanrw - * - */ -public class ComponentActivityUpgradeChecker implements - HealthChecker<ComponentActivity> { - private static final String OUTDATED_MSG = "Component out of date"; - private static final VisitKind visitKind = ComponentHealthCheck - .getInstance(); - private static Logger logger = getLogger(ComponentActivityUpgradeChecker.class); - private ComponentUtil utils; - - @Required - public void setComponentUtil(ComponentUtil util) { - this.utils = util; - } - - @Override - public boolean canVisit(Object o) { - return o instanceof ComponentActivity; - } - - @Override - public boolean isTimeConsuming() { - return false; - } - - @Override - public VisitReport visit(ComponentActivity activity, List<Object> ancestry) { - ComponentActivityConfigurationBean config = activity.getConfigBean(); - int versionNumber = config.getComponentVersion(); - int latestVersion = 0; - - try { - latestVersion = utils - .getComponent(config.getRegistryBase(), - config.getFamilyName(), config.getComponentName()) - .getComponentVersionMap().lastKey(); - } catch (ComponentException e) { - logger.error("failed to get component description", e); - } - - if (latestVersion > versionNumber) - return new VisitReport(visitKind, activity, OUTDATED_MSG, - OUT_OF_DATE, WARNING); - return null; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentExceptionFactory.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentExceptionFactory.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentExceptionFactory.java deleted file mode 100644 index 243fe84..0000000 --- a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentExceptionFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.github.taverna_extras.component.activity; -/* - * 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. - */ - -class ComponentExceptionFactory { - private static final String UNEXPECTED_ID = "http://ns.taverna.org.uk/2012/component/unexpected"; - - ComponentExceptionFactory() { - } - - public ComponentImplementationException createComponentException( - String exceptionId, String message) { - ComponentImplementationException result = new ComponentImplementationException(message); - result.setExceptionId(exceptionId); - return result; - } - - public ComponentImplementationException createUnexpectedComponentException( - String message) { - return createComponentException(UNEXPECTED_ID, message); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentHealthCheck.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentHealthCheck.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentHealthCheck.java deleted file mode 100644 index 0381de1..0000000 --- a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentHealthCheck.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.taverna_extras.component.activity; -/* - * 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. - */ - -import org.apache.taverna.visit.VisitKind; -import org.apache.taverna.visit.Visitor; - -public class ComponentHealthCheck extends VisitKind { - public static final int NO_PROBLEM = 0; - public static final int OUT_OF_DATE = 10; - public static final int NON_SHAREABLE = 20; - public static final int FAILS_PROFILE = 30; - - @Override - public Class<? extends Visitor<?>> getVisitorClass() { - return ComponentActivityUpgradeChecker.class; - } - - private static class Singleton { - private static ComponentHealthCheck instance = new ComponentHealthCheck(); - } - - public static ComponentHealthCheck getInstance() { - return Singleton.instance; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentImplementationException.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentImplementationException.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentImplementationException.java deleted file mode 100644 index 7ef77f7..0000000 --- a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ComponentImplementationException.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.taverna_extras.component.activity; -/* - * 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. - */ - -public class ComponentImplementationException extends Exception { - public ComponentImplementationException(String string) { - super(string); - this.setStackTrace(new StackTraceElement[] {}); - } - - private static final long serialVersionUID = -3844030382222698090L; - private String exceptionId; - - public void setExceptionId(String exceptionId) { - this.exceptionId = exceptionId; - } - - public String getExceptionId() { - return exceptionId; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ProxyCallback.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ProxyCallback.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ProxyCallback.java deleted file mode 100644 index 3a04af3..0000000 --- a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/ProxyCallback.java +++ /dev/null @@ -1,264 +0,0 @@ -package io.github.taverna_extras.component.activity; -/* - * 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. - */ - -import static org.apache.log4j.Logger.getLogger; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.xml.ws.Holder; - -import org.apache.log4j.Logger; -import io.github.taverna_extras.component.api.profile.ExceptionHandling; -import io.github.taverna_extras.component.api.profile.ExceptionReplacement; -import io.github.taverna_extras.component.api.profile.HandleException; -import org.apache.taverna.invocation.InvocationContext; -import org.apache.taverna.reference.ErrorDocument; -import org.apache.taverna.reference.ErrorDocumentService; -import org.apache.taverna.reference.IdentifiedList; -import org.apache.taverna.reference.ListService; -import org.apache.taverna.reference.ReferenceService; -import org.apache.taverna.reference.T2Reference; -import static org.apache.taverna.reference.T2ReferenceType.ErrorDocument; -import static org.apache.taverna.reference.T2ReferenceType.IdentifiedList; -import static org.apache.taverna.reference.T2ReferenceType.ReferenceSet; -import org.apache.taverna.workflowmodel.processor.activity.AsynchronousActivityCallback; -import org.apache.taverna.workflowmodel.processor.dispatch.events.DispatchErrorType; - -/** - * @author alanrw - * - */ -public class ProxyCallback implements AsynchronousActivityCallback { - private static final Logger logger = getLogger(ProxyCallback.class); - - private final ComponentExceptionFactory cef; - private final AsynchronousActivityCallback proxiedCallback; - private final ReferenceService references; - private final InvocationContext context; - private final ExceptionHandling exceptionHandling; - private final ListService lists; - private final ErrorDocumentService errors; - - /** - * @param proxiedCallback - * @param invocationContext - * @param exceptionHandling - * @param exnFactory - */ - ProxyCallback(AsynchronousActivityCallback proxiedCallback, - InvocationContext invocationContext, - ExceptionHandling exceptionHandling, - ComponentExceptionFactory exnFactory) { - this.proxiedCallback = proxiedCallback; - this.exceptionHandling = exceptionHandling; - context = invocationContext; - references = context.getReferenceService(); - lists = references.getListService(); - errors = references.getErrorDocumentService(); - cef = exnFactory; - } - - @Override - public InvocationContext getContext() { - return context; - } - - @Override - public void requestRun(Runnable runMe) { - proxiedCallback.requestRun(runMe); - } - - @Override - public void receiveResult(Map<String, T2Reference> data, int[] index) { - if (exceptionHandling == null) { - proxiedCallback.receiveResult(data, index); - return; - } - - List<T2Reference> exceptions = new ArrayList<>(); - Map<String, T2Reference> replacement = new HashMap<>(); - for (Entry<String, T2Reference> entry : data.entrySet()) - replacement.put(entry.getKey(), - considerReference(entry.getValue(), exceptions)); - replacement.put("error_channel", - references.register(exceptions, 1, true, context)); - proxiedCallback.receiveResult(replacement, index); - } - - private T2Reference considerReference(T2Reference value, - List<T2Reference> exceptions) { - if (!value.containsErrors()) - return value; - else if (!value.getReferenceType().equals(IdentifiedList)) - return replaceErrors(value, value.getDepth(), exceptions); - else if (exceptionHandling.failLists()) - return replaceErrors(findFirstFailure(value), value.getDepth(), - exceptions); - - List<T2Reference> replacementList = new ArrayList<>(); - for (T2Reference subValue : lists.getList(value)) - replacementList.add(considerReference(subValue, exceptions)); - return references.register(replacementList, value.getDepth(), true, - context); - } - - private T2Reference findFirstFailure(T2Reference value) { - IdentifiedList<T2Reference> originalList = lists.getList(value); - for (T2Reference subValue : originalList) { - if (subValue.getReferenceType().equals(ErrorDocument)) - return subValue; - if (subValue.getReferenceType().equals(IdentifiedList)) - if (subValue.containsErrors()) - return findFirstFailure(subValue); - // No need to consider value - } - return null; - } - - private T2Reference replaceErrors(T2Reference value, int depth, - List<T2Reference> exceptions) { - ErrorDocument doc = errors.getError(value); - - Holder<HandleException> handleException = new Holder<>(); - Set<ErrorDocument> toConsider = new HashSet<>(); - Set<ErrorDocument> considered = new HashSet<>(); - toConsider.add(doc); - - while (!toConsider.isEmpty()) - try { - ErrorDocument nudoc = remapException(toConsider, considered, - handleException); - if (nudoc != null) { - doc = nudoc; - break; - } - } catch (Exception e) { - logger.error("failed to locate exception mapping", e); - } - - String exceptionMessage = doc.getExceptionMessage(); - // An exception that is not mentioned - if (handleException.value == null) { - ComponentImplementationException newException = cef - .createUnexpectedComponentException(exceptionMessage); - T2Reference replacement = errors.registerError(exceptionMessage, - newException, depth, context).getId(); - exceptions.add(errors.registerError(exceptionMessage, newException, - 0, context).getId()); - return replacement; - } - - if (handleException.value.pruneStack()) - doc.getStackTraceStrings().clear(); - - ExceptionReplacement exnReplacement = handleException.value - .getReplacement(); - if (exnReplacement == null) { - T2Reference replacement = references.register(doc, depth, true, - context); - exceptions.add(references.register(doc, 0, true, context)); - return replacement; - } - - ComponentImplementationException newException = cef - .createComponentException(exnReplacement.getReplacementId(), - exnReplacement.getReplacementMessage()); - T2Reference replacement = errors.registerError( - exnReplacement.getReplacementMessage(), newException, depth, - context).getId(); - exceptions.add(errors.registerError( - exnReplacement.getReplacementMessage(), newException, 0, - context).getId()); - return replacement; - } - - private ErrorDocument remapException(Set<ErrorDocument> toConsider, - Set<ErrorDocument> considered, - Holder<HandleException> handleException) { - ErrorDocument found = null; - ErrorDocument errorDoc = toConsider.iterator().next(); - - considered.add(errorDoc); - toConsider.remove(errorDoc); - String exceptionMessage = errorDoc.getExceptionMessage(); - for (HandleException he : exceptionHandling.getHandleExceptions()) { - if (!he.matches(exceptionMessage)) - continue; - handleException.value = he; - found = errorDoc; - } - if (!errorDoc.getErrorReferences().isEmpty()) - for (T2Reference subRef : errorDoc.getErrorReferences()) - for (T2Reference newErrorRef : getErrors(subRef)) { - ErrorDocument subDoc = errors.getError(newErrorRef); - if (subDoc == null) - logger.error("Error document contains references to non-existent sub-errors"); - else if (!considered.contains(subDoc)) - toConsider.add(subDoc); - } - return found; - } - - private Set<T2Reference> getErrors(T2Reference ref) { - Set<T2Reference> result = new HashSet<>(); - if (ref.getReferenceType().equals(ReferenceSet)) { - // nothing - } else if (ref.getReferenceType().equals(IdentifiedList)) { - IdentifiedList<T2Reference> originalList = lists.getList(ref); - for (T2Reference subValue : originalList) - if (subValue.containsErrors()) - result.addAll(getErrors(subValue)); - } else - result.add(ref); - return result; - } - - @Override - public void receiveCompletion(int[] completionIndex) { - proxiedCallback.receiveCompletion(completionIndex); - } - - @Override - public void fail(String message, Throwable t, DispatchErrorType errorType) { - proxiedCallback.fail(message, t, errorType); - } - - @Override - public void fail(String message, Throwable t) { - proxiedCallback.fail(message, t); - } - - @Override - public void fail(String message) { - proxiedCallback.fail(message); - } - - @Override - public String getParentProcessIdentifier() { - // return ""; - return proxiedCallback.getParentProcessIdentifier(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/package-info.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/package-info.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/package-info.java deleted file mode 100644 index 086a49b..0000000 --- a/taverna-component-activity/src/main/java/org/apache/taverna/component/activity/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 io.github.taverna_extras.component.activity; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/org/apache/taverna/component/profile/ActivityProfileImpl.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/profile/ActivityProfileImpl.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/profile/ActivityProfileImpl.java deleted file mode 100644 index a948cd4..0000000 --- a/taverna-component-activity/src/main/java/org/apache/taverna/component/profile/ActivityProfileImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.github.taverna_extras.component.profile; -/* - * 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. - */ - -import java.util.ArrayList; -import java.util.List; - -import io.github.taverna_extras.component.api.profile.ActivityProfile; -import io.github.taverna_extras.component.api.profile.SemanticAnnotationProfile; - -import io.github.taverna_extras.component.api.profile.doc.Activity; -import io.github.taverna_extras.component.api.profile.doc.SemanticAnnotation; - -/** - * Specifies the semantic annotations that an activity must have. - * - * @author David Withers - */ -public class ActivityProfileImpl implements ActivityProfile { - private final ComponentProfileImpl componentProfile; - private final Activity activity; - - public ActivityProfileImpl(ComponentProfileImpl componentProfile, - Activity activity) { - this.componentProfile = componentProfile; - this.activity = activity; - } - - @Override - public List<SemanticAnnotationProfile> getSemanticAnnotations() { - List<SemanticAnnotationProfile> saProfiles = new ArrayList<>(); - for (SemanticAnnotation annotation : activity.getSemanticAnnotation()) - saProfiles.add(new SemanticAnnotationProfileImpl(componentProfile, - annotation)); - return saProfiles; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/b7b61e71/taverna-component-activity/src/main/java/org/apache/taverna/component/profile/BaseProfileLocator.java ---------------------------------------------------------------------- diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/profile/BaseProfileLocator.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/profile/BaseProfileLocator.java deleted file mode 100644 index 989f411..0000000 --- a/taverna-component-activity/src/main/java/org/apache/taverna/component/profile/BaseProfileLocator.java +++ /dev/null @@ -1,154 +0,0 @@ -package io.github.taverna_extras.component.profile; -/* - * 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. - */ - -import static java.util.Locale.UK; -import static org.apache.commons.httpclient.HttpStatus.SC_OK; -import static org.apache.commons.io.FileUtils.writeStringToFile; -import static org.apache.log4j.Logger.getLogger; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.text.ParseException; -import java.text.SimpleDateFormat; - -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.params.HttpClientParams; -import org.apache.log4j.Logger; -import io.github.taverna_extras.component.api.ComponentException; -import org.apache.taverna.configuration.app.ApplicationConfiguration; - -public class BaseProfileLocator { - private static final String BASE_PROFILE_PATH = "BaseProfile.xml"; - private static final String BASE_PROFILE_URI = "http://build.mygrid.org.uk/taverna/BaseProfile.xml"; - private static final int TIMEOUT = 5000; - private static final String pattern = "EEE, dd MMM yyyy HH:mm:ss z"; - private static final SimpleDateFormat format = new SimpleDateFormat( - pattern, UK); - - private Logger logger = getLogger(BaseProfileLocator.class); - private ApplicationConfiguration appConfig; - private ComponentProfileImpl profile; - - private void locateBaseProfile() { - File baseProfileFile = getBaseProfileFile(); - @SuppressWarnings("unused") - boolean load = false; - Long remoteBaseProfileTime = null; - long localBaseProfileTime = -1; - - HttpClientParams params = new HttpClientParams(); - params.setConnectionManagerTimeout(TIMEOUT); - params.setSoTimeout(TIMEOUT); - HttpClient client = new HttpClient(params); - - try { - remoteBaseProfileTime = getRemoteBaseProfileTimestamp(client); - logger.info("NoticeTime is " + remoteBaseProfileTime); - } catch (URISyntaxException e) { - logger.error("URI problem", e); - } catch (IOException e) { - logger.info("Could not read base profile", e); - } catch (ParseException e) { - logger.error("Could not parse last-modified time", e); - } - if (baseProfileFile.exists()) - localBaseProfileTime = baseProfileFile.lastModified(); - - try { - if ((remoteBaseProfileTime != null) - && (remoteBaseProfileTime > localBaseProfileTime)) { - profile = new ComponentProfileImpl(null, new URL(BASE_PROFILE_URI), - null); - writeStringToFile(baseProfileFile, profile.getXML()); - } - } catch (MalformedURLException e) { - logger.error("URI problem", e); - profile = null; - } catch (ComponentException e) { - logger.error("Component Registry problem", e); - profile = null; - } catch (IOException e) { - logger.error("Unable to write profile", e); - profile = null; - } - - try { - if ((profile == null) && baseProfileFile.exists()) - profile = new ComponentProfileImpl(null, baseProfileFile.toURI() - .toURL(), null); - } catch (Exception e) { - logger.error("URI problem", e); - profile = null; - } - } - - private long parseTime(String timestamp) throws ParseException { - timestamp = timestamp.trim(); - if (timestamp.endsWith(" GMT")) - timestamp = timestamp.substring(0, timestamp.length() - 3) - + " +0000"; - else if (timestamp.endsWith(" BST")) - timestamp = timestamp.substring(0, timestamp.length() - 3) - + " +0100"; - return format.parse(timestamp).getTime(); - } - - private long getRemoteBaseProfileTimestamp(HttpClient client) - throws URISyntaxException, IOException, HttpException, - ParseException { - URI baseProfileURI = new URI(BASE_PROFILE_URI); - HttpMethod method = new GetMethod(baseProfileURI.toString()); - int statusCode = client.executeMethod(method); - if (statusCode != SC_OK) { - logger.warn("HTTP status " + statusCode + " while getting " - + baseProfileURI); - return -1; - } - Header h = method.getResponseHeader("Last-Modified"); - if (h == null) - return -1; - return parseTime(h.getValue()); - } - - private File getBaseProfileFile() { - File config = new File(appConfig.getApplicationHomeDir().toFile(), "conf"); - if (!config.exists()) - config.mkdir(); - return new File(config, BASE_PROFILE_PATH); - } - - public synchronized ComponentProfileImpl getProfile() { - if (profile == null) - locateBaseProfile(); - return profile; - } - - public void setAppConfig(ApplicationConfiguration appConfig) { - this.appConfig = appConfig; - } -}
