Skip to content

Commit 3864445

Browse files
author
Mark Robinson
committed
Add retrieved information to RO bundle manifest
1 parent e850374 commit 3864445

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

pom.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
<id>jitpack.io</id>
3030
<url>https://jitpack.io</url>
3131
</repository>
32+
<repository>
33+
<id>apache.snapshots</id>
34+
<name>Apache Snapshot Repository</name>
35+
<url>http://repository.apache.org/snapshots</url>
36+
<releases>
37+
<enabled>false</enabled>
38+
</releases>
39+
</repository>
3240
</repositories>
3341

3442
<dependencies>
@@ -72,7 +80,7 @@
7280
<dependency>
7381
<groupId>org.apache.taverna.language</groupId>
7482
<artifactId>taverna-robundle</artifactId>
75-
<version>0.15.1-incubating</version>
83+
<version>0.16.0-incubating-SNAPSHOT</version>
7684
<exclusions>
7785
<exclusion>
7886
<groupId>org.slf4j</groupId>
@@ -90,6 +98,5 @@
9098
</plugin>
9199
</plugins>
92100
</build>
93-
94-
101+
95102
</project>

src/main/java/org/commonwl/viewer/domain/ROBundle.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@
1919

2020
package org.commonwl.viewer.domain;
2121

22+
import com.fasterxml.jackson.databind.JsonNode;
23+
import com.fasterxml.jackson.databind.ObjectMapper;
24+
import org.apache.commons.io.FilenameUtils;
2225
import org.apache.taverna.robundle.Bundle;
2326
import org.apache.taverna.robundle.Bundles;
2427
import org.apache.taverna.robundle.manifest.Agent;
2528
import org.apache.taverna.robundle.manifest.Manifest;
29+
import org.apache.taverna.robundle.manifest.PathMetadata;
2630
import org.commonwl.viewer.services.GitHubService;
2731
import org.eclipse.egit.github.core.RepositoryContents;
2832
import org.eclipse.egit.github.core.User;
2933
import org.slf4j.Logger;
3034
import org.slf4j.LoggerFactory;
35+
import org.yaml.snakeyaml.Yaml;
3136

3237
import java.io.IOException;
3338
import java.net.URI;
@@ -36,6 +41,8 @@
3641
import java.nio.file.Path;
3742
import java.util.ArrayList;
3843
import java.util.List;
44+
import java.util.regex.Matcher;
45+
import java.util.regex.Pattern;
3946

4047
/**
4148
* Represents a Workflow Research Object Bundle
@@ -69,6 +76,7 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo, String co
6976

7077
// Simplified attribution for RO bundle
7178
try {
79+
// Tool attribution in createdBy
7280
Agent cwlViewer = new Agent(appName);
7381
cwlViewer.setUri(new URI(appURL));
7482
manifest.setCreatedBy(cwlViewer);
@@ -92,8 +100,14 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo, String co
92100
authorList.add(author);
93101
manifest.setAuthoredBy(authorList);
94102

103+
// Retrieval Info
104+
manifest.setRetrievedBy(cwlViewer);
105+
manifest.setRetrievedOn(manifest.getCreatedOn());
106+
manifest.setRetrievedFrom(new URI("https://github.com/" + githubInfo.getOwner() + "/"
107+
+ githubInfo.getRepoName() + "/tree/" + commitSha + "/" + githubInfo.getPath()));
108+
95109
} catch (URISyntaxException ex) {
96-
logger.error(ex.getMessage());
110+
logger.error("Error creating URI for RO Bundle", ex);
97111
}
98112

99113
// Make a directory in the RO bundle to store the files
@@ -102,15 +116,16 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo, String co
102116

103117
// Add the files from the Github repo to this workflow
104118
List<RepositoryContents> repoContents = githubService.getContents(githubInfo);
105-
addFiles(repoContents, bundleFiles);
119+
addFiles(repoContents, bundleFiles, manifest);
106120
}
107121

108122
/**
109123
* Add files to this bundle from a list of Github repository contents
110124
* @param repoContents The contents of the Github repository
111125
* @param path The path in the Research Object to add the files
112126
*/
113-
private void addFiles(List<RepositoryContents> repoContents, Path path) throws IOException {
127+
private void addFiles(List<RepositoryContents> repoContents, Path path,
128+
Manifest manifest) throws IOException {
114129

115130
// Loop through repo contents and add them
116131
for (RepositoryContents repoContent : repoContents) {
@@ -128,7 +143,7 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
128143
Files.createDirectory(subdirPath);
129144

130145
// Add the files in the subdirectory to this new folder
131-
addFiles(subdirectory, subdirPath);
146+
addFiles(subdirectory, subdirPath, manifest);
132147

133148
// Otherwise this is a file so add to the bundle
134149
} else if (repoContent.getType().equals("file")) {
@@ -142,6 +157,23 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
142157
Path newFilePort = path.resolve(repoContent.getName());
143158
Bundles.setStringValue(newFilePort, fileContent);
144159

160+
// Manifest aggregation
161+
PathMetadata aggregation = manifest.getAggregation(newFilePort);
162+
163+
try {
164+
// Special handling for cwl files
165+
if (FilenameUtils.getExtension(repoContent.getName()).equals("cwl")) {
166+
// Correct mime type (no official standard for yaml)
167+
aggregation.setMediatype("text/x-yaml");
168+
}
169+
170+
// Set retrievedFrom information for this file in the manifest
171+
aggregation.setRetrievedFrom(new URI("https://github.com/" + githubFile.getOwner() + "/" +
172+
githubFile.getRepoName() + "/blob/" + commitSha + "/" + githubFile.getPath()));
173+
} catch (URISyntaxException ex) {
174+
logger.error("Error creating URI for RO Bundle", ex);
175+
}
176+
145177
}
146178
}
147179
}

0 commit comments

Comments
 (0)