Skip to content

Commit 6c56c57

Browse files
committed
Refactoring and RO bundle info from Git log
1 parent efae9f8 commit 6c56c57

13 files changed

+78
-59
lines changed

src/main/java/org/commonwl/view/cwl/CWLService.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
import org.apache.jena.rdf.model.StmtIterator;
3636
import org.apache.jena.riot.RiotException;
3737
import org.commonwl.view.docker.DockerService;
38-
import org.commonwl.view.github.GitDetails;
39-
import org.commonwl.view.github.GitService;
38+
import org.commonwl.view.git.GitDetails;
39+
import org.commonwl.view.git.GitService;
4040
import org.commonwl.view.graphviz.ModelDotWriter;
4141
import org.commonwl.view.graphviz.RDFDotWriter;
4242
import org.commonwl.view.workflow.Workflow;
@@ -67,7 +67,7 @@ public class CWLService {
6767
private final Logger logger = LoggerFactory.getLogger(this.getClass());
6868

6969
// Autowired properties/services
70-
private final GitService githubService;
70+
private final GitService gitService;
7171
private final RDFService rdfService;
7272
private final CWLTool cwlTool;
7373
private final int singleFileSizeLimit;
@@ -98,16 +98,16 @@ public class CWLService {
9898

9999
/**
100100
* Constructor for the Common Workflow Language service
101-
* @param githubService A service for accessing Github functionality
101+
* @param gitService A service for accessing Github functionality
102102
* @param cwlTool Handles cwltool integration
103103
* @param singleFileSizeLimit The file size limit for single files
104104
*/
105105
@Autowired
106-
public CWLService(GitService githubService,
106+
public CWLService(GitService gitService,
107107
RDFService rdfService,
108108
CWLTool cwlTool,
109109
@Value("${singleFileSizeLimit}") int singleFileSizeLimit) {
110-
this.githubService = githubService;
110+
this.gitService = gitService;
111111
this.rdfService = rdfService;
112112
this.cwlTool = cwlTool;
113113
this.singleFileSizeLimit = singleFileSizeLimit;
@@ -421,6 +421,7 @@ public Workflow parseWorkflowWithCwltool(GitDetails gitDetails,
421421
logger.error("Failed to create DOT graph for workflow: " + ex.getMessage());
422422
}
423423

424+
424425
return workflowModel;
425426

426427
}

src/main/java/org/commonwl/view/github/GitDetails.java renamed to src/main/java/org/commonwl/view/git/GitDetails.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.commonwl.view.github;
20+
package org.commonwl.view.git;
2121

2222
import java.io.Serializable;
2323

@@ -96,7 +96,7 @@ public String getUrl(String branchOverride) {
9696
return repoUrl;
9797
case GITHUB:
9898
case GITLAB:
99-
return "https://" + normaliseURL(repoUrl).replace(".git", "") + "/blob/" + branchOverride + "/" + path;
99+
return "https://" + normaliseUrl(repoUrl).replace(".git", "") + "/blob/" + branchOverride + "/" + path;
100100
default:
101101
return null;
102102
}
@@ -117,10 +117,29 @@ public String getUrl() {
117117
public String getInternalUrl() {
118118
switch (this.type) {
119119
case GENERIC:
120-
return "/workflows/" + normaliseURL(repoUrl) + "/" + branch + "/" + path;
120+
return "/workflows/" + normaliseUrl(repoUrl) + "/" + branch + "/" + path;
121121
case GITHUB:
122122
case GITLAB:
123-
return "/workflows/" + normaliseURL(repoUrl).replace(".git", "") + "/blob/" + branch + "/" + path;
123+
return "/workflows/" + normaliseUrl(repoUrl).replace(".git", "") + "/blob/" + branch + "/" + path;
124+
default:
125+
return null;
126+
}
127+
}
128+
129+
/**
130+
* Get the URL directly to the resource
131+
* @return The URL
132+
*/
133+
public String getRawUrl() {
134+
switch (this.type) {
135+
case GENERIC:
136+
return repoUrl;
137+
case GITHUB:
138+
return "https://raw.githubusercontent.com/" +
139+
normaliseUrl(repoUrl).replace("github.com/", "").replace(".git", "") +
140+
"/" + branch + "/" + path;
141+
case GITLAB:
142+
return "https://whatever/gitlab/uses";
124143
default:
125144
return null;
126145
}
@@ -131,7 +150,7 @@ public String getInternalUrl() {
131150
* @param url The URL to be normalised
132151
* @return The normalised URL
133152
*/
134-
private String normaliseURL(String url) {
153+
private String normaliseUrl(String url) {
135154
return url.replace("http://", "")
136155
.replace("https://", "")
137156
.replace("ssh://", "")

src/main/java/org/commonwl/view/github/GitService.java renamed to src/main/java/org/commonwl/view/git/GitService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.commonwl.view.github;
20+
package org.commonwl.view.git;
2121

2222
import org.eclipse.jgit.api.Git;
2323
import org.eclipse.jgit.api.errors.GitAPIException;

src/main/java/org/commonwl/view/github/GitType.java renamed to src/main/java/org/commonwl/view/git/GitType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.commonwl.view.github;
20+
package org.commonwl.view.git;
2121

2222
/**
2323
* Differentiates supported sites for the

src/main/java/org/commonwl/view/researchobject/ROBundleFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import org.apache.commons.io.FilenameUtils;
2323
import org.apache.taverna.robundle.Bundle;
24-
import org.commonwl.view.github.GitDetails;
24+
import org.commonwl.view.git.GitDetails;
2525
import org.commonwl.view.workflow.Workflow;
2626
import org.commonwl.view.workflow.WorkflowRepository;
2727
import org.slf4j.Logger;

src/main/java/org/commonwl/view/researchobject/ROBundleService.java

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import org.apache.taverna.robundle.Bundles;
2626
import org.apache.taverna.robundle.manifest.*;
2727
import org.commonwl.view.cwl.CWLTool;
28-
import org.commonwl.view.github.GitDetails;
29-
import org.commonwl.view.github.GitService;
28+
import org.commonwl.view.git.GitDetails;
3029
import org.commonwl.view.graphviz.GraphVizService;
3130
import org.commonwl.view.workflow.Workflow;
3231
import org.eclipse.jgit.api.Git;
32+
import org.eclipse.jgit.api.errors.GitAPIException;
3333
import org.eclipse.jgit.lib.PersonIdent;
3434
import org.eclipse.jgit.revwalk.RevCommit;
3535
import org.slf4j.Logger;
@@ -63,7 +63,6 @@ public class ROBundleService {
6363
private final Logger logger = LoggerFactory.getLogger(this.getClass());
6464

6565
// Services
66-
private GitService githubService;
6766
private GraphVizService graphVizService;
6867
private CWLTool cwlTool;
6968

@@ -82,22 +81,19 @@ public class ROBundleService {
8281
* @param appName The name of the application from properties, for attribution
8382
* @param appURL The URL of the application from properties, for attribution
8483
* @param singleFileSizeLimit The file size limit for each file in the RO bundle
85-
* @param githubService The service for handling Github functionality
8684
* @throws URISyntaxException Error in creating URI for appURL
8785
*/
8886
@Autowired
8987
public ROBundleService(@Value("${bundleStorage}") Path bundleStorage,
9088
@Value("${applicationName}") String appName,
9189
@Value("${applicationURL}") String appURL,
9290
@Value("${singleFileSizeLimit}") int singleFileSizeLimit,
93-
GitService githubService,
9491
GraphVizService graphVizService,
9592
CWLTool cwlTool) throws URISyntaxException {
9693
this.bundleStorage = bundleStorage;
9794
this.appAgent = new Agent(appName);
9895
appAgent.setUri(new URI(appURL));
9996
this.singleFileSizeLimit = singleFileSizeLimit;
100-
this.githubService = githubService;
10197
this.graphVizService = graphVizService;
10298
this.cwlTool = cwlTool;
10399
}
@@ -153,16 +149,13 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
153149
GitDetails wfDetails = workflow.getRetrievedFrom();
154150

155151
// Run cwltool
156-
/*
157-
String url = "https://raw.githubusercontent.com/" + wfDetails.getOwner() + "/" +
158-
wfDetails.getRepoName() + "/" + wfDetails.getBranch() + "/" + wfDetails.getPath();
152+
String rawUrl = wfDetails.getRawUrl();
159153
List<PathAnnotation> manifestAnnotations = new ArrayList<>();
160154
addAggregation(bundle, manifestAnnotations,
161-
"merged.cwl", cwlTool.getPackedVersion(url));
155+
"merged.cwl", cwlTool.getPackedVersion(rawUrl));
162156
addAggregation(bundle, manifestAnnotations,
163-
"workflow.ttl", cwlTool.getRDF(url));
157+
"workflow.ttl", cwlTool.getRDF(rawUrl));
164158
bundle.getManifest().setAnnotations(manifestAnnotations);
165-
*/
166159

167160
// Git2prov history
168161
List<Path> history = new ArrayList<>();
@@ -208,8 +201,7 @@ private void addFilesToBundle(Bundle bundle, Path bundlePath,
208201
Path bundleFilePath = bundlePath.resolve(file.getName());
209202

210203
// Get direct URL
211-
URI rawURI = new URI("https://raw.githubusercontent.com/" + githubFile.getOwner() + "/" +
212-
githubFile.getRepoName() + "/" + commitSha + "/" + githubFile.getPath());
204+
URI rawURI = new URI("http://example.com");
213205

214206
// Variable to store file contents and aggregation
215207
String fileContent = null;
@@ -254,31 +246,38 @@ private void addFilesToBundle(Bundle bundle, Path bundlePath,
254246
}
255247
}
256248

257-
// Add authors from github commits to the file
258-
Set<HashableAgent> fileAuthors = new HashSet<>();
259-
Iterable<RevCommit> logs = gitRepo.log()
260-
.addPath(bundlePath.toString())
261-
.call();
262-
for (RevCommit rev : logs) {
263-
PersonIdent author = rev.getAuthorIdent();
264-
PersonIdent committer = rev.getCommitterIdent();
265-
if (author != null || committer != null) {
249+
// Add authors from git commits to the file
250+
try {
251+
Set<HashableAgent> fileAuthors = new HashSet<>();
252+
Iterable<RevCommit> logs = gitRepo.log()
253+
.addPath(bundlePath.toString())
254+
.call();
255+
for (RevCommit rev : logs) {
256+
// Use author first with backup of committer
257+
PersonIdent author = rev.getAuthorIdent();
258+
if (author == null) {
259+
author = rev.getCommitterIdent();
260+
}
266261
// Create a new agent and add as much detail as possible
267-
HashableAgent newAgent = new HashableAgent();
268262
if (author != null) {
269-
newAgent.setName(author.getName());
270-
newAgent.setUri(new URI("mailto:" + author.getEmailAddress()));
271-
} else {
272-
newAgent.setName(committer.getName());
273-
newAgent.setUri(new URI("mailto:" + committer.getEmailAddress()));
263+
HashableAgent newAgent = new HashableAgent();
264+
String name = author.getName();
265+
if (name != null && name.length() > 0) {
266+
newAgent.setName(author.getName());
267+
}
268+
String email = author.getEmailAddress();
269+
if (email != null && email.length() > 0) {
270+
newAgent.setUri(new URI("mailto:" + author.getEmailAddress()));
271+
}
272+
fileAuthors.add(newAgent);
274273
}
275-
fileAuthors.add(newAgent);
276274
}
275+
authors.addAll(fileAuthors);
276+
aggregation.setAuthoredBy(new ArrayList<>(fileAuthors));
277+
} catch (GitAPIException ex) {
278+
logger.error("Could not get commits for file " + repoPath, ex);
277279
}
278280

279-
authors.addAll(fileAuthors);
280-
aggregation.setAuthoredBy(new ArrayList<>(fileAuthors));
281-
282281
// Set retrieved information for this file in the manifest
283282
aggregation.setRetrievedFrom(rawURI);
284283
aggregation.setRetrievedBy(appAgent);

src/main/java/org/commonwl/view/workflow/QueuedWorkflowRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.commonwl.view.workflow;
22

3-
import org.commonwl.view.github.GitDetails;
3+
import org.commonwl.view.git.GitDetails;
44
import org.springframework.data.mongodb.repository.Query;
55
import org.springframework.data.repository.PagingAndSortingRepository;
66

src/main/java/org/commonwl/view/workflow/Workflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.fasterxml.jackson.annotation.JsonInclude;
2424
import org.commonwl.view.cwl.CWLElement;
2525
import org.commonwl.view.cwl.CWLStep;
26-
import org.commonwl.view.github.GitDetails;
26+
import org.commonwl.view.git.GitDetails;
2727
import org.springframework.data.annotation.Id;
2828
import org.springframework.data.mongodb.core.index.Indexed;
2929
import org.springframework.data.mongodb.core.mapping.Document;

src/main/java/org/commonwl/view/workflow/WorkflowController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import org.apache.commons.lang.StringUtils;
2323
import org.commonwl.view.cwl.CWLToolStatus;
2424
import org.commonwl.view.cwl.CWLValidationException;
25-
import org.commonwl.view.github.GitDetails;
26-
import org.commonwl.view.github.GitType;
25+
import org.commonwl.view.git.GitDetails;
26+
import org.commonwl.view.git.GitType;
2727
import org.commonwl.view.graphviz.GraphVizService;
2828
import org.eclipse.jgit.api.errors.GitAPIException;
2929
import org.slf4j.Logger;

src/main/java/org/commonwl/view/workflow/WorkflowFormValidator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
package org.commonwl.view.workflow;
2121

22-
import org.commonwl.view.github.GitDetails;
23-
import org.commonwl.view.github.GitService;
24-
import org.commonwl.view.github.GitType;
22+
import org.commonwl.view.git.GitDetails;
23+
import org.commonwl.view.git.GitService;
24+
import org.commonwl.view.git.GitType;
2525
import org.slf4j.Logger;
2626
import org.slf4j.LoggerFactory;
2727
import org.springframework.beans.factory.annotation.Autowired;

0 commit comments

Comments
 (0)