Skip to content

Commit c90193b

Browse files
authored
Correct external referencing of resources to use URI format in RO (#79)
* Correct external referencing of resources to use uri format Changed from reference format if over singleFileSize which is not appropriate * Remove leftover testing code
1 parent d46ce36 commit c90193b

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.taverna.robundle.manifest.Agent;
2727
import org.apache.taverna.robundle.manifest.Manifest;
2828
import org.apache.taverna.robundle.manifest.PathMetadata;
29+
import org.apache.taverna.robundle.manifest.Proxy;
2930
import org.commonwl.viewer.services.GitHubService;
3031
import org.eclipse.egit.github.core.RepositoryContents;
3132
import org.slf4j.Logger;
@@ -49,7 +50,6 @@
4950
public class ROBundle {
5051

5152
private final Logger logger = LoggerFactory.getLogger(this.getClass());
52-
5353
private GitHubService githubService;
5454

5555
private Bundle bundle;
@@ -139,36 +139,44 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
139139
} else if (repoContent.getType().equals("file")) {
140140

141141
try {
142-
// Where to store the new file in bundle
143-
Path bundleFilePath = path.resolve(repoContent.getName());
144-
145142
// Raw URI of the bundle
146143
GithubDetails githubFile = new GithubDetails(githubInfo.getOwner(),
147144
githubInfo.getRepoName(), githubInfo.getBranch(), repoContent.getPath());
148145
URI rawURI = new URI("https://raw.githubusercontent.com/" + githubFile.getOwner() + "/" +
149146
githubFile.getRepoName() + "/" + commitSha + "/" + githubFile.getPath());
150147

151-
// Variable to store file contents
148+
// Variable to store file contents and aggregation
152149
String fileContent = null;
150+
PathMetadata aggregation;
153151

154152
// Download or externally link if oversized
155153
if (repoContent.getSize() <= singleFileSizeLimit) {
156154
// Get the content of this file from Github
157155
fileContent = githubService.downloadFile(githubFile, commitSha);
158156

159157
// Save file to research object bundle
158+
Path bundleFilePath = path.resolve(repoContent.getName());
160159
Bundles.setStringValue(bundleFilePath, fileContent);
160+
161+
// Set retrieved information for this file in the manifest
162+
aggregation = bundle.getManifest().getAggregation(bundleFilePath);
163+
aggregation.setRetrievedFrom(rawURI);
164+
aggregation.setRetrievedBy(thisApp);
165+
aggregation.setRetrievedOn(aggregation.getCreatedOn());
161166
} else {
162-
logger.info("File " + repoContent.getName() + " is too large to download -" +
167+
logger.info("File " + repoContent.getName() + " is too large to download - " +
163168
FileUtils.byteCountToDisplaySize(repoContent.getSize()) + "/" +
164169
FileUtils.byteCountToDisplaySize(singleFileSizeLimit) +
165-
" + linking externally to RO bundle");
166-
bundleFilePath = Bundles.setReference(bundleFilePath, rawURI);
170+
", linking externally to RO bundle");
171+
172+
// Set information for this file in the manifest
173+
aggregation = bundle.getManifest().getAggregation(rawURI);
174+
Proxy bundledAs = new Proxy();
175+
bundledAs.setURI();
176+
bundledAs.setFolder(path);
177+
aggregation.setBundledAs(bundledAs);
167178
}
168179

169-
// Manifest aggregation
170-
PathMetadata aggregation = bundle.getManifest().getAggregation(bundleFilePath);
171-
172180
// Special handling for cwl files
173181
if (FilenameUtils.getExtension(repoContent.getName()).equals("cwl")) {
174182
// Correct mime type (no official standard for yaml)
@@ -188,11 +196,6 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
188196
authors.addAll(fileAuthors);
189197
aggregation.setAuthoredBy(new ArrayList<Agent>(fileAuthors));
190198

191-
// Set retrieved information for this file in the manifest
192-
aggregation.setRetrievedFrom(rawURI);
193-
aggregation.setRetrievedBy(thisApp);
194-
aggregation.setRetrievedOn(aggregation.getCreatedOn());
195-
196199
} catch (URISyntaxException ex) {
197200
logger.error("Error creating URI for RO Bundle", ex);
198201
}

0 commit comments

Comments
 (0)