Skip to content

Commit e49c905

Browse files
committed
MODWRKFLOW-54: Address SonarQube reported problems.
- java:S5738: Deprecation of `JsonSerializer`. - java:S1130: Remove unnecessary exceptions. - java:S1488: Immediately return when using builder for `ObjectMapper` creating bean. - java:S1068: Remove unused constant.
1 parent 07f11a7 commit e49c905

8 files changed

Lines changed: 24 additions & 43 deletions

File tree

service/src/main/java/org/folio/rest/workflow/config/KafkaProducerConfig.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.HashMap;
44
import java.util.Map;
5-
65
import org.apache.kafka.clients.producer.ProducerConfig;
76
import org.apache.kafka.common.serialization.StringSerializer;
87
import org.folio.spring.messaging.model.Event;
@@ -13,7 +12,7 @@
1312
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
1413
import org.springframework.kafka.core.KafkaTemplate;
1514
import org.springframework.kafka.core.ProducerFactory;
16-
import org.springframework.kafka.support.serializer.JsonSerializer;
15+
import org.springframework.kafka.support.serializer.JacksonJsonSerializer;
1716

1817
@Configuration
1918
@Profile({ "messaging", "!test" })
@@ -27,7 +26,7 @@ public ProducerFactory<String, Event> eventProducerFactory() {
2726
Map<String, Object> configProps = new HashMap<>();
2827
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
2928
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
30-
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
29+
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JacksonJsonSerializer.class);
3130

3231
return new DefaultKafkaProducerFactory<>(configProps);
3332
}

service/src/main/java/org/folio/rest/workflow/controller/WorkflowController.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import java.net.URI;
55
import java.net.URISyntaxException;
66
import lombok.extern.slf4j.Slf4j;
7-
import org.apache.commons.compress.archivers.ArchiveException;
8-
import org.apache.commons.compress.compressors.CompressorException;
97
import org.folio.rest.workflow.exception.WorkflowEngineServiceException;
108
import org.folio.rest.workflow.exception.WorkflowImportException;
119
import org.folio.rest.workflow.exception.WorkflowNotFoundException;
@@ -56,7 +54,7 @@ public ResponseEntity<Object> importWorkflow(
5654
@RequestPart(name = "file") MultipartFile fwz,
5755
@TenantHeader String tenant,
5856
@TokenHeader String token
59-
) throws URISyntaxException, IOException, CompressorException, ArchiveException, WorkflowImportException {
57+
) throws URISyntaxException, IOException, WorkflowImportException {
6058

6159
log.debug("Importing FWZ");
6260

service/src/main/java/org/folio/rest/workflow/service/OkapiDiscoveryService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public List<Action> getActionsByTenant(String tenant) throws IOException {
6262
return actions;
6363
}
6464

65-
public List<Action> getActionsByTenantAndModuleId(String tenant, String id) throws IOException {
65+
public List<Action> getActionsByTenantAndModuleId(String tenant, String id) {
6666
Map<String, List<Handler>> handlerMap = getHandlers(tenant, id);
6767
List<Action> actions = new ArrayList<>();
6868
for (Map.Entry<String, List<Handler>> entry : handlerMap.entrySet()) {
@@ -73,7 +73,7 @@ public List<Action> getActionsByTenantAndModuleId(String tenant, String id) thro
7373
return actions;
7474
}
7575

76-
public Map<String, List<Handler>> getHandlers(String tenant, String id) throws IOException {
76+
public Map<String, List<Handler>> getHandlers(String tenant, String id) {
7777
JsonNode moduleDescriptorNode = getModuleDescriptor(tenant, id);
7878

7979
Map<String, List<Handler>> handlerMap = new HashMap<>();

service/src/main/java/org/folio/rest/workflow/service/WorkflowImportService.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@
3131
import java.util.Map;
3232
import java.util.Map.Entry;
3333
import lombok.extern.slf4j.Slf4j;
34-
import org.apache.commons.compress.archivers.ArchiveException;
3534
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
3635
import org.apache.commons.compress.archivers.tar.TarFile;
3736
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
3837
import org.apache.commons.compress.archivers.zip.ZipFile;
39-
import org.apache.commons.compress.compressors.CompressorException;
4038
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
4139
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
4240
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
@@ -90,12 +88,10 @@ public WorkflowImportService(ObjectMapper objectMapper, NodeRepo nodeRepo, Trigg
9088
*
9189
* @return The created Workflow.
9290
*
93-
* @throws ArchiveException On archive error.
94-
* @throws CompressorException On compressor error.
9591
* @throws IOException On error reading the file stream, extracting the JSON, or other such errors.
9692
* @throws WorkflowImportException On import failure.
9793
*/
98-
public Workflow importFile(Resource fwz) throws IOException, CompressorException, ArchiveException, WorkflowImportException {
94+
public Workflow importFile(Resource fwz) throws IOException, WorkflowImportException {
9995
CompressFileFormat format = CompressFileMagic.detectFormat(fwz.getInputStream());
10096

10197
if (format != null) {
@@ -210,10 +206,8 @@ private boolean collapseNodeScriptsContinue(Entry<String, JsonNode> entry) throw
210206
*
211207
* @param nodes The Nodes to iterate over.
212208
* @param expanded An array of IDs of nodes representing the top-down order of creation.
213-
*
214-
* @throws JsonProcessingException On JSON parse failure.
215209
*/
216-
private void createNodes(Map<String, JsonNode> nodes, List<String> expanded) throws JsonProcessingException {
210+
private void createNodes(Map<String, JsonNode> nodes, List<String> expanded) {
217211
for (String uuid : expanded) {
218212
Node node = objectMapper.readValue(nodes.get(uuid).toString(), Node.class);
219213
nodeRepo.save(node);
@@ -224,10 +218,8 @@ private void createNodes(Map<String, JsonNode> nodes, List<String> expanded) thr
224218
* Create the Triggers in the database.
225219
*
226220
* @param triggers The Triggers to iterate over.
227-
*
228-
* @throws JsonProcessingException On JSON parse failure.
229221
*/
230-
private void createTriggers(Map<String, JsonNode> triggers) throws JsonProcessingException {
222+
private void createTriggers(Map<String, JsonNode> triggers) {
231223
for (JsonNode triggerNode : triggers.values()) {
232224
Trigger trigger = objectMapper.readValue(triggerNode.toString(), Trigger.class);
233225
triggerRepo.save(trigger);
@@ -240,10 +232,8 @@ private void createTriggers(Map<String, JsonNode> triggers) throws JsonProcessin
240232
* @param workflowJson The Workflow JSON to save.
241233
*
242234
* @return The created Workflow.
243-
*
244-
* @throws JsonProcessingException On JSON parse failure.
245235
*/
246-
private Workflow createWorkflow(JsonNode workflowJson) throws JsonProcessingException {
236+
private Workflow createWorkflow(JsonNode workflowJson) {
247237
Workflow workflow = objectMapper.readValue(workflowJson.toString(), Workflow.class);
248238
return workflowRepo.save(workflow);
249239
}

service/src/test/java/org/folio/rest/workflow/config/JunitHelperWebMvcConfig.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ public class JunitHelperWebMvcConfig {
1616

1717
@Bean
1818
ObjectMapper objectMapper() {
19-
final ObjectMapper mapper = JsonMapper
19+
return JsonMapper
2020
.builder()
2121
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
2222
.build();
23-
24-
return mapper;
2523
}
2624
}

service/src/test/java/org/folio/rest/workflow/controller/EventControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static Stream<Arguments> uploadRejected() {
121121
arguments("diku", "a", join(separator,"..", "..", "..", "..", "x.txt")));
122122
}
123123

124-
MockMultipartHttpServletRequestBuilder upload(String tenant, String dir, String file) throws Exception {
124+
MockMultipartHttpServletRequestBuilder upload(String tenant, String dir, String file) {
125125
var sampleFile = new MockMultipartFile(
126126
"file",
127127
file,

service/src/test/java/org/folio/rest/workflow/controller/advice/WorkflowControllerAdviceTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ class WorkflowControllerAdviceTest {
4444

4545
private static final WorkflowEngineServiceException WES_EXC = new WorkflowEngineServiceException(VALUE);
4646

47-
private static final WorkflowImportException WI_EXC = new WorkflowImportException(VALUE);
48-
4947
private static final WorkflowImportAlreadyImported WIAI_EXC = new WorkflowImportAlreadyImported(VALUE);
5048

5149
private static final WorkflowImportInvalidOrMissingProperty WIIOMP_EXC = new WorkflowImportInvalidOrMissingProperty(VALUE, VALUE);

service/src/test/java/org/folio/rest/workflow/service/WorkflowImportServiceTest.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import static org.mockito.Mockito.when;
99

1010
import java.io.IOException;
11-
import org.apache.commons.compress.archivers.ArchiveException;
12-
import org.apache.commons.compress.compressors.CompressorException;
1311
import org.folio.rest.workflow.config.JunitHelperWebMvcConfig;
1412
import org.folio.rest.workflow.exception.WorkflowImportAlreadyImported;
1513
import org.folio.rest.workflow.exception.WorkflowImportException;
@@ -257,91 +255,91 @@ void importFileThrowsExceptionWithMisWorkflowTest() {
257255
}
258256

259257
@Test
260-
void importFileWorksForBzip2Test() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
258+
void importFileWorksForBzip2Test() throws IOException, WorkflowImportException {
261259
Workflow imported = workflowImportService.importFile(fwzBzip2Resource);
262260
assertNotNull(imported);
263261
assertEquals(workflow.getId(), imported.getId());
264262
}
265263

266264
@Test
267-
void importFileWorksForBzip2AsBz2Test() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
265+
void importFileWorksForBzip2AsBz2Test() throws IOException, WorkflowImportException {
268266
Workflow imported = workflowImportService.importFile(fwzBzip2AsBz2Resource);
269267
assertNotNull(imported);
270268
assertEquals(workflow.getId(), imported.getId());
271269
}
272270

273271
@Test
274-
void importFileWorksForGzipTest() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
272+
void importFileWorksForGzipTest() throws IOException, WorkflowImportException {
275273
Workflow imported = workflowImportService.importFile(fwzGzipResource);
276274
assertNotNull(imported);
277275
assertEquals(workflow.getId(), imported.getId());
278276
}
279277

280278
@Test
281-
void importFileWorksForGzipAsGzTest() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
279+
void importFileWorksForGzipAsGzTest() throws IOException, WorkflowImportException {
282280
Workflow imported = workflowImportService.importFile(fwzGzipAsGzResource);
283281
assertNotNull(imported);
284282
assertEquals(workflow.getId(), imported.getId());
285283
}
286284

287285
@Test
288-
void importFileWorksForGzipWithBadVersionTest() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
286+
void importFileWorksForGzipWithBadVersionTest() throws IOException, WorkflowImportException {
289287
Workflow imported = workflowImportService.importFile(fwzGzipBadVersionResource);
290288
assertNotNull(imported);
291289
assertEquals(workflow.getId(), imported.getId());
292290
}
293291

294292
@Test
295-
void importFileWorksForGzipWithJavaTest() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
293+
void importFileWorksForGzipWithJavaTest() throws IOException, WorkflowImportException {
296294
Workflow imported = workflowImportService.importFile(fwzGzipJavaResource);
297295
assertNotNull(imported);
298296
assertEquals(workflow.getId(), imported.getId());
299297
}
300298

301299
@Test
302-
void importFileWorksForGzipWithOddFilesTest() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
300+
void importFileWorksForGzipWithOddFilesTest() throws IOException, WorkflowImportException {
303301
Workflow imported = workflowImportService.importFile(fwzGzipOddFilesResource);
304302
assertNotNull(imported);
305303
assertEquals(workflow.getId(), imported.getId());
306304
}
307305

308306
@Test
309-
void importFileWorksForGzipWithPythonTest() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
307+
void importFileWorksForGzipWithPythonTest() throws IOException, WorkflowImportException {
310308
Workflow imported = workflowImportService.importFile(fwzGzipPythonResource);
311309
assertNotNull(imported);
312310
assertEquals(workflow.getId(), imported.getId());
313311
}
314312

315313
@Test
316-
void importFileWorksForGzipWithRubyTest() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
314+
void importFileWorksForGzipWithRubyTest() throws IOException, WorkflowImportException {
317315
Workflow imported = workflowImportService.importFile(fwzGzipRubyResource);
318316
assertNotNull(imported);
319317
assertEquals(workflow.getId(), imported.getId());
320318
}
321319

322320
@Test
323-
void importFileWorksForGzipWithMissingVersionTest() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
321+
void importFileWorksForGzipWithMissingVersionTest() throws IOException, WorkflowImportException {
324322
Workflow imported = workflowImportService.importFile(fwzGzipMisVersionResource);
325323
assertNotNull(imported);
326324
assertEquals(workflow.getId(), imported.getId());
327325
}
328326

329327
@Test
330-
void importFileWorksForGzipWithUnknownVersionTest() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
328+
void importFileWorksForGzipWithUnknownVersionTest() throws IOException, WorkflowImportException {
331329
Workflow imported = workflowImportService.importFile(fwzGzipUnVerResource);
332330
assertNotNull(imported);
333331
assertEquals(workflow.getId(), imported.getId());
334332
}
335333

336334
@Test
337-
void importFileWorksForZipTest() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
335+
void importFileWorksForZipTest() throws IOException, WorkflowImportException {
338336
Workflow imported = workflowImportService.importFile(fwzZipResource);
339337
assertNotNull(imported);
340338
assertEquals(workflow.getId(), imported.getId());
341339
}
342340

343341
@Test
344-
void importFileWorksForZipAsZipTest() throws IOException, CompressorException, ArchiveException, WorkflowImportException {
342+
void importFileWorksForZipAsZipTest() throws IOException, WorkflowImportException {
345343
Workflow imported = workflowImportService.importFile(fwzZipAsZipResource);
346344
assertNotNull(imported);
347345
assertEquals(workflow.getId(), imported.getId());

0 commit comments

Comments
 (0)