diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/adapter/out/cosys/CosysAdapter.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/adapter/out/cosys/CosysAdapter.java index aeb070e1..95e8d4b3 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/adapter/out/cosys/CosysAdapter.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/adapter/out/cosys/CosysAdapter.java @@ -18,6 +18,7 @@ public class CosysAdapter implements GenerateDocumentOutPort { public static final String DATA_FILE_NAME = "data"; public static final String MERGE_FILE_NAME = "merge"; + public static final String DOC_GEN_EXCEPTION_MESSAGE = "Document could not be created."; private final CosysConfiguration configuration; private final GenerationApi generationApi; @@ -47,15 +48,15 @@ public Mono generateCosysDocument(final GenerateDocument generateDocumen null) .onStatus(HttpStatusCode::is5xxServerError, response -> response.bodyToMono(byte[].class) - .flatMap(body -> Mono.error(new CosysException("Document could not be created.")))) + .flatMap(body -> Mono.error(new CosysException(DOC_GEN_EXCEPTION_MESSAGE)))) .onStatus(HttpStatusCode::is4xxClientError, response -> response.bodyToMono(byte[].class) - .flatMap(body -> Mono.error(new CosysException("Document could not be created.")))) + .flatMap(body -> Mono.error(new CosysException(DOC_GEN_EXCEPTION_MESSAGE)))) .bodyToMono(byte[].class); } catch (final IOException ex) { - log.error("Document could not be created.", ex); - throw new CosysException("Document could not be created."); + log.error(DOC_GEN_EXCEPTION_MESSAGE, ex); + throw new CosysException(DOC_GEN_EXCEPTION_MESSAGE, ex); } } diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/adapter/out/cosys/FileUtils.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/adapter/out/cosys/FileUtils.java index adac24da..566a4f76 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/adapter/out/cosys/FileUtils.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/adapter/out/cosys/FileUtils.java @@ -5,7 +5,9 @@ import java.nio.file.Files; import java.nio.file.Path; -public class FileUtils { +public final class FileUtils { + private FileUtils() { + } public static File createFile(final String name, final byte[] content) throws IOException { final Path tempFile = Files.createTempFile(name, ".json"); diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/adapter/out/s3/S3Adapter.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/adapter/out/s3/S3Adapter.java index c67d82e0..3a1ffdb6 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/adapter/out/s3/S3Adapter.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/adapter/out/s3/S3Adapter.java @@ -34,9 +34,10 @@ public void saveDocumentInStorage( } private void validateFileSize(final byte[] data) { - if (!fileValidationService.isValidFileSize(data)) + if (!fileValidationService.isValidFileSize(data)) { throw new FileSizeValidationException( String.format("Invalid file size %d MB. Allowed are %d MB.", DataSize.ofBytes(data.length).toMegabytes(), fileValidationService.getMaxFileSize().toMegabytes())); + } } } diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/application/port/in/CreateDocumentInPort.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/application/port/in/CreateDocumentInPort.java index 5e2a48fa..faaadbeb 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/application/port/in/CreateDocumentInPort.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/application/port/in/CreateDocumentInPort.java @@ -9,6 +9,6 @@ public interface CreateDocumentInPort { void createDocument( - @Valid final GenerateDocument generateDocument, - @NotBlank final String filePath) throws CosysException, DocumentStorageException; + @Valid GenerateDocument generateDocument, + @NotBlank String filePath) throws CosysException, DocumentStorageException; } diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/application/port/out/GenerateDocumentOutPort.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/application/port/out/GenerateDocumentOutPort.java index 7aa6feb0..5fab2d13 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/application/port/out/GenerateDocumentOutPort.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/application/port/out/GenerateDocumentOutPort.java @@ -6,6 +6,6 @@ public interface GenerateDocumentOutPort { - Mono generateCosysDocument(final GenerateDocument generateDocument) throws CosysException; + Mono generateCosysDocument(GenerateDocument generateDocument) throws CosysException; } diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/application/port/out/SaveFileToStorageOutPort.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/application/port/out/SaveFileToStorageOutPort.java index 3f38eb9d..d17cc71d 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/application/port/out/SaveFileToStorageOutPort.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/application/port/out/SaveFileToStorageOutPort.java @@ -4,6 +4,6 @@ public interface SaveFileToStorageOutPort { void saveDocumentInStorage( - final String filePath, - final byte[] data) throws DocumentStorageException; + String filePath, + byte[] data) throws DocumentStorageException; } diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/domain/exception/CosysException.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/domain/exception/CosysException.java index 59a93cb8..4e083e40 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/domain/exception/CosysException.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/main/java/de/muenchen/refarch/integration/cosys/domain/exception/CosysException.java @@ -1,7 +1,12 @@ package de.muenchen.refarch.integration.cosys.domain.exception; +@SuppressWarnings("PMD.MissingSerialVersionUID") public class CosysException extends Exception { public CosysException(final String message) { super(message); } + + public CosysException(final String message, final Throwable cause) { + super(message, cause); + } } diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/test/java/de/muenchen/refarch/integration/cosys/adapter/out/cosys/CosysAdapterTest.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/test/java/de/muenchen/refarch/integration/cosys/adapter/out/cosys/CosysAdapterTest.java index 5c9d8d7d..54ff9e46 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/test/java/de/muenchen/refarch/integration/cosys/adapter/out/cosys/CosysAdapterTest.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/test/java/de/muenchen/refarch/integration/cosys/adapter/out/cosys/CosysAdapterTest.java @@ -12,7 +12,6 @@ import de.muenchen.refarch.integration.cosys.domain.model.GenerateDocument; import java.io.File; import java.io.IOException; -import lombok.val; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -40,11 +39,11 @@ void setUp() { } @Test - void testGenerateCosysDocument_Success() throws IOException, CosysException { + void testGenerateCosysDocumentSuccess() throws IOException, CosysException { // given - val generateDocument = generateDocument(); - val response = "Response".getBytes(); - val responseSpecMock = Mockito.mock(WebClient.ResponseSpec.class); + final GenerateDocument generateDocument = generateDocument(); + final byte[] response = "Response".getBytes(); + final WebClient.ResponseSpec responseSpecMock = Mockito.mock(WebClient.ResponseSpec.class); when(responseSpecMock.onStatus(any(), any())).thenReturn(responseSpecMock); when(responseSpecMock.bodyToMono(byte[].class)).thenReturn(Mono.just(response)); final ArgumentCaptor dataFileCaptor = ArgumentCaptor.forClass(File.class); diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/test/java/de/muenchen/refarch/integration/cosys/adapter/out/s3/S3AdapterTest.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/test/java/de/muenchen/refarch/integration/cosys/adapter/out/s3/S3AdapterTest.java index a5c52fe7..af079c6d 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/test/java/de/muenchen/refarch/integration/cosys/adapter/out/s3/S3AdapterTest.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/test/java/de/muenchen/refarch/integration/cosys/adapter/out/s3/S3AdapterTest.java @@ -52,18 +52,18 @@ void saveDocumentInStorageWithThrowsDocumentStorageException() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { doThrow(new DocumentStorageException("DocumentStorageClientErrorException", new Exception())).when(documentStorageFileRepository) .saveFile(anyString(), any(), eq(1)); - DocumentStorageException documentStorageException = assertThrows(DocumentStorageException.class, + final DocumentStorageException documentStorageException = assertThrows(DocumentStorageException.class, () -> s3Adapter.saveDocumentInStorage("filePath.txt", DATA_AS_BYTE_ARRAY)); - String expectedMessage = "Document could not be saved."; - String actualMessage = documentStorageException.getMessage(); + final String expectedMessage = "Document could not be saved."; + final String actualMessage = documentStorageException.getMessage(); assertEquals(expectedMessage, actualMessage); } @Test void testSaveDocumentInStorageThrowsBpmnErrorForInvalidFileSize() { - String expectedMessage = String.format("Invalid file size %d MB. Allowed are %d MB.", DataSize.ofBytes(TOO_LARGE_FILE.length).toMegabytes(), + final String expectedMessage = String.format("Invalid file size %d MB. Allowed are %d MB.", DataSize.ofBytes(TOO_LARGE_FILE.length).toMegabytes(), ALLOWED_FILE_SIZE.toMegabytes()); assertThatThrownBy(() -> s3Adapter.saveDocumentInStorage("filePath.txt", TOO_LARGE_FILE)) diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/test/java/de/muenchen/refarch/integration/cosys/application/usecase/CreateDocumentUseCaseTest.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/test/java/de/muenchen/refarch/integration/cosys/application/usecase/CreateDocumentUseCaseTest.java index 9e57fdfd..73d2db05 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/test/java/de/muenchen/refarch/integration/cosys/application/usecase/CreateDocumentUseCaseTest.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-core/src/test/java/de/muenchen/refarch/integration/cosys/application/usecase/CreateDocumentUseCaseTest.java @@ -24,7 +24,7 @@ class CreateDocumentUseCaseTest { private final GenerateDocument generateDocument = new GenerateDocument("Client", "Role", "guid", new ObjectMapper().readTree("{\"key1\":\"value\"}")); - CreateDocumentUseCaseTest() throws JsonProcessingException { + protected CreateDocumentUseCaseTest() throws JsonProcessingException { } @Test diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-example/src/main/java/de/muenchen/refarch/integration/cosys/example/CosysExampleApplication.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-example/src/main/java/de/muenchen/refarch/integration/cosys/example/CosysExampleApplication.java index 040470d6..19fa1351 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-example/src/main/java/de/muenchen/refarch/integration/cosys/example/CosysExampleApplication.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-example/src/main/java/de/muenchen/refarch/integration/cosys/example/CosysExampleApplication.java @@ -4,6 +4,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication() +@SuppressWarnings("PMD.UseUtilityClass") public class CosysExampleApplication { public static void main(final String[] args) { diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-example/src/main/java/de/muenchen/refarch/integration/cosys/example/NoSecurityConfiguration.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-example/src/main/java/de/muenchen/refarch/integration/cosys/example/NoSecurityConfiguration.java index 25792181..1c7712b1 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-example/src/main/java/de/muenchen/refarch/integration/cosys/example/NoSecurityConfiguration.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-example/src/main/java/de/muenchen/refarch/integration/cosys/example/NoSecurityConfiguration.java @@ -13,7 +13,7 @@ public class NoSecurityConfiguration { @Bean - public SecurityFilterChain mainSecurityFilterChain(HttpSecurity http) throws Exception { + public SecurityFilterChain mainSecurityFilterChain(final HttpSecurity http) throws Exception { // @formatter:off http .headers(httpSecurityHeadersConfigurer -> httpSecurityHeadersConfigurer.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)) diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-example/src/main/java/de/muenchen/refarch/integration/cosys/example/api/controller/ExampleController.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-example/src/main/java/de/muenchen/refarch/integration/cosys/example/api/controller/ExampleController.java index 4aad7899..92d82b46 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-example/src/main/java/de/muenchen/refarch/integration/cosys/example/api/controller/ExampleController.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-example/src/main/java/de/muenchen/refarch/integration/cosys/example/api/controller/ExampleController.java @@ -18,7 +18,7 @@ public class ExampleController { private final GenerateDocumentOutPort generateDocumentOutPort; - @PostMapping(value = "/test/document") + @PostMapping("/test/document") public ResponseEntity testCreateCosysDocument() throws CosysException { final byte[] file = this.generateDocumentOutPort.generateCosysDocument(this.generateDocument()).block(); return ResponseEntity.ok(file); diff --git a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-starter/src/main/java/de/muenchen/refarch/integration/cosys/configuration/CosysAutoConfiguration.java b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-starter/src/main/java/de/muenchen/refarch/integration/cosys/configuration/CosysAutoConfiguration.java index 7508d612..8feee2e1 100644 --- a/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-starter/src/main/java/de/muenchen/refarch/integration/cosys/configuration/CosysAutoConfiguration.java +++ b/refarch-integrations/refarch-cosys-integration/refarch-cosys-integration-starter/src/main/java/de/muenchen/refarch/integration/cosys/configuration/CosysAutoConfiguration.java @@ -71,7 +71,7 @@ public ApiClient cosysApiClient(final ClientRegistrationRepository clientRegistr private WebClient webClient( final ClientRegistrationRepository clientRegistrationRepository, final OAuth2AuthorizedClientService authorizedClientService) { - final var oauth = new ServletOAuth2AuthorizedClientExchangeFilterFunction( + final ServletOAuth2AuthorizedClientExchangeFilterFunction oauth = new ServletOAuth2AuthorizedClientExchangeFilterFunction( new AuthorizedClientServiceOAuth2AuthorizedClientManager( clientRegistrationRepository, authorizedClientService)); oauth.setDefaultClientRegistrationId("cosys");