35
35
import org .apache .jena .rdf .model .StmtIterator ;
36
36
import org .apache .jena .riot .RiotException ;
37
37
import org .commonwl .view .docker .DockerService ;
38
- import org .commonwl .view .github .GitHubService ;
39
- import org .commonwl .view .github .GithubDetails ;
38
+ import org .commonwl .view .github .GitDetails ;
39
+ import org .commonwl .view .github .GitService ;
40
40
import org .commonwl .view .graphviz .ModelDotWriter ;
41
41
import org .commonwl .view .graphviz .RDFDotWriter ;
42
42
import org .commonwl .view .workflow .Workflow ;
49
49
import org .yaml .snakeyaml .Yaml ;
50
50
51
51
import java .io .ByteArrayInputStream ;
52
+ import java .io .File ;
52
53
import java .io .IOException ;
53
54
import java .io .StringWriter ;
54
55
import java .nio .file .Path ;
55
56
import java .nio .file .Paths ;
56
57
import java .util .*;
57
58
59
+ import static org .apache .commons .io .FileUtils .readFileToString ;
60
+
58
61
/**
59
62
* Provides CWL parsing for workflows to gather an overview
60
63
* for display and visualisation
@@ -65,7 +68,7 @@ public class CWLService {
65
68
private final Logger logger = LoggerFactory .getLogger (this .getClass ());
66
69
67
70
// Autowired properties/services
68
- private final GitHubService githubService ;
71
+ private final GitService githubService ;
69
72
private final RDFService rdfService ;
70
73
private final CWLTool cwlTool ;
71
74
private final int singleFileSizeLimit ;
@@ -101,7 +104,7 @@ public class CWLService {
101
104
* @param singleFileSizeLimit The file size limit for single files
102
105
*/
103
106
@ Autowired
104
- public CWLService (GitHubService githubService ,
107
+ public CWLService (GitService githubService ,
105
108
RDFService rdfService ,
106
109
CWLTool cwlTool ,
107
110
@ Value ("${singleFileSizeLimit}" ) int singleFileSizeLimit ) {
@@ -113,21 +116,17 @@ public CWLService(GitHubService githubService,
113
116
114
117
/**
115
118
* Gets the Workflow object from internal parsing
116
- * @param githubInfo The Github repository information
117
- * @param latestCommit The latest commit ID
119
+ * @param workflowFile The workflow file to be parsed
118
120
* @return The constructed workflow object
119
121
*/
120
- public Workflow parseWorkflowNative (GithubDetails githubInfo , String latestCommit ) throws IOException {
121
-
122
- // Get the content of this file from Github
123
- String fileContent = githubService .downloadFile (githubInfo , latestCommit );
124
- int fileSizeBytes = fileContent .getBytes ("UTF-8" ).length ;
122
+ public Workflow parseWorkflowNative (File workflowFile ) throws IOException {
125
123
126
124
// Check file size limit before parsing
125
+ long fileSizeBytes = workflowFile .length ();
127
126
if (fileSizeBytes <= singleFileSizeLimit ) {
128
127
129
128
// Parse file as yaml
130
- JsonNode cwlFile = yamlStringToJson (fileContent );
129
+ JsonNode cwlFile = yamlStringToJson (readFileToString ( workflowFile ) );
131
130
132
131
// If the CWL file is packed there can be multiple workflows in a file
133
132
Map <String , JsonNode > packedFiles = new HashMap <>();
@@ -144,7 +143,7 @@ public Workflow parseWorkflowNative(GithubDetails githubInfo, String latestCommi
144
143
// Use filename for label if there is no defined one
145
144
String label = extractLabel (cwlFile );
146
145
if (label == null ) {
147
- label = FilenameUtils .getName (githubInfo .getPath ());
146
+ label = FilenameUtils .getName (workflowFile .getPath ());
148
147
}
149
148
150
149
// Construct the rest of the workflow model
@@ -170,7 +169,7 @@ public Workflow parseWorkflowNative(GithubDetails githubInfo, String latestCommi
170
169
return workflowModel ;
171
170
172
171
} else {
173
- throw new IOException ("File '" + githubInfo . getPath () + "' is over singleFileSizeLimit - " +
172
+ throw new IOException ("File '" + workflowFile . getName () + "' is over singleFileSizeLimit - " +
174
173
FileUtils .byteCountToDisplaySize (fileSizeBytes ) + "/" +
175
174
FileUtils .byteCountToDisplaySize (singleFileSizeLimit ));
176
175
}
@@ -184,7 +183,7 @@ public Workflow parseWorkflowNative(GithubDetails githubInfo, String latestCommi
184
183
* @param packedWorkflowID The workflow ID if the file has multiple objects
185
184
* @return The constructed workflow object
186
185
*/
187
- public Workflow parseWorkflowWithCwltool (GithubDetails githubInfo ,
186
+ public Workflow parseWorkflowWithCwltool (GitDetails githubInfo ,
188
187
String latestCommit ,
189
188
String packedWorkflowID ) throws CWLValidationException {
190
189
@@ -432,7 +431,7 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
432
431
* @return A constructed WorkflowOverview of the workflow
433
432
* @throws IOException Any API errors which may have occurred
434
433
*/
435
- public WorkflowOverview getWorkflowOverview (GithubDetails githubInfo ) throws IOException {
434
+ public WorkflowOverview getWorkflowOverview (GitDetails githubInfo ) throws IOException {
436
435
437
436
// Get the content of this file from Github
438
437
String fileContent = githubService .downloadFile (githubInfo );
0 commit comments