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
22
import org .apache .commons .io .FilenameUtils ;
25
23
import org .apache .taverna .robundle .Bundle ;
26
24
import org .apache .taverna .robundle .Bundles ;
29
27
import org .apache .taverna .robundle .manifest .PathMetadata ;
30
28
import org .commonwl .viewer .services .GitHubService ;
31
29
import org .eclipse .egit .github .core .RepositoryContents ;
32
- import org .eclipse .egit .github .core .User ;
33
30
import org .slf4j .Logger ;
34
31
import org .slf4j .LoggerFactory ;
35
- import org .yaml .snakeyaml .Yaml ;
36
32
37
33
import java .io .IOException ;
38
34
import java .net .URI ;
39
35
import java .net .URISyntaxException ;
40
36
import java .nio .file .Files ;
41
37
import java .nio .file .Path ;
42
38
import java .util .ArrayList ;
39
+ import java .util .HashSet ;
43
40
import java .util .List ;
41
+ import java .util .Set ;
44
42
import java .util .regex .Matcher ;
45
43
import java .util .regex .Pattern ;
46
44
@@ -56,6 +54,7 @@ public class ROBundle {
56
54
private Bundle bundle ;
57
55
private GithubDetails githubInfo ;
58
56
private String commitSha ;
57
+ private Set <HashableAgent > authors = new HashSet <HashableAgent >();
59
58
60
59
// Pattern for extracting version from a cwl file
61
60
private final String CWL_VERSION_REGEX = "cwlVersion:\\ s*\" ?(?:cwl:)?([^\\ s\" ]+)\" ?" ;
@@ -85,25 +84,6 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo, String co
85
84
cwlViewer .setUri (new URI (appURL ));
86
85
manifest .setCreatedBy (cwlViewer );
87
86
88
- // Github author attribution
89
- // TODO: way to add all the contributors somehow
90
- // TODO: set the aggregates details according to the github information
91
- User authorDetails = githubService .getUser (githubInfo .getOwner ());
92
-
93
- List <Agent > authorList = new ArrayList <>(1 );
94
- Agent author = new Agent (authorDetails .getName ());
95
- author .setUri (new URI (authorDetails .getHtmlUrl ()));
96
-
97
- // This tool supports putting your ORCID in the blog field of github as a URL
98
- // eg http://orcid.org/0000-0000-0000-0000
99
- String authorBlog = authorDetails .getBlog ();
100
- if (authorBlog != null && authorBlog .startsWith ("http://orcid.org/" )) {
101
- author .setOrcid (new URI (authorBlog ));
102
- }
103
-
104
- authorList .add (author );
105
- manifest .setAuthoredBy (authorList );
106
-
107
87
// Retrieval Info
108
88
manifest .setRetrievedBy (cwlViewer );
109
89
manifest .setRetrievedOn (manifest .getCreatedOn ());
@@ -120,16 +100,18 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo, String co
120
100
121
101
// Add the files from the Github repo to this workflow
122
102
List <RepositoryContents > repoContents = githubService .getContents (githubInfo );
123
- addFiles (repoContents , bundleFiles , manifest );
103
+ addFiles (repoContents , bundleFiles );
104
+
105
+ // Add combined authors
106
+ manifest .setAuthoredBy (new ArrayList <Agent >(authors ));
124
107
}
125
108
126
109
/**
127
110
* Add files to this bundle from a list of Github repository contents
128
111
* @param repoContents The contents of the Github repository
129
112
* @param path The path in the Research Object to add the files
130
113
*/
131
- private void addFiles (List <RepositoryContents > repoContents , Path path ,
132
- Manifest manifest ) throws IOException {
114
+ private void addFiles (List <RepositoryContents > repoContents , Path path ) throws IOException {
133
115
134
116
// Loop through repo contents and add them
135
117
for (RepositoryContents repoContent : repoContents ) {
@@ -147,7 +129,7 @@ private void addFiles(List<RepositoryContents> repoContents, Path path,
147
129
Files .createDirectory (subdirPath );
148
130
149
131
// Add the files in the subdirectory to this new folder
150
- addFiles (subdirectory , subdirPath , manifest );
132
+ addFiles (subdirectory , subdirPath );
151
133
152
134
// Otherwise this is a file so add to the bundle
153
135
} else if (repoContent .getType ().equals ("file" )) {
@@ -162,7 +144,7 @@ private void addFiles(List<RepositoryContents> repoContents, Path path,
162
144
Bundles .setStringValue (newFilePort , fileContent );
163
145
164
146
// Manifest aggregation
165
- PathMetadata aggregation = manifest .getAggregation (newFilePort );
147
+ PathMetadata aggregation = bundle . getManifest () .getAggregation (newFilePort );
166
148
167
149
try {
168
150
// Special handling for cwl files
@@ -178,6 +160,11 @@ private void addFiles(List<RepositoryContents> repoContents, Path path,
178
160
}
179
161
}
180
162
163
+ // Add authors from github commits to the file
164
+ Set <HashableAgent > fileAuthors = githubService .getContributors (githubFile , commitSha );
165
+ authors .addAll (fileAuthors );
166
+ aggregation .setAuthoredBy (new ArrayList <Agent >(fileAuthors ));
167
+
181
168
// Set retrievedFrom information for this file in the manifest
182
169
aggregation .setRetrievedFrom (new URI ("https://github.com/" + githubFile .getOwner () + "/" +
183
170
githubFile .getRepoName () + "/blob/" + commitSha + "/" + githubFile .getPath ()));
0 commit comments