Skip to content

Commit 7fed9ae

Browse files
committed
address some deprecations
1 parent 57001d4 commit 7fed9ae

File tree

8 files changed

+39
-45
lines changed

8 files changed

+39
-45
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.InputStream;
2828
import java.io.StringWriter;
2929
import java.net.URI;
30+
import java.nio.charset.StandardCharsets;
3031
import java.nio.file.Files;
3132
import java.nio.file.Path;
3233
import java.util.ArrayList;
@@ -128,7 +129,7 @@ public boolean isPacked(File workflowFile) throws IOException {
128129
if (workflowFile.length() > singleFileSizeLimit) {
129130
return false;
130131
}
131-
String fileContent = readFileToString(workflowFile);
132+
String fileContent = readFileToString(workflowFile, StandardCharsets.UTF_8);
132133
return fileContent.contains("$graph");
133134
}
134135

src/main/java/org/commonwl/view/git/GitService.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
import org.eclipse.jgit.lib.ObjectId;
3939
import org.eclipse.jgit.lib.PersonIdent;
4040
import org.eclipse.jgit.revwalk.RevCommit;
41-
import org.slf4j.Logger;
42-
import org.slf4j.LoggerFactory;
4341
import org.springframework.beans.factory.annotation.Autowired;
4442
import org.springframework.beans.factory.annotation.Value;
4543
import org.springframework.stereotype.Service;
@@ -48,8 +46,6 @@
4846
@Service
4947
public class GitService {
5048

51-
private final Logger logger = LoggerFactory.getLogger(this.getClass());
52-
5349
// Location to check out git repositories into
5450
private final Path gitStorage;
5551

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import java.util.regex.Pattern;
2424
import org.apache.commons.lang.StringUtils;
2525
import org.commonwl.view.git.GitDetails;
26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
2826
import org.springframework.stereotype.Component;
2927
import org.springframework.validation.Errors;
3028
import org.springframework.validation.ValidationUtils;
@@ -33,8 +31,6 @@
3331
@Component
3432
public class WorkflowFormValidator {
3533

36-
private final Logger logger = LoggerFactory.getLogger(this.getClass());
37-
3834
// URL validation for cwl files on github.com
3935
private static final String GITHUB_CWL_REGEX =
4036
"^https?:\\/\\/github\\.com\\/([A-Za-z0-9_.-]+)\\/([A-Za-z0-9_.-]+)\\/?(?:tree|blob)\\/([^/]+)(?:\\/(.+\\.cwl))$";

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import java.util.*;
2727
import org.commonwl.view.cwl.CWLValidationException;
2828
import org.commonwl.view.git.GitDetails;
29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
3129
import org.springframework.beans.factory.annotation.Autowired;
3230
import org.springframework.data.domain.Page;
3331
import org.springframework.data.domain.Pageable;
@@ -44,8 +42,6 @@
4442
@RestController
4543
public class WorkflowJSONController {
4644

47-
private final Logger logger = LoggerFactory.getLogger(this.getClass());
48-
4945
private final WorkflowFormValidator workflowFormValidator;
5046
private final WorkflowService workflowService;
5147

@@ -67,7 +63,7 @@ public WorkflowJSONController(
6763
*
6864
* @return A list of all the workflows
6965
*/
70-
@GetMapping(value = "/workflows", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
66+
@GetMapping(value = "/workflows", produces = MediaType.APPLICATION_JSON_VALUE)
7167
public Page<Workflow> listWorkflowsJson(
7268
Model model, @PageableDefault(size = 10) Pageable pageable) {
7369
return workflowService.getPageOfWorkflows(pageable);
@@ -81,7 +77,7 @@ public Page<Workflow> listWorkflowsJson(
8177
@GetMapping(
8278
value = "/workflows",
8379
params = "search",
84-
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
80+
produces = MediaType.APPLICATION_JSON_VALUE)
8581
public Page<Workflow> searchWorkflowsJson(
8682
Model model,
8783
@PageableDefault(size = 10) Pageable pageable,
@@ -98,7 +94,7 @@ public Page<Workflow> searchWorkflowsJson(
9894
* @param packedId The ID of the workflow if the file is packed
9995
* @return Appropriate response code and optional JSON string with message
10096
*/
101-
@PostMapping(value = "/workflows", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
97+
@PostMapping(value = "/workflows", produces = MediaType.APPLICATION_JSON_VALUE)
10298
public ResponseEntity<?> newWorkflowFromGitURLJson(
10399
@RequestParam(value = "url") String url,
104100
@RequestParam(value = "branch", required = false) String branch,
@@ -119,7 +115,7 @@ public ResponseEntity<?> newWorkflowFromGitURLJson(
119115
error = "Could not parse workflow details from URL";
120116
}
121117
Map<String, String> message = Collections.singletonMap("message", "Error: " + error);
122-
return new ResponseEntity<Map>(message, HttpStatus.BAD_REQUEST);
118+
return new ResponseEntity<Map<String, String>>(message, HttpStatus.BAD_REQUEST);
123119
} else {
124120
// Get workflow or create if does not exist
125121
Workflow workflow = workflowService.getWorkflow(gitInfo);
@@ -139,7 +135,6 @@ public ResponseEntity<?> newWorkflowFromGitURLJson(
139135
}
140136
} else {
141137
// Error with alternatives suggested
142-
List<WorkflowOverview> test = queued.getWorkflowList();
143138
List<String> workflowUris = new ArrayList<>();
144139
for (WorkflowOverview overview : queued.getWorkflowList()) {
145140
workflowUris.add(overview.getFileName().substring(1));
@@ -150,18 +145,19 @@ public ResponseEntity<?> newWorkflowFromGitURLJson(
150145
"This workflow file is packed and contains multiple workflow "
151146
+ "descriptions. Please provide a packedId parameter with one of the following");
152147
responseMap.put("packedId", workflowUris);
153-
return new ResponseEntity<Map>(responseMap, HttpStatus.UNPROCESSABLE_ENTITY);
148+
return new ResponseEntity<Map<String, Object>>(
149+
responseMap, HttpStatus.UNPROCESSABLE_ENTITY);
154150
}
155151
}
156152
} catch (CWLValidationException ex) {
157153
Map<String, String> message =
158154
Collections.singletonMap("message", "Error:" + ex.getMessage());
159-
return new ResponseEntity<Map>(message, HttpStatus.BAD_REQUEST);
155+
return new ResponseEntity<Map<String, String>>(message, HttpStatus.BAD_REQUEST);
160156
} catch (Exception ex) {
161157
Map<String, String> message =
162158
Collections.singletonMap(
163159
"message", "Error: Workflow could not be created from the provided cwl file");
164-
return new ResponseEntity<Map>(message, HttpStatus.BAD_REQUEST);
160+
return new ResponseEntity<Map<String, String>>(message, HttpStatus.BAD_REQUEST);
165161
}
166162
}
167163
response.setHeader("Location", "/queue/" + queued.getId());
@@ -190,7 +186,7 @@ public ResponseEntity<?> newWorkflowFromGitURLJson(
190186
"/workflows/{domain}.com/{owner}/{repoName}/tree/{branch}/**",
191187
"/workflows/{domain}.com/{owner}/{repoName}/blob/{branch}/**"
192188
},
193-
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
189+
produces = MediaType.APPLICATION_JSON_VALUE)
194190
public Workflow getWorkflowJson(
195191
@PathVariable("domain") String domain,
196192
@PathVariable("owner") String owner,
@@ -222,7 +218,7 @@ public Workflow getWorkflowJson(
222218
*/
223219
@GetMapping(
224220
value = "/workflows/*/*.git/{branch}/**",
225-
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
221+
produces = MediaType.APPLICATION_JSON_VALUE)
226222
public Workflow getWorkflowJsonGeneric(
227223
@PathVariable("branch") String branch, HttpServletRequest request) {
228224
// The wildcard end of the URL is the path
@@ -248,7 +244,7 @@ public Workflow getWorkflowJsonGeneric(
248244
* @return 303 see other status w/ location header if success, otherwise JSON representation of
249245
* object
250246
*/
251-
@GetMapping(value = "/queue/{queueID}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
247+
@GetMapping(value = "/queue/{queueID}", produces = MediaType.APPLICATION_JSON_VALUE)
252248
public QueuedWorkflow checkQueueJson(
253249
@PathVariable("queueID") String queueID, HttpServletResponse response) {
254250
QueuedWorkflow queuedWorkflow = workflowService.getQueuedWorkflow(queueID);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public String uriList(
8787
produces = {
8888
MediaType.TEXT_HTML_VALUE,
8989
MediaType.APPLICATION_JSON_VALUE,
90-
MediaType.APPLICATION_JSON_UTF8_VALUE
90+
MediaType.APPLICATION_JSON_VALUE
9191
})
9292
public void goToViewer(
9393
@PathVariable("commitid") String commitId,

src/test/java/org/commonwl/view/cwl/CWLServiceTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.ByteArrayInputStream;
3131
import java.io.File;
3232
import java.io.IOException;
33+
import java.nio.charset.StandardCharsets;
3334
import java.nio.file.Paths;
3435
import java.util.List;
3536
import java.util.Map;
@@ -70,7 +71,10 @@ public void setUp() throws Exception {
7071
File packedWorkflowRdf = new File("src/test/resources/cwl/make_to_cwl/dna.ttl");
7172
Model workflowModel = ModelFactory.createDefaultModel();
7273
workflowModel.read(
73-
new ByteArrayInputStream(readFileToString(packedWorkflowRdf).getBytes()), null, "TURTLE");
74+
new ByteArrayInputStream(
75+
readFileToString(packedWorkflowRdf, StandardCharsets.UTF_8).getBytes()),
76+
null,
77+
"TURTLE");
7478
Dataset workflowDataset = DatasetFactory.create();
7579
workflowDataset.addNamedModel(
7680
"https://w3id.org/cwl/view/git/549c973ccc01781595ce562dea4cedc6c9540fe0/workflows/make-to-cwl/dna.cwl#main",
@@ -235,7 +239,8 @@ public void parseWorkflowWithCwltool() throws Exception {
235239
// Mock CWLTool
236240
CWLTool mockCwlTool = Mockito.mock(CWLTool.class);
237241
File packedWorkflowRdf = new File("src/test/resources/cwl/make_to_cwl/dna.ttl");
238-
when(mockCwlTool.getRDF(any(String.class))).thenReturn(readFileToString(packedWorkflowRdf));
242+
when(mockCwlTool.getRDF(any(String.class)))
243+
.thenReturn(readFileToString(packedWorkflowRdf, StandardCharsets.UTF_8));
239244

240245
// CWLService to test
241246
CWLService cwlService =
@@ -264,7 +269,8 @@ public void parseWorkflowWithCwltool() throws Exception {
264269
assertEquals(1, workflow.getOutputs().size());
265270
assertEquals(3, workflow.getSteps().size());
266271
File expectedDotCode = new File("src/test/resources/cwl/make_to_cwl/visualisation.dot");
267-
assertEquals(readFileToString(expectedDotCode), workflow.getVisualisationDot());
272+
assertEquals(
273+
readFileToString(expectedDotCode, StandardCharsets.UTF_8), workflow.getVisualisationDot());
268274
assertEquals("https://spdx.org/licenses/Apache-2.0", workflow.getLicenseLink());
269275
assertEquals("Apache License 2.0", workflow.getLicenseName());
270276
}

src/test/java/org/commonwl/view/graphviz/ModelDotWriterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import java.io.File;
2525
import java.io.StringWriter;
26-
import java.nio.charset.Charset;
26+
import java.nio.charset.StandardCharsets;
2727
import java.util.HashMap;
2828
import java.util.Map;
2929
import org.apache.commons.io.FileUtils;
@@ -104,6 +104,6 @@ public void writeGraph() throws Exception {
104104

105105
File expectedDot = new File("src/test/resources/graphviz/testWorkflow.dot");
106106
assertEquals(
107-
FileUtils.readFileToString(expectedDot, Charset.defaultCharset()), dotSource.toString());
107+
FileUtils.readFileToString(expectedDot, StandardCharsets.UTF_8), dotSource.toString());
108108
}
109109
}

src/test/java/org/commonwl/view/workflow/WorkflowJSONControllerTest.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,17 @@ public void newWorkflowFromGithubURLJson() throws Exception {
9191

9292
// Error in validation
9393
mockMvc
94-
.perform(
95-
post("/workflows").param("url", "invalidurl").accept(MediaType.APPLICATION_JSON_UTF8))
94+
.perform(post("/workflows").param("url", "invalidurl").accept(MediaType.APPLICATION_JSON))
9695
.andExpect(status().isBadRequest())
97-
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
96+
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
9897
.andExpect(jsonPath("$.message", is("Error: Could not parse workflow details from URL")));
9998

10099
// Workflow already exists
101100
mockMvc
102101
.perform(
103102
post("/workflows")
104103
.param("url", "https://github.com/owner/repoName/tree/branch/path/workflow.cwl")
105-
.accept(MediaType.APPLICATION_JSON_UTF8))
104+
.accept(MediaType.APPLICATION_JSON))
106105
.andExpect(status().isSeeOther())
107106
.andExpect(
108107
header()
@@ -115,15 +114,15 @@ public void newWorkflowFromGithubURLJson() throws Exception {
115114
.perform(
116115
post("/workflows")
117116
.param("url", "https://github.com/owner/repoName/tree/branch/path/workflow.cwl")
118-
.accept(MediaType.APPLICATION_JSON_UTF8))
117+
.accept(MediaType.APPLICATION_JSON))
119118
.andExpect(status().isBadRequest());
120119

121120
// Success
122121
mockMvc
123122
.perform(
124123
post("/workflows")
125124
.param("url", "https://github.com/owner/repoName/tree/branch/path/success.cwl")
126-
.accept(MediaType.APPLICATION_JSON_UTF8))
125+
.accept(MediaType.APPLICATION_JSON))
127126
.andExpect(status().isAccepted())
128127
.andExpect(header().string("Location", is("/queue/123")));
129128

@@ -132,7 +131,7 @@ public void newWorkflowFromGithubURLJson() throws Exception {
132131
.perform(
133132
post("/workflows")
134133
.param("url", "https://github.com/owner/repoName/tree/branch/path/singlePacked.cwl")
135-
.accept(MediaType.APPLICATION_JSON_UTF8))
134+
.accept(MediaType.APPLICATION_JSON))
136135
.andExpect(status().isAccepted())
137136
.andExpect(header().string("Location", is("/queue/123")));
138137

@@ -142,7 +141,7 @@ public void newWorkflowFromGithubURLJson() throws Exception {
142141
post("/workflows")
143142
.param(
144143
"url", "https://github.com/owner/repoName/tree/branch/path/multiplePacked.cwl")
145-
.accept(MediaType.APPLICATION_JSON_UTF8))
144+
.accept(MediaType.APPLICATION_JSON))
146145
.andExpect(status().isUnprocessableEntity())
147146
.andExpect(
148147
jsonPath(
@@ -174,7 +173,7 @@ public void getWorkflowByGithubDetailsJson() throws Exception {
174173
get("/workflows/github.com/owner/repo/blob/branch/path/to/workflow.cwl")
175174
.accept(MediaType.APPLICATION_JSON))
176175
.andExpect(status().isOk())
177-
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
176+
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
178177
.andExpect(jsonPath("$.retrievedFrom.repoUrl", is("https://github.com/owner/repo.git")))
179178
.andExpect(jsonPath("$.retrievedFrom.branch", is("branch")))
180179
.andExpect(jsonPath("$.retrievedFrom.path", is("path/to/workflow.cwl")))
@@ -224,29 +223,29 @@ public void checkQueue() throws Exception {
224223

225224
// No workflow
226225
mockMvc
227-
.perform(get("/queue/123").accept(MediaType.APPLICATION_JSON_UTF8))
226+
.perform(get("/queue/123").accept(MediaType.APPLICATION_JSON))
228227
.andExpect(status().isNotFound());
229228

230229
// Running workflow
231230
mockMvc
232-
.perform(get("/queue/123").accept(MediaType.APPLICATION_JSON_UTF8))
231+
.perform(get("/queue/123").accept(MediaType.APPLICATION_JSON))
233232
.andExpect(status().isOk())
234-
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
233+
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
235234
.andExpect(jsonPath("$.cwltoolStatus", is("RUNNING")))
236235
.andExpect(jsonPath("$.cwltoolVersion", is("v1.0")));
237236

238237
// Error workflow
239238
mockMvc
240-
.perform(get("/queue/123").accept(MediaType.APPLICATION_JSON_UTF8))
239+
.perform(get("/queue/123").accept(MediaType.APPLICATION_JSON))
241240
.andExpect(status().isOk())
242-
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
241+
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
243242
.andExpect(jsonPath("$.cwltoolStatus", is("ERROR")))
244243
.andExpect(jsonPath("$.message", is("cwltool error message")))
245244
.andExpect(jsonPath("$.cwltoolVersion", is("v1.0")));
246245

247246
// Success workflow
248247
mockMvc
249-
.perform(get("/queue/123").accept(MediaType.APPLICATION_JSON_UTF8))
248+
.perform(get("/queue/123").accept(MediaType.APPLICATION_JSON))
250249
.andExpect(status().isSeeOther())
251250
.andExpect(
252251
header()

0 commit comments

Comments
 (0)