24
24
import com .fasterxml .jackson .databind .node .ArrayNode ;
25
25
import com .fasterxml .jackson .databind .node .ObjectNode ;
26
26
import com .fasterxml .jackson .databind .node .TextNode ;
27
- import org .apache .commons .io .FileUtils ;
28
27
import org .apache .commons .io .FilenameUtils ;
29
28
import org .apache .jena .ontology .OntModelSpec ;
30
29
import org .apache .jena .query .QuerySolution ;
36
35
import org .apache .jena .riot .RiotException ;
37
36
import org .commonwl .view .docker .DockerService ;
38
37
import org .commonwl .view .git .GitDetails ;
38
+ import org .commonwl .view .git .GitService ;
39
39
import org .commonwl .view .graphviz .ModelDotWriter ;
40
40
import org .commonwl .view .graphviz .RDFDotWriter ;
41
41
import org .commonwl .view .workflow .Workflow ;
42
+ import org .eclipse .jgit .errors .LargeObjectException ;
42
43
import org .slf4j .Logger ;
43
44
import org .slf4j .LoggerFactory ;
44
45
import org .springframework .beans .factory .annotation .Autowired ;
45
- import org .springframework .beans .factory .annotation .Value ;
46
46
import org .springframework .stereotype .Service ;
47
47
import org .yaml .snakeyaml .Yaml ;
48
48
49
49
import java .io .ByteArrayInputStream ;
50
- import java .io .File ;
51
50
import java .io .IOException ;
52
51
import java .io .StringWriter ;
53
52
import java .nio .file .Path ;
54
53
import java .nio .file .Paths ;
55
54
import java .util .*;
56
55
57
- import static org .apache .commons .io .FileUtils .readFileToString ;
58
-
59
56
/**
60
57
* Provides CWL parsing for workflows to gather an overview
61
58
* for display and visualisation
@@ -68,7 +65,7 @@ public class CWLService {
68
65
// Autowired properties/services
69
66
private final RDFService rdfService ;
70
67
private final CWLTool cwlTool ;
71
- private final int singleFileSizeLimit ;
68
+ private final GitService gitService ;
72
69
73
70
// CWL specific strings
74
71
private final String DOC_GRAPH = "$graph" ;
@@ -98,30 +95,27 @@ public class CWLService {
98
95
* Constructor for the Common Workflow Language service
99
96
* @param rdfService A service for handling RDF queries
100
97
* @param cwlTool Handles cwltool integration
101
- * @param singleFileSizeLimit The file size limit for single files
98
+ * @param gitService Handles Git repository functionality
102
99
*/
103
100
@ Autowired
104
101
public CWLService (RDFService rdfService ,
105
102
CWLTool cwlTool ,
106
- @ Value ( "${singleFileSizeLimit}" ) int singleFileSizeLimit ) {
103
+ GitService gitService ) {
107
104
this .rdfService = rdfService ;
108
105
this .cwlTool = cwlTool ;
109
- this .singleFileSizeLimit = singleFileSizeLimit ;
106
+ this .gitService = gitService ;
110
107
}
111
108
112
109
/**
113
110
* Gets the Workflow object from internal parsing
114
- * @param workflowFile The workflow file to be parsed
111
+ * @param gitDetails The details for the workflow in the git repository
115
112
* @return The constructed workflow object
116
113
*/
117
- public Workflow parseWorkflowNative (File workflowFile ) throws IOException {
118
-
119
- // Check file size limit before parsing
120
- long fileSizeBytes = workflowFile .length ();
121
- if (fileSizeBytes <= singleFileSizeLimit ) {
122
-
114
+ public Workflow parseWorkflowNative (GitDetails gitDetails ) throws IOException {
115
+ try {
123
116
// Parse file as yaml
124
- JsonNode cwlFile = yamlStringToJson (readFileToString (workflowFile ));
117
+ JsonNode cwlFile = yamlStringToJson (gitService .getFile (gitService
118
+ .getRepository (gitDetails ).getRepository (), gitDetails .getPath ()));
125
119
126
120
// If the CWL file is packed there can be multiple workflows in a file
127
121
Map <String , JsonNode > packedFiles = new HashMap <>();
@@ -138,7 +132,7 @@ public Workflow parseWorkflowNative(File workflowFile) throws IOException {
138
132
// Use filename for label if there is no defined one
139
133
String label = extractLabel (cwlFile );
140
134
if (label == null ) {
141
- label = FilenameUtils .getName (workflowFile .getPath ());
135
+ label = FilenameUtils .getName (gitDetails .getPath ());
142
136
}
143
137
144
138
// Construct the rest of the workflow model
@@ -163,22 +157,19 @@ public Workflow parseWorkflowNative(File workflowFile) throws IOException {
163
157
164
158
return workflowModel ;
165
159
166
- } else {
167
- throw new IOException ("File '" + workflowFile .getName () + "' is over singleFileSizeLimit - " +
168
- FileUtils .byteCountToDisplaySize (fileSizeBytes ) + "/" +
169
- FileUtils .byteCountToDisplaySize (singleFileSizeLimit ));
160
+ } catch (LargeObjectException ex ) {
161
+ throw new IOException ("File '" + FilenameUtils .getName (gitDetails .getPath ()) +
162
+ "' is over singleFileSizeLimit" ;
170
163
}
171
164
172
165
}
173
166
174
167
/**
175
168
* Create a workflow model using cwltool rdf output
176
169
* @param basicModel The basic workflow object created thus far
177
- * @param workflowFile The workflow file to run cwltool on
178
170
* @return The constructed workflow object
179
171
*/
180
- public Workflow parseWorkflowWithCwltool (Workflow basicModel ,
181
- File workflowFile ) throws CWLValidationException {
172
+ public Workflow parseWorkflowWithCwltool (Workflow basicModel ) throws CWLValidationException {
182
173
GitDetails gitDetails = basicModel .getRetrievedFrom ();
183
174
String latestCommit = basicModel .getLastCommit ();
184
175
String packedWorkflowID = basicModel .getPackedWorkflowID ();
0 commit comments