27
27
import org .apache .commons .io .FileUtils ;
28
28
import org .apache .commons .io .FilenameUtils ;
29
29
import org .commonwl .viewer .services .DockerService ;
30
- import org .eclipse .egit .github .core .RepositoryContents ;
31
30
import org .commonwl .viewer .services .GitHubService ;
31
+ import org .eclipse .egit .github .core .RepositoryContents ;
32
32
import org .yaml .snakeyaml .Yaml ;
33
33
34
34
import java .io .IOException ;
@@ -44,6 +44,8 @@ public class CWLCollection {
44
44
private GithubDetails githubInfo ;
45
45
private String commitSha ;
46
46
47
+ private int totalFileSize ;
48
+ private int totalFileSizeLimit ;
47
49
private int singleFileSizeLimit ;
48
50
49
51
// Maps of ID to associated JSON
@@ -93,11 +95,13 @@ public class CWLCollection {
93
95
* @throws IOException Any API errors which may have occurred
94
96
*/
95
97
public CWLCollection (GitHubService githubService , GithubDetails githubInfo ,
96
- String commitSha , int singleFileSizeLimit ) throws IOException {
98
+ String commitSha , int singleFileSizeLimit , int totalFileSizeLimit ) throws IOException {
97
99
this .githubInfo = githubInfo ;
98
100
this .githubService = githubService ;
99
101
this .commitSha = commitSha ;
100
102
this .singleFileSizeLimit = singleFileSizeLimit ;
103
+ this .totalFileSizeLimit = totalFileSizeLimit ;
104
+ this .totalFileSize = 0 ;
101
105
102
106
// Add any CWL files from the Github repo to this collection
103
107
List <RepositoryContents > repoContents = githubService .getContents (githubInfo );
@@ -123,37 +127,41 @@ private void addDocs(List<RepositoryContents> repoContents) throws IOException {
123
127
// Add the files in the subdirectory to this new folder
124
128
addDocs (subdirectory );
125
129
126
- // Otherwise this is a file so add to the bundle
127
130
} else if (repoContent .getType ().equals (FILE )) {
128
-
129
- // Get the file extension
130
- int eIndex = repoContent .getName ().lastIndexOf ('.' ) + 1 ;
131
- if (eIndex > 0 ) {
132
- String extension = repoContent .getName ().substring (eIndex );
133
-
134
- // If this is a cwl file which needs to be parsed
135
- if (extension .equals (CWL_EXTENSION )) {
136
- if (repoContent .getSize () <= singleFileSizeLimit ) {
137
- // Get the content of this file from Github
138
- GithubDetails githubFile = new GithubDetails (githubInfo .getOwner (),
139
- githubInfo .getRepoName (), githubInfo .getBranch (), repoContent .getPath ());
140
- String fileContent = githubService .downloadFile (githubFile , commitSha );
141
-
142
- // Parse yaml to JsonNode
143
- Yaml reader = new Yaml ();
144
- ObjectMapper mapper = new ObjectMapper ();
145
- JsonNode cwlFile = mapper .valueToTree (reader .load (fileContent ));
146
-
147
- // Add document to those being considered
148
- addDoc (cwlFile , repoContent .getName ());
149
- } else {
150
- throw new IOException ("File '" + repoContent .getName () + "' is over singleFileSizeLimit - " +
151
- FileUtils .byteCountToDisplaySize (repoContent .getSize ()) + "/" +
152
- FileUtils .byteCountToDisplaySize (singleFileSizeLimit ));
131
+ // Keep track of total file size for limit
132
+ totalFileSize += repoContent .getSize ();
133
+ if (totalFileSize <= totalFileSizeLimit ) {
134
+ // Get the file extension
135
+ int eIndex = repoContent .getName ().lastIndexOf ('.' ) + 1 ;
136
+ if (eIndex > 0 ) {
137
+ String extension = repoContent .getName ().substring (eIndex );
138
+
139
+ // If this is a cwl file which needs to be parsed
140
+ if (extension .equals (CWL_EXTENSION )) {
141
+ if (repoContent .getSize () <= singleFileSizeLimit ) {
142
+ // Get the content of this file from Github
143
+ GithubDetails githubFile = new GithubDetails (githubInfo .getOwner (),
144
+ githubInfo .getRepoName (), githubInfo .getBranch (), repoContent .getPath ());
145
+ String fileContent = githubService .downloadFile (githubFile , commitSha );
146
+
147
+ // Parse yaml to JsonNode
148
+ Yaml reader = new Yaml ();
149
+ ObjectMapper mapper = new ObjectMapper ();
150
+ JsonNode cwlFile = mapper .valueToTree (reader .load (fileContent ));
151
+
152
+ // Add document to those being considered
153
+ addDoc (cwlFile , repoContent .getName ());
154
+ } else {
155
+ throw new IOException ("File '" + repoContent .getName () + "' is over singleFileSizeLimit - " +
156
+ FileUtils .byteCountToDisplaySize (repoContent .getSize ()) + "/" +
157
+ FileUtils .byteCountToDisplaySize (singleFileSizeLimit ));
158
+ }
153
159
}
154
160
}
161
+ } else {
162
+ throw new IOException ("Contents of the repository are over totalFileSizeLimit of " +
163
+ FileUtils .byteCountToDisplaySize (totalFileSizeLimit ));
155
164
}
156
-
157
165
}
158
166
}
159
167
}
0 commit comments