Skip to content

Commit 14c927a

Browse files
committed
Bug fixes involving templates and URLs
1 parent eeea757 commit 14c927a

File tree

8 files changed

+47
-22
lines changed

8 files changed

+47
-22
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
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;
3839
import org.commonwl.view.github.GitService;
3940
import org.commonwl.view.graphviz.ModelDotWriter;
4041
import org.commonwl.view.graphviz.RDFDotWriter;
@@ -180,20 +181,24 @@ public Workflow parseWorkflowNative(File workflowFile) throws IOException {
180181
* @param packedWorkflowID The workflow ID if the file has multiple objects
181182
* @return The constructed workflow object
182183
*/
183-
public Workflow parseWorkflowWithCwltool(File workflowFile,
184+
public Workflow parseWorkflowWithCwltool(GitDetails gitDetails,
185+
File workflowFile,
184186
String packedWorkflowID) throws CWLValidationException {
185187

186188
// Get RDF representation from cwltool
187-
String url = workflowFile.toPath().toAbsolutePath().toString();
189+
String path = workflowFile.toPath().toAbsolutePath().toString();
190+
String url = gitDetails.getUrl().replace("https://", "");
188191
if (packedWorkflowID != null) {
189192
if (packedWorkflowID.charAt(0) != '#') {
193+
path += "#";
190194
url += "#";
191195
}
196+
path += packedWorkflowID;
192197
url += packedWorkflowID;
193198
}
194199

195200
if (!rdfService.graphExists(url)) {
196-
String rdf = cwlTool.getRDF(url);
201+
String rdf = cwlTool.getRDF(path);
197202

198203
// Create a workflow model from RDF representation
199204
Model model = ModelFactory.createDefaultModel();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public void createWorkflowFromQueued(QueuedWorkflow queuedWorkflow, File workflo
7676
// Parse using cwltool and replace in database
7777
try {
7878
Workflow newWorkflow = cwlService.parseWorkflowWithCwltool(
79+
tempWorkflow.getRetrievedFrom(),
7980
workflowFile,
8081
tempWorkflow.getPackedWorkflowID());
8182

src/main/java/org/commonwl/view/github/GitDetails.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,29 @@ public void setType(GitType type) {
8787

8888
/**
8989
* Get the URL to the external resource representing this workflow
90+
* @param branchOverride The branch to use instead of the one in this instance
9091
* @return The URL
9192
*/
92-
public String getUrl() {
93+
public String getUrl(String branchOverride) {
9394
switch (this.type) {
9495
case GENERIC:
9596
return repoUrl;
9697
case GITHUB:
9798
case GITLAB:
98-
return "https://" + normaliseURL(repoUrl).replace(".git", "") + "/" + branch + "/" + path;
99+
return "https://" + normaliseURL(repoUrl).replace(".git", "") + "/blob/" + branchOverride + "/" + path;
99100
default:
100101
return null;
101102
}
102103
}
103104

105+
/**
106+
* Get the URL to the external resource representing this workflow
107+
* @return The URL
108+
*/
109+
public String getUrl() {
110+
return getUrl(branch);
111+
}
112+
104113
/**
105114
* Get the URL to the page containing this workflow
106115
* @return The URL
@@ -111,7 +120,7 @@ public String getInternalUrl() {
111120
return "/workflows/" + normaliseURL(repoUrl) + "/" + branch + "/" + path;
112121
case GITHUB:
113122
case GITLAB:
114-
return "/workflows/" + normaliseURL(repoUrl).replace(".git", "") + "/" + branch + "/" + path;
123+
return "/workflows/" + normaliseURL(repoUrl).replace(".git", "") + "/blob/" + branch + "/" + path;
115124
default:
116125
return null;
117126
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.taverna.robundle.manifest.Agent;
2525
import org.apache.taverna.robundle.manifest.Manifest;
2626
import org.apache.taverna.robundle.manifest.PathAnnotation;
27+
import org.apache.taverna.robundle.manifest.PathMetadata;
2728
import org.commonwl.view.cwl.CWLTool;
2829
import org.commonwl.view.github.GitDetails;
2930
import org.commonwl.view.github.GitService;
@@ -36,11 +37,15 @@
3637
import org.springframework.beans.factory.annotation.Value;
3738
import org.springframework.stereotype.Service;
3839

40+
import java.io.File;
3941
import java.io.IOException;
4042
import java.net.URI;
4143
import java.net.URISyntaxException;
4244
import java.nio.file.Files;
4345
import java.nio.file.Path;
46+
import java.nio.file.Paths;
47+
import java.util.ArrayList;
48+
import java.util.HashSet;
4449
import java.util.List;
4550
import java.util.Set;
4651
import java.util.regex.Pattern;
@@ -103,7 +108,7 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
103108
// Create a new RO bundle
104109
Bundle bundle = Bundles.createBundle();
105110
Manifest manifest = bundle.getManifest();
106-
/*
111+
107112
// Simplified attribution for RO bundle
108113
try {
109114
// Tool attribution in createdBy
@@ -141,15 +146,18 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
141146

142147
// Add annotation files
143148
GitDetails wfDetails = workflow.getRetrievedFrom();
149+
150+
// Run cwltool
151+
/*
144152
String url = "https://raw.githubusercontent.com/" + wfDetails.getOwner() + "/" +
145153
wfDetails.getRepoName() + "/" + wfDetails.getBranch() + "/" + wfDetails.getPath();
146-
147154
List<PathAnnotation> manifestAnnotations = new ArrayList<>();
148155
addAggregation(bundle, manifestAnnotations,
149156
"merged.cwl", cwlTool.getPackedVersion(url));
150157
addAggregation(bundle, manifestAnnotations,
151158
"workflow.ttl", cwlTool.getRDF(url));
152159
bundle.getManifest().setAnnotations(manifestAnnotations);
160+
*/
153161

154162
// Git2prov history
155163
List<Path> history = new ArrayList<>();
@@ -159,7 +167,7 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
159167

160168
} catch (URISyntaxException ex) {
161169
logger.error("Error creating URI for RO Bundle", ex);
162-
}*/
170+
}
163171

164172
// Return the completed bundle
165173
return bundle;

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.io.File;
4343
import java.io.IOException;
4444
import java.nio.file.Path;
45+
import java.util.Calendar;
4546
import java.util.Date;
4647

4748
@Service
@@ -233,7 +234,7 @@ public QueuedWorkflow createQueuedWorkflow(GitDetails gitInfo)
233234
}
234235
}
235236
}
236-
File localPath = repo.getRepository().getDirectory();
237+
File localPath = repo.getRepository().getWorkTree();
237238
String latestCommit = repo.getRepository().findRef("HEAD").getObjectId().getName();
238239

239240
Path pathToWorkflowFile = localPath.toPath().resolve(gitInfo.getPath()).normalize().toAbsolutePath();
@@ -277,7 +278,7 @@ public void retryCwltool(QueuedWorkflow queuedWorkflow) {
277278
queuedWorkflow.setCwltoolStatus(CWLToolStatus.RUNNING);
278279
queuedWorkflowRepository.save(queuedWorkflow);
279280
try {
280-
cwlToolRunner.createWorkflowFromQueued(queuedWorkflow);
281+
//cwlToolRunner.createWorkflowFromQueued(queuedWorkflow);
281282
} catch (Exception e) {
282283
logger.error("Could not update workflow with cwltool", e);
283284
}
@@ -326,7 +327,7 @@ private void removeWorkflow(Workflow workflow) {
326327
* @return Whether or not there are new commits
327328
*/
328329
private boolean cacheExpired(Workflow workflow) {
329-
/*try {
330+
try {
330331
// Calculate expiration
331332
Calendar expireCal = Calendar.getInstance();
332333
expireCal.setTime(workflow.getRetrievedOn());
@@ -338,7 +339,9 @@ private boolean cacheExpired(Workflow workflow) {
338339
// Cache expiry time has elapsed
339340
// Check current head of the branch with the cached head
340341
logger.debug("Time has expired for caching, checking commits...");
341-
String currentHead = githubService.getCommitSha(workflow.getRetrievedFrom());
342+
String repoPath = workflow.getGitRepoPath();
343+
Git repo = Git.open(new File(repoPath));
344+
String currentHead = repo.getRepository().findRef("HEAD").getObjectId().getName();
342345
logger.debug("Current: " + workflow.getLastCommit() + ", HEAD: " + currentHead);
343346

344347
// Reset date in database if there are still no changes
@@ -357,8 +360,7 @@ private boolean cacheExpired(Workflow workflow) {
357360
} catch (Exception ex) {
358361
// Default to no expiry if there was an API error
359362
return false;
360-
}*/
361-
return false;
363+
}
362364
}
363365

364366
/**

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ spring.data.mongodb.port = 27017
4545
#=======================
4646
# SPARQL endpoint
4747
#=======================
48-
sparql.endpoint = http://localhost:3030/all/
48+
sparql.endpoint = http://localhost:3030/cwlviewer/

src/main/resources/templates/fragments/footer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
(required <a href="https://github.com/common-workflow-language/cwlviewer/blob/master/NOTICE.md" rel="noopener" target="_blank">attribution notices</a>)
3636
<br />
3737
<span th:if="${workflow != null}">
38-
<a th:href="@{${workflow.retrievedFrom.getURL(workflow.lastCommit)}}" href="#" rel="noopener" target="_blank">Shown workflow</a> has separate copyright and license.
38+
<a th:href="@{${workflow.retrievedFrom.getUrl(workflow.lastCommit)}}" href="#" rel="noopener" target="_blank">Shown workflow</a> has separate copyright and license.
3939
</span>
4040
</div>
4141
</div>

src/main/resources/templates/workflows.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ <h3>Showing results for "<span th:text="${search}">query</span>" <a href="/workf
5959
</tr>
6060
</thead>
6161
<tbody>
62-
<tr th:each="workflow : ${workflows}" th:with="githubURLPart=${workflow.retrievedFrom.getURL().replace('https://', '')}">
62+
<tr th:each="workflow : ${workflows}" th:with="githubURLPart=${workflow.retrievedFrom.getUrl().replace('https://', '')}">
6363
<td>
64-
<a th:href="@{${workflow.retrievedFrom.getURL()}}">
64+
<a th:href="@{${workflow.retrievedFrom.getUrl()}}">
6565
<img class="workflow-thumb" th:src="@{'/graph/svg/' + ${githubURLPart}}" alt="workflow graph" />
6666
</a>
6767
</td>
@@ -70,11 +70,11 @@ <h3>Showing results for "<span th:text="${search}">query</span>" <a href="/workf
7070
<p><i th:text="${workflow.doc}">Description</i></p>
7171
</td>
7272
<td>
73-
<a th:href="@{${workflow.retrievedFrom.getURL()}}" rel="noopener" target="_blank">
73+
<a th:href="@{${workflow.retrievedFrom.getUrl()}}" rel="noopener" target="_blank">
7474
<img id="githubLogo" src="../static/img/GitHub-Mark-32px.png" th:src="@{/img/GitHub-Mark-32px.png}" width="20" height="20" />
75-
<span th:if="${workflow.retrievedFrom.path != null}" th:text="@{${workflow.retrievedFrom.owner} + '/' + ${workflow.retrievedFrom.repoName} + '/' + ${workflow.retrievedFrom.path}}">https://github.com</span>
76-
<span th:unless="${workflow.retrievedFrom.path != null}" th:text="@{${workflow.retrievedFrom.owner} + '/' + ${workflow.retrievedFrom.repoName} + '/'}">https://github.com</span>
75+
<span th:text="@{${workflow.retrievedFrom.repoUrl}}">https://github.com/test/test2/repo.git</span>
7776
</a>
77+
<p th:if="${workflow.retrievedFrom.path != null}">Path: <i th:text="${workflow.retrievedFrom.path}">/path/to/workflow.cwl</i></p>
7878
<p>Branch/Commit ID: <i th:text="${workflow.retrievedFrom.branch}">master</i></p>
7979
</td>
8080
<td><a th:href="@{'/workflows/' + ${githubURLPart}}"><span class="icon-view glyphicon glyphicon-chevron-right"></span></a></td>

0 commit comments

Comments
 (0)