Skip to content

Commit 45b4852

Browse files
committed
address some deprecations
1 parent 6aa264e commit 45b4852

File tree

9 files changed

+42
-50
lines changed

9 files changed

+42
-50
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/Workflow.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
@Index(columnList = "retrievedFrom", unique = true),
5959
@Index(columnList = "retrievedOn")
6060
})
61-
@SuppressWarnings("deprecation")
6261
public class Workflow extends BaseEntity implements Serializable {
6362

6463
// ID for database

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 & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import javax.servlet.http.HttpServletResponse;
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);
@@ -78,10 +74,7 @@ public Page<Workflow> listWorkflowsJson(
7874
*
7975
* @return A list of all the workflows
8076
*/
81-
@GetMapping(
82-
value = "/workflows",
83-
params = "search",
84-
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
77+
@GetMapping(value = "/workflows", params = "search", produces = MediaType.APPLICATION_JSON_VALUE)
8578
public Page<Workflow> searchWorkflowsJson(
8679
Model model,
8780
@PageableDefault(size = 10) Pageable pageable,
@@ -98,7 +91,7 @@ public Page<Workflow> searchWorkflowsJson(
9891
* @param packedId The ID of the workflow if the file is packed
9992
* @return Appropriate response code and optional JSON string with message
10093
*/
101-
@PostMapping(value = "/workflows", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
94+
@PostMapping(value = "/workflows", produces = MediaType.APPLICATION_JSON_VALUE)
10295
public ResponseEntity<?> newWorkflowFromGitURLJson(
10396
@RequestParam(value = "url") String url,
10497
@RequestParam(value = "branch", required = false) String branch,
@@ -119,7 +112,7 @@ public ResponseEntity<?> newWorkflowFromGitURLJson(
119112
error = "Could not parse workflow details from URL";
120113
}
121114
Map<String, String> message = Collections.singletonMap("message", "Error: " + error);
122-
return new ResponseEntity<Map>(message, HttpStatus.BAD_REQUEST);
115+
return new ResponseEntity<Map<String, String>>(message, HttpStatus.BAD_REQUEST);
123116
} else {
124117
// Get workflow or create if does not exist
125118
Workflow workflow = workflowService.getWorkflow(gitInfo);
@@ -139,7 +132,6 @@ public ResponseEntity<?> newWorkflowFromGitURLJson(
139132
}
140133
} else {
141134
// Error with alternatives suggested
142-
List<WorkflowOverview> test = queued.getWorkflowList();
143135
List<String> workflowUris = new ArrayList<>();
144136
for (WorkflowOverview overview : queued.getWorkflowList()) {
145137
workflowUris.add(overview.getFileName().substring(1));
@@ -150,18 +142,19 @@ public ResponseEntity<?> newWorkflowFromGitURLJson(
150142
"This workflow file is packed and contains multiple workflow "
151143
+ "descriptions. Please provide a packedId parameter with one of the following");
152144
responseMap.put("packedId", workflowUris);
153-
return new ResponseEntity<Map>(responseMap, HttpStatus.UNPROCESSABLE_ENTITY);
145+
return new ResponseEntity<Map<String, Object>>(
146+
responseMap, HttpStatus.UNPROCESSABLE_ENTITY);
154147
}
155148
}
156149
} catch (CWLValidationException ex) {
157150
Map<String, String> message =
158151
Collections.singletonMap("message", "Error:" + ex.getMessage());
159-
return new ResponseEntity<Map>(message, HttpStatus.BAD_REQUEST);
152+
return new ResponseEntity<Map<String, String>>(message, HttpStatus.BAD_REQUEST);
160153
} catch (Exception ex) {
161154
Map<String, String> message =
162155
Collections.singletonMap(
163156
"message", "Error: Workflow could not be created from the provided cwl file");
164-
return new ResponseEntity<Map>(message, HttpStatus.BAD_REQUEST);
157+
return new ResponseEntity<Map<String, String>>(message, HttpStatus.BAD_REQUEST);
165158
}
166159
}
167160
response.setHeader("Location", "/queue/" + queued.getId());
@@ -190,7 +183,7 @@ public ResponseEntity<?> newWorkflowFromGitURLJson(
190183
"/workflows/{domain}.com/{owner}/{repoName}/tree/{branch}/**",
191184
"/workflows/{domain}.com/{owner}/{repoName}/blob/{branch}/**"
192185
},
193-
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
186+
produces = MediaType.APPLICATION_JSON_VALUE)
194187
public Workflow getWorkflowJson(
195188
@PathVariable("domain") String domain,
196189
@PathVariable("owner") String owner,
@@ -222,7 +215,7 @@ public Workflow getWorkflowJson(
222215
*/
223216
@GetMapping(
224217
value = "/workflows/**/*.git/{branch}/**",
225-
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
218+
produces = MediaType.APPLICATION_JSON_VALUE)
226219
public Workflow getWorkflowJsonGeneric(
227220
@PathVariable("branch") String branch, HttpServletRequest request) {
228221
// The wildcard end of the URL is the path
@@ -248,7 +241,7 @@ public Workflow getWorkflowJsonGeneric(
248241
* @return 303 see other status w/ location header if success, otherwise JSON representation of
249242
* object
250243
*/
251-
@GetMapping(value = "/queue/{queueID}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
244+
@GetMapping(value = "/queue/{queueID}", produces = MediaType.APPLICATION_JSON_VALUE)
252245
public QueuedWorkflow checkQueueJson(
253246
@PathVariable("queueID") String queueID, HttpServletResponse response) {
254247
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: 11 additions & 5 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;
@@ -71,13 +72,16 @@ public void setUp() throws Exception {
7172
File packedWorkflowRdf = new File("src/test/resources/cwl/make_to_cwl/dna.ttl");
7273
Model workflowModel = ModelFactory.createDefaultModel();
7374
workflowModel.read(
74-
new ByteArrayInputStream(readFileToString(packedWorkflowRdf).getBytes()), null, "TURTLE");
75+
new ByteArrayInputStream(
76+
readFileToString(packedWorkflowRdf, StandardCharsets.UTF_8).getBytes()),
77+
null,
78+
"TURTLE");
7579
Dataset workflowDataset = DatasetFactory.create();
7680
workflowDataset.addNamedModel(
7781
"https://w3id.org/cwl/view/git/549c973ccc01781595ce562dea4cedc6c9540fe0/workflows/make-to-cwl/dna.cwl#main",
7882
workflowModel);
7983

80-
Answer queryRdf =
84+
Answer<ResultSet> queryRdf =
8185
new Answer<ResultSet>() {
8286
@Override
8387
public ResultSet answer(InvocationOnMock invocation) throws Throwable {
@@ -89,7 +93,7 @@ public ResultSet answer(InvocationOnMock invocation) throws Throwable {
8993
}
9094
};
9195

92-
Answer apacheLicense =
96+
Answer<ResultSet> apacheLicense =
9397
new Answer<ResultSet>() {
9498
@Override
9599
public ResultSet answer(InvocationOnMock invocationOnMock) throws Throwable {
@@ -247,7 +251,8 @@ public void parseWorkflowWithCwltool() throws Exception {
247251
// Mock CWLTool
248252
CWLTool mockCwlTool = Mockito.mock(CWLTool.class);
249253
File packedWorkflowRdf = new File("src/test/resources/cwl/make_to_cwl/dna.ttl");
250-
when(mockCwlTool.getRDF(any(String.class))).thenReturn(readFileToString(packedWorkflowRdf));
254+
when(mockCwlTool.getRDF(any(String.class)))
255+
.thenReturn(readFileToString(packedWorkflowRdf, StandardCharsets.UTF_8));
251256

252257
// CWLService to test
253258
CWLService cwlService =
@@ -276,7 +281,8 @@ public void parseWorkflowWithCwltool() throws Exception {
276281
assertEquals(1, workflow.getOutputs().size());
277282
assertEquals(3, workflow.getSteps().size());
278283
File expectedDotCode = new File("src/test/resources/cwl/make_to_cwl/visualisation.dot");
279-
assertEquals(readFileToString(expectedDotCode), workflow.getVisualisationDot());
284+
assertEquals(
285+
readFileToString(expectedDotCode, StandardCharsets.UTF_8), workflow.getVisualisationDot());
280286
assertEquals("https://spdx.org/licenses/Apache-2.0", workflow.getLicenseLink());
281287
assertEquals("Apache License 2.0", workflow.getLicenseName());
282288
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.io.File;
2525
import java.io.StringWriter;
26+
import java.nio.charset.StandardCharsets;
2627
import java.util.HashMap;
2728
import java.util.Map;
2829
import org.apache.commons.io.FileUtils;
@@ -102,6 +103,7 @@ public void writeGraph() throws Exception {
102103
dotWriter.writeGraph(testWorkflow);
103104

104105
File expectedDot = new File("src/test/resources/graphviz/testWorkflow.dot");
105-
assertEquals(FileUtils.readFileToString(expectedDot), dotSource.toString());
106+
assertEquals(
107+
FileUtils.readFileToString(expectedDot, StandardCharsets.UTF_8), dotSource.toString());
106108
}
107109
}

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)