You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2015/02/17 12:29:06 UTC
[02/50] [abbrv] incubator-taverna-server git commit: Expose delimiter
control through the REST interface.
Expose delimiter control through the REST interface.
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/commit/ef9a2890
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/tree/ef9a2890
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/diff/ef9a2890
Branch: refs/heads/master
Commit: ef9a2890047643699cdb1301f67a1d91fcf7b2db
Parents: 974751b
Author: Donal Fellows <do...@manchester.ac.uk>
Authored: Wed Mar 26 15:28:02 2014 +0000
Committer: Donal Fellows <do...@manchester.ac.uk>
Committed: Wed Mar 26 15:28:02 2014 +0000
----------------------------------------------------------------------
.../org/taverna/server/master/InputREST.java | 21 +++++++-----
.../taverna/server/master/interfaces/Input.java | 27 +++++++++++++++
.../master/rest/TavernaServerInputREST.java | 35 +++++++++++++++-----
.../server/master/worker/RemoteRunDelegate.java | 20 +++++++++++
.../taverna/server/master/mocks/ExampleRun.java | 17 ++++++++++
5 files changed, 102 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/ef9a2890/server-webapp/src/main/java/org/taverna/server/master/InputREST.java
----------------------------------------------------------------------
diff --git a/server-webapp/src/main/java/org/taverna/server/master/InputREST.java b/server-webapp/src/main/java/org/taverna/server/master/InputREST.java
index e6659ed..a1a7387 100644
--- a/server-webapp/src/main/java/org/taverna/server/master/InputREST.java
+++ b/server-webapp/src/main/java/org/taverna/server/master/InputREST.java
@@ -100,11 +100,11 @@ class InputREST implements TavernaServerInputREST, InputBean {
@Override
@CallCounted
@PerfLogged
- public InDesc getInput(String name) throws BadInputPortNameException {
+ public InDesc getInput(String name, UriInfo ui) throws BadInputPortNameException {
Input i = support.getInput(run, name);
if (i == null)
throw new BadInputPortNameException("unknown input port name");
- return new InDesc(i);
+ return new InDesc(i, ui);
}
@Override
@@ -121,17 +121,18 @@ class InputREST implements TavernaServerInputREST, InputBean {
@Override
@CallCounted
@PerfLogged
- public InDesc setInput(String name, InDesc inputDescriptor)
+ public InDesc setInput(String name, InDesc inputDescriptor, UriInfo ui)
throws NoUpdateException, BadStateChangeException,
FilesystemAccessException, BadInputPortNameException,
BadPropertyValueException {
+ inputDescriptor.descriptorRef = null;
AbstractContents ac = inputDescriptor.assignment;
if (name == null || name.isEmpty())
throw new BadInputPortNameException("bad input name");
if (ac == null)
throw new BadPropertyValueException("no content!");
if (ac instanceof InDesc.Reference)
- return setRemoteInput(name, (InDesc.Reference) ac);
+ return setRemoteInput(name, (InDesc.Reference) ac, inputDescriptor.delimiter, ui);
if (!(ac instanceof InDesc.File || ac instanceof InDesc.Value))
throw new BadPropertyValueException("unknown content type");
support.permitUpdate(run);
@@ -142,12 +143,13 @@ class InputREST implements TavernaServerInputREST, InputBean {
i.setFile(ac.contents);
else
i.setValue(ac.contents);
- return new InDesc(i);
+ i.setDelimiter(inputDescriptor.delimiter);
+ return new InDesc(i, ui);
}
- private InDesc setRemoteInput(String name, Reference ref)
- throws BadStateChangeException, BadPropertyValueException,
- FilesystemAccessException {
+ private InDesc setRemoteInput(String name, Reference ref, String delimiter,
+ UriInfo ui) throws BadStateChangeException,
+ BadPropertyValueException, FilesystemAccessException {
URITemplate tmpl = new URITemplate(ui.getBaseUri()
+ "/runs/{runName}/wd/{path:.+}");
MultivaluedMap<String, String> mvm = new MetadataMap<String, String>();
@@ -168,7 +170,8 @@ class InputREST implements TavernaServerInputREST, InputBean {
if (i == null)
i = run.makeInput(name);
i.setFile(to.getFullName());
- return new InDesc(i);
+ i.setDelimiter(delimiter);
+ return new InDesc(i, ui);
} catch (UnknownRunException e) {
throw new BadStateChangeException("may not copy from that run", e);
} catch (NoDirectoryEntryException e) {
http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/ef9a2890/server-webapp/src/main/java/org/taverna/server/master/interfaces/Input.java
----------------------------------------------------------------------
diff --git a/server-webapp/src/main/java/org/taverna/server/master/interfaces/Input.java b/server-webapp/src/main/java/org/taverna/server/master/interfaces/Input.java
index 71d9c8d..b6ce3e5 100644
--- a/server-webapp/src/main/java/org/taverna/server/master/interfaces/Input.java
+++ b/server-webapp/src/main/java/org/taverna/server/master/interfaces/Input.java
@@ -9,6 +9,9 @@ import org.taverna.server.master.common.Status;
import org.taverna.server.master.exceptions.BadStateChangeException;
import org.taverna.server.master.exceptions.FilesystemAccessException;
+import edu.umd.cs.findbugs.annotations.NonNull;
+import edu.umd.cs.findbugs.annotations.Nullable;
+
/**
* This represents the assignment of inputs to input ports of the workflow. Note
* that the <tt>file</tt> and <tt>value</tt> properties are never set at the
@@ -21,20 +24,30 @@ public interface Input {
* @return The file currently assigned to this input port, or <tt>null</tt>
* if no file is assigned.
*/
+ @Nullable
public String getFile();
/**
* @return The name of this input port. This may not be changed.
*/
+ @NonNull
public String getName();
/**
* @return The value currently assigned to this input port, or <tt>null</tt>
* if no value is assigned.
*/
+ @Nullable
public String getValue();
/**
+ * @return The delimiter for the input port, or <tt>null</tt> if the value
+ * is not to be split.
+ */
+ @Nullable
+ public String getDelimiter();
+
+ /**
* Sets the file to use for this input. This overrides the use of the
* previous file and any set value.
*
@@ -62,4 +75,18 @@ public interface Input {
* Initialized} state.
*/
public void setValue(String value) throws BadStateChangeException;
+
+ /**
+ * Sets (or clears) the delimiter for the input port.
+ *
+ * @param delimiter
+ * The delimiter character, or <tt>null</tt> if the value is not
+ * to be split.
+ * @throws BadStateChangeException
+ * If the run isn't in the {@link Status#Initialized
+ * Initialized} state.
+ */
+ @Nullable
+ public void setDelimiter(String delimiter) throws BadStateChangeException;
+
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/ef9a2890/server-webapp/src/main/java/org/taverna/server/master/rest/TavernaServerInputREST.java
----------------------------------------------------------------------
diff --git a/server-webapp/src/main/java/org/taverna/server/master/rest/TavernaServerInputREST.java b/server-webapp/src/main/java/org/taverna/server/master/rest/TavernaServerInputREST.java
index 0ac0f01..14aad3f 100644
--- a/server-webapp/src/main/java/org/taverna/server/master/rest/TavernaServerInputREST.java
+++ b/server-webapp/src/main/java/org/taverna/server/master/rest/TavernaServerInputREST.java
@@ -24,7 +24,10 @@ import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
@@ -34,7 +37,6 @@ import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
import org.apache.cxf.jaxrs.model.wadl.Description;
-import org.taverna.server.port_description.InputDescription;
import org.taverna.server.master.common.Uri;
import org.taverna.server.master.common.VersionedElement;
import org.taverna.server.master.exceptions.BadInputPortNameException;
@@ -44,6 +46,7 @@ import org.taverna.server.master.exceptions.FilesystemAccessException;
import org.taverna.server.master.exceptions.NoUpdateException;
import org.taverna.server.master.interfaces.Input;
import org.taverna.server.master.interfaces.TavernaRun;
+import org.taverna.server.port_description.InputDescription;
import edu.umd.cs.findbugs.annotations.NonNull;
@@ -137,6 +140,8 @@ public interface TavernaServerInputREST {
*
* @param name
* The input to set.
+ * @param uriInfo
+ * About the URI used to access this resource.
* @return A description of the input.
* @throws BadInputPortNameException
* If no input with that name exists.
@@ -147,8 +152,8 @@ public interface TavernaServerInputREST {
@Description("Gives a description of what is used to supply a particular "
+ "input.")
@NonNull
- InDesc getInput(@NonNull @PathParam("name") String name)
- throws BadInputPortNameException;
+ InDesc getInput(@NonNull @PathParam("name") String name,
+ @Context UriInfo uriInfo) throws BadInputPortNameException;
/**
* Set what an input uses to provide data into the workflow run.
@@ -157,6 +162,8 @@ public interface TavernaServerInputREST {
* The name of the input.
* @param inputDescriptor
* A description of the input
+ * @param uriInfo
+ * About the URI used to access this resource.
* @return A description of the input.
* @throws NoUpdateException
* If the user can't update the run.
@@ -177,7 +184,7 @@ public interface TavernaServerInputREST {
@Description("Sets the source for a particular input port.")
@NonNull
InDesc setInput(@NonNull @PathParam("name") String name,
- @NonNull InDesc inputDescriptor) throws NoUpdateException,
+ @NonNull InDesc inputDescriptor, @Context UriInfo uriInfo) throws NoUpdateException,
BadStateChangeException, FilesystemAccessException,
BadPropertyValueException, BadInputPortNameException;
@@ -258,7 +265,7 @@ public interface TavernaServerInputREST {
*
* @param inputPort
*/
- public InDesc(Input inputPort) {
+ public InDesc(Input inputPort, UriInfo ui) {
super(true);
name = inputPort.getName();
if (inputPort.getFile() != null) {
@@ -268,11 +275,25 @@ public interface TavernaServerInputREST {
assignment = new InDesc.Value();
assignment.contents = inputPort.getValue();
}
+ // .../runs/{id}/input/input/{name} ->
+ // .../runs/{id}/input/expected#{name}
+ UriBuilder ub = ui.getBaseUriBuilder();
+ List<PathSegment> segments = ui.getPathSegments();
+ for (PathSegment s : segments.subList(0, segments.size() - 2))
+ ub.segment(s.getPath());
+ ub.fragment(name);
+ descriptorRef = new Uri(ub);
}
/** The name of the port. */
@XmlAttribute(required = false)
public String name;
+ /** Where the port is described. Ignored in user input. */
+ @XmlAttribute(required = false)
+ public Uri descriptorRef;
+ /** The character to use to split the input into a list. */
+ @XmlAttribute(required = false)
+ public String delimiter;
/**
* Either a filename or a literal string, used to provide input to a
@@ -282,10 +303,6 @@ public interface TavernaServerInputREST {
*/
@XmlType(name = "InputContents")
public static abstract class AbstractContents {
- @XmlAttribute
- public Uri descriptorRef;
- @XmlAttribute
- public String delimiter;
/**
* The contents of the description of the input port. Meaning not
* defined.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/ef9a2890/server-webapp/src/main/java/org/taverna/server/master/worker/RemoteRunDelegate.java
----------------------------------------------------------------------
diff --git a/server-webapp/src/main/java/org/taverna/server/master/worker/RemoteRunDelegate.java b/server-webapp/src/main/java/org/taverna/server/master/worker/RemoteRunDelegate.java
index 0c4bffa..44a2b3a 100644
--- a/server-webapp/src/main/java/org/taverna/server/master/worker/RemoteRunDelegate.java
+++ b/server-webapp/src/main/java/org/taverna/server/master/worker/RemoteRunDelegate.java
@@ -945,6 +945,26 @@ class RunInput implements Input {
throw new BadStateChangeException(e);
}
}
+
+ @Override
+ public String getDelimiter() {
+ try {
+ return i.getDelimiter();
+ } catch (RemoteException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public void setDelimiter(String delimiter) throws BadStateChangeException {
+ try {
+ if (delimiter != null)
+ delimiter = delimiter.substring(0, 1);
+ i.setDelimiter(delimiter);
+ } catch (RemoteException e) {
+ throw new BadStateChangeException(e);
+ }
+ }
}
@SuppressWarnings("serial")
http://git-wip-us.apache.org/repos/asf/incubator-taverna-server/blob/ef9a2890/server-webapp/src/test/java/org/taverna/server/master/mocks/ExampleRun.java
----------------------------------------------------------------------
diff --git a/server-webapp/src/test/java/org/taverna/server/master/mocks/ExampleRun.java b/server-webapp/src/test/java/org/taverna/server/master/mocks/ExampleRun.java
index 9616c2e..2796c7b 100644
--- a/server-webapp/src/test/java/org/taverna/server/master/mocks/ExampleRun.java
+++ b/server-webapp/src/test/java/org/taverna/server/master/mocks/ExampleRun.java
@@ -203,6 +203,7 @@ public class ExampleRun implements TavernaRun, TavernaSecurityContext {
public String name;
public String file;
public String value;
+ public String delim;
public ExampleInput(String name) {
this.name = name;
@@ -247,6 +248,22 @@ public class ExampleRun implements TavernaRun, TavernaSecurityContext {
this.file = null;
this.value = null;
}
+
+ @Override
+ public String getDelimiter() {
+ return delim;
+ }
+
+ @Override
+ public void setDelimiter(String delimiter)
+ throws BadStateChangeException {
+ if (status != Status.Initialized)
+ throw new BadStateChangeException();
+ if (delimiter == null)
+ delim = null;
+ else
+ delim = delimiter.substring(0, 1);
+ }
}
@Override