TAVERNA-1047: Ensure annotations have /.ro/ relative URIs
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/commit/3336e75e Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/tree/3336e75e Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/diff/3336e75e Branch: refs/heads/master Commit: 3336e75e396fad0594db3b761aea8d10a95d3a92 Parents: 71708bc Author: Stian Soiland-Reyes <[email protected]> Authored: Fri May 11 09:42:56 2018 +0100 Committer: Stian Soiland-Reyes <[email protected]> Committed: Fri May 11 09:42:56 2018 +0100 ---------------------------------------------------------------------- .../robundle/manifest/PathAnnotation.java | 29 ++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/3336e75e/taverna-robundle/src/main/java/org/apache/taverna/robundle/manifest/PathAnnotation.java ---------------------------------------------------------------------- diff --git a/taverna-robundle/src/main/java/org/apache/taverna/robundle/manifest/PathAnnotation.java b/taverna-robundle/src/main/java/org/apache/taverna/robundle/manifest/PathAnnotation.java index 17783f7..451be52 100644 --- a/taverna-robundle/src/main/java/org/apache/taverna/robundle/manifest/PathAnnotation.java +++ b/taverna-robundle/src/main/java/org/apache/taverna/robundle/manifest/PathAnnotation.java @@ -8,9 +8,9 @@ package org.apache.taverna.robundle.manifest; * 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 @@ -25,6 +25,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; @@ -87,15 +88,26 @@ public class PathAnnotation { } private URI relativizePath(Path path) { - return URI.create("/.ro/").relativize( + return relativizeUri( URI.create(path.toUri().getRawPath())); } + private URI relativizeUri(URI relativeOrAbsolute) { + // NOTE: We can't fix absolute URIs within the RO bundle here, as + // we don't know the root. We can however get rid of "/.ro/" + // if it is present. + return URI.create("/.ro/").relativize(relativeOrAbsolute); + } + public void setAbout(List<URI> about) { if (about == null) { throw new NullPointerException("about list can't be null"); } - this.about = about; + // Relativize if needed. + // Note: This will also ensure we make a copy of the list. + this.about = about.stream() + .map(this::relativizeUri) + .collect(Collectors.toList()); } public void setAbout(Path path) { @@ -105,7 +117,7 @@ public class PathAnnotation { public void setAbout(URI about) { this.about.clear(); if (about != null) { - this.about.add(about); + this.about.add(relativizeUri(about)); } } @@ -119,15 +131,16 @@ public class PathAnnotation { } public void setContent(URI content) { - this.content = content; + this.content = relativizeUri(content); } public void setUri(URI uri) { - this.uri = uri; + // Normally absolute urn:uuid: URIs, but just in case.. + this.uri = relativizeUri(uri); } @Override public String toString() { - return "Annotation: " + getContent() + " about " + getAbout(); + return "Annotation: " + getContent() + " about " + getAboutList(); } }
