19
19
20
20
package org .commonwl .viewer .domain ;
21
21
22
+ import com .fasterxml .jackson .databind .JsonNode ;
23
+ import com .fasterxml .jackson .databind .ObjectMapper ;
24
+ import org .apache .commons .io .FilenameUtils ;
22
25
import org .apache .taverna .robundle .Bundle ;
23
26
import org .apache .taverna .robundle .Bundles ;
24
27
import org .apache .taverna .robundle .manifest .Agent ;
25
28
import org .apache .taverna .robundle .manifest .Manifest ;
29
+ import org .apache .taverna .robundle .manifest .PathMetadata ;
26
30
import org .commonwl .viewer .services .GitHubService ;
27
31
import org .eclipse .egit .github .core .RepositoryContents ;
28
32
import org .eclipse .egit .github .core .User ;
29
33
import org .slf4j .Logger ;
30
34
import org .slf4j .LoggerFactory ;
35
+ import org .yaml .snakeyaml .Yaml ;
31
36
32
37
import java .io .IOException ;
33
38
import java .net .URI ;
36
41
import java .nio .file .Path ;
37
42
import java .util .ArrayList ;
38
43
import java .util .List ;
44
+ import java .util .regex .Matcher ;
45
+ import java .util .regex .Pattern ;
39
46
40
47
/**
41
48
* Represents a Workflow Research Object Bundle
@@ -69,6 +76,7 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo, String co
69
76
70
77
// Simplified attribution for RO bundle
71
78
try {
79
+ // Tool attribution in createdBy
72
80
Agent cwlViewer = new Agent (appName );
73
81
cwlViewer .setUri (new URI (appURL ));
74
82
manifest .setCreatedBy (cwlViewer );
@@ -92,8 +100,14 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo, String co
92
100
authorList .add (author );
93
101
manifest .setAuthoredBy (authorList );
94
102
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
+
95
109
} catch (URISyntaxException ex ) {
96
- logger .error (ex . getMessage () );
110
+ logger .error ("Error creating URI for RO Bundle" , ex );
97
111
}
98
112
99
113
// Make a directory in the RO bundle to store the files
@@ -102,15 +116,16 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo, String co
102
116
103
117
// Add the files from the Github repo to this workflow
104
118
List <RepositoryContents > repoContents = githubService .getContents (githubInfo );
105
- addFiles (repoContents , bundleFiles );
119
+ addFiles (repoContents , bundleFiles , manifest );
106
120
}
107
121
108
122
/**
109
123
* Add files to this bundle from a list of Github repository contents
110
124
* @param repoContents The contents of the Github repository
111
125
* @param path The path in the Research Object to add the files
112
126
*/
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 {
114
129
115
130
// Loop through repo contents and add them
116
131
for (RepositoryContents repoContent : repoContents ) {
@@ -128,7 +143,7 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
128
143
Files .createDirectory (subdirPath );
129
144
130
145
// Add the files in the subdirectory to this new folder
131
- addFiles (subdirectory , subdirPath );
146
+ addFiles (subdirectory , subdirPath , manifest );
132
147
133
148
// Otherwise this is a file so add to the bundle
134
149
} else if (repoContent .getType ().equals ("file" )) {
@@ -142,6 +157,23 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
142
157
Path newFilePort = path .resolve (repoContent .getName ());
143
158
Bundles .setStringValue (newFilePort , fileContent );
144
159
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
+
145
177
}
146
178
}
147
179
}
0 commit comments