From ce13f94db71ab69666d896c0344b9eac4f784518 Mon Sep 17 00:00:00 2001 From: Simon Hirtreiter <14137977+simonhir@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:10:11 +0100 Subject: [PATCH] Feature/pmd integrations (#208) * :heavy_plus_sign: gateway add pmd * :heavy_plus_sign: gateway add spotbugs * :rotating_light: gateway fix pmd and spotbugs findings * :rotating_light: gateway fix pmd findings * :construction_worker: ci whitelist spotbugs license * :heavy_plus_sign: integrations add pmd and spotbugs * :rotating_light: integrations fix pmd and spotbugs findings * :rotating_light: s3 fix pmd and spotbugs findings * :rotating_light: mail fix pmd findings * :bug: s3 integration fix imports * :art: integrations format with spotless * :rotating_light: s3 fix pmd warnings * :rotating_light: mail fix pmd warnings * :rotating_light: dms fix pmd warnings * :rotating_light: dms fix pmd warnings * :rotating_light: dms fix pmd warnings * :rotating_light: dms fix pmd warnings * :rotating_light: dms fix pmd warnings * :art: dms spotless format * :heavy_minus_sign: integrations rm spotbugs * :rotating_light: dms fix pmd warnings * :arrow_up: integrations use pmd module and pmd 3.26 * :arrow_up: integrations pmd use new junit warning names * :rotating_light: integrations suppress instead of exclude warnings * :arrow_up: integrations use pmd conf v1.0.1 * :recycle: pom reorder pmd module * :recycle: s3 refactor test instead suppressing * :recycle: s3 use import for assert methods * :recycle: integrations supress serial for exceptions * :recycle: dms use english and use assert instead of suppressing for test * :fire: dms rm unnecessary supress * :recycle: dms use assert instead of suppressing for test * :fire: dms rm unnecessary supress * :pencil2: dms fix class name typo * :recycle: integrations supress serial * :art: format spotless * :recycle: dms refactor exception encapsulation * :green_heart: codeql disable js * :recycle: dms refactor exception encapsulation fix test --------- Co-authored-by: Tobias Stadler <28538704+devtobi@users.noreply.github.com> --- .github/workflows/codeql.yaml | 2 +- refarch-gateway/pom.xml | 2 +- refarch-integrations/pom.xml | 39 ++++ .../adapter/out/fabasoft/DMSErrorHandler.java | 2 +- .../adapter/out/fabasoft/DMSObjectClass.java | 1 + .../adapter/out/fabasoft/DMSStatusCode.java | 2 +- .../adapter/out/fabasoft/FabasoftAdapter.java | 42 ++-- .../dms/adapter/out/s3/S3Adapter.java | 35 +-- .../port/in/CancelObjectInPort.java | 2 +- .../port/in/CreateDocumentInPort.java | 4 +- .../application/port/in/CreateFileInPort.java | 2 +- .../port/in/CreateProcedureInPort.java | 3 +- .../port/in/DepositObjectInPort.java | 2 +- .../port/in/ReadMetadataInPort.java | 2 +- .../application/port/in/SearchFileInPort.java | 1 + .../port/out/ListContentOutPort.java | 2 +- .../port/out/ReadContentOutPort.java | 2 +- .../port/out/ReadMetadataOutPort.java | 4 +- .../port/out/SearchFileOutPort.java | 1 + .../usecase/CreateDocumentUseCase.java | 4 +- .../usecase/CreateProcedureUseCase.java | 1 + .../usecase/DepositObjectUseCase.java | 2 +- .../usecase/ReadContentUseCase.java | 4 +- .../usecase/ReadMetadataUseCase.java | 4 +- .../usecase/SearchFileUseCase.java | 4 +- .../usecase/SearchSubjectAreaUseCase.java | 4 +- .../usecase/UpdateDocumentUseCase.java | 2 +- .../dms/domain/exception/DmsException.java | 1 + .../dms/domain/model/ObjectType.java | 1 + .../dms/domain/model/Procedure.java | 2 +- .../out/fabasoft/DMSErrorHandlerTest.java | 27 +-- .../out/fabasoft/FabasoftAdapterTest.java | 217 ++++++++++-------- .../dms/adapter/out/s3/S3AdapterTest.java | 163 ++++--------- .../usecase/CancelObjectUseCaseTest.java | 1 - .../usecase/CreateDocumentUseCaseTest.java | 15 +- .../usecase/DepositObjectUseCaseTest.java | 1 - .../usecase/ReadContentUseCaseTest.java | 4 +- .../usecase/ReadMetadataUseCaseTest.java | 20 +- .../usecase/SearchFileUseCaseTest.java | 1 - .../usecase/SearchSubjectAreaUseCaseTest.java | 1 - .../usecase/UpdateDocumentUseCaseTest.java | 12 +- .../mock/service/FabasoftMockApplication.java | 1 + .../mock/service/cases/CancelObjectCase.java | 5 +- .../mock/service/cases/CreateFileCase.java | 5 +- .../cases/CreateIncomingDocumentCase.java | 5 +- .../cases/CreateInternalDocumentCase.java | 5 +- .../cases/CreateOutgoingDocumentCase.java | 5 +- .../service/cases/CreateProcedureCase.java | 5 +- .../mock/service/cases/DMSObjectClass.java | 1 + .../mock/service/cases/DepositObjectCase.java | 5 +- .../mock/service/cases/MockInitializer.java | 2 +- .../mock/service/cases/ReadContentCase.java | 13 +- .../cases/ReadContentObjectMetaDataCase.java | 7 +- .../service/cases/ReadMetadataObjectCase.java | 5 +- .../mock/service/cases/SearchFileCase.java | 9 +- .../service/cases/SearchSubjectAreaCase.java | 9 +- .../cases/UpdateIncomingDocumentCase.java | 5 +- .../cases/UpdateInternalDocumentCase.java | 5 +- .../cases/UpdateOutgoingDocumentCase.java | 5 +- .../fabasoft/mock/service/ExampleTest.java | 11 +- ...actory.java => FabasoftClientFactory.java} | 6 +- .../dms/fabasoft/mock/SoapObjectMatcher.java | 6 +- .../fabasoft/mock/WiremockWsdlUtility.java | 45 ++-- .../dms/fabasoft/mock/ExampleTest.java | 12 +- .../configuration/DmsAutoConfiguration.java | 14 +- .../adapter/out/mail/MailAdapter.java | 4 +- .../integration/adapter/out/s3/S3Adapter.java | 10 +- .../application/port/in/SendMailInPort.java | 4 +- .../port/out/LoadMailAttachmentOutPort.java | 2 +- .../application/usecase/SendMailUseCase.java | 20 +- .../domain/exception/LoadAttachmentError.java | 7 +- .../domain/exception/TemplateError.java | 7 +- .../domain/model/TemplateMail.java | 5 +- .../integration/domain/model/TextMail.java | 4 +- .../adapter/out/mail/MailAdapterTest.java | 4 +- .../adapter/out/s3/S3AdapterTest.java | 4 +- .../usecase/SendMailUseCaseTest.java | 14 +- .../EmailJavaExampleApplication.java | 10 +- ...stService.java => ExampleMailService.java} | 10 +- .../EmailRestExampleApplication.java | 10 +- ...stService.java => ExampleMailService.java} | 10 +- .../refarch/email/impl/EmailApiImpl.java | 26 +-- .../refarch/email/EmailApiImplTest.java | 125 +++++----- .../configuration/EmailAutoConfiguration.java | 2 +- .../domain/model/SupportedFileExtensions.java | 1 + .../DocumentStorageClientErrorException.java | 2 +- .../exception/DocumentStorageException.java | 2 +- .../DocumentStorageServerErrorException.java | 2 +- .../FileSizeValidationException.java | 1 + .../FileTypeValidationException.java | 1 + .../client/exception/NoFileTypeException.java | 6 +- .../exception/PropertyNotSetException.java | 2 +- .../DocumentStorageFileRepository.java | 2 +- .../transfer/S3FileTransferRepository.java | 76 ++---- .../client/service/FileValidationService.java | 24 +- .../S3FileTransferRepositoryTest.java | 79 +++---- .../service/FileValidationServiceTest.java | 20 +- .../s3/adapter/out/s3/S3Adapter.java | 24 +- .../port/in/FileOperationsInPort.java | 6 +- .../in/FileOperationsPresignedUrlInPort.java | 11 +- .../s3/application/port/out/S3OutPort.java | 12 +- .../usecase/CreatePresignedUrlsUseCase.java | 2 +- .../FileOperationsPresignedUrlUseCase.java | 17 +- .../usecase/FileOperationsUseCase.java | 2 +- .../exception/FileExistenceException.java | 1 + .../exception/FileSystemAccessException.java | 1 + .../s3/domain/model/FileSizesInFolder.java | 9 + .../s3/domain/model/FilesInFolder.java | 9 + .../s3/adapter/out/s3/S3AdapterTest.java | 27 +-- ...FileOperationsPresignedUrlUseCaseTest.java | 172 +++++++------- .../usecase/FolderOperationsUseCaseTest.java | 4 +- .../S3IntegrationClientAutoConfiguration.java | 1 + .../S3IntegrationClientProperties.java | 4 +- .../DocumentStorageFileJavaRepository.java | 2 +- .../DocumentStorageFolderJavaRepository.java | 7 +- .../PresignedUrlJavaRepository.java | 8 +- .../S3IntegrationClientAutoConfiguration.java | 9 +- .../S3IntegrationClientProperties.java | 4 +- .../PresignedUrlRestRepository.java | 4 +- ...DocumentStorageFileRestRepositoryTest.java | 77 +++---- ...cumentStorageFolderRestRepositoryTest.java | 43 ++-- .../PresignedUrlRestRepositoryTest.java | 137 ++++++----- .../s3/adapter/in/rest/FileController.java | 24 +- .../s3/adapter/in/rest/FolderController.java | 6 +- .../adapter/in/rest/RestExceptionMapping.java | 2 +- .../in/rest/mapper/FileDataMapper.java | 2 +- .../in/rest/mapper/FilesInFolderMapper.java | 2 +- .../in/rest/mapper/PresignedUrlMapper.java | 4 +- .../s3/S3IntegrationApplication.java | 4 +- .../CacheControlConfiguration.java | 8 +- .../JwtUserInfoAuthenticationConverter.java | 4 +- .../NoSecurityConfiguration.java | 2 +- .../configuration/SecurityConfiguration.java | 2 +- .../UserInfoAuthoritiesService.java | 24 +- .../configuration/nfcconverter/NfcHelper.java | 18 +- .../configuration/nfcconverter/NfcReader.java | 8 +- .../nfcconverter/NfcRequest.java | 12 +- .../nfcconverter/NfcRequestFilter.java | 2 +- .../nfcconverter/NfcServletInputStream.java | 1 + .../integration/s3/security/AuthUtils.java | 4 +- .../RequestResponseLoggingFilter.java | 6 +- .../nfcconverter/NfcConverterTest.java | 22 +- .../nfcconverter/NfcHelperTest.java | 22 +- .../S3IntegrationAutoConfiguration.java | 17 +- .../properties/S3IntegrationProperties.java | 2 +- 145 files changed, 1056 insertions(+), 1063 deletions(-) rename refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/{FabasoftClienFactory.java => FabasoftClientFactory.java} (78%) rename refarch-integrations/refarch-email-integration/refarch-email-integration-java-example/src/main/java/de/muenchen/refarch/email/integration/{TestService.java => ExampleMailService.java} (83%) rename refarch-integrations/refarch-email-integration/refarch-email-integration-rest-example/src/main/java/de/muenchen/refarch/email/integration/{TestService.java => ExampleMailService.java} (83%) diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml index 06e076db..0a927b42 100644 --- a/.github/workflows/codeql.yaml +++ b/.github/workflows/codeql.yaml @@ -12,5 +12,5 @@ jobs: uses: it-at-m/.github/.github/workflows/codeql.yml@main with: analyze-java: true - analyze-javascript-typescript-vue: true + analyze-javascript-typescript-vue: false java-build-paths: "['./refarch-gateway','./refarch-integrations','./refarch-tools/refarch-java-tools']" diff --git a/refarch-gateway/pom.xml b/refarch-gateway/pom.xml index 4d24c80f..5bf0239e 100644 --- a/refarch-gateway/pom.xml +++ b/refarch-gateway/pom.xml @@ -25,7 +25,6 @@ 2023.0.3 - 1.0.0 8.0 @@ -46,6 +45,7 @@ 3.17.0 + 1.0.0 5.5.0 diff --git a/refarch-integrations/pom.xml b/refarch-integrations/pom.xml index c5df51cd..e9f2f2d7 100644 --- a/refarch-integrations/pom.xml +++ b/refarch-integrations/pom.xml @@ -38,6 +38,7 @@ 2.34.0 1.0.10 + 3.26.0 0.5.0 @@ -50,6 +51,7 @@ 1.6.2 0.2.0 + 1.0.1 2.6.0 @@ -245,6 +247,43 @@ + + + + org.apache.maven.plugins + maven-pmd-plugin + ${pmd-maven-plugin.version} + + 100 + ${java.version} + true + false + true + + target/generated + target/generated-sources + target/generated-test-sources + + + refarch-pmd-ruleset.xml + + + + + + check + cpd-check + + + + + + de.muenchen.refarch.tools + refarch-pmd + ${refarch-tools.version} + + + diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSErrorHandler.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSErrorHandler.java index 7913537a..a285a9be 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSErrorHandler.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSErrorHandler.java @@ -3,7 +3,7 @@ import de.muenchen.refarch.integration.dms.domain.exception.DmsException; public class DMSErrorHandler { - public void handleError(int code, String errorMessage) throws DmsException { + public void handleError(final int code, final String errorMessage) throws DmsException { final DMSStatusCode statusCode = DMSStatusCode.byCode(code); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSObjectClass.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSObjectClass.java index a2bfb81a..9d24b035 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSObjectClass.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSObjectClass.java @@ -3,6 +3,7 @@ /** * All known object classes to provide soap requests with. */ +@SuppressWarnings({ "PMD.ExcessivePublicCount", "PMD.FieldNamingConventions" }) public enum DMSObjectClass { Fileplan("COOELAK@1.1001:Fileplan"), diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSStatusCode.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSStatusCode.java index b65f185b..c1a1f15e 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSStatusCode.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSStatusCode.java @@ -26,7 +26,7 @@ public enum DMSStatusCode { } public static DMSStatusCode byCode(final int code) { - for (final DMSStatusCode status : DMSStatusCode.values()) { + for (final DMSStatusCode status : values()) { if (status.statuscode == code) { return status; } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/FabasoftAdapter.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/FabasoftAdapter.java index 50d1bbf2..0927651a 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/FabasoftAdapter.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/FabasoftAdapter.java @@ -21,9 +21,11 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectGI; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectGIResponse; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectMetaDataGI; +import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectMetaDataGIResponse; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadDocumentGIObjects; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadDocumentGIObjectsResponse; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadMetadataObjectGI; +import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadMetadataObjectGIResponse; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.SearchObjNameGI; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.SearchObjNameGIResponse; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.UpdateIncomingGI; @@ -57,7 +59,6 @@ import java.util.Objects; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import lombok.val; import org.apache.commons.lang3.StringUtils; import org.springframework.lang.NonNull; @@ -68,6 +69,7 @@ @Slf4j @RequiredArgsConstructor +@SuppressWarnings({ "PMD.UseObjectForClearerAPI", "PMD.CouplingBetweenObjects" }) public class FabasoftAdapter implements CreateFileOutPort, CreateProcedureOutPort, @@ -87,7 +89,7 @@ public class FabasoftAdapter implements private final DMSErrorHandler dmsErrorHandler = new DMSErrorHandler(); @Override - public String createFile(File file, String user) throws DmsException { + public String createFile(final File file, final String user) throws DmsException { //logging for dms team log.info("calling CreateFileGI Userlogin: {} Apentry: {} Filesubj: {} Shortname: {} Apentrysearch: true", user, file.apentryCOO(), file.title(), file.title()); @@ -107,7 +109,7 @@ public String createFile(File file, String user) throws DmsException { } @Override - public Procedure createProcedure(Procedure procedure, String user) throws DmsException { + public Procedure createProcedure(final Procedure procedure, final String user) throws DmsException { log.info("calling CreateProcedureGI: {}", procedure.toString()); final CreateProcedureGI request = new CreateProcedureGI(); @@ -311,7 +313,7 @@ private void updateInternalDocument(final String documentCOO, final List listContentCoos(@NonNull String documentCoo, @NonNull final String user) throws DmsException { - ReadDocumentGIObjects request = new ReadDocumentGIObjects(); + public List listContentCoos(@NonNull final String documentCoo, @NonNull final String user) throws DmsException { + final ReadDocumentGIObjects request = new ReadDocumentGIObjects(); request.setUserlogin(user); request.setBusinessapp(this.properties.getBusinessapp()); request.setObjaddress(documentCoo); - ReadDocumentGIObjectsResponse response = this.wsClient.readDocumentGIObjects(request); + final ReadDocumentGIObjectsResponse response = this.wsClient.readDocumentGIObjects(request); dmsErrorHandler.handleError(response.getStatus(), response.getErrormessage()); return response.getGiobjecttype().getLHMBAI151700GIObjectType().stream() @@ -365,12 +367,12 @@ public List listContentCoos(@NonNull String documentCoo, @NonNull final public List readContent(final List coos, final String user) throws DmsException { final List files = new ArrayList<>(); - for (val coo : coos) { - val request = new ReadContentObjectGI(); + for (final String coo : coos) { + final ReadContentObjectGI request = new ReadContentObjectGI(); request.setUserlogin(user); request.setBusinessapp(this.properties.getBusinessapp()); request.setObjaddress(coo); - val response = this.wsClient.readContentObjectGI(request); + final ReadContentObjectGIResponse response = this.wsClient.readContentObjectGI(request); dmsErrorHandler.handleError(response.getStatus(), response.getErrormessage()); files.add(this.map(response)); } @@ -378,7 +380,7 @@ public List readContent(final List coos, final String user) thr return files; } - private Content map(ReadContentObjectGIResponse response) { + private Content map(final ReadContentObjectGIResponse response) { return new Content( response.getGiattachmenttype().getLHMBAI151700Fileextension(), response.getGiattachmenttype().getLHMBAI151700Filename(), @@ -386,7 +388,7 @@ private Content map(ReadContentObjectGIResponse response) { } @Override - public List searchFile(String searchString, String user, String reference, String value) throws DmsException { + public List searchFile(final String searchString, final String user, final String reference, final String value) throws DmsException { return this.searchObject(searchString, DMSObjectClass.Sachakte, user, reference, value).stream() .map(LHMBAI151700GIObjectType::getLHMBAI151700Objaddress) .toList(); @@ -403,11 +405,11 @@ public List searchSubjectArea(final String searchString, final String us public Metadata readMetadata(final String coo, final String username) throws DmsException { log.info("calling ReadMetadataObjectGI Userlogin: {} COO: {}", username, coo); - val request = new ReadMetadataObjectGI(); + final ReadMetadataObjectGI request = new ReadMetadataObjectGI(); request.setObjaddress(coo); request.setBusinessapp(this.properties.getBusinessapp()); request.setUserlogin(username); - val response = this.wsClient.readMetadataObjectGI(request); + final ReadMetadataObjectGIResponse response = this.wsClient.readMetadataObjectGI(request); dmsErrorHandler.handleError(response.getStatus(), response.getErrormessage()); @@ -421,11 +423,11 @@ public Metadata readMetadata(final String coo, final String username) throws Dms public Metadata readContentMetadata(final String coo, final String username) throws DmsException { log.info("calling ReadContentObjectMetaDataGI Userlogin: {} COO: {}", username, coo); - val request = new ReadContentObjectMetaDataGI(); + final ReadContentObjectMetaDataGI request = new ReadContentObjectMetaDataGI(); request.setObjaddress(coo); request.setBusinessapp(this.properties.getBusinessapp()); request.setUserlogin(username); - val response = this.wsClient.readContentObjectMetaDataGI(request); + final ReadContentObjectMetaDataGIResponse response = this.wsClient.readContentObjectMetaDataGI(request); dmsErrorHandler.handleError(response.getStatus(), response.getErrormessage()); @@ -472,8 +474,12 @@ private List searchObject(final String searchString, f params.setBusinessapp(this.properties.getBusinessapp()); params.setObjclass(dmsObjectClass.getName()); params.setSearchstring(searchString); - if (Objects.nonNull(reference)) params.setReference(reference); - if (Objects.nonNull(value)) params.setValue(value); + if (Objects.nonNull(reference)) { + params.setReference(reference); + } + if (Objects.nonNull(value)) { + params.setValue(value); + } final SearchObjNameGIResponse response = this.wsClient.searchObjNameGI(params); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/s3/S3Adapter.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/s3/S3Adapter.java index ef4c935a..123bef39 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/s3/S3Adapter.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/adapter/out/s3/S3Adapter.java @@ -19,7 +19,6 @@ import java.util.Set; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import lombok.val; import org.apache.commons.io.FilenameUtils; import org.springframework.util.unit.DataSize; @@ -37,7 +36,7 @@ public class S3Adapter implements LoadFileOutPort, TransferContentOutPort { public List loadFiles(final List filePaths) throws DocumentStorageException { validateFileSizes(filePaths); final List contents = new ArrayList<>(); - for (String path : filePaths) { + for (final String path : filePaths) { if (path.endsWith("/")) { contents.addAll(getFilesFromFolder(path)); } else { @@ -64,15 +63,16 @@ private void validateFileSizes(final List filePaths) throws DocumentStor // Validate total batch size final DataSize totalFileSize = fileService.getTotalBatchSize(fileSizesWithPaths); - if (!fileService.isValidBatchSize(totalFileSize)) + if (!fileService.isValidBatchSize(totalFileSize)) { throw new FileSizeValidationException(String.format("Batch size of %d MB is too large. Allowed are %d MB.", totalFileSize.toMegabytes(), fileService.getMaxBatchSize().toMegabytes())); + } } private Map getFileSizesWithPaths(final List filePaths) throws DocumentStorageException { - Map map = new HashMap<>(); - for (String path : filePaths) { - for (Map.Entry stringLongEntry : getFileSizeForPath(path).entrySet()) { + final Map map = new HashMap<>(); + for (final String path : filePaths) { + for (final Map.Entry stringLongEntry : getFileSizeForPath(path).entrySet()) { if (map.put(stringLongEntry.getKey(), stringLongEntry.getValue()) != null) { throw new IllegalStateException("Duplicate key"); } @@ -93,7 +93,7 @@ private Map getSizesInFolderRecursively(final String folderPath) t try { return Objects.requireNonNull(documentStorageFolderRepository .getAllFileSizesInFolderRecursively(folderPath)); - } catch (final DocumentStorageException | DocumentStorageServerErrorException | DocumentStorageClientErrorException e) { + } catch (final DocumentStorageServerErrorException | DocumentStorageClientErrorException e) { throw new DocumentStorageException("Metadata of a folder could not be loaded from url: " + folderPath, e); } } @@ -102,7 +102,7 @@ private long getFileSize(final String filePath) throws DocumentStorageException try { return Objects.requireNonNull(documentStorageFileRepository .getFileSize(filePath)); - } catch (final DocumentStorageException | DocumentStorageServerErrorException | DocumentStorageClientErrorException e) { + } catch (final DocumentStorageServerErrorException | DocumentStorageClientErrorException e) { throw new DocumentStorageException("Metadata of a folder could not be loaded from url: " + filePath, e); } } @@ -112,12 +112,14 @@ private List getFilesFromFolder(final String folderPath) throws Documen final List contents = new ArrayList<>(); final Set filepath; filepath = documentStorageFolderRepository.getAllFilesInFolderRecursively(folderPath); - if (Objects.isNull(filepath)) throw new DocumentStorageException("An folder could not be loaded from url: " + folderPath); - for (String file : filepath) { + if (Objects.isNull(filepath)) { + throw new DocumentStorageException("An folder could not be loaded from url: " + folderPath); + } + for (final String file : filepath) { contents.add(getFile(file)); } return contents; - } catch (final DocumentStorageException | DocumentStorageServerErrorException | DocumentStorageClientErrorException e) { + } catch (final DocumentStorageServerErrorException | DocumentStorageClientErrorException e) { throw new DocumentStorageException("An folder could not be loaded from url: " + folderPath, e); } } @@ -129,22 +131,23 @@ private Content getFile(final String filePath) throws DocumentStorageException { final String mimeType = fileService.detectFileType(bytes); final String filename = FilenameUtils.getBaseName(filePath); - if (!fileService.isSupported(mimeType)) + if (!fileService.isSupported(mimeType)) { throw new FileTypeValidationException("The type of this file is not supported: " + filePath); + } return new Content(fileService.getFileExtension(mimeType), filename, bytes); - } catch (final DocumentStorageException | DocumentStorageServerErrorException | DocumentStorageClientErrorException e) { + } catch (final DocumentStorageServerErrorException | DocumentStorageClientErrorException e) { throw new DocumentStorageException("An file could not be loaded from url: " + filePath, e); } } @Override public void transferContent(final List content, final String filepath) throws DocumentStorageException { - for (val file : content) { + for (final Content file : content) { try { - val fullFilePath = (filepath + "/" + file.name() + "." + file.extension()).replace("//", "/"); + final String fullFilePath = (filepath + "/" + file.name() + "." + file.extension()).replace("//", "/"); this.documentStorageFileRepository.saveFile(fullFilePath, file.content(), 1); - } catch (Exception e) { + } catch (final Exception e) { throw new DocumentStorageException("An file could not be saved to path: " + filepath, e); } } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CancelObjectInPort.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CancelObjectInPort.java index c4759e17..f2ee70b1 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CancelObjectInPort.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CancelObjectInPort.java @@ -5,6 +5,6 @@ public interface CancelObjectInPort { - void cancelObject(@NotBlank final String objectCoo, @NotBlank final String user) throws DmsException; + void cancelObject(@NotBlank String objectCoo, @NotBlank String user) throws DmsException; } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CreateDocumentInPort.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CreateDocumentInPort.java index 77f1f2d3..6e00688c 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CreateDocumentInPort.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CreateDocumentInPort.java @@ -10,7 +10,7 @@ public interface CreateDocumentInPort { - DocumentResponse createDocument(final String procedureCOO, final String title, final LocalDate date, final String user, DocumentType type, - final List filepaths) throws DmsException, DocumentStorageException; + DocumentResponse createDocument(String procedureCOO, String title, LocalDate date, String user, DocumentType type, + List filepaths) throws DmsException, DocumentStorageException; } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CreateFileInPort.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CreateFileInPort.java index 7d3c8b9e..c5e852b6 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CreateFileInPort.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CreateFileInPort.java @@ -5,6 +5,6 @@ public interface CreateFileInPort { - String createFile(@NotBlank final String titel, @NotBlank final String apentryCOO, @NotBlank final String user) throws DmsException; + String createFile(@NotBlank String titel, @NotBlank String apentryCOO, @NotBlank String user) throws DmsException; } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CreateProcedureInPort.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CreateProcedureInPort.java index e425e021..78b65faa 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CreateProcedureInPort.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/CreateProcedureInPort.java @@ -4,9 +4,10 @@ import de.muenchen.refarch.integration.dms.domain.model.Procedure; import jakarta.validation.constraints.NotBlank; +@SuppressWarnings("PMD.UseObjectForClearerAPI") public interface CreateProcedureInPort { - Procedure createProcedure(@NotBlank final String titel, @NotBlank final String fileCOO, final String fileSubj, @NotBlank final String user) + Procedure createProcedure(@NotBlank String titel, @NotBlank String fileCOO, String fileSubj, @NotBlank String user) throws DmsException; } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/DepositObjectInPort.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/DepositObjectInPort.java index 5402d96a..fd23b2ae 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/DepositObjectInPort.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/DepositObjectInPort.java @@ -5,6 +5,6 @@ public interface DepositObjectInPort { - void depositObject(@NotBlank final String objectCoo, @NotBlank final String user) throws DmsException; + void depositObject(@NotBlank String objectCoo, @NotBlank String user) throws DmsException; } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/ReadMetadataInPort.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/ReadMetadataInPort.java index fa4de18b..c2f60b7b 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/ReadMetadataInPort.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/ReadMetadataInPort.java @@ -8,6 +8,6 @@ public interface ReadMetadataInPort { - Metadata readMetadata(@NotNull final ObjectType objectclass, @NotBlank final String coo, @NotBlank final String user) throws DmsException; + Metadata readMetadata(@NotNull ObjectType objectclass, @NotBlank String coo, @NotBlank String user) throws DmsException; } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/SearchFileInPort.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/SearchFileInPort.java index 11621684..0441f065 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/SearchFileInPort.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/in/SearchFileInPort.java @@ -3,6 +3,7 @@ import de.muenchen.refarch.integration.dms.domain.exception.DmsException; import java.util.List; +@SuppressWarnings("PMD.UseObjectForClearerAPI") public interface SearchFileInPort { /** diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/ListContentOutPort.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/ListContentOutPort.java index 4cdd3116..06ca2664 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/ListContentOutPort.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/ListContentOutPort.java @@ -12,5 +12,5 @@ public interface ListContentOutPort { * @param documentCoo The document coo to list the content for. * @return The list of content coos contained in the document. */ - List listContentCoos(@NonNull final String documentCoo, @NonNull final String user) throws DmsException; + List listContentCoos(@NonNull String documentCoo, @NonNull String user) throws DmsException; } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/ReadContentOutPort.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/ReadContentOutPort.java index e5d38373..732f0256 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/ReadContentOutPort.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/ReadContentOutPort.java @@ -7,6 +7,6 @@ public interface ReadContentOutPort { - List readContent(final List coos, final String user) throws DmsException; + List readContent(List coos, String user) throws DmsException; } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/ReadMetadataOutPort.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/ReadMetadataOutPort.java index e3d3efc2..d04f038c 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/ReadMetadataOutPort.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/ReadMetadataOutPort.java @@ -5,8 +5,8 @@ public interface ReadMetadataOutPort { - Metadata readMetadata(final String coo, final String user) throws DmsException; + Metadata readMetadata(String coo, String user) throws DmsException; - Metadata readContentMetadata(final String coo, final String user) throws DmsException; + Metadata readContentMetadata(String coo, String user) throws DmsException; } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/SearchFileOutPort.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/SearchFileOutPort.java index c6c32ffb..b7c01c43 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/SearchFileOutPort.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/port/out/SearchFileOutPort.java @@ -3,6 +3,7 @@ import de.muenchen.refarch.integration.dms.domain.exception.DmsException; import java.util.List; +@SuppressWarnings("PMD.UseObjectForClearerAPI") public interface SearchFileOutPort { List searchFile(String searchString, String user, String reference, String value) throws DmsException; diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/CreateDocumentUseCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/CreateDocumentUseCase.java index 59014a69..b8b36b31 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/CreateDocumentUseCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/CreateDocumentUseCase.java @@ -38,8 +38,8 @@ public DocumentResponse createDocument( final Document document = new Document(procedureCOO, title, date, type, contents); - String documentCoo = createDocumentOutPort.createDocument(document, user); - List contentCoos = listContentOutPort.listContentCoos(documentCoo, user); + final String documentCoo = createDocumentOutPort.createDocument(document, user); + final List contentCoos = listContentOutPort.listContentCoos(documentCoo, user); return new DocumentResponse(documentCoo, contentCoos); } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/CreateProcedureUseCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/CreateProcedureUseCase.java index 4743e185..d6f18caa 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/CreateProcedureUseCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/CreateProcedureUseCase.java @@ -10,6 +10,7 @@ @Validated @RequiredArgsConstructor +@SuppressWarnings("PMD.UseObjectForClearerAPI") public class CreateProcedureUseCase implements CreateProcedureInPort { private final CreateProcedureOutPort createProcedureOutPort; diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/DepositObjectUseCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/DepositObjectUseCase.java index 22848ca8..30bd1a7b 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/DepositObjectUseCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/DepositObjectUseCase.java @@ -14,7 +14,7 @@ public class DepositObjectUseCase implements DepositObjectInPort { private final DepositObjectOutPort depositObjectOutPort; @Override - public void depositObject(@NotBlank String objectCoo, @NotBlank String user) throws DmsException { + public void depositObject(@NotBlank final String objectCoo, @NotBlank final String user) throws DmsException { depositObjectOutPort.depositObject(objectCoo, user); } } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/ReadContentUseCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/ReadContentUseCase.java index e2a151b3..eb63e030 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/ReadContentUseCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/ReadContentUseCase.java @@ -4,10 +4,10 @@ import de.muenchen.refarch.integration.dms.application.port.out.ReadContentOutPort; import de.muenchen.refarch.integration.dms.application.port.out.TransferContentOutPort; import de.muenchen.refarch.integration.dms.domain.exception.DmsException; +import de.muenchen.refarch.integration.dms.domain.model.Content; import de.muenchen.refarch.integration.s3.client.exception.DocumentStorageException; import jakarta.validation.constraints.NotBlank; import lombok.RequiredArgsConstructor; -import lombok.val; import org.springframework.validation.annotation.Validated; import java.util.List; @@ -24,7 +24,7 @@ public void readContent( final List contentCoos, @NotBlank final String user, @NotBlank final String filePath) throws DmsException, DocumentStorageException { - val content = readContentOutPort.readContent(contentCoos, user); + final List content = readContentOutPort.readContent(contentCoos, user); transferContentOutPort.transferContent(content, filePath); } } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/ReadMetadataUseCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/ReadMetadataUseCase.java index 0433b48f..c2bf291c 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/ReadMetadataUseCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/ReadMetadataUseCase.java @@ -25,9 +25,9 @@ public Metadata readMetadata( return readMetadataOutPort.readContentMetadata(coo, user); } - Metadata metadata = readMetadataOutPort.readMetadata(coo, user); + final Metadata metadata = readMetadataOutPort.readMetadata(coo, user); - String object = objectclass == ObjectType.Intern ? "Internes Dokument" : objectclass.toString(); + final String object = objectclass == ObjectType.Intern ? "Internes Dokument" : objectclass.toString(); if (!object.equals(metadata.type())) { throw new DmsException("WRONG_INPUT_OBJECT_CLASS", String.format( diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/SearchFileUseCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/SearchFileUseCase.java index ff258e04..f1d0cee3 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/SearchFileUseCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/SearchFileUseCase.java @@ -4,13 +4,13 @@ import de.muenchen.refarch.integration.dms.application.port.out.SearchFileOutPort; import de.muenchen.refarch.integration.dms.domain.exception.DmsException; import lombok.RequiredArgsConstructor; -import lombok.val; import org.springframework.validation.annotation.Validated; import java.util.List; @Validated @RequiredArgsConstructor +@SuppressWarnings("PMD.UseObjectForClearerAPI") public class SearchFileUseCase implements SearchFileInPort { private final SearchFileOutPort searchFileOutPort; @@ -18,7 +18,7 @@ public class SearchFileUseCase implements SearchFileInPort { @Override public List searchFile(final String searchString, final String user, final String reference, final String value) throws DmsException { - val files = searchFileOutPort.searchFile(searchString, user, reference, value); + final List files = searchFileOutPort.searchFile(searchString, user, reference, value); if (files.isEmpty()) { throw new DmsException("OBJECT_NOT_FOUND", String.format("File not found with searchString %s and user %s", searchString, user)); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/SearchSubjectAreaUseCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/SearchSubjectAreaUseCase.java index db5efada..d962a8d0 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/SearchSubjectAreaUseCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/SearchSubjectAreaUseCase.java @@ -3,8 +3,8 @@ import de.muenchen.refarch.integration.dms.application.port.out.SearchSubjectAreaOutPort; import de.muenchen.refarch.integration.dms.application.port.in.SearchSubjectAreaInPort; import de.muenchen.refarch.integration.dms.domain.exception.DmsException; +import java.util.List; import lombok.RequiredArgsConstructor; -import lombok.val; import org.springframework.validation.annotation.Validated; @Validated @@ -16,7 +16,7 @@ public class SearchSubjectAreaUseCase implements SearchSubjectAreaInPort { @Override public String searchSubjectArea(final String searchString, final String user) throws DmsException { - val subjectAreas = searchSubjectAreaOutPort.searchSubjectArea(searchString, user); + final List subjectAreas = searchSubjectAreaOutPort.searchSubjectArea(searchString, user); if (subjectAreas.isEmpty()) { throw new DmsException("OBJECT_NOT_FOUND", String.format("Subject Area not found with searchString %s and user %s", searchString, user)); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/UpdateDocumentUseCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/UpdateDocumentUseCase.java index 1b2630ed..018bd696 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/UpdateDocumentUseCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/application/usecase/UpdateDocumentUseCase.java @@ -33,7 +33,7 @@ public DocumentResponse updateDocument( final List contents = loadFileOutPort.loadFiles(filepaths); updateDocumentOutPort.updateDocument(documentCOO, type, contents, user); - List contentCoos = listContentOutPort.listContentCoos(documentCOO, user); + final List contentCoos = listContentOutPort.listContentCoos(documentCOO, user); return new DocumentResponse(documentCOO, contentCoos); } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/domain/exception/DmsException.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/domain/exception/DmsException.java index d8ca138d..6c0a380c 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/domain/exception/DmsException.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/domain/exception/DmsException.java @@ -3,6 +3,7 @@ import lombok.Getter; @Getter +@SuppressWarnings("PMD.MissingSerialVersionUID") public class DmsException extends Exception { private final String statusCode; diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/domain/model/ObjectType.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/domain/model/ObjectType.java index 57687564..4ca04ca8 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/domain/model/ObjectType.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/domain/model/ObjectType.java @@ -1,5 +1,6 @@ package de.muenchen.refarch.integration.dms.domain.model; +@SuppressWarnings("PMD.FieldNamingConventions") public enum ObjectType { Sachakte, Vorgang, diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/domain/model/Procedure.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/domain/model/Procedure.java index 14e7b2ff..3352bcc5 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/domain/model/Procedure.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/main/java/de/muenchen/refarch/integration/dms/domain/model/Procedure.java @@ -1,7 +1,7 @@ package de.muenchen.refarch.integration.dms.domain.model; public record Procedure(String coo, String fileCOO, String title, String fileSubj) { - public Procedure(String fileCOO, String title, String fileSubj) { + public Procedure(final String fileCOO, final String title, final String fileSubj) { this(null, fileCOO, title, fileSubj); } } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSErrorHandlerTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSErrorHandlerTest.java index 1a5ab859..ebef47ca 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSErrorHandlerTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/DMSErrorHandlerTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -19,13 +20,13 @@ void setup() { @Test void handleDmsExceptionUnknown() { - int errorCode = -1; - String statusCode = "UNBEKANNTER_FEHLER"; - String errorMessage = "Unbekannter Fehler"; + final int errorCode = -1; + final String statusCode = "UNBEKANNTER_FEHLER"; + final String errorMessage = "Unbekannter Fehler"; - DmsException dmsException = assertThrows(DmsException.class, () -> this.dmsErrorHandler.handleError(errorCode, errorMessage)); + final DmsException dmsException = assertThrows(DmsException.class, () -> this.dmsErrorHandler.handleError(errorCode, errorMessage)); - String actualMessage = dmsException.getMessage(); + final String actualMessage = dmsException.getMessage(); assertEquals(statusCode + ": " + errorMessage, actualMessage); @@ -35,13 +36,13 @@ void handleDmsExceptionUnknown() { @Test void handleDmsException() { - int errorCode = 2; - String statusCode = "FEHLENDE_BERECHTIGUNG"; - String errorMessage = "Fehlende Berechtigung"; + final int errorCode = 2; + final String statusCode = "FEHLENDE_BERECHTIGUNG"; + final String errorMessage = "Fehlende Berechtigung"; - DmsException dmsException = assertThrows(DmsException.class, () -> this.dmsErrorHandler.handleError(errorCode, errorMessage)); + final DmsException dmsException = assertThrows(DmsException.class, () -> this.dmsErrorHandler.handleError(errorCode, errorMessage)); - String actualMessage = dmsException.getMessage(); + final String actualMessage = dmsException.getMessage(); assertEquals(statusCode + ": " + errorMessage, actualMessage); @@ -50,10 +51,10 @@ void handleDmsException() { } @Test - void uebertragungErfolgreich() throws DmsException { + void handleNoError() { - int code = 0; + final int code = 0; - this.dmsErrorHandler.handleError(code, null); + assertDoesNotThrow(() -> this.dmsErrorHandler.handleError(code, null)); } } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/FabasoftAdapterTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/FabasoftAdapterTest.java index b5ab0bca..8b0d838b 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/FabasoftAdapterTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/adapter/out/fabasoft/FabasoftAdapterTest.java @@ -18,6 +18,7 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.LHMBAI151700GIAttachmentType; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.LHMBAI151700GIMetadataType; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.LHMBAI151700GIObjectType; +import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.LHMBAI151700GIWSDSoap; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectGIResponse; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectMetaDataGI; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectMetaDataGIResponse; @@ -39,10 +40,10 @@ import de.muenchen.refarch.integration.dms.domain.model.Document; import de.muenchen.refarch.integration.dms.domain.model.DocumentType; import de.muenchen.refarch.integration.dms.domain.model.File; +import de.muenchen.refarch.integration.dms.domain.model.Metadata; import de.muenchen.refarch.integration.dms.domain.model.Procedure; -import de.muenchen.refarch.integration.dms.fabasoft.mock.FabasoftClienFactory; +import de.muenchen.refarch.integration.dms.fabasoft.mock.FabasoftClientFactory; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -51,61 +52,70 @@ import java.util.Optional; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @WireMockTest() +@SuppressWarnings("PMD.CouplingBetweenObjects") class FabasoftAdapterTest { + public static final String USER = "user"; + public static final String OBJID = "1234567890"; + public static final byte[] CONTENT = "content".getBytes(); + public static final String NAME = "name"; + public static final String EXTENSION = "extension"; + public static final String DOCUMENT_COO = "documentCOO"; + private final FabasoftProperties properties = new FabasoftProperties(); private FabasoftAdapter fabasoftAdapter; @BeforeEach - public void setUp(WireMockRuntimeInfo wmRuntimeInfo) { - this.properties.setUsername("user"); + public void setUp(final WireMockRuntimeInfo wmRuntimeInfo) { + this.properties.setUsername(USER); this.properties.setPassword("password"); this.properties.setBusinessapp("businessapp"); this.properties.setUiUrl("uiurl"); - val soapClient = FabasoftClienFactory.dmsWsClient("http://localhost:" + wmRuntimeInfo.getHttpPort() + "/"); + final LHMBAI151700GIWSDSoap soapClient = FabasoftClientFactory.dmsWsClient("http://localhost:" + wmRuntimeInfo.getHttpPort() + "/"); fabasoftAdapter = new FabasoftAdapter(properties, soapClient); } @Test - void execute_createFile_request() throws DmsException { - val response = new CreateFileGIResponse(); - response.setObjid("1234567890"); + void executeCreateFileRequest() throws DmsException { + final CreateFileGIResponse response = new CreateFileGIResponse(); + response.setObjid(OBJID); WiremockWsdlUtility.stubOperation( "CreateFileGI", CreateFileGI.class, (u) -> "new file".equals(u.getShortname()), response); - val file = new File("apentryCOO", "new file"); + final File file = new File("apentryCOO", "new file"); - val procedureResponse = fabasoftAdapter.createFile(file, "user"); + final String procedureResponse = fabasoftAdapter.createFile(file, USER); - assertEquals(procedureResponse, "1234567890"); + assertEquals(procedureResponse, OBJID); } @Test - void execute_createProcedure_request() throws DmsException { - val response = new CreateProcedureGIResponse(); - response.setObjid("1234567890"); + void executeCreateProcedureRequest() throws DmsException { + final CreateProcedureGIResponse response = new CreateProcedureGIResponse(); + response.setObjid(OBJID); WiremockWsdlUtility.stubOperation( "CreateProcedureGI", CreateProcedureGI.class, (u) -> "new procedure".equals(u.getShortname()), response); - val procedure = new Procedure("fileCOO", "new procedure", "custom file subject"); + final Procedure procedure = new Procedure("fileCOO", "new procedure", "custom file subject"); - val procedureResponse = fabasoftAdapter.createProcedure(procedure, "user"); + final Procedure procedureResponse = fabasoftAdapter.createProcedure(procedure, USER); - assertEquals(procedureResponse.coo(), "1234567890"); + assertEquals(procedureResponse.coo(), OBJID); } @Test - void execute_depositObject_request() throws DmsException { - val response = new DepositObjectGIResponse(); + void executeDepositObjectRequest() { + final DepositObjectGIResponse response = new DepositObjectGIResponse(); response.setObjid("objectCoo"); WiremockWsdlUtility.stubOperation( @@ -113,111 +123,111 @@ void execute_depositObject_request() throws DmsException { DepositObjectGI.class, (u) -> true, response); - fabasoftAdapter.depositObject("objectCoo", "user"); + assertDoesNotThrow(() -> fabasoftAdapter.depositObject("objectCoo", USER)); } @Test - void execute_createIncomingDocument_request() throws DmsException { - Content content = new Content("extension", "name", "content".getBytes()); + void executeCreateIncomingDocumentRequest() throws DmsException { + final Content content = new Content(EXTENSION, NAME, CONTENT); - val response = new CreateIncomingGIResponse(); - response.setObjid("documentCOO"); + final CreateIncomingGIResponse response = new CreateIncomingGIResponse(); + response.setObjid(DOCUMENT_COO); WiremockWsdlUtility.stubOperation( "CreateIncomingGI", CreateIncomingGI.class, (u) -> true, response); - val documentResponse = fabasoftAdapter - .createDocument(new Document("procedureCOO", "title", LocalDate.parse("2023-12-31"), DocumentType.EINGEHEND, List.of(content)), "user"); + final String documentResponse = fabasoftAdapter + .createDocument(new Document("procedureCOO", "title", LocalDate.parse("2023-12-31"), DocumentType.EINGEHEND, List.of(content)), USER); - assertEquals(documentResponse, "documentCOO"); + assertEquals(documentResponse, DOCUMENT_COO); } @Test - void execute_createOutgoingDocument_request() throws DmsException { - Content content = new Content("extension", "name", "content".getBytes()); + void executeCreateOutgoingDocumentRequest() throws DmsException { + final Content content = new Content(EXTENSION, NAME, CONTENT); - val response = new CreateOutgoingGIResponse(); - response.setObjid("documentCOO"); + final CreateOutgoingGIResponse response = new CreateOutgoingGIResponse(); + response.setObjid(DOCUMENT_COO); WiremockWsdlUtility.stubOperation( "CreateOutgoingGI", CreateOutgoingGI.class, (u) -> true, response); - val documentResponse = fabasoftAdapter - .createDocument(new Document("procedureCOO", "title", LocalDate.parse("2023-12-31"), DocumentType.AUSGEHEND, List.of(content)), "user"); + final String documentResponse = fabasoftAdapter + .createDocument(new Document("procedureCOO", "title", LocalDate.parse("2023-12-31"), DocumentType.AUSGEHEND, List.of(content)), USER); - assertEquals(documentResponse, "documentCOO"); + assertEquals(documentResponse, DOCUMENT_COO); } @Test - void execute_createInternalDocument_request() throws DmsException { - Content content = new Content("extension", "name", "content".getBytes()); + void executeCreateInternalDocumentRequest() throws DmsException { + final Content content = new Content(EXTENSION, NAME, CONTENT); - val response = new CreateInternalGIResponse(); - response.setObjid("documentCOO"); + final CreateInternalGIResponse response = new CreateInternalGIResponse(); + response.setObjid(DOCUMENT_COO); WiremockWsdlUtility.stubOperation( "CreateInternalGI", CreateInternalGI.class, (u) -> true, response); - val documentResponse = fabasoftAdapter - .createDocument(new Document("procedureCOO", "title", LocalDate.parse("2023-12-31"), DocumentType.INTERN, List.of(content)), "user"); + final String documentResponse = fabasoftAdapter + .createDocument(new Document("procedureCOO", "title", LocalDate.parse("2023-12-31"), DocumentType.INTERN, List.of(content)), USER); - assertEquals(documentResponse, "documentCOO"); + assertEquals(documentResponse, DOCUMENT_COO); } @Test - void execute_updateIncomingDocument_request() throws DmsException { - Content content = new Content("extension", "name", "content".getBytes()); + void executeUpdateIncomingDocumentRequest() { + final Content content = new Content(EXTENSION, NAME, CONTENT); - val response = new UpdateIncomingGIResponse(); - response.setObjid("documentCOO"); + final UpdateIncomingGIResponse response = new UpdateIncomingGIResponse(); + response.setObjid(DOCUMENT_COO); WiremockWsdlUtility.stubOperation( "UpdateIncomingGI", UpdateIncomingGI.class, (u) -> true, response); - fabasoftAdapter.updateDocument("documentCOO", DocumentType.EINGEHEND, List.of(content), "user"); + assertDoesNotThrow(() -> fabasoftAdapter.updateDocument(DOCUMENT_COO, DocumentType.EINGEHEND, List.of(content), USER)); } @Test - void execute_updateOutgoingDocument_request() throws DmsException { - Content content = new Content("extension", "name", "content".getBytes()); + void executeUpdateOutgoingDocumentRequest() { + final Content content = new Content(EXTENSION, NAME, CONTENT); - val response = new UpdateOutgoingGIResponse(); - response.setObjid("documentCOO"); + final UpdateOutgoingGIResponse response = new UpdateOutgoingGIResponse(); + response.setObjid(DOCUMENT_COO); WiremockWsdlUtility.stubOperation( "UpdateOutgoingGI", UpdateOutgoingGI.class, (u) -> true, response); - fabasoftAdapter.updateDocument("documentCOO", DocumentType.AUSGEHEND, List.of(content), "user"); + assertDoesNotThrow(() -> fabasoftAdapter.updateDocument(DOCUMENT_COO, DocumentType.AUSGEHEND, List.of(content), USER)); } @Test - void execute_updateInternalDocument_request() throws DmsException { - Content content = new Content("extension", "name", "content".getBytes()); + void executeUpdateInternalDocumentRequest() { + final Content content = new Content(EXTENSION, NAME, CONTENT); - val response = new UpdateInternalGIResponse(); - response.setObjid("documentCOO"); + final UpdateInternalGIResponse response = new UpdateInternalGIResponse(); + response.setObjid(DOCUMENT_COO); WiremockWsdlUtility.stubOperation( "UpdateInternalGI", UpdateInternalGI.class, (u) -> true, response); - fabasoftAdapter.updateDocument("documentCOO", DocumentType.INTERN, List.of(content), "user"); + assertDoesNotThrow(() -> fabasoftAdapter.updateDocument(DOCUMENT_COO, DocumentType.INTERN, List.of(content), USER)); } @Test - void execute_cancelObject_request() throws DmsException { - val response = new CancelObjectGIResponse(); + void executeCancelObjectRequest() throws DmsException { + final CancelObjectGIResponse response = new CancelObjectGIResponse(); response.setStatus(0); WiremockWsdlUtility.stubOperation( @@ -225,18 +235,18 @@ void execute_cancelObject_request() throws DmsException { CancelObjectGI.class, (u) -> true, response); - fabasoftAdapter.cancelObject("objectCoo", "user"); + assertDoesNotThrow(() -> fabasoftAdapter.cancelObject("objectCoo", USER)); } @Test - void execute_list_files() throws DmsException { - val file1 = new LHMBAI151700GIObjectType(); + void executeListRiles() throws DmsException { + final LHMBAI151700GIObjectType file1 = new LHMBAI151700GIObjectType(); file1.setLHMBAI151700Objaddress("contentCoo1"); file1.setLHMBAI151700Objname("File-Name"); - val content = new ArrayOfLHMBAI151700GIObjectType(); + final ArrayOfLHMBAI151700GIObjectType content = new ArrayOfLHMBAI151700GIObjectType(); content.getLHMBAI151700GIObjectType().add(file1); - val response = new ReadDocumentGIObjectsResponse(); + final ReadDocumentGIObjectsResponse response = new ReadDocumentGIObjectsResponse(); response.setStatus(0); response.setGiobjecttype(content); @@ -245,22 +255,22 @@ void execute_list_files() throws DmsException { CancelObjectGI.class, (u) -> true, response); - val contentCoos = fabasoftAdapter.listContentCoos("coo1", "user"); + final List contentCoos = fabasoftAdapter.listContentCoos("coo1", USER); - val expectedCoos = List.of("contentCoo1"); + final List expectedCoos = List.of("contentCoo1"); assertThat(contentCoos.size()).isEqualTo(1); assertEquals(expectedCoos, contentCoos); } @Test - void execute_read_files() throws DmsException { - val content = new LHMBAI151700GIAttachmentType(); + void executeReadFiles() throws DmsException { + final LHMBAI151700GIAttachmentType content = new LHMBAI151700GIAttachmentType(); content.setLHMBAI151700Filename("filename"); - content.setLHMBAI151700Fileextension("extension"); - content.setLHMBAI151700Filecontent("content".getBytes()); + content.setLHMBAI151700Fileextension(EXTENSION); + content.setLHMBAI151700Filecontent(CONTENT); - val response = new ReadContentObjectGIResponse(); + final ReadContentObjectGIResponse response = new ReadContentObjectGIResponse(); response.setStatus(0); response.setGiattachmenttype(content); @@ -269,9 +279,9 @@ void execute_read_files() throws DmsException { CancelObjectGI.class, (u) -> true, response); - val files = fabasoftAdapter.readContent(List.of("coo1"), "user"); + final List files = fabasoftAdapter.readContent(List.of("coo1"), USER); - val expectedFile = new Content("extension", "filename", "content".getBytes()); + final Content expectedFile = new Content(EXTENSION, "filename", CONTENT); assertThat(files.size()).isEqualTo(1); assertThat(files.getFirst()).usingRecursiveComparison().isEqualTo(expectedFile); @@ -281,31 +291,31 @@ void execute_read_files() throws DmsException { * Tests a file search. */ @Test - void execute_searchFile_request() throws DmsException { - internalSearchFileCallTest(DMSObjectClass.Sachakte, "searchString", "user", null, null); + void executeSearchFileRequest() { + assertDoesNotThrow(() -> internalSearchFileCallTest(DMSObjectClass.Sachakte, "searchString", USER, null, null)); } /** * Tests a file search but includes refinement on a business date/'Fachdatum'. */ @Test - void execute_searchFile_request_business_data() throws DmsException { - internalSearchFileCallTest(DMSObjectClass.Sachakte, "searchString", "user", "reference", "value"); + void executeSearchFileRequestBusinessData() throws DmsException { + assertDoesNotThrow(() -> internalSearchFileCallTest(DMSObjectClass.Sachakte, "searchString", USER, "reference", "value")); } /** * Tests a subject search. */ @Test - void execute_searchSubjectArea_request() throws DmsException { - val file = new LHMBAI151700GIObjectType(); + void executeSearchSubjectAreaRequest() throws DmsException { + final LHMBAI151700GIObjectType file = new LHMBAI151700GIObjectType(); file.setLHMBAI151700Objaddress("testCoo"); file.setLHMBAI151700Objname("testName"); - val array = new ArrayOfLHMBAI151700GIObjectType(); + final ArrayOfLHMBAI151700GIObjectType array = new ArrayOfLHMBAI151700GIObjectType(); array.getLHMBAI151700GIObjectType().add(file); - val response = new SearchObjNameGIResponse(); + final SearchObjNameGIResponse response = new SearchObjNameGIResponse(); response.setStatus(0); response.setGiobjecttype(array); @@ -314,7 +324,7 @@ void execute_searchSubjectArea_request() throws DmsException { SearchObjNameGI.class, (u) -> u.getObjclass().equals(DMSObjectClass.Aktenplaneintrag.getName()), response); - val files = fabasoftAdapter.searchSubjectArea("searchString", "user"); + final List files = fabasoftAdapter.searchSubjectArea("searchString", USER); assertThat(files.size()).isEqualTo(1); } @@ -322,14 +332,14 @@ void execute_searchSubjectArea_request() throws DmsException { private void internalSearchFileCallTest(final DMSObjectClass dmsObjectClass, final String searchString, final String user, final String reference, final String value) throws DmsException { - val file = new LHMBAI151700GIObjectType(); + final LHMBAI151700GIObjectType file = new LHMBAI151700GIObjectType(); file.setLHMBAI151700Objaddress("testCoo"); file.setLHMBAI151700Objname("testName"); - val array = new ArrayOfLHMBAI151700GIObjectType(); + final ArrayOfLHMBAI151700GIObjectType array = new ArrayOfLHMBAI151700GIObjectType(); array.getLHMBAI151700GIObjectType().add(file); - val response = new SearchObjNameGIResponse(); + final SearchObjNameGIResponse response = new SearchObjNameGIResponse(); response.setStatus(0); response.setGiobjecttype(array); @@ -338,45 +348,48 @@ private void internalSearchFileCallTest(final DMSObjectClass dmsObjectClass, fin SearchObjNameGI.class, (u) -> u.getObjclass().equals(dmsObjectClass.getName()) && validateBusinessData(u), response); - val files = fabasoftAdapter.searchFile(searchString, user, reference, value); + final List files = fabasoftAdapter.searchFile(searchString, user, reference, value); assertThat(files.size()).isEqualTo(1); } private boolean validateBusinessData(final SearchObjNameGI searchObjNameGI) { - val reference = Optional.ofNullable(searchObjNameGI.getReference()).orElse(""); - val value = Optional.ofNullable(searchObjNameGI.getValue()).orElse(""); - if (reference.isEmpty()) return true; - if (value.isEmpty()) return false; - return !reference.equals("reference") || value.equals("value"); + final String reference = Optional.ofNullable(searchObjNameGI.getReference()).orElse(""); + final String value = Optional.ofNullable(searchObjNameGI.getValue()).orElse(""); + if (reference.isEmpty()) { + return true; + } + if (value.isEmpty()) { + return false; + } + return !"reference".equals(reference) || "value".equals(value); } @Test - void execute_read_metadata() throws DmsException { - - val response = new ReadMetadataObjectGIResponse(); + void executeReadMetadata() throws DmsException { + final ReadMetadataObjectGIResponse response = new ReadMetadataObjectGIResponse(); response.setStatus(0); response.setObjclass("Vorgang"); - response.setObjname("name"); + response.setObjname(NAME); WiremockWsdlUtility.stubOperation( "ReadMetadataObjectGI", ReadMetadataObjectGI.class, (u) -> true, response); - val metadata = fabasoftAdapter.readMetadata("coo", "user"); + final Metadata metadata = fabasoftAdapter.readMetadata("coo", USER); - assertThat(metadata.name()).isEqualTo("name"); + assertThat(metadata.name()).isEqualTo(NAME); assertThat(metadata.type()).isEqualTo("Vorgang"); } @Test - void execute_read_content_metadata() throws DmsException { - val content = new LHMBAI151700GIMetadataType(); - content.setLHMBAI151700Filename("name"); + void executeReadContentMetadata() throws DmsException { + final LHMBAI151700GIMetadataType content = new LHMBAI151700GIMetadataType(); + content.setLHMBAI151700Filename(NAME); content.setLHMBAI151700Objclass("pdf"); - val response = new ReadContentObjectMetaDataGIResponse(); + final ReadContentObjectMetaDataGIResponse response = new ReadContentObjectMetaDataGIResponse(); response.setStatus(0); response.setGimetadatatype(content); @@ -385,9 +398,9 @@ void execute_read_content_metadata() throws DmsException { ReadContentObjectMetaDataGI.class, (u) -> true, response); - val metadata = fabasoftAdapter.readContentMetadata("coo", "user"); + final Metadata metadata = fabasoftAdapter.readContentMetadata("coo", USER); - assertThat(metadata.name()).isEqualTo("name"); + assertThat(metadata.name()).isEqualTo(NAME); assertThat(metadata.type()).isEqualTo("pdf"); } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/adapter/out/s3/S3AdapterTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/adapter/out/s3/S3AdapterTest.java index 4492d37c..22405138 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/adapter/out/s3/S3AdapterTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/adapter/out/s3/S3AdapterTest.java @@ -41,13 +41,22 @@ class S3AdapterTest { private static final DataSize ALLOWED_FILE_SIZE = DataSize.ofMegabytes(100); private static final DataSize ALLOWED_BATCH_SIZE = DataSize.ofMegabytes(110); private static final long TOO_LARGE_FILE_SIZE = ALLOWED_FILE_SIZE.toBytes() + DataSize.ofMegabytes(1L).toBytes(); // 1 Mbyte over allowed + public static final String PDF = "pdf"; + public static final String PNG = "png"; + public static final String PDF_PATH = "files/test/test-pdf.pdf"; + public static final String PNG_PATH = "files/test/test-png.png"; + public static final String PDF_NAME = "test-pdf"; + public static final String PNG_NAME = "test-png"; + public static final String SOME_ERROR = "Some error"; + public static final String FOLDER_PATH = "test/"; + public static final String FULL_WORD_PATH = "files/test/test-word.docx"; private final DocumentStorageFileRepository documentStorageFileRepository = mock(DocumentStorageFileRepository.class); private final DocumentStorageFolderRepository documentStorageFolderRepository = mock(DocumentStorageFolderRepository.class); - private final SupportedFileExtensions supportedExtensions = new SupportedFileExtensions(Map.of("pdf", "application/pdf", - "png", "image/png", + private final Map supportedExtensions = new SupportedFileExtensions(Map.of(PDF, "application/pdf", + PNG, "image/png", "docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")); private final FileValidationService fileValidationService = new FileValidationService(supportedExtensions, ALLOWED_FILE_SIZE, ALLOWED_BATCH_SIZE); @@ -63,47 +72,19 @@ void setup() { void testLoadFileFromFilePath() throws IOException, DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String pdfPath = "files/test/test-pdf.pdf"; - final String pngPath = "files/test/test-png.png"; + final List filePaths = List.of(PDF_PATH, PNG_PATH); - final List filePaths = List.of(pdfPath, pngPath); + final byte[] testPdf = new ClassPathResource(PDF_PATH).getInputStream().readAllBytes(); + final byte[] testPng = new ClassPathResource(PNG_PATH).getInputStream().readAllBytes(); - final byte[] testPdf = new ClassPathResource(pdfPath).getInputStream().readAllBytes(); - final byte[] testPng = new ClassPathResource(pngPath).getInputStream().readAllBytes(); - - when(documentStorageFileRepository.getFile(pdfPath, 3)).thenReturn(testPdf); - when(documentStorageFileRepository.getFile(pngPath, 3)).thenReturn(testPng); - when(documentStorageFileRepository.getFileSize(anyString())).thenReturn(1_000_000L); - - final List contents = this.s3Adapter.loadFiles(filePaths); - - final Content pdfContent = new Content("pdf", "test-pdf", testPdf); - final Content pngContent = new Content("png", "test-png", testPng); - - assertTrue(contents.contains(pdfContent)); - assertTrue(contents.contains(pngContent)); - } - - @Test - void testLoadFileFromFilePathWithStorageUrl() - throws IOException, DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - - final String pdfPath = "files/test/test-pdf.pdf"; - final String pngPath = "files/test/test-png.png"; - - final List filePaths = List.of(pdfPath, pngPath); - - final byte[] testPdf = new ClassPathResource(pdfPath).getInputStream().readAllBytes(); - final byte[] testPng = new ClassPathResource(pngPath).getInputStream().readAllBytes(); - - when(documentStorageFileRepository.getFile(pdfPath, 3)).thenReturn(testPdf); - when(documentStorageFileRepository.getFile(pngPath, 3)).thenReturn(testPng); + when(documentStorageFileRepository.getFile(PDF_PATH, 3)).thenReturn(testPdf); + when(documentStorageFileRepository.getFile(PNG_PATH, 3)).thenReturn(testPng); when(documentStorageFileRepository.getFileSize(anyString())).thenReturn(1_000_000L); final List contents = this.s3Adapter.loadFiles(filePaths); - final Content pdfContent = new Content("pdf", "test-pdf", testPdf); - final Content pngContent = new Content("png", "test-png", testPng); + final Content pdfContent = new Content(PDF, PDF_NAME, testPdf); + final Content pngContent = new Content(PNG, PNG_NAME, testPng); assertTrue(contents.contains(pdfContent)); assertTrue(contents.contains(pngContent)); @@ -113,67 +94,25 @@ void testLoadFileFromFilePathWithStorageUrl() void testLoadFileFromFolderPath() throws IOException, DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String folderPath = "test/"; - - final String pdfPath = "files/test/test-pdf.pdf"; - final String pngPath = "files/test/test-png.png"; - final String fullWordPath = "files/test/test-word.docx"; - - final List paths = List.of(folderPath); - - final Set filesPaths = new HashSet<>(List.of(pdfPath, pngPath, fullWordPath)); - - final byte[] testPdf = new ClassPathResource(pdfPath).getInputStream().readAllBytes(); - final byte[] testPng = new ClassPathResource(pngPath).getInputStream().readAllBytes(); - final byte[] testWord = new ClassPathResource(fullWordPath).getInputStream().readAllBytes(); - - when(documentStorageFolderRepository.getAllFilesInFolderRecursively(folderPath)).thenReturn(filesPaths); - - when(documentStorageFileRepository.getFile(pdfPath, 3)).thenReturn(testPdf); - when(documentStorageFileRepository.getFile(pngPath, 3)).thenReturn(testPng); - when(documentStorageFileRepository.getFile(fullWordPath, 3)).thenReturn(testWord); - when(documentStorageFolderRepository.getAllFileSizesInFolderRecursively(anyString())).thenReturn(Map.of("", 1_000_000L)); - - final List contents = this.s3Adapter.loadFiles(paths); - - final Content pdfContent = new Content("pdf", "test-pdf", testPdf); - final Content pngContent = new Content("png", "test-png", testPng); - final Content wordContent = new Content("docx", "test-word", testWord); - - assertTrue(contents.contains(pdfContent)); - assertTrue(contents.contains(pngContent)); - assertTrue(contents.contains(wordContent)); - } - - @Test - void testLoadFileFromFolderPathWithStorageUrl() - throws IOException, DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - - final String folderPath = "test/"; - - final String pdfPath = "files/test/test-pdf.pdf"; - final String pngPath = "files/test/test-png.png"; - final String fullWordPath = "files/test/test-word.docx"; - - final List paths = List.of(folderPath); + final List paths = List.of(FOLDER_PATH); - Set filesPaths = new HashSet<>(List.of(pdfPath, pngPath, fullWordPath)); + final Set filesPaths = new HashSet<>(List.of(PDF_PATH, PNG_PATH, FULL_WORD_PATH)); - final byte[] testPdf = new ClassPathResource(pdfPath).getInputStream().readAllBytes(); - final byte[] testPng = new ClassPathResource(pngPath).getInputStream().readAllBytes(); - final byte[] testWord = new ClassPathResource(fullWordPath).getInputStream().readAllBytes(); + final byte[] testPdf = new ClassPathResource(PDF_PATH).getInputStream().readAllBytes(); + final byte[] testPng = new ClassPathResource(PNG_PATH).getInputStream().readAllBytes(); + final byte[] testWord = new ClassPathResource(FULL_WORD_PATH).getInputStream().readAllBytes(); - when(documentStorageFolderRepository.getAllFilesInFolderRecursively(folderPath)).thenReturn(filesPaths); + when(documentStorageFolderRepository.getAllFilesInFolderRecursively(FOLDER_PATH)).thenReturn(filesPaths); - when(documentStorageFileRepository.getFile(pdfPath, 3)).thenReturn(testPdf); - when(documentStorageFileRepository.getFile(pngPath, 3)).thenReturn(testPng); - when(documentStorageFileRepository.getFile(fullWordPath, 3)).thenReturn(testWord); + when(documentStorageFileRepository.getFile(PDF_PATH, 3)).thenReturn(testPdf); + when(documentStorageFileRepository.getFile(PNG_PATH, 3)).thenReturn(testPng); + when(documentStorageFileRepository.getFile(FULL_WORD_PATH, 3)).thenReturn(testWord); when(documentStorageFolderRepository.getAllFileSizesInFolderRecursively(anyString())).thenReturn(Map.of("", 1_000_000L)); final List contents = this.s3Adapter.loadFiles(paths); - final Content pdfContent = new Content("pdf", "test-pdf", testPdf); - final Content pngContent = new Content("png", "test-png", testPng); + final Content pdfContent = new Content(PDF, PDF_NAME, testPdf); + final Content pngContent = new Content(PNG, PNG_NAME, testPng); final Content wordContent = new Content("docx", "test-word", testWord); assertTrue(contents.contains(pdfContent)); @@ -191,32 +130,29 @@ void testLoadFileFromFilePathThrowsDocumentStorageException() when(documentStorageFileRepository.getFileSize(anyString())).thenReturn(1_000_000L); when(documentStorageFileRepository.getFile(pdfPath, 3)).thenThrow( - new DocumentStorageException("Some error", new RuntimeException("Some error"))); + new DocumentStorageException(SOME_ERROR, new RuntimeException(SOME_ERROR))); - DocumentStorageException documentStorageException = assertThrows(DocumentStorageException.class, () -> this.s3Adapter.loadFiles(filePaths)); + final DocumentStorageException documentStorageException = assertThrows(DocumentStorageException.class, () -> this.s3Adapter.loadFiles(filePaths)); - String expectedMessage = "An file could not be loaded from url: " + pdfPath; - String actualMessage = documentStorageException.getMessage(); - - assertEquals(expectedMessage, actualMessage); + assertEquals(SOME_ERROR, documentStorageException.getMessage()); } @Test void testLoadFileFromFolderPathThrowsDocumentStorageServerErrorException() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String folderPath = "test/"; + final String folderPath = FOLDER_PATH; final List filePaths = List.of(folderPath); when(documentStorageFolderRepository.getAllFileSizesInFolderRecursively(anyString())).thenReturn(Map.of("", 1_000_000L)); when(documentStorageFolderRepository.getAllFilesInFolderRecursively(folderPath)).thenThrow( - new DocumentStorageServerErrorException("Some error", new RuntimeException("Some error"))); + new DocumentStorageServerErrorException(SOME_ERROR, new RuntimeException(SOME_ERROR))); - DocumentStorageException documentStorageException = assertThrows(DocumentStorageException.class, () -> this.s3Adapter.loadFiles(filePaths)); + final DocumentStorageException documentStorageException = assertThrows(DocumentStorageException.class, () -> this.s3Adapter.loadFiles(filePaths)); - String expectedMessage = "An folder could not be loaded from url: " + folderPath; - String actualMessage = documentStorageException.getMessage(); + final String expectedMessage = "An folder could not be loaded from url: " + folderPath; + final String actualMessage = documentStorageException.getMessage(); assertEquals(expectedMessage, actualMessage); } @@ -234,7 +170,7 @@ void testLoadFileFromFilePathThrowsUnsupportedFileTypeException() when(documentStorageFileRepository.getFile(htmlPath, 3)).thenReturn(testHtml); when(documentStorageFileRepository.getFileSize(anyString())).thenReturn(1_000_000L); - String expectedMessage = "The type of this file is not supported: " + htmlPath; + final String expectedMessage = "The type of this file is not supported: " + htmlPath; assertThatThrownBy(() -> s3Adapter.loadFiles(filePaths)) .isInstanceOf(FileTypeValidationException.class) @@ -244,16 +180,17 @@ void testLoadFileFromFilePathThrowsUnsupportedFileTypeException() @Test void testLoadFilesThrowsFileSizeValidationExceptionDueToInvalidBatchSize() throws Exception { - String pathLargeFile = "path/to/largeFile"; - String pathSmallFile = "path/to/smallFile"; - List filePaths = Arrays.asList(pathLargeFile, pathSmallFile); + final String pathLargeFile = "path/to/largeFile"; + final String pathSmallFile = "path/to/smallFile"; + final List filePaths = Arrays.asList(pathLargeFile, pathSmallFile); when(documentStorageFileRepository.getFileSize(eq(pathLargeFile))).thenReturn(ALLOWED_FILE_SIZE.toBytes()); when(documentStorageFileRepository.getFileSize(eq(pathSmallFile))).thenReturn( DataSize.ofMegabytes(20).toBytes()); - DataSize sum = DataSize.ofBytes(ALLOWED_FILE_SIZE.toBytes() + DataSize.ofMegabytes(20).toBytes()); - String expectedMessage = String.format("Batch size of %d MB is too large. Allowed are %d MB.", sum.toMegabytes(), ALLOWED_BATCH_SIZE.toMegabytes()); + final DataSize sum = DataSize.ofBytes(ALLOWED_FILE_SIZE.toBytes() + DataSize.ofMegabytes(20).toBytes()); + final String expectedMessage = String.format("Batch size of %d MB is too large. Allowed are %d MB.", sum.toMegabytes(), + ALLOWED_BATCH_SIZE.toMegabytes()); assertThatThrownBy(() -> s3Adapter.loadFiles(filePaths)) .isInstanceOf(FileSizeValidationException.class) @@ -263,14 +200,14 @@ void testLoadFilesThrowsFileSizeValidationExceptionDueToInvalidBatchSize() throw @Test void testLoadFilesThrowsFileSizeValidationExceptionDueToFileExceedingMaxSize() throws Exception { - String pathLargeFile = "path/to/largeFile"; - String pathSmallFile = "path/to/smallFile"; - List filePaths = Arrays.asList(pathLargeFile, pathSmallFile); + final String pathLargeFile = "path/to/largeFile"; + final String pathSmallFile = "path/to/smallFile"; + final List filePaths = Arrays.asList(pathLargeFile, pathSmallFile); when(documentStorageFileRepository.getFileSize(eq(pathLargeFile))).thenReturn(TOO_LARGE_FILE_SIZE); when(documentStorageFileRepository.getFileSize(eq(pathSmallFile))).thenReturn(10_240L); - String expectedMessage = String.format("The following files exceed the maximum size of %d MB:%n%s: %d MB", ALLOWED_FILE_SIZE.toMegabytes(), + final String expectedMessage = String.format("The following files exceed the maximum size of %d MB:%n%s: %d MB", ALLOWED_FILE_SIZE.toMegabytes(), pathLargeFile, DataSize.ofBytes(TOO_LARGE_FILE_SIZE).toMegabytes()); assertThatThrownBy(() -> s3Adapter.loadFiles(filePaths)) @@ -283,8 +220,8 @@ void testLoadFilesThrowsFileSizeValidationExceptionDueToFileExceedingMaxSize() t void testTransferContent() throws IOException, DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final String folderPathWithSlash = "folder/"; final String folderPathWithoutSlash = "folder"; - final byte[] testPdf = new ClassPathResource("files/test/test-pdf.pdf").getInputStream().readAllBytes(); - final Content pdfContent = new Content("pdf", "test-pdf", testPdf); + final byte[] testPdf = new ClassPathResource(PDF_PATH).getInputStream().readAllBytes(); + final Content pdfContent = new Content(PDF, PDF_NAME, testPdf); final String fullPath = String.format("%s/%s", folderPathWithoutSlash, "test-pdf.pdf"); final String fullPathWrong = String.format("%s//%s", folderPathWithoutSlash, "test-pdf.pdf"); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/CancelObjectUseCaseTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/CancelObjectUseCaseTest.java index 2c5c8db7..4b067cce 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/CancelObjectUseCaseTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/CancelObjectUseCaseTest.java @@ -1,7 +1,6 @@ package de.muenchen.refarch.integration.dms.application.usecase; import de.muenchen.refarch.integration.dms.application.port.out.CancelObjectOutPort; -import de.muenchen.refarch.integration.dms.application.usecase.CancelObjectUseCase; import de.muenchen.refarch.integration.dms.domain.exception.DmsException; import org.junit.jupiter.api.Test; diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/CreateDocumentUseCaseTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/CreateDocumentUseCaseTest.java index cc92b0b8..e68b2144 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/CreateDocumentUseCaseTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/CreateDocumentUseCaseTest.java @@ -33,18 +33,19 @@ class CreateDocumentUseCaseTest { @Test void createDocument() throws DmsException, DocumentStorageException { - Content content = new Content("extension", "name", "content".getBytes()); - List filepaths = List.of("path/content.pdf"); - LocalDate testDate = LocalDate.parse("2023-12-01"); - String docCoo = "documentCOO"; - String user = "user"; - List fileCoos = List.of("contentCoo1", "contentCoo2"); + final Content content = new Content("extension", "name", "content".getBytes()); + final List filepaths = List.of("path/content.pdf"); + final LocalDate testDate = LocalDate.parse("2023-12-01"); + final String docCoo = "documentCOO"; + final String user = "user"; + final List fileCoos = List.of("contentCoo1", "contentCoo2"); when(this.loadFileOutPort.loadFiles(any())).thenReturn(List.of(content)); when(this.createDocumentOutPort.createDocument(any(), any())).thenReturn(docCoo); when(this.listContentOutPort.listContentCoos(docCoo, user)).thenReturn(fileCoos); - DocumentResponse documentResponse = createDocumentUseCase.createDocument("procedureCOO", "title", testDate, "user", DocumentType.EINGEHEND, filepaths); + final DocumentResponse documentResponse = createDocumentUseCase.createDocument("procedureCOO", "title", testDate, "user", DocumentType.EINGEHEND, + filepaths); assertEquals(docCoo, documentResponse.documentCoo()); assertEquals(fileCoos, documentResponse.contentCoos()); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/DepositObjectUseCaseTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/DepositObjectUseCaseTest.java index a798a269..171bbbc9 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/DepositObjectUseCaseTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/DepositObjectUseCaseTest.java @@ -1,7 +1,6 @@ package de.muenchen.refarch.integration.dms.application.usecase; import de.muenchen.refarch.integration.dms.application.port.out.DepositObjectOutPort; -import de.muenchen.refarch.integration.dms.application.usecase.DepositObjectUseCase; import de.muenchen.refarch.integration.dms.domain.exception.DmsException; import org.junit.jupiter.api.Test; diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/ReadContentUseCaseTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/ReadContentUseCaseTest.java index 3867382a..26304262 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/ReadContentUseCaseTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/ReadContentUseCaseTest.java @@ -25,9 +25,9 @@ class ReadContentUseCaseTest { private final ReadContentUseCase readContentUseCase = new ReadContentUseCase(transferContentOutPort, readContent); @Test - void readContent() throws DmsException, DocumentStorageException { + void testReadContent() throws DmsException, DocumentStorageException { - Content content = new Content("extension", "name", "content".getBytes()); + final Content content = new Content("extension", "name", "content".getBytes()); when(this.readContent.readContent(any(), any())).thenReturn(List.of(content)); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/ReadMetadataUseCaseTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/ReadMetadataUseCaseTest.java index 2455740e..244f6ae1 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/ReadMetadataUseCaseTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/ReadMetadataUseCaseTest.java @@ -16,6 +16,8 @@ class ReadMetadataUseCaseTest { + public static final String COO = "coo"; + public static final String USER = "user"; private final ReadMetadataOutPort readMetadataOutPort = mock(ReadMetadataOutPort.class); private final ReadMetadataUseCase readMetadataUseCase = new ReadMetadataUseCase(readMetadataOutPort); @@ -24,35 +26,35 @@ class ReadMetadataUseCaseTest { void readMetadata() throws DmsException { when(this.readMetadataOutPort.readMetadata(any(), any())).thenReturn(new Metadata("name", "Sachakte", "url")); - readMetadataUseCase.readMetadata(ObjectType.Sachakte, "coo", "user"); + readMetadataUseCase.readMetadata(ObjectType.Sachakte, COO, USER); - verify(this.readMetadataOutPort, times(1)).readMetadata("coo", "user"); + verify(this.readMetadataOutPort, times(1)).readMetadata(COO, USER); } @Test void readContentMetadata() throws DmsException { when(this.readMetadataOutPort.readContentMetadata(any(), any())).thenReturn(new Metadata("name", "type", "url")); - readMetadataUseCase.readMetadata(ObjectType.Schriftstueck, "coo", "user"); + readMetadataUseCase.readMetadata(ObjectType.Schriftstueck, COO, USER); - verify(this.readMetadataOutPort, times(1)).readContentMetadata("coo", "user"); + verify(this.readMetadataOutPort, times(1)).readContentMetadata(COO, USER); } @Test void readMetadataThrowsDmsException() throws DmsException { when(this.readMetadataOutPort.readMetadata(any(), any())).thenReturn(new Metadata("name", "Ausgang", "url")); - DmsException dmsException = catchThrowableOfType(() -> readMetadataUseCase.readMetadata(ObjectType.Sachakte, "coo", "user"), DmsException.class); + final DmsException dmsException = catchThrowableOfType(() -> readMetadataUseCase.readMetadata(ObjectType.Sachakte, COO, USER), DmsException.class); - String expectedMessage = String.format( + final String expectedMessage = String.format( "WRONG_INPUT_OBJECT_CLASS: The input object with the COO address %s is invalid because it is of the object class %s and this does not match the expected object class(es) %s.", - "coo", "Ausgang", "Sachakte"); - String actualMessage = dmsException.getMessage(); + COO, "Ausgang", "Sachakte"); + final String actualMessage = dmsException.getMessage(); assertThat(actualMessage).isEqualTo(expectedMessage); assertThat(dmsException.getStatusCode()).isEqualTo("WRONG_INPUT_OBJECT_CLASS"); - verify(this.readMetadataOutPort, times(1)).readMetadata("coo", "user"); + verify(this.readMetadataOutPort, times(1)).readMetadata(COO, USER); } } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/SearchFileUseCaseTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/SearchFileUseCaseTest.java index ee8f8dcc..0f841edf 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/SearchFileUseCaseTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/SearchFileUseCaseTest.java @@ -1,7 +1,6 @@ package de.muenchen.refarch.integration.dms.application.usecase; import de.muenchen.refarch.integration.dms.application.port.out.SearchFileOutPort; -import de.muenchen.refarch.integration.dms.application.usecase.SearchFileUseCase; import de.muenchen.refarch.integration.dms.domain.exception.DmsException; import org.junit.jupiter.api.Test; diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/SearchSubjectAreaUseCaseTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/SearchSubjectAreaUseCaseTest.java index 11ab062b..dc8710ba 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/SearchSubjectAreaUseCaseTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/SearchSubjectAreaUseCaseTest.java @@ -1,7 +1,6 @@ package de.muenchen.refarch.integration.dms.application.usecase; import de.muenchen.refarch.integration.dms.application.port.out.SearchSubjectAreaOutPort; -import de.muenchen.refarch.integration.dms.application.usecase.SearchSubjectAreaUseCase; import de.muenchen.refarch.integration.dms.domain.exception.DmsException; import org.junit.jupiter.api.Test; diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/UpdateDocumentUseCaseTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/UpdateDocumentUseCaseTest.java index b6397d08..0fc80cac 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/UpdateDocumentUseCaseTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-core/src/test/java/de/muenchen/refarch/integration/dms/application/usecase/UpdateDocumentUseCaseTest.java @@ -32,19 +32,19 @@ class UpdateDocumentUseCaseTest { @Test void updateDocument() throws DmsException, DocumentStorageException { - Content content = new Content("extension", "name", "content".getBytes()); + final Content content = new Content("extension", "name", "content".getBytes()); - List filepaths = List.of("path/content.pdf"); - String docCoo = "documentCOO"; - String user = "user"; - List fileCoos = List.of("contentCoo1", "contentCoo2"); + final List filepaths = List.of("path/content.pdf"); + final String docCoo = "documentCOO"; + final String user = "user"; + final List fileCoos = List.of("contentCoo1", "contentCoo2"); when(this.loadFileOutPort.loadFiles(any())).thenReturn(List.of(content)); when(this.listContentOutPort.listContentCoos(docCoo, user)).thenReturn(fileCoos); doNothing().when(updateDocumentOutPort).updateDocument(any(), any(), any(), any()); - DocumentResponse documentResponse = updateDocumentUseCase.updateDocument(docCoo, "user", DocumentType.EINGEHEND, filepaths); + final DocumentResponse documentResponse = updateDocumentUseCase.updateDocument(docCoo, "user", DocumentType.EINGEHEND, filepaths); assertEquals(docCoo, documentResponse.documentCoo()); assertEquals(fileCoos, documentResponse.contentCoos()); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/FabasoftMockApplication.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/FabasoftMockApplication.java index f8fb8139..03bd8f9d 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/FabasoftMockApplication.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/FabasoftMockApplication.java @@ -4,6 +4,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication +@SuppressWarnings("PMD.UseUtilityClass") public class FabasoftMockApplication { public static void main(final String[] args) { diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CancelObjectCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CancelObjectCase.java index 16099c99..983eb455 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CancelObjectCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CancelObjectCase.java @@ -4,16 +4,15 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.CancelObjectGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class CancelObjectCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val cancelObjectGIResponse = new CancelObjectGIResponse(); + final CancelObjectGIResponse cancelObjectGIResponse = new CancelObjectGIResponse(); cancelObjectGIResponse.setStatus(0); WiremockWsdlUtility.stubOperation( diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateFileCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateFileCase.java index eb9217ec..072d0035 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateFileCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateFileCase.java @@ -4,16 +4,15 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.CreateFileGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class CreateFileCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val createFileGIResponse = new CreateFileGIResponse(); + final CreateFileGIResponse createFileGIResponse = new CreateFileGIResponse(); createFileGIResponse.setObjid("1234567890"); WiremockWsdlUtility.stubOperation( diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateIncomingDocumentCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateIncomingDocumentCase.java index 125dda15..ca497777 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateIncomingDocumentCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateIncomingDocumentCase.java @@ -4,16 +4,15 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.CreateIncomingGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class CreateIncomingDocumentCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val createIncomingGIResponse = new CreateIncomingGIResponse(); + final CreateIncomingGIResponse createIncomingGIResponse = new CreateIncomingGIResponse(); createIncomingGIResponse.setObjid("1234567890"); WiremockWsdlUtility.stubOperation( diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateInternalDocumentCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateInternalDocumentCase.java index 6767710a..f335ee74 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateInternalDocumentCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateInternalDocumentCase.java @@ -4,16 +4,15 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.CreateInternalGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class CreateInternalDocumentCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val createInternalGIResponse = new CreateInternalGIResponse(); + final CreateInternalGIResponse createInternalGIResponse = new CreateInternalGIResponse(); createInternalGIResponse.setObjid("1234567890"); WiremockWsdlUtility.stubOperation( diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateOutgoingDocumentCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateOutgoingDocumentCase.java index 758d44ea..7aac8ac8 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateOutgoingDocumentCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateOutgoingDocumentCase.java @@ -4,16 +4,15 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.CreateOutgoingGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class CreateOutgoingDocumentCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val createOutgoingGIResponse = new CreateOutgoingGIResponse(); + final CreateOutgoingGIResponse createOutgoingGIResponse = new CreateOutgoingGIResponse(); createOutgoingGIResponse.setObjid("1234567890"); WiremockWsdlUtility.stubOperation( diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateProcedureCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateProcedureCase.java index 478d22a5..a93175fc 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateProcedureCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/CreateProcedureCase.java @@ -4,16 +4,15 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.CreateProcedureGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class CreateProcedureCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val createProcedureGIResponse = new CreateProcedureGIResponse(); + final CreateProcedureGIResponse createProcedureGIResponse = new CreateProcedureGIResponse(); createProcedureGIResponse.setObjid("1234567890"); WiremockWsdlUtility.stubOperation( diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/DMSObjectClass.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/DMSObjectClass.java index 59687200..5330753d 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/DMSObjectClass.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/DMSObjectClass.java @@ -3,6 +3,7 @@ /** * All known object classes to provide soap requests with. */ +@SuppressWarnings({ "PMD.FieldNamingConventions", "PMD.ExcessivePublicCount" }) public enum DMSObjectClass { Fileplan("COOELAK@1.1001:Fileplan"), diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/DepositObjectCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/DepositObjectCase.java index 0f7f43ae..6744f050 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/DepositObjectCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/DepositObjectCase.java @@ -4,16 +4,15 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.DepositObjectGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class DepositObjectCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val depositObjectGIResponse = new DepositObjectGIResponse(); + final DepositObjectGIResponse depositObjectGIResponse = new DepositObjectGIResponse(); depositObjectGIResponse.setObjid("1234567890"); WiremockWsdlUtility.stubOperation( diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/MockInitializer.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/MockInitializer.java index cd2b9fd3..6b538e06 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/MockInitializer.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/MockInitializer.java @@ -19,7 +19,7 @@ public class MockInitializer { @PostConstruct public void init() { - WireMockServer server = new WireMockServer(port); + final WireMockServer server = new WireMockServer(port); server.start(); mockCases.forEach(mock -> mock.initCase(server)); } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/ReadContentCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/ReadContentCase.java index 9d913748..ac59faf5 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/ReadContentCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/ReadContentCase.java @@ -5,7 +5,6 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.stereotype.Component; @@ -16,21 +15,21 @@ public class ReadContentCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val content = new LHMBAI151700GIAttachmentType(); + final LHMBAI151700GIAttachmentType content = new LHMBAI151700GIAttachmentType(); content.setLHMBAI151700Filename("test"); content.setLHMBAI151700Fileextension("pdf"); try { - Resource resource = new ClassPathResource("data/test.pdf"); - byte[] data = resource.getInputStream().readAllBytes(); + final Resource resource = new ClassPathResource("data/test.pdf"); + final byte[] data = resource.getInputStream().readAllBytes(); content.setLHMBAI151700Filecontent(data); - } catch (IOException e) { + } catch (final IOException e) { throw new RuntimeException(e); } - val response = new ReadContentObjectGIResponse(); + final ReadContentObjectGIResponse response = new ReadContentObjectGIResponse(); response.setStatus(0); response.setGiattachmenttype(content); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/ReadContentObjectMetaDataCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/ReadContentObjectMetaDataCase.java index 24e2270e..f37c2456 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/ReadContentObjectMetaDataCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/ReadContentObjectMetaDataCase.java @@ -5,20 +5,19 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectMetaDataGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class ReadContentObjectMetaDataCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val content = new LHMBAI151700GIMetadataType(); + final LHMBAI151700GIMetadataType content = new LHMBAI151700GIMetadataType(); content.setLHMBAI151700Filename("name"); content.setLHMBAI151700Objclass("pdf"); - val response = new ReadContentObjectMetaDataGIResponse(); + final ReadContentObjectMetaDataGIResponse response = new ReadContentObjectMetaDataGIResponse(); response.setStatus(0); response.setGimetadatatype(content); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/ReadMetadataObjectCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/ReadMetadataObjectCase.java index 09b47b7b..c6462829 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/ReadMetadataObjectCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/ReadMetadataObjectCase.java @@ -4,7 +4,6 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadMetadataObjectGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @@ -12,9 +11,9 @@ public class ReadMetadataObjectCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val response = new ReadMetadataObjectGIResponse(); + final ReadMetadataObjectGIResponse response = new ReadMetadataObjectGIResponse(); response.setStatus(0); response.setObjclass("Vorgang"); response.setObjname("name"); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/SearchFileCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/SearchFileCase.java index 1e758992..3296b658 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/SearchFileCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/SearchFileCase.java @@ -6,23 +6,22 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.SearchObjNameGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class SearchFileCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val file = new LHMBAI151700GIObjectType(); + final LHMBAI151700GIObjectType file = new LHMBAI151700GIObjectType(); file.setLHMBAI151700Objaddress("fileCoo"); file.setLHMBAI151700Objname("fileName"); - val array = new ArrayOfLHMBAI151700GIObjectType(); + final ArrayOfLHMBAI151700GIObjectType array = new ArrayOfLHMBAI151700GIObjectType(); array.getLHMBAI151700GIObjectType().add(file); - val response = new SearchObjNameGIResponse(); + final SearchObjNameGIResponse response = new SearchObjNameGIResponse(); response.setStatus(0); response.setGiobjecttype(array); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/SearchSubjectAreaCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/SearchSubjectAreaCase.java index 6ce541dc..757465b4 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/SearchSubjectAreaCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/SearchSubjectAreaCase.java @@ -6,23 +6,22 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.SearchObjNameGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class SearchSubjectAreaCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val file = new LHMBAI151700GIObjectType(); + final LHMBAI151700GIObjectType file = new LHMBAI151700GIObjectType(); file.setLHMBAI151700Objaddress("subjectAreaCoo"); file.setLHMBAI151700Objname("subjectAreaName"); - val array = new ArrayOfLHMBAI151700GIObjectType(); + final ArrayOfLHMBAI151700GIObjectType array = new ArrayOfLHMBAI151700GIObjectType(); array.getLHMBAI151700GIObjectType().add(file); - val response = new SearchObjNameGIResponse(); + final SearchObjNameGIResponse response = new SearchObjNameGIResponse(); response.setStatus(0); response.setGiobjecttype(array); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/UpdateIncomingDocumentCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/UpdateIncomingDocumentCase.java index a4378983..10cd060c 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/UpdateIncomingDocumentCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/UpdateIncomingDocumentCase.java @@ -4,16 +4,15 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.UpdateIncomingGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class UpdateIncomingDocumentCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val updateIncomingGIResponse = new UpdateIncomingGIResponse(); + final UpdateIncomingGIResponse updateIncomingGIResponse = new UpdateIncomingGIResponse(); updateIncomingGIResponse.setObjid("1234567890"); WiremockWsdlUtility.stubOperation( diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/UpdateInternalDocumentCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/UpdateInternalDocumentCase.java index 13f1642a..ed8efbb7 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/UpdateInternalDocumentCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/UpdateInternalDocumentCase.java @@ -4,16 +4,15 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.UpdateInternalGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class UpdateInternalDocumentCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val updateInternalGIResponse = new UpdateInternalGIResponse(); + final UpdateInternalGIResponse updateInternalGIResponse = new UpdateInternalGIResponse(); updateInternalGIResponse.setObjid("1234567890"); WiremockWsdlUtility.stubOperation( diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/UpdateOutgoingDocumentCase.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/UpdateOutgoingDocumentCase.java index f1264d9b..250438ef 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/UpdateOutgoingDocumentCase.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/cases/UpdateOutgoingDocumentCase.java @@ -4,16 +4,15 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.UpdateOutgoingGIResponse; import com.github.tomakehurst.wiremock.WireMockServer; import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; -import lombok.val; import org.springframework.stereotype.Component; @Component public class UpdateOutgoingDocumentCase implements MockCase { @Override - public void initCase(WireMockServer server) { + public void initCase(final WireMockServer server) { - val updateOutgoingGIResponse = new UpdateOutgoingGIResponse(); + final UpdateOutgoingGIResponse updateOutgoingGIResponse = new UpdateOutgoingGIResponse(); updateOutgoingGIResponse.setObjid("1234567890"); WiremockWsdlUtility.stubOperation( diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/test/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/ExampleTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/test/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/ExampleTest.java index 037f6d4a..375f3727 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/test/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/ExampleTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock-service/src/test/java/de/muenchen/refarch/integration/dms/fabasoft/mock/service/ExampleTest.java @@ -5,8 +5,7 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.CreateProcedureGI; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.CreateProcedureGIResponse; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.LHMBAI151700GIWSDSoap; -import de.muenchen.refarch.integration.dms.fabasoft.mock.FabasoftClienFactory; -import de.muenchen.refarch.integration.dms.fabasoft.mock.service.FabasoftMockApplication; +import de.muenchen.refarch.integration.dms.fabasoft.mock.FabasoftClientFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; @@ -15,7 +14,7 @@ @SpringBootTest(classes = FabasoftMockApplication.class, properties = "mock.port=9070", webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("itest") -public class ExampleTest { +class ExampleTest { @Value("${mock.port:9070}") private int port; @@ -23,12 +22,12 @@ public class ExampleTest { private LHMBAI151700GIWSDSoap soapClient; @BeforeEach - public void setUp() { - this.soapClient = FabasoftClienFactory.dmsWsClient("http://localhost:" + port + "/"); + void setUp() { + this.soapClient = FabasoftClientFactory.dmsWsClient("http://localhost:" + port + "/"); } @Test - public void execute_createProcedure_request() { + void executeCreateProcedureRequest() { final CreateProcedureGI request = new CreateProcedureGI(); request.setUserlogin("user"); request.setReferrednumber("fileCOO"); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/FabasoftClienFactory.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/FabasoftClientFactory.java similarity index 78% rename from refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/FabasoftClienFactory.java rename to refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/FabasoftClientFactory.java index e74fba39..180144ce 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/FabasoftClienFactory.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/FabasoftClientFactory.java @@ -8,9 +8,11 @@ /** * Configuration of the Webservice Client. */ -public class FabasoftClienFactory { +public final class FabasoftClientFactory { + private FabasoftClientFactory() { + } - public static LHMBAI151700GIWSDSoap dmsWsClient(String address) { + public static LHMBAI151700GIWSDSoap dmsWsClient(final String address) { final LHMBAI151700GIWSD service = new LHMBAI151700GIWSD(); final LHMBAI151700GIWSDSoap soapClient = service.getLHMBAI151700GIWSDSoap(); ((BindingProvider) soapClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address); diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/SoapObjectMatcher.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/SoapObjectMatcher.java index 1d84a41c..abe22c55 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/SoapObjectMatcher.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/SoapObjectMatcher.java @@ -15,14 +15,14 @@ public class SoapObjectMatcher extends RequestMatcherExtension { private final Predicate predicate; @Override - public MatchResult match(Request request, Parameters parameters) { + public MatchResult match(final Request request, final Parameters parameters) { if (!request.getHeader("SOAPAction").equals("\"http://schemas.fabasoft.com/object/LHMBAI_15_1700_" + operation + "\"")) { return MatchResult.noMatch(); } - T object = WiremockWsdlUtility.deserializeSoapRequest(request.getBodyAsString(), clazz); - boolean erg = predicate.test(object); + final T object = WiremockWsdlUtility.deserializeSoapRequest(request.getBodyAsString(), clazz); + final boolean erg = predicate.test(object); return erg ? MatchResult.exactMatch() : MatchResult.noMatch(); } } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/WiremockWsdlUtility.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/WiremockWsdlUtility.java index 3359d81e..e12ff8ee 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/WiremockWsdlUtility.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/main/java/de/muenchen/refarch/integration/dms/fabasoft/mock/WiremockWsdlUtility.java @@ -22,28 +22,30 @@ import org.apache.commons.lang3.StringUtils; import org.w3c.dom.Document; -public class WiremockWsdlUtility { +public final class WiremockWsdlUtility { + private WiremockWsdlUtility() { + } /** * Accepts a WebService response object (as defined in the WSDL) and marshals * to a SOAP envelope String. */ - static String serializeObject(T object) { - ByteArrayOutputStream byteArrayOutputStream; - Class clazz = object.getClass(); - String responseRootTag = StringUtils.uncapitalize(clazz.getSimpleName()); - QName payloadName = new QName("your_namespace_URI", responseRootTag, "namespace_prefix"); + public static String serializeObject(final T object) { + final ByteArrayOutputStream byteArrayOutputStream; + final Class clazz = object.getClass(); + final String responseRootTag = StringUtils.uncapitalize(clazz.getSimpleName()); + final QName payloadName = new QName("your_namespace_URI", responseRootTag, "namespace_prefix"); try { - JAXBContext jaxbContext = JAXBContext.newInstance(clazz); - Marshaller objectMarshaller = jaxbContext.createMarshaller(); + final JAXBContext jaxbContext = JAXBContext.newInstance(clazz); + final Marshaller objectMarshaller = jaxbContext.createMarshaller(); - JAXBElement jaxbElement = new JAXBElement<>(payloadName, clazz, null, object); - Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + final JAXBElement jaxbElement = new JAXBElement<>(payloadName, clazz, null, object); + final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); objectMarshaller.marshal(jaxbElement, document); - SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); - SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); + final SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); + final SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); body.addDocument(document); byteArrayOutputStream = new ByteArrayOutputStream(); @@ -60,21 +62,21 @@ static String serializeObject(T object) { * Accepts a WebService request object (as defined in the WSDL) and unmarshals * to the supplied type. */ - static T deserializeSoapRequest(String soapRequest, Class clazz) { + public static T deserializeSoapRequest(final String soapRequest, final Class clazz) { - XMLInputFactory xif = XMLInputFactory.newFactory(); - JAXBElement jb; + final XMLInputFactory xif = XMLInputFactory.newFactory(); + final JAXBElement jb; try { - XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(soapRequest)); + final XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(soapRequest)); // Advance the tag iterator to the tag after Body, eg the start of the SOAP payload object do { xsr.nextTag(); - } while (!xsr.getLocalName().equals("Body")); + } while (!"Body".equals(xsr.getLocalName())); xsr.nextTag(); - JAXBContext jc = JAXBContext.newInstance(clazz); - Unmarshaller unmarshaller = jc.createUnmarshaller(); + final JAXBContext jc = JAXBContext.newInstance(clazz); + final Unmarshaller unmarshaller = jc.createUnmarshaller(); jb = unmarshaller.unmarshal(xsr, clazz); xsr.close(); } catch (Exception e) { @@ -84,14 +86,15 @@ static T deserializeSoapRequest(String soapRequest, Class clazz) { return jb.getValue(); } - public static void stubOperation(String operation, Class clazz, Predicate predicate, Object response) { + public static void stubOperation(final String operation, final Class clazz, final Predicate predicate, final Object response) { stubFor(requestMatching(new SoapObjectMatcher<>(clazz, operation, predicate)) .willReturn(aResponse() .withHeader("Content-Type", "text/xml") .withBody(serializeObject(response)))); } - public static void stubOperation(WireMockServer server, String operation, Class clazz, Predicate predicate, Object response) { + public static void stubOperation(final WireMockServer server, final String operation, final Class clazz, final Predicate predicate, + final Object response) { server.stubFor(requestMatching(new SoapObjectMatcher<>(clazz, operation, predicate)) .willReturn(aResponse() .withHeader("Content-Type", "text/xml") diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/test/java/de/muenchen/refarch/integration/dms/fabasoft/mock/ExampleTest.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/test/java/de/muenchen/refarch/integration/dms/fabasoft/mock/ExampleTest.java index fdddda0a..a6d73e1c 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/test/java/de/muenchen/refarch/integration/dms/fabasoft/mock/ExampleTest.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-fabasoft/refarch-dms-integration-fabasoft-mock/src/test/java/de/muenchen/refarch/integration/dms/fabasoft/mock/ExampleTest.java @@ -1,6 +1,5 @@ package de.muenchen.refarch.integration.dms.fabasoft.mock; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.CreateProcedureGI; @@ -8,23 +7,21 @@ import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.LHMBAI151700GIWSDSoap; import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; import com.github.tomakehurst.wiremock.junit5.WireMockTest; -import de.muenchen.refarch.integration.dms.fabasoft.mock.FabasoftClienFactory; -import de.muenchen.refarch.integration.dms.fabasoft.mock.WiremockWsdlUtility; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @WireMockTest() -public class ExampleTest { +class ExampleTest { private LHMBAI151700GIWSDSoap soapClient; @BeforeEach - public void setUp(WireMockRuntimeInfo wmRuntimeInfo) { - soapClient = FabasoftClienFactory.dmsWsClient("http://localhost:" + wmRuntimeInfo.getHttpPort() + "/"); + public void setUp(final WireMockRuntimeInfo wmRuntimeInfo) { + soapClient = FabasoftClientFactory.dmsWsClient("http://localhost:" + wmRuntimeInfo.getHttpPort() + "/"); } @Test - public void execute_createProcedure_request() { + void executeCreateProcedureRequest() { WiremockWsdlUtility.stubOperation( "CreateProcedureGI", CreateProcedureGI.class, (u) -> "new procedure".equals(u.getShortname()), @@ -39,6 +36,7 @@ public void execute_createProcedure_request() { request.setFiletype("Elektronisch"); final CreateProcedureGIResponse response = this.soapClient.createProcedureGI(request); + assertNotNull(response); } diff --git a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-starter/src/main/java/de/muenchen/refarch/integration/dms/configuration/DmsAutoConfiguration.java b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-starter/src/main/java/de/muenchen/refarch/integration/dms/configuration/DmsAutoConfiguration.java index 2ec4104e..abd6a76e 100644 --- a/refarch-integrations/refarch-dms-integration/refarch-dms-integration-starter/src/main/java/de/muenchen/refarch/integration/dms/configuration/DmsAutoConfiguration.java +++ b/refarch-integrations/refarch-dms-integration/refarch-dms-integration-starter/src/main/java/de/muenchen/refarch/integration/dms/configuration/DmsAutoConfiguration.java @@ -53,6 +53,7 @@ @RequiredArgsConstructor @Import(FabasoftClientConfiguration.class) @EnableConfigurationProperties({ FabasoftProperties.class, DmsProperties.class }) +@SuppressWarnings("PMD.CouplingBetweenObjects") public class DmsAutoConfiguration { @Bean @@ -83,6 +84,7 @@ public S3Adapter s3Adapter(final DocumentStorageFileRepository documentStorageFi * @return {@link SupportedFileExtensions} object representing the supported file extensions. */ @Bean + @SuppressWarnings("PMD.LooseCoupling") public SupportedFileExtensions supportedFileExtensions(final DmsProperties dmsProperties) { final SupportedFileExtensions supportedFileExtensions = new SupportedFileExtensions(); supportedFileExtensions.putAll(dmsProperties.getSupportedFileExtensions()); @@ -121,37 +123,37 @@ public UpdateDocumentInPort updateDocumentInPort( @Bean @ConditionalOnMissingBean - public DepositObjectInPort depositObjectInPort(DepositObjectOutPort depositObjectOutPort) { + public DepositObjectInPort depositObjectInPort(final DepositObjectOutPort depositObjectOutPort) { return new DepositObjectUseCase(depositObjectOutPort); } @Bean @ConditionalOnMissingBean - public CancelObjectInPort cancelObjectInPort(CancelObjectOutPort cancelObjectOutPort) { + public CancelObjectInPort cancelObjectInPort(final CancelObjectOutPort cancelObjectOutPort) { return new CancelObjectUseCase(cancelObjectOutPort); } @Bean @ConditionalOnMissingBean - public ReadContentInPort readContentInPort(ReadContentOutPort readContentOutPort, TransferContentOutPort transferContentOutPort) { + public ReadContentInPort readContentInPort(final ReadContentOutPort readContentOutPort, final TransferContentOutPort transferContentOutPort) { return new ReadContentUseCase(transferContentOutPort, readContentOutPort); } @Bean @ConditionalOnMissingBean - public SearchFileInPort searchFileInPort(SearchFileOutPort searchFileOutPort) { + public SearchFileInPort searchFileInPort(final SearchFileOutPort searchFileOutPort) { return new SearchFileUseCase(searchFileOutPort); } @Bean @ConditionalOnMissingBean - public SearchSubjectAreaInPort searchSubjectAreaInPort(SearchSubjectAreaOutPort searchSubjectAreaOutPort) { + public SearchSubjectAreaInPort searchSubjectAreaInPort(final SearchSubjectAreaOutPort searchSubjectAreaOutPort) { return new SearchSubjectAreaUseCase(searchSubjectAreaOutPort); } @Bean @ConditionalOnMissingBean - public ReadMetadataInPort readMetadataInPort(ReadMetadataOutPort readMetadataOutPort) { + public ReadMetadataInPort readMetadataInPort(final ReadMetadataOutPort readMetadataOutPort) { return new ReadMetadataUseCase(readMetadataOutPort); } } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/adapter/out/mail/MailAdapter.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/adapter/out/mail/MailAdapter.java index ab4c8ecc..d9d0faad 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/adapter/out/mail/MailAdapter.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/adapter/out/mail/MailAdapter.java @@ -15,12 +15,12 @@ public class MailAdapter implements MailOutPort { private final EmailApi emailApi; @Override - public void sendMail(Mail mail, String logoPath) throws MessagingException { + public void sendMail(final Mail mail, final String logoPath) throws MessagingException { this.emailApi.sendMail(mail, logoPath); } @Override - public String getBodyFromTemplate(String templateName, Map content) throws TemplateException, IOException { + public String getBodyFromTemplate(final String templateName, final Map content) throws TemplateException, IOException { return this.emailApi.getBodyFromTemplate(templateName, content); } } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/adapter/out/s3/S3Adapter.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/adapter/out/s3/S3Adapter.java index 99cd98d3..f7518f6a 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/adapter/out/s3/S3Adapter.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/adapter/out/s3/S3Adapter.java @@ -44,12 +44,13 @@ private List getFilesFromFolder(final String folderPath) { final List contents = new ArrayList<>(); final Set filepath; filepath = documentStorageFolderRepository.getAllFilesInFolderRecursively(folderPath); - if (Objects.isNull(filepath)) + if (Objects.isNull(filepath)) { throw new LoadAttachmentError("An folder could not be loaded from url: " + folderPath); + } filepath.forEach(file -> contents.add(getFile(file))); return contents; } catch (final DocumentStorageException | DocumentStorageServerErrorException | DocumentStorageClientErrorException e) { - throw new LoadAttachmentError("An folder could not be loaded from path: " + folderPath); + throw new LoadAttachmentError("An folder could not be loaded from path: " + folderPath, e); } } @@ -61,12 +62,13 @@ private FileAttachment getFile(final String filePath) { final String filename = FilenameUtils.getName(filePath); final ByteArrayDataSource file = new ByteArrayDataSource(bytes, mimeType); - if (!fileValidationService.isSupported(mimeType)) + if (!fileValidationService.isSupported(mimeType)) { throw new LoadAttachmentError("The type of this file is not supported: " + filePath); + } return new FileAttachment(filename, file); } catch (final DocumentStorageException | DocumentStorageServerErrorException | DocumentStorageClientErrorException e) { - throw new LoadAttachmentError("An file could not be loaded from path: " + filePath); + throw new LoadAttachmentError("An file could not be loaded from path: " + filePath, e); } } } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/application/port/in/SendMailInPort.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/application/port/in/SendMailInPort.java index 33bd8a94..89c837a0 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/application/port/in/SendMailInPort.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/application/port/in/SendMailInPort.java @@ -6,8 +6,8 @@ public interface SendMailInPort { - void sendMailWithText(@Valid final TextMail mail); + void sendMailWithText(@Valid TextMail mail); - void sendMailWithTemplate(@Valid final TemplateMail mail); + void sendMailWithTemplate(@Valid TemplateMail mail); } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/application/port/out/LoadMailAttachmentOutPort.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/application/port/out/LoadMailAttachmentOutPort.java index f56157a4..5daf3fb5 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/application/port/out/LoadMailAttachmentOutPort.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/application/port/out/LoadMailAttachmentOutPort.java @@ -4,5 +4,5 @@ import java.util.List; public interface LoadMailAttachmentOutPort { - List loadAttachments(final List filePaths); + List loadAttachments(List filePaths); } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/application/usecase/SendMailUseCase.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/application/usecase/SendMailUseCase.java index 7b460417..ade794ad 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/application/usecase/SendMailUseCase.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/application/usecase/SendMailUseCase.java @@ -36,32 +36,32 @@ public class SendMailUseCase implements SendMailInPort { */ @Override public void sendMailWithText(@Valid final TextMail mail) { - Mail mailModel = createMail(mail, mail.getBody(), false); + final Mail mailModel = createMail(mail, mail.getBody(), false); this.sendMail(mailModel, null); } @Override - public void sendMailWithTemplate(@Valid final TemplateMail mail) throws TemplateError { + public void sendMailWithTemplate(@Valid final TemplateMail mail) { // get body from template try { - Map content = new HashMap<>(mail.getContent()); - String body = this.mailOutPort.getBodyFromTemplate(mail.getTemplate(), content); + final Map content = new HashMap<>(mail.getContent()); + final String body = this.mailOutPort.getBodyFromTemplate(mail.getTemplate(), content); - Mail mailModel = createMail(mail, body, true); + final Mail mailModel = createMail(mail, body, true); this.sendMail(mailModel, "templates/email-logo.png"); } catch (IOException ioException) { - throw new TemplateError("The template " + mail.getTemplate() + " could not be loaded"); + throw new TemplateError("The template " + mail.getTemplate() + " could not be loaded", ioException); } catch (TemplateException templateException) { - throw new TemplateError(templateException.getMessage()); + throw new TemplateError(templateException.getMessage(), templateException); } } private Mail createMail(final BasicMail mail, final String body, final boolean htmlBody) { // load Attachments - List attachments = loadAttachmentOutPort.loadAttachments(mail.getFilePaths()); + final List attachments = loadAttachmentOutPort.loadAttachments(mail.getFilePaths()); // send mail return new Mail( @@ -76,12 +76,12 @@ private Mail createMail(final BasicMail mail, final String body, final boolean h attachments); } - private void sendMail(Mail mailModel, String logoPath) throws MailSendException { + private void sendMail(final Mail mailModel, final String logoPath) { try { this.mailOutPort.sendMail(mailModel, logoPath); } catch (final MessagingException ex) { log.error("Sending mail failed with exception: {}", ex.getMessage()); - throw new MailSendException(ex.getMessage()); + throw new MailSendException(ex.getMessage(), ex); } } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/exception/LoadAttachmentError.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/exception/LoadAttachmentError.java index ba854d6b..35a1674c 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/exception/LoadAttachmentError.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/exception/LoadAttachmentError.java @@ -1,7 +1,12 @@ package de.muenchen.refarch.email.integration.domain.exception; -public class LoadAttachmentError extends Error { +@SuppressWarnings("PMD.MissingSerialVersionUID") +public class LoadAttachmentError extends RuntimeException { public LoadAttachmentError(final String message) { super(message); } + + public LoadAttachmentError(final String message, final Exception cause) { + super(message, cause); + } } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/exception/TemplateError.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/exception/TemplateError.java index 7189207f..21d5049d 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/exception/TemplateError.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/exception/TemplateError.java @@ -1,7 +1,8 @@ package de.muenchen.refarch.email.integration.domain.exception; -public class TemplateError extends Error { - public TemplateError(final String message) { - super(message); +@SuppressWarnings("PMD.MissingSerialVersionUID") +public class TemplateError extends RuntimeException { + public TemplateError(final String message, final Exception cause) { + super(message, cause); } } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/model/TemplateMail.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/model/TemplateMail.java index 56ca2683..2dc64b1e 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/model/TemplateMail.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/model/TemplateMail.java @@ -23,8 +23,9 @@ public class TemplateMail extends BasicMail { @NotEmpty(message = "No content given") private final Map content; - public TemplateMail(String receivers, String receiversCc, String receiversBcc, String subject, String replyTo, List filePaths, - String template, Map content) { + public TemplateMail(final String receivers, final String receiversCc, final String receiversBcc, final String subject, final String replyTo, + final List filePaths, + final String template, final Map content) { super(receivers, receiversCc, receiversBcc, subject, replyTo, filePaths); this.template = template; this.content = content; diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/model/TextMail.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/model/TextMail.java index 315a381c..a0d1d056 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/model/TextMail.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/main/java/de/muenchen/refarch/email/integration/domain/model/TextMail.java @@ -18,8 +18,8 @@ public class TextMail extends BasicMail { @NotBlank(message = "No body given") private final String body; - public TextMail(String receivers, String receiversCc, String receiversBcc, String subject, String body, String replyTo, - List filePaths) { + public TextMail(final String receivers, final String receiversCc, final String receiversBcc, final String subject, final String body, final String replyTo, + final List filePaths) { super(receivers, receiversCc, receiversBcc, subject, replyTo, filePaths); this.body = body; } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/test/java/de/muenchen/refarch/email/integration/adapter/out/mail/MailAdapterTest.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/test/java/de/muenchen/refarch/email/integration/adapter/out/mail/MailAdapterTest.java index d39bc472..c26fcc5e 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/test/java/de/muenchen/refarch/email/integration/adapter/out/mail/MailAdapterTest.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/test/java/de/muenchen/refarch/email/integration/adapter/out/mail/MailAdapterTest.java @@ -37,10 +37,10 @@ void sendMail() throws MessagingException { } @Test - void getBodyFromTemplate() throws TemplateException, IOException { + void testGetBodyFromTemplate() throws TemplateException, IOException { final MailAdapter mailAdapter = new MailAdapter(emailApi); when(emailApi.getBodyFromTemplate(anyString(), anyMap())).thenReturn("generated body"); - String body = mailAdapter.getBodyFromTemplate("template", Map.of("key", "value")); + final String body = mailAdapter.getBodyFromTemplate("template", Map.of("key", "value")); assertThat(body).isEqualTo("generated body"); verify(emailApi).getBodyFromTemplate("template", Map.of("key", "value")); diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/test/java/de/muenchen/refarch/email/integration/adapter/out/s3/S3AdapterTest.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/test/java/de/muenchen/refarch/email/integration/adapter/out/s3/S3AdapterTest.java index cff7d114..f9d4a908 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/test/java/de/muenchen/refarch/email/integration/adapter/out/s3/S3AdapterTest.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/test/java/de/muenchen/refarch/email/integration/adapter/out/s3/S3AdapterTest.java @@ -41,7 +41,7 @@ void setup() { } @Test - void testLoadAttachment_DocumentStorageException() + void testLoadAttachmentDocumentStorageException() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final String path = "path/to/some-file.txt"; @@ -53,7 +53,7 @@ void testLoadAttachment_DocumentStorageException() } @Test - void testLoadAttachment_Success() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { + void testLoadAttachmentSuccess() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final Map files = Map.of( "test-logo.png", "image/png", "test-pdf.pdf", "application/pdf", diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/test/java/de/muenchen/refarch/email/integration/application/usecase/SendMailUseCaseTest.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/test/java/de/muenchen/refarch/email/integration/application/usecase/SendMailUseCaseTest.java index f43cda9f..768217ba 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/test/java/de/muenchen/refarch/email/integration/application/usecase/SendMailUseCaseTest.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-core/src/test/java/de/muenchen/refarch/email/integration/application/usecase/SendMailUseCaseTest.java @@ -118,23 +118,23 @@ void sendMailWithTemplate() throws MessagingException, TemplateException, IOExce @Test void sendMailWithTemplateThrowsIOException() throws TemplateException, IOException { doThrow(new IOException("IO Exception")).when(mailOutPort).getBodyFromTemplate(anyString(), anyMap()); - TemplateError error = catchThrowableOfType(() -> sendMailInPort.sendMailWithTemplate(templateMail), TemplateError.class); + final TemplateError error = catchThrowableOfType(() -> sendMailInPort.sendMailWithTemplate(templateMail), TemplateError.class); - String expectedMessage = "The template " + templateMail.getTemplate() + " could not be loaded"; - String actualMessage = error.getMessage(); + final String expectedMessage = "The template " + templateMail.getTemplate() + " could not be loaded"; + final String actualMessage = error.getMessage(); assertThat(actualMessage).isEqualTo(expectedMessage); } @Test void sendMailWithTemplateThrowsTemplateException() throws TemplateException, IOException { - TemplateException templateException = mock(TemplateException.class); + final TemplateException templateException = mock(TemplateException.class); when(templateException.getMessage()).thenReturn("Template Exception Message"); doThrow(templateException).when(mailOutPort).getBodyFromTemplate(anyString(), anyMap()); - TemplateError error = catchThrowableOfType(() -> sendMailInPort.sendMailWithTemplate(templateMail), TemplateError.class); + final TemplateError error = catchThrowableOfType(() -> sendMailInPort.sendMailWithTemplate(templateMail), TemplateError.class); - String expectedMessage = "Template Exception Message"; - String actualMessage = error.getMessage(); + final String expectedMessage = "Template Exception Message"; + final String actualMessage = error.getMessage(); assertThat(actualMessage).isEqualTo(expectedMessage); } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-java-example/src/main/java/de/muenchen/refarch/email/integration/EmailJavaExampleApplication.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-java-example/src/main/java/de/muenchen/refarch/email/integration/EmailJavaExampleApplication.java index ceb02d27..f7a29065 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-java-example/src/main/java/de/muenchen/refarch/email/integration/EmailJavaExampleApplication.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-java-example/src/main/java/de/muenchen/refarch/email/integration/EmailJavaExampleApplication.java @@ -4,20 +4,22 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.ApplicationContext; import org.springframework.context.event.EventListener; @SpringBootApplication @RequiredArgsConstructor public class EmailJavaExampleApplication { - private final TestService testService; + private final ExampleMailService exampleMailService; + private final ApplicationContext context; public static void main(final String[] args) { SpringApplication.run(EmailJavaExampleApplication.class, args); } @EventListener(ApplicationReadyEvent.class) - void sendTestMail() { - this.testService.testSendMail(); - System.exit(0); + public void sendTestMail() { + this.exampleMailService.testSendMail(); + SpringApplication.exit(context); } } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-java-example/src/main/java/de/muenchen/refarch/email/integration/TestService.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-java-example/src/main/java/de/muenchen/refarch/email/integration/ExampleMailService.java similarity index 83% rename from refarch-integrations/refarch-email-integration/refarch-email-integration-java-example/src/main/java/de/muenchen/refarch/email/integration/TestService.java rename to refarch-integrations/refarch-email-integration/refarch-email-integration-java-example/src/main/java/de/muenchen/refarch/email/integration/ExampleMailService.java index eebbf175..9718928b 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-java-example/src/main/java/de/muenchen/refarch/email/integration/TestService.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-java-example/src/main/java/de/muenchen/refarch/email/integration/ExampleMailService.java @@ -13,13 +13,13 @@ @Service @RequiredArgsConstructor @Slf4j -public class TestService { +public class ExampleMailService { private final SendMailInPort sendMailInPort; private final DocumentStorageFileRepository documentStorageFileRepository; - void testSendMail() { + public void testSendMail() { this.uploadTestFile(); - TextMail mail = new TextMail( + final TextMail mail = new TextMail( "test.receiver@muenchen.de", null, null, @@ -32,8 +32,8 @@ void testSendMail() { } @SneakyThrows - void uploadTestFile() { - ClassPathResource resource = new ClassPathResource("/files/test-pdf.pdf"); + private void uploadTestFile() { + final ClassPathResource resource = new ClassPathResource("/files/test-pdf.pdf"); documentStorageFileRepository.updateFile("/test/test-pdf.pdf", resource.getContentAsByteArray(), 1); log.info("Test file uploaded"); } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-rest-example/src/main/java/de/muenchen/refarch/email/integration/EmailRestExampleApplication.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-rest-example/src/main/java/de/muenchen/refarch/email/integration/EmailRestExampleApplication.java index fee5c8b9..45012c1f 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-rest-example/src/main/java/de/muenchen/refarch/email/integration/EmailRestExampleApplication.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-rest-example/src/main/java/de/muenchen/refarch/email/integration/EmailRestExampleApplication.java @@ -4,20 +4,22 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.ApplicationContext; import org.springframework.context.event.EventListener; @SpringBootApplication @RequiredArgsConstructor public class EmailRestExampleApplication { - private final TestService testService; + private final ExampleMailService exampleMailService; + private final ApplicationContext context; public static void main(final String[] args) { SpringApplication.run(EmailRestExampleApplication.class, args); } @EventListener(ApplicationReadyEvent.class) - void sendTestMail() { - this.testService.testSendMail(); - System.exit(0); + public void sendTestMail() { + this.exampleMailService.testSendMail(); + SpringApplication.exit(context); } } diff --git a/refarch-integrations/refarch-email-integration/refarch-email-integration-rest-example/src/main/java/de/muenchen/refarch/email/integration/TestService.java b/refarch-integrations/refarch-email-integration/refarch-email-integration-rest-example/src/main/java/de/muenchen/refarch/email/integration/ExampleMailService.java similarity index 83% rename from refarch-integrations/refarch-email-integration/refarch-email-integration-rest-example/src/main/java/de/muenchen/refarch/email/integration/TestService.java rename to refarch-integrations/refarch-email-integration/refarch-email-integration-rest-example/src/main/java/de/muenchen/refarch/email/integration/ExampleMailService.java index eebbf175..9718928b 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email-integration-rest-example/src/main/java/de/muenchen/refarch/email/integration/TestService.java +++ b/refarch-integrations/refarch-email-integration/refarch-email-integration-rest-example/src/main/java/de/muenchen/refarch/email/integration/ExampleMailService.java @@ -13,13 +13,13 @@ @Service @RequiredArgsConstructor @Slf4j -public class TestService { +public class ExampleMailService { private final SendMailInPort sendMailInPort; private final DocumentStorageFileRepository documentStorageFileRepository; - void testSendMail() { + public void testSendMail() { this.uploadTestFile(); - TextMail mail = new TextMail( + final TextMail mail = new TextMail( "test.receiver@muenchen.de", null, null, @@ -32,8 +32,8 @@ void testSendMail() { } @SneakyThrows - void uploadTestFile() { - ClassPathResource resource = new ClassPathResource("/files/test-pdf.pdf"); + private void uploadTestFile() { + final ClassPathResource resource = new ClassPathResource("/files/test-pdf.pdf"); documentStorageFileRepository.updateFile("/test/test-pdf.pdf", resource.getContentAsByteArray(), 1); log.info("Test file uploaded"); } diff --git a/refarch-integrations/refarch-email-integration/refarch-email/refarch-email-api/src/main/java/de/muenchen/refarch/email/impl/EmailApiImpl.java b/refarch-integrations/refarch-email-integration/refarch-email/refarch-email-api/src/main/java/de/muenchen/refarch/email/impl/EmailApiImpl.java index c8eb2121..cb849b39 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email/refarch-email-api/src/main/java/de/muenchen/refarch/email/impl/EmailApiImpl.java +++ b/refarch-integrations/refarch-email-integration/refarch-email/refarch-email-api/src/main/java/de/muenchen/refarch/email/impl/EmailApiImpl.java @@ -1,6 +1,7 @@ package de.muenchen.refarch.email.impl; import de.muenchen.refarch.email.api.EmailApi; +import de.muenchen.refarch.email.model.FileAttachment; import de.muenchen.refarch.email.model.Mail; import freemarker.template.Template; import freemarker.template.TemplateException; @@ -14,7 +15,6 @@ import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import lombok.val; import org.owasp.html.PolicyFactory; import org.owasp.html.Sanitizers; import org.springframework.core.io.Resource; @@ -41,17 +41,17 @@ public class EmailApiImpl implements EmailApi { .and(Sanitizers.TABLES); @Override - public void sendMail(@Valid Mail mail) throws MessagingException { + public void sendMail(@Valid final Mail mail) throws MessagingException { this.sendMail(mail, null); } @Override - public void sendMailWithDefaultLogo(@Valid Mail mail) throws MessagingException { + public void sendMailWithDefaultLogo(@Valid final Mail mail) throws MessagingException { this.sendMail(mail, "bausteine/mail/email-logo.png"); } @Override - public void sendMail(@Valid Mail mail, String logoPath) throws MessagingException { + public void sendMail(@Valid final Mail mail, final String logoPath) throws MessagingException { final MimeMessage mimeMessage = this.mailSender.createMimeMessage(); mimeMessage.setRecipients(Message.RecipientType.TO, InternetAddress.parse(mail.receivers())); @@ -69,7 +69,7 @@ public void sendMail(@Valid Mail mail, String logoPath) throws MessagingExceptio mimeMessage.setReplyTo(InternetAddress.parse(defaultReplyToAddress)); } - final var helper = new MimeMessageHelper(mimeMessage, true, StandardCharsets.UTF_8.name()); + final MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, StandardCharsets.UTF_8.name()); helper.setSubject(mail.subject()); helper.setText(mail.body(), mail.htmlBody()); @@ -78,7 +78,7 @@ public void sendMail(@Valid Mail mail, String logoPath) throws MessagingExceptio // mail attachments if (mail.hasAttachment()) { - for (val attachment : mail.attachments()) { + for (final FileAttachment attachment : mail.attachments()) { helper.addAttachment(attachment.fileName(), attachment.file()); } } @@ -94,15 +94,15 @@ public void sendMail(@Valid Mail mail, String logoPath) throws MessagingExceptio } @Override - public String getBodyFromTemplate(String templateName, Map content) throws IOException, TemplateException { - Template template = freeMarkerConfigurer.getConfiguration().getTemplate(templateName); + public String getBodyFromTemplate(final String templateName, final Map content) throws IOException, TemplateException { + final Template template = freeMarkerConfigurer.getConfiguration().getTemplate(templateName); return FreeMarkerTemplateUtils.processTemplateIntoString(template, content); } @Override - public String getEmailBodyFromTemplate(String templatePath, Map content) { + public String getEmailBodyFromTemplate(final String templatePath, final Map content) { String mailTemplate = this.getTemplate(templatePath); - for (val entry : content.entrySet()) { + for (final Map.Entry entry : content.entrySet()) { // make sure inputs are sanitized to prevent XSS final String value = policy.sanitize(entry.getValue()); // Make sure new lines are converted to
tags @@ -111,7 +111,7 @@ public String getEmailBodyFromTemplate(String templatePath, Map return mailTemplate; } - private String getTemplate(String templatePath) { + private String getTemplate(final String templatePath) { final Resource resource = this.getRessourceFromClassPath(templatePath); if (!resource.exists()) { log.error("Email Template not found: {}", templatePath); @@ -119,7 +119,7 @@ private String getTemplate(String templatePath) { } try { - byte[] byteArray = FileCopyUtils.copyToByteArray(resource.getInputStream()); + final byte[] byteArray = FileCopyUtils.copyToByteArray(resource.getInputStream()); return new String(byteArray, StandardCharsets.UTF_8); } catch (Exception e) { log.warn("Failed to load file: {}", templatePath); @@ -127,7 +127,7 @@ private String getTemplate(String templatePath) { } } - private Resource getRessourceFromClassPath(String path) { + private Resource getRessourceFromClassPath(final String path) { return resourceLoader.getResource("classpath:" + path); } } diff --git a/refarch-integrations/refarch-email-integration/refarch-email/refarch-email-api/src/test/java/de/muenchen/refarch/email/EmailApiImplTest.java b/refarch-integrations/refarch-email-integration/refarch-email/refarch-email-api/src/test/java/de/muenchen/refarch/email/EmailApiImplTest.java index c622ed23..e6cc8bd7 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email/refarch-email-api/src/test/java/de/muenchen/refarch/email/EmailApiImplTest.java +++ b/refarch-integrations/refarch-email-integration/refarch-email/refarch-email-api/src/test/java/de/muenchen/refarch/email/EmailApiImplTest.java @@ -32,6 +32,7 @@ import org.mockito.ArgumentCaptor; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; +import org.springframework.http.MediaType; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; @@ -41,85 +42,81 @@ class EmailApiImplTest { private final ResourceLoader resourceLoader = mock(ResourceLoader.class); private final FreeMarkerConfigurer freeMarkerConfigurer = mock(FreeMarkerConfigurer.class); // test data - private final String receiver = "mailReceiver1@muenchen.de,mailReceiver2@muenchen.de"; - private final String receiverCC = "receiverCC@muenchen.de"; - private final String receiverBCC = "receiverBCC@muenchen.de"; - private final String subject = "Test Mail"; - private final String body = "This is a test mail"; - private final String replyTo = "test@muenchen.de"; - private final String defaultReplyTo = "noreply@muenchen.de"; - private final String sender = "some-custom-sender@muenchen.de"; + private static final String RECEIVER = "mailReceiver1@muenchen.de,mailReceiver2@muenchen.de"; + private static final String RECEIVER_CC = "receiverCC@muenchen.de"; + private static final String RECEIVER_BCC = "receiverBCC@muenchen.de"; + private static final String SUBJECT = "Test Mail"; + private static final String BODY = "This is a test mail"; + private static final String REPLY_TO = "test@muenchen.de"; + private static final String DEFAULT_REPLY_TO = "noreply@muenchen.de"; + private static final String SENDER = "some-custom-sender@muenchen.de"; private EmailApi emailApi; @BeforeEach void setUp() { when(this.javaMailSender.createMimeMessage()).thenReturn(new MimeMessage((Session) null)); - this.emailApi = new EmailApiImpl(this.javaMailSender, this.resourceLoader, freeMarkerConfigurer, "test@muenchen.de", defaultReplyTo); + this.emailApi = new EmailApiImpl(this.javaMailSender, this.resourceLoader, freeMarkerConfigurer, "test@muenchen.de", DEFAULT_REPLY_TO); } @Test void testSendMail() throws MessagingException, IOException { final Mail mail = new Mail( - this.receiver, + RECEIVER, null, null, - this.subject, - this.body, + SUBJECT, + BODY, false, null, null, null); this.emailApi.sendMail(mail); - final ArgumentCaptor messageArgumentCaptor = ArgumentCaptor.forClass(MimeMessage.class); - verify(this.javaMailSender).send(messageArgumentCaptor.capture()); - - assertThat(messageArgumentCaptor.getValue().getAllRecipients()).hasSize(2); - assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(this.subject); - assertThat(messageArgumentCaptor.getValue().getReplyTo()).hasSize(1); - assertThat(messageArgumentCaptor.getValue().getReplyTo()).contains(new InternetAddress(this.defaultReplyTo)); - final MimeMultipart content = (MimeMultipart) messageArgumentCaptor.getValue().getContent(); - assertThat(content.getContentType()).contains("multipart/mixed"); + assertMailSend(new InternetAddress(DEFAULT_REPLY_TO)); } @Test void testSendMailNoDefaultReplyTo() throws MessagingException, IOException { - var customAddress = new InternetAddress("custom.test@muenchen.de"); + final InternetAddress customAddress = new InternetAddress("custom.test@muenchen.de"); final Mail mail = new Mail( - this.receiver, + RECEIVER, null, null, - this.subject, - this.body, + SUBJECT, + BODY, false, null, null, null); new EmailApiImpl(this.javaMailSender, this.resourceLoader, freeMarkerConfigurer, customAddress.getAddress(), null).sendMail(mail); + assertMailSend(new InternetAddress(customAddress.getAddress())); + } + + private void assertMailSend(final InternetAddress replyToAddress) throws MessagingException, IOException { final ArgumentCaptor messageArgumentCaptor = ArgumentCaptor.forClass(MimeMessage.class); verify(this.javaMailSender).send(messageArgumentCaptor.capture()); assertThat(messageArgumentCaptor.getValue().getAllRecipients()).hasSize(2); - assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(this.subject); + assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(SUBJECT); assertThat(messageArgumentCaptor.getValue().getReplyTo()).hasSize(1); - assertThat(messageArgumentCaptor.getValue().getReplyTo()).contains(new InternetAddress(customAddress.getAddress())); + assertThat(messageArgumentCaptor.getValue().getReplyTo()).contains(replyToAddress); final MimeMultipart content = (MimeMultipart) messageArgumentCaptor.getValue().getContent(); - assertThat(content.getContentType()).contains("multipart/mixed"); + assertThat(content.getContentType()).contains(MediaType.MULTIPART_MIXED.getType()); } @Test void testSendMailWithOptions() throws MessagingException, IOException { final Mail mail = new Mail( - this.receiver, - this.receiverCC, - this.receiverBCC, - this.subject, - this.body, + RECEIVER, + RECEIVER_CC, + RECEIVER_BCC, + SUBJECT, + BODY, false, - this.sender, - this.replyTo, + SENDER, + REPLY_TO, null); this.emailApi.sendMail(mail); @@ -129,23 +126,23 @@ void testSendMailWithOptions() throws MessagingException, IOException { assertThat(messageArgumentCaptor.getValue().getAllRecipients()).hasSize(4); assertThat(messageArgumentCaptor.getValue().getAllRecipients()).containsAll( List.of(new InternetAddress("mailReceiver1@muenchen.de"), new InternetAddress("mailReceiver2@muenchen.de"), - new InternetAddress(this.receiverCC), new InternetAddress(this.receiverBCC))); - assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(this.subject); + new InternetAddress(RECEIVER_CC), new InternetAddress(RECEIVER_BCC))); + assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(SUBJECT); assertThat(messageArgumentCaptor.getValue().getReplyTo()).hasSize(1); - assertThat(messageArgumentCaptor.getValue().getReplyTo()).contains(new InternetAddress(this.replyTo)); - assertThat(messageArgumentCaptor.getValue().getFrom()).contains(new InternetAddress(this.sender)); + assertThat(messageArgumentCaptor.getValue().getReplyTo()).contains(new InternetAddress(REPLY_TO)); + assertThat(messageArgumentCaptor.getValue().getFrom()).contains(new InternetAddress(SENDER)); final MimeMultipart content = (MimeMultipart) messageArgumentCaptor.getValue().getContent(); - assertThat(content.getContentType()).contains("multipart/mixed"); + assertThat(content.getContentType()).contains(MediaType.MULTIPART_MIXED.getType()); } @Test void sendMailWithAttachments() throws MessagingException, IOException { final Mail mail = new Mail( - this.receiver, + RECEIVER, null, null, - this.subject, - this.body, + SUBJECT, + BODY, false, null, null, @@ -159,22 +156,22 @@ void sendMailWithAttachments() throws MessagingException, IOException { verify(this.javaMailSender).send(messageArgumentCaptor.capture()); assertThat(messageArgumentCaptor.getValue().getAllRecipients()).hasSize(2); - assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(this.subject); + assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(SUBJECT); final MimeMultipart content = (MimeMultipart) messageArgumentCaptor.getValue().getContent(); - assertThat(content.getContentType()).contains("multipart/mixed"); + assertThat(content.getContentType()).contains(MediaType.MULTIPART_MIXED.getType()); } @Test void sendMailWithMultipleReplyToAddresses() throws MessagingException, IOException { - var reply1 = new InternetAddress("address1@muenchen.de"); - var reply2 = new InternetAddress("address2@muenchen.de"); + final InternetAddress reply1 = new InternetAddress("address1@muenchen.de"); + final InternetAddress reply2 = new InternetAddress("address2@muenchen.de"); final Mail mail = new Mail( - this.receiver, + RECEIVER, null, null, - this.subject, - this.body, + SUBJECT, + BODY, false, null, reply1.getAddress() + "," + reply2.getAddress(), @@ -185,11 +182,11 @@ void sendMailWithMultipleReplyToAddresses() throws MessagingException, IOExcepti verify(this.javaMailSender).send(messageArgumentCaptor.capture()); assertThat(messageArgumentCaptor.getValue().getAllRecipients()).hasSize(2); - assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(this.subject); + assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(SUBJECT); assertThat(messageArgumentCaptor.getValue().getReplyTo()).hasSize(2); assertThat(messageArgumentCaptor.getValue().getReplyTo()).containsAll(List.of(reply1, reply2)); final MimeMultipart content = (MimeMultipart) messageArgumentCaptor.getValue().getContent(); - assertThat(content.getContentType()).contains("multipart/mixed"); + assertThat(content.getContentType()).contains(MediaType.MULTIPART_MIXED.getType()); } @Test @@ -197,11 +194,11 @@ void sendMailWithDefaultLogo() throws MessagingException, IOException { when(this.resourceLoader.getResource(anyString())).thenReturn(this.getResourceForText("Default Logo", true)); final Mail mail = new Mail( - this.receiver, + RECEIVER, null, null, - this.subject, - this.body, + SUBJECT, + BODY, false, null, null, @@ -213,9 +210,9 @@ void sendMailWithDefaultLogo() throws MessagingException, IOException { verify(this.resourceLoader).getResource("classpath:bausteine/mail/email-logo.png"); assertThat(messageArgumentCaptor.getValue().getAllRecipients()).hasSize(2); - assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(this.subject); + assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(SUBJECT); final MimeMultipart content = (MimeMultipart) messageArgumentCaptor.getValue().getContent(); - assertThat(content.getContentType()).contains("multipart/mixed"); + assertThat(content.getContentType()).contains(MediaType.MULTIPART_MIXED.getType()); } @Test @@ -223,11 +220,11 @@ void sendMailWithCustomLogo() throws MessagingException, IOException { when(this.resourceLoader.getResource(anyString())).thenReturn(this.getResourceForText("Custom Logo", true)); final Mail mail = new Mail( - this.receiver, + RECEIVER, null, null, - this.subject, - this.body, + SUBJECT, + BODY, false, null, null, @@ -239,16 +236,16 @@ void sendMailWithCustomLogo() throws MessagingException, IOException { verify(this.resourceLoader).getResource("classpath:some/random/path/on/classpath"); assertThat(messageArgumentCaptor.getValue().getAllRecipients()).hasSize(2); - assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(this.subject); + assertThat(messageArgumentCaptor.getValue().getSubject()).isEqualTo(SUBJECT); final MimeMultipart content = (MimeMultipart) messageArgumentCaptor.getValue().getContent(); - assertThat(content.getContentType()).contains("multipart/mixed"); + assertThat(content.getContentType()).contains(MediaType.MULTIPART_MIXED.getType()); } @Test void testGetBodyFromFreemarkerTemplate() throws IOException, TemplateException { final String templateName = "test-template.ftl"; - Map content = Map.of("data", "test"); - Configuration configuration = new Configuration(Configuration.VERSION_2_3_30); + final Map content = Map.of("data", "test"); + final Configuration configuration = new Configuration(Configuration.VERSION_2_3_30); configuration.setClassForTemplateLoading(this.getClass(), "/templates/"); when(this.freeMarkerConfigurer.getConfiguration()).thenReturn(configuration); diff --git a/refarch-integrations/refarch-email-integration/refarch-email/refarch-email-starter/src/main/java/de/muenchen/refarch/email/configuration/EmailAutoConfiguration.java b/refarch-integrations/refarch-email-integration/refarch-email/refarch-email-starter/src/main/java/de/muenchen/refarch/email/configuration/EmailAutoConfiguration.java index 976b08cd..b2168c0c 100644 --- a/refarch-integrations/refarch-email-integration/refarch-email/refarch-email-starter/src/main/java/de/muenchen/refarch/email/configuration/EmailAutoConfiguration.java +++ b/refarch-integrations/refarch-email-integration/refarch-email/refarch-email-starter/src/main/java/de/muenchen/refarch/email/configuration/EmailAutoConfiguration.java @@ -55,7 +55,7 @@ public EmailApi emailApi(final ResourceLoader resourceLoader, final JavaMailSend @Bean @ConditionalOnMissingBean public FreeMarkerConfigurer freemarkerConfig() { - FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer(); + final FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer(); freeMarkerConfigurer.setTemplateLoaderPath("classpath:templates/"); return freeMarkerConfigurer; } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/domain/model/SupportedFileExtensions.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/domain/model/SupportedFileExtensions.java index b60243d0..5a63a7c5 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/domain/model/SupportedFileExtensions.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/domain/model/SupportedFileExtensions.java @@ -9,6 +9,7 @@ * I.e. "pdf: application/pdf" */ @NoArgsConstructor +@SuppressWarnings("PMD.MissingSerialVersionUID") public class SupportedFileExtensions extends HashMap { public SupportedFileExtensions(final Map map) { super(map); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/DocumentStorageClientErrorException.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/DocumentStorageClientErrorException.java index 75927bf8..ad1e0575 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/DocumentStorageClientErrorException.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/DocumentStorageClientErrorException.java @@ -1,7 +1,7 @@ package de.muenchen.refarch.integration.s3.client.exception; +@SuppressWarnings("PMD.MissingSerialVersionUID") public class DocumentStorageClientErrorException extends Exception { - public DocumentStorageClientErrorException(final String message, final Exception exception) { super(message, exception); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/DocumentStorageException.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/DocumentStorageException.java index 6c23bbcf..f23229b1 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/DocumentStorageException.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/DocumentStorageException.java @@ -1,7 +1,7 @@ package de.muenchen.refarch.integration.s3.client.exception; +@SuppressWarnings("PMD.MissingSerialVersionUID") public class DocumentStorageException extends Exception { - public DocumentStorageException(final String message, final Exception exception) { super(message, exception); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/DocumentStorageServerErrorException.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/DocumentStorageServerErrorException.java index 2fe6161d..4b1e89ca 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/DocumentStorageServerErrorException.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/DocumentStorageServerErrorException.java @@ -1,7 +1,7 @@ package de.muenchen.refarch.integration.s3.client.exception; +@SuppressWarnings("PMD.MissingSerialVersionUID") public class DocumentStorageServerErrorException extends Exception { - public DocumentStorageServerErrorException(final String message, final Exception exception) { super(message, exception); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/FileSizeValidationException.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/FileSizeValidationException.java index 2c0a1f51..212ed5f5 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/FileSizeValidationException.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/FileSizeValidationException.java @@ -1,5 +1,6 @@ package de.muenchen.refarch.integration.s3.client.exception; +@SuppressWarnings("PMD.MissingSerialVersionUID") public class FileSizeValidationException extends RuntimeException { public FileSizeValidationException(final String message) { super(message); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/FileTypeValidationException.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/FileTypeValidationException.java index 82057ffc..239b0b3f 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/FileTypeValidationException.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/FileTypeValidationException.java @@ -1,5 +1,6 @@ package de.muenchen.refarch.integration.s3.client.exception; +@SuppressWarnings("PMD.MissingSerialVersionUID") public class FileTypeValidationException extends RuntimeException { public FileTypeValidationException(final String message) { super(message); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/NoFileTypeException.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/NoFileTypeException.java index 33a289e7..ae8271ec 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/NoFileTypeException.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/NoFileTypeException.java @@ -1,8 +1,12 @@ package de.muenchen.refarch.integration.s3.client.exception; +@SuppressWarnings("PMD.MissingSerialVersionUID") public class NoFileTypeException extends RuntimeException { - public NoFileTypeException(final String message) { super(message); } + + public NoFileTypeException(final String message, final Exception e) { + super(message, e); + } } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/PropertyNotSetException.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/PropertyNotSetException.java index cec40f02..42261f7c 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/PropertyNotSetException.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/exception/PropertyNotSetException.java @@ -1,7 +1,7 @@ package de.muenchen.refarch.integration.s3.client.exception; +@SuppressWarnings("PMD.MissingSerialVersionUID") public class PropertyNotSetException extends Exception { - public PropertyNotSetException(final String message) { super(message); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRepository.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRepository.java index eb704b39..9c78d006 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRepository.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRepository.java @@ -25,7 +25,7 @@ public abstract class DocumentStorageFileRepository { * @throws DocumentStorageException if the problem cannot be assigned to either the client or the S3 * storage or the document storage. */ - public byte[] getFile(String pathToFile, int expireInMinutes) + public byte[] getFile(final String pathToFile, final int expireInMinutes) throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final String presignedUrl = this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes); return this.s3FileTransferRepository.getFile(presignedUrl); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/repository/transfer/S3FileTransferRepository.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/repository/transfer/S3FileTransferRepository.java index 2b0d0803..535fa760 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/repository/transfer/S3FileTransferRepository.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/repository/transfer/S3FileTransferRepository.java @@ -6,9 +6,9 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.util.concurrent.Callable; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import lombok.val; import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; @@ -17,9 +17,9 @@ import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Repository; +import org.springframework.util.MultiValueMap; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpServerErrorException; -import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; @Slf4j @@ -43,8 +43,8 @@ public class S3FileTransferRepository { * storage. */ public byte[] getFile(final String presignedUrl) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { - try { - val headers = new HttpHeaders(); + return executeWithErrorHandling(() -> { + final MultiValueMap headers = new HttpHeaders(); final HttpEntity httpEntity = new HttpEntity<>(headers); /* * Using the RestTemplate without any authorization. @@ -56,19 +56,7 @@ public byte[] getFile(final String presignedUrl) throws DocumentStorageClientErr httpEntity, byte[].class); return responseEntity.getBody(); - } catch (final HttpClientErrorException exception) { - final String message = String.format(REQUEST_FAILED_WITH_STATUS_CODE, exception.getStatusCode()); - log.error(message); - throw new DocumentStorageClientErrorException(message, exception); - } catch (final HttpServerErrorException exception) { - final String message = String.format(REQUEST_FAILED_WITH_STATUS_CODE, exception.getStatusCode()); - log.error(message); - throw new DocumentStorageServerErrorException(message, exception); - } catch (final RestClientException exception) { - final String message = REQUEST_FAILED; - log.error(message); - throw new DocumentStorageException(message, exception); - } + }); } /** @@ -81,7 +69,7 @@ public byte[] getFile(final String presignedUrl) throws DocumentStorageClientErr */ public InputStream getFileInputStream(final String presignedUrl) throws DocumentStorageException { try { - val urlResource = new UrlResource(presignedUrl); + final UrlResource urlResource = new UrlResource(presignedUrl); return urlResource.getInputStream(); } catch (final IOException exception) { final String message = REQUEST_FAILED; @@ -102,8 +90,8 @@ public InputStream getFileInputStream(final String presignedUrl) throws Document */ public void saveFile(final String presignedUrl, final byte[] file) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { - try { - val headers = new HttpHeaders(); + executeWithErrorHandling(() -> { + final MultiValueMap headers = new HttpHeaders(); final HttpEntity fileHttpEntity = new HttpEntity<>(file, headers); /* * Using the RestTemplate without any authorization. @@ -114,19 +102,8 @@ public void saveFile(final String presignedUrl, final byte[] file) HttpMethod.PUT, fileHttpEntity, Void.class); - } catch (final HttpClientErrorException exception) { - final String message = String.format(REQUEST_FAILED_WITH_STATUS_CODE, exception.getStatusCode()); - log.error(message); - throw new DocumentStorageClientErrorException(message, exception); - } catch (final HttpServerErrorException exception) { - final String message = String.format(REQUEST_FAILED_WITH_STATUS_CODE, exception.getStatusCode()); - log.error(message); - throw new DocumentStorageServerErrorException(message, exception); - } catch (final RestClientException exception) { - final String message = REQUEST_FAILED; - log.error(message); - throw new DocumentStorageException(message, exception); - } + return null; + }); } /** @@ -141,8 +118,8 @@ public void saveFile(final String presignedUrl, final byte[] file) */ public void saveFileInputStream(final String presignedUrl, final InputStream file) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { - try { - val headers = new HttpHeaders(); + executeWithErrorHandling(() -> { + final MultiValueMap headers = new HttpHeaders(); final HttpEntity fileHttpEntity = new HttpEntity<>(new InputStreamResource(file), headers); /* * Using the RestTemplate without any authorization. @@ -153,19 +130,8 @@ public void saveFileInputStream(final String presignedUrl, final InputStream fil HttpMethod.PUT, fileHttpEntity, Void.class); - } catch (final HttpClientErrorException exception) { - final String message = String.format(REQUEST_FAILED_WITH_STATUS_CODE, exception.getStatusCode()); - log.error(message); - throw new DocumentStorageClientErrorException(message, exception); - } catch (final HttpServerErrorException exception) { - final String message = String.format(REQUEST_FAILED_WITH_STATUS_CODE, exception.getStatusCode()); - log.error(message); - throw new DocumentStorageServerErrorException(message, exception); - } catch (final RestClientException exception) { - final String message = REQUEST_FAILED; - log.error(message); - throw new DocumentStorageException(message, exception); - } + return null; + }); } /** @@ -209,8 +175,8 @@ public void updateFileInputStream(final String presignedUrl, final InputStream f */ public void deleteFile(final String presignedUrl) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { - try { - val headers = new HttpHeaders(); + executeWithErrorHandling(() -> { + final MultiValueMap headers = new HttpHeaders(); final HttpEntity fileHttpEntity = new HttpEntity<>(headers); /* * Using the RestTemplate without any authorization. @@ -221,6 +187,14 @@ public void deleteFile(final String presignedUrl) HttpMethod.DELETE, fileHttpEntity, Void.class); + return null; + }); + } + + private T executeWithErrorHandling(final Callable callable) + throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { + try { + return callable.call(); } catch (final HttpClientErrorException exception) { final String message = String.format(REQUEST_FAILED_WITH_STATUS_CODE, exception.getStatusCode()); log.error(message); @@ -229,7 +203,7 @@ public void deleteFile(final String presignedUrl) final String message = String.format(REQUEST_FAILED_WITH_STATUS_CODE, exception.getStatusCode()); log.error(message); throw new DocumentStorageServerErrorException(message, exception); - } catch (final RestClientException exception) { + } catch (final Exception exception) { final String message = REQUEST_FAILED; log.error(message); throw new DocumentStorageException(message, exception); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/service/FileValidationService.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/service/FileValidationService.java index 37846bca..54c34912 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/service/FileValidationService.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/main/java/de/muenchen/refarch/integration/s3/client/service/FileValidationService.java @@ -23,7 +23,7 @@ public class FileValidationService { * Map stores supported file extensions and their corresponding MIME types. If it is empty, all * types are supported. */ - private final SupportedFileExtensions supportedFileExtensions; + private final Map supportedFileExtensions; /** The maximum allowed file size. A value of 0 indicates no limits. */ @Getter @@ -33,7 +33,7 @@ public class FileValidationService { @Getter private final DataSize maxBatchSize; - public FileValidationService(final SupportedFileExtensions supportedFileExtensions, final DataSize maxFileSize, final DataSize maxBatchSize) { + public FileValidationService(final Map supportedFileExtensions, final DataSize maxFileSize, final DataSize maxBatchSize) { this.supportedFileExtensions = Objects.nonNull(supportedFileExtensions) ? supportedFileExtensions : new SupportedFileExtensions(); this.maxFileSize = maxFileSize; this.maxBatchSize = maxBatchSize; @@ -56,7 +56,9 @@ public boolean isValidFileSize(final byte[] file) { * @return {@code true} if the file size is valid, {@code false} otherwise. */ public boolean isValidFileSize(final long fileSizeInBytes) { - if (Objects.isNull(maxFileSize) || maxFileSize.toBytes() == 0L) return true; + if (Objects.isNull(maxFileSize) || maxFileSize.toBytes() == 0L) { + return true; + } return DataSize.ofBytes(fileSizeInBytes).compareTo(maxFileSize) <= 0; } @@ -87,7 +89,9 @@ public boolean isValidBatchSize(final long batchSizeInBytes) { * @return {@code true} if the batch size is valid, {@code false} otherwise. */ public boolean isValidBatchSize(final DataSize batchSizeInBytes) { - if (Objects.isNull(maxBatchSize) || maxBatchSize.toBytes() == 0L) return true; + if (Objects.isNull(maxBatchSize) || maxBatchSize.toBytes() == 0L) { + return true; + } return batchSizeInBytes.compareTo(maxBatchSize) <= 0; } @@ -122,17 +126,21 @@ public boolean isSupported(final String type) { */ public String getFileExtension(final String type) { final MimeTypes allMimeTypes = MimeTypes.getDefaultMimeTypes(); - MimeType mimeType; + final MimeType mimeType; try { mimeType = allMimeTypes.forName(type); } catch (MimeTypeException e) { - throw new NoFileTypeException(String.format(NO_FILE_EXTENSION, type)); + throw new NoFileTypeException(String.format(NO_FILE_EXTENSION, type), e); } final String extension = mimeType.getExtension(); final int lastDotIndex = extension.lastIndexOf('.'); - if (lastDotIndex == -1) throw new NoFileTypeException(String.format(NO_FILE_EXTENSION, type)); + if (lastDotIndex == -1) { + throw new NoFileTypeException(String.format(NO_FILE_EXTENSION, type)); + } final String fileExtension = extension.substring(lastDotIndex + 1); - if (fileExtension.isEmpty()) throw new NoFileTypeException(String.format(NO_FILE_EXTENSION, type)); + if (fileExtension.isEmpty()) { + throw new NoFileTypeException(String.format(NO_FILE_EXTENSION, type)); + } return fileExtension; } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/test/java/de/muenchen/refarch/integration/s3/client/repository/transfer/S3FileTransferRepositoryTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/test/java/de/muenchen/refarch/integration/s3/client/repository/transfer/S3FileTransferRepositoryTest.java index 797e505e..cab5eba2 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/test/java/de/muenchen/refarch/integration/s3/client/repository/transfer/S3FileTransferRepositoryTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/test/java/de/muenchen/refarch/integration/s3/client/repository/transfer/S3FileTransferRepositoryTest.java @@ -2,6 +2,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; @@ -9,8 +10,6 @@ import de.muenchen.refarch.integration.s3.client.exception.DocumentStorageClientErrorException; import de.muenchen.refarch.integration.s3.client.exception.DocumentStorageException; import de.muenchen.refarch.integration.s3.client.exception.DocumentStorageServerErrorException; -import de.muenchen.refarch.integration.s3.client.repository.transfer.S3FileTransferRepository; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; @@ -22,88 +21,90 @@ @WireMockTest class S3FileTransferRepositoryTest { - private final String PRESIGNED_URL = "/expected-presigned-url"; + private static final String PRESIGNED_URL = "/expected-presigned-url"; + public static final String LOCALHOST_PREFIX = "http://localhost:"; + public static final String INVALID_URL_PATH = "/invalid-url"; private final S3FileTransferRepository s3FileTransferRepository = new S3FileTransferRepository(); @Test - void getFile(final WireMockRuntimeInfo wmRuntimeInfo) + void testGetFile(final WireMockRuntimeInfo wmRuntimeInfo) throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final String baseUrl = wmRuntimeInfo.getHttpBaseUrl(); - final byte[] file = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; - final String presignedUrl = baseUrl + this.PRESIGNED_URL; + final byte[] file = { 1, 2, 3, 4, 5, 6, 7 }; + final String presignedUrl = baseUrl + PRESIGNED_URL; - WireMock.stubFor(WireMock.get(this.PRESIGNED_URL).willReturn(WireMock.aResponse().withBody(file).withStatus(200))); + WireMock.stubFor(WireMock.get(PRESIGNED_URL).willReturn(WireMock.aResponse().withBody(file).withStatus(200))); final byte[] result = this.s3FileTransferRepository.getFile(presignedUrl); assertThat(result, is(file)); - WireMock.stubFor(WireMock.get(this.PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(400))); - Assertions.assertThrows(DocumentStorageClientErrorException.class, () -> this.s3FileTransferRepository.getFile(presignedUrl)); + WireMock.stubFor(WireMock.get(PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(400))); + assertThrows(DocumentStorageClientErrorException.class, () -> this.s3FileTransferRepository.getFile(presignedUrl)); - WireMock.stubFor(WireMock.get(this.PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(500))); - Assertions.assertThrows(DocumentStorageServerErrorException.class, () -> this.s3FileTransferRepository.getFile(presignedUrl)); + WireMock.stubFor(WireMock.get(PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(500))); + assertThrows(DocumentStorageServerErrorException.class, () -> this.s3FileTransferRepository.getFile(presignedUrl)); - Assertions.assertThrows(DocumentStorageException.class, - () -> this.s3FileTransferRepository.getFile("http://localhost:" + (wmRuntimeInfo.getHttpPort() + 1) + "/invalid-url")); + assertThrows(DocumentStorageException.class, + () -> this.s3FileTransferRepository.getFile(LOCALHOST_PREFIX + (wmRuntimeInfo.getHttpPort() + 1) + INVALID_URL_PATH)); } @Test void saveFile(final WireMockRuntimeInfo wmRuntimeInfo) throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final String baseUrl = wmRuntimeInfo.getHttpBaseUrl(); - final byte[] file = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; - final String presignedUrl = baseUrl + this.PRESIGNED_URL; + final byte[] file = { 1, 2, 3, 4, 5, 6, 7 }; + final String presignedUrl = baseUrl + PRESIGNED_URL; - WireMock.stubFor(WireMock.put(this.PRESIGNED_URL).withRequestBody(WireMock.binaryEqualTo(file)).willReturn(WireMock.ok())); + WireMock.stubFor(WireMock.put(PRESIGNED_URL).withRequestBody(WireMock.binaryEqualTo(file)).willReturn(WireMock.ok())); this.s3FileTransferRepository.saveFile(presignedUrl, file); - WireMock.stubFor(WireMock.put(this.PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(400))); - Assertions.assertThrows(DocumentStorageClientErrorException.class, () -> this.s3FileTransferRepository.saveFile(presignedUrl, file)); + WireMock.stubFor(WireMock.put(PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(400))); + assertThrows(DocumentStorageClientErrorException.class, () -> this.s3FileTransferRepository.saveFile(presignedUrl, file)); - WireMock.stubFor(WireMock.put(this.PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(500))); - Assertions.assertThrows(DocumentStorageServerErrorException.class, () -> this.s3FileTransferRepository.saveFile(presignedUrl, file)); + WireMock.stubFor(WireMock.put(PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(500))); + assertThrows(DocumentStorageServerErrorException.class, () -> this.s3FileTransferRepository.saveFile(presignedUrl, file)); - Assertions.assertThrows(DocumentStorageException.class, - () -> this.s3FileTransferRepository.saveFile("http://localhost:" + (wmRuntimeInfo.getHttpPort() + 1) + "/invalid-url", file)); + assertThrows(DocumentStorageException.class, + () -> this.s3FileTransferRepository.saveFile(LOCALHOST_PREFIX + (wmRuntimeInfo.getHttpPort() + 1) + INVALID_URL_PATH, file)); } @Test void updateFile(final WireMockRuntimeInfo wmRuntimeInfo) throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final String baseUrl = wmRuntimeInfo.getHttpBaseUrl(); - final byte[] file = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; - final String presignedUrl = baseUrl + this.PRESIGNED_URL; + final byte[] file = { 1, 2, 3, 4, 5, 6, 7 }; + final String presignedUrl = baseUrl + PRESIGNED_URL; - WireMock.stubFor(WireMock.put(this.PRESIGNED_URL).withRequestBody(WireMock.binaryEqualTo(file)).willReturn(WireMock.ok())); + WireMock.stubFor(WireMock.put(PRESIGNED_URL).withRequestBody(WireMock.binaryEqualTo(file)).willReturn(WireMock.ok())); this.s3FileTransferRepository.updateFile(presignedUrl, file); - WireMock.stubFor(WireMock.put(this.PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(400))); - Assertions.assertThrows(DocumentStorageClientErrorException.class, () -> this.s3FileTransferRepository.updateFile(presignedUrl, file)); + WireMock.stubFor(WireMock.put(PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(400))); + assertThrows(DocumentStorageClientErrorException.class, () -> this.s3FileTransferRepository.updateFile(presignedUrl, file)); - WireMock.stubFor(WireMock.put(this.PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(500))); - Assertions.assertThrows(DocumentStorageServerErrorException.class, () -> this.s3FileTransferRepository.updateFile(presignedUrl, file)); + WireMock.stubFor(WireMock.put(PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(500))); + assertThrows(DocumentStorageServerErrorException.class, () -> this.s3FileTransferRepository.updateFile(presignedUrl, file)); - Assertions.assertThrows(DocumentStorageException.class, - () -> this.s3FileTransferRepository.updateFile("http://localhost:" + (wmRuntimeInfo.getHttpPort() + 1) + "/invalid-url", file)); + assertThrows(DocumentStorageException.class, + () -> this.s3FileTransferRepository.updateFile(LOCALHOST_PREFIX + (wmRuntimeInfo.getHttpPort() + 1) + INVALID_URL_PATH, file)); } @Test void deleteFile(final WireMockRuntimeInfo wmRuntimeInfo) throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final String baseUrl = wmRuntimeInfo.getHttpBaseUrl(); - final String presignedUrl = baseUrl + this.PRESIGNED_URL; + final String presignedUrl = baseUrl + PRESIGNED_URL; - WireMock.stubFor(WireMock.delete(this.PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(204))); + WireMock.stubFor(WireMock.delete(PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(204))); this.s3FileTransferRepository.deleteFile(presignedUrl); - WireMock.stubFor(WireMock.delete(this.PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(400))); - Assertions.assertThrows(DocumentStorageClientErrorException.class, () -> this.s3FileTransferRepository.deleteFile(presignedUrl)); + WireMock.stubFor(WireMock.delete(PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(400))); + assertThrows(DocumentStorageClientErrorException.class, () -> this.s3FileTransferRepository.deleteFile(presignedUrl)); - WireMock.stubFor(WireMock.delete(this.PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(500))); - Assertions.assertThrows(DocumentStorageServerErrorException.class, () -> this.s3FileTransferRepository.deleteFile(presignedUrl)); + WireMock.stubFor(WireMock.delete(PRESIGNED_URL).willReturn(WireMock.aResponse().withStatus(500))); + assertThrows(DocumentStorageServerErrorException.class, () -> this.s3FileTransferRepository.deleteFile(presignedUrl)); - Assertions.assertThrows(DocumentStorageException.class, - () -> this.s3FileTransferRepository.deleteFile("http://localhost:" + (wmRuntimeInfo.getHttpPort() + 1) + "/invalid-url")); + assertThrows(DocumentStorageException.class, + () -> this.s3FileTransferRepository.deleteFile(LOCALHOST_PREFIX + (wmRuntimeInfo.getHttpPort() + 1) + INVALID_URL_PATH)); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/test/java/de/muenchen/refarch/integration/s3/client/service/FileValidationServiceTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/test/java/de/muenchen/refarch/integration/s3/client/service/FileValidationServiceTest.java index b2709c82..5b315f74 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/test/java/de/muenchen/refarch/integration/s3/client/service/FileValidationServiceTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-core/src/test/java/de/muenchen/refarch/integration/s3/client/service/FileValidationServiceTest.java @@ -19,7 +19,7 @@ class FileValidationServiceTest { @BeforeEach void setUp() { - final SupportedFileExtensions fileExtensions = new SupportedFileExtensions(); + final Map fileExtensions = new SupportedFileExtensions(); fileExtensions.put("pdf", "application/pdf"); fileExtensions.put("txt", "text/plain"); fileValidationService = new FileValidationService(fileExtensions, DataSize.ofKilobytes(10), DataSize.ofMegabytes(5)); @@ -61,31 +61,31 @@ void testIsValidFileSizeByteArray() { @Test void testIsValidFileSizeLong() { - assertFalse(fileValidationService.isValidFileSize(10000000L)); // Assuming maxFileSize is set to 10MB + assertFalse(fileValidationService.isValidFileSize(10_000_000L)); // Assuming maxFileSize is set to 10MB } @Test void testGetTotalBatchSize() { - Map fileSizesWithPaths = new HashMap<>(); + final Map fileSizesWithPaths = new HashMap<>(); fileSizesWithPaths.put("path/to/file1", 1024L); fileSizesWithPaths.put("path/to/file2", 2048L); - DataSize expectedTotalSize = DataSize.ofBytes(3072); // 1024 + 2048 + final DataSize expectedTotalSize = DataSize.ofBytes(3072); // 1024 + 2048 assertEquals(expectedTotalSize, fileValidationService.getTotalBatchSize(fileSizesWithPaths)); } @Test void testGetOversizedFiles() { - Map fileSizesWithPaths = new HashMap<>(); + final Map fileSizesWithPaths = new HashMap<>(); fileSizesWithPaths.put("path/to/smallFile.txt", 500L); - fileSizesWithPaths.put("path/to/largeFile.pdf", 15000000L); - fileSizesWithPaths.put("path/to/mediumFile.docx", 7000L); + fileSizesWithPaths.put("path/to/largeFile.pdf", 15_000_000L); + fileSizesWithPaths.put("path/to/mediumFile.docx", 7_000L); - Map expectedOversizedFiles = new HashMap<>(); - expectedOversizedFiles.put("path/to/largeFile.pdf", 15000000L); + final Map expectedOversizedFiles = new HashMap<>(); + expectedOversizedFiles.put("path/to/largeFile.pdf", 15_000_000L); - Map oversizedFiles = fileValidationService.getOversizedFiles(fileSizesWithPaths); + final Map oversizedFiles = fileValidationService.getOversizedFiles(fileSizesWithPaths); assertEquals(expectedOversizedFiles, oversizedFiles); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/out/s3/S3Adapter.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/out/s3/S3Adapter.java index edd9b084..4716caae 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/out/s3/S3Adapter.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/out/s3/S3Adapter.java @@ -18,6 +18,7 @@ import io.minio.errors.XmlParserException; import io.minio.http.Method; import io.minio.messages.Item; +import jakarta.annotation.PreDestroy; import java.io.IOException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -46,17 +47,18 @@ public class S3Adapter implements S3OutPort { * * @param bucketName to which this Repository should connect. * @param client to communicate with the s3 storage. - * @param s3InitialConnectionTest to enable initial connection test to the s3 storage when true. - * @throws FileSystemAccessException if the initial connection test fails. */ public S3Adapter( final String bucketName, - final MinioClient client, - final boolean s3InitialConnectionTest) throws FileSystemAccessException { + final MinioClient client) { this.bucketName = bucketName; this.client = client; - if (s3InitialConnectionTest) { - this.initialConnectionTest(bucketName, client); + } + + @PreDestroy + public void cleanup() throws Exception { + if (client != null) { + client.close(); } } @@ -73,9 +75,11 @@ public boolean fileExists(final String path) throws FileSystemAccessException { client.statObject(StatObjectArgs.builder() .bucket(bucketName).object(path).build()); } catch (final ErrorResponseException errorResponseException) { - if (RESPONSE_CODE_NO_SUCH_KEY.equals(errorResponseException.errorResponse().code())) return false; - else + if (RESPONSE_CODE_NO_SUCH_KEY.equals(errorResponseException.errorResponse().code())) { + return false; + } else { throw new FileSystemAccessException(errorResponseException.errorResponse().code(), errorResponseException); + } } catch (InsufficientDataException | InternalException | InvalidKeyException | InvalidResponseException | IOException | NoSuchAlgorithmException | ServerException | XmlParserException exception) { final String message = String.format("Failed to request metadata for file %s.", path); @@ -231,11 +235,9 @@ public String getPresignedUrl(final String pathToFile, final Method action, fina /** * Performs an initial connection test against the S3 storage. * - * @param bucketName to which this Repository should connect. - * @param client to communicate with the s3 storage. * @throws FileSystemAccessException if the initial connection test fails. */ - private void initialConnectionTest(final String bucketName, final MinioClient client) throws FileSystemAccessException { + public void testConnection() throws FileSystemAccessException { try { final boolean bucketExists = client.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()); if (!bucketExists) { diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/port/in/FileOperationsInPort.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/port/in/FileOperationsInPort.java index d08adf1c..120ecdab 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/port/in/FileOperationsInPort.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/port/in/FileOperationsInPort.java @@ -4,9 +4,9 @@ import de.muenchen.refarch.integration.s3.domain.model.FileSize; public interface FileOperationsInPort { - boolean fileExists(final String path) throws FileSystemAccessException; + boolean fileExists(String path) throws FileSystemAccessException; - void deleteFile(final String pathToFile) throws FileSystemAccessException; + void deleteFile(String pathToFile) throws FileSystemAccessException; - FileSize getFileSize(final String pathToFile) throws FileSystemAccessException; + FileSize getFileSize(String pathToFile) throws FileSystemAccessException; } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/port/in/FileOperationsPresignedUrlInPort.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/port/in/FileOperationsPresignedUrlInPort.java index 4afc452b..7f153027 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/port/in/FileOperationsPresignedUrlInPort.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/port/in/FileOperationsPresignedUrlInPort.java @@ -1,6 +1,5 @@ package de.muenchen.refarch.integration.s3.application.port.in; -import de.muenchen.refarch.integration.s3.domain.exception.FileExistenceException; import de.muenchen.refarch.integration.s3.domain.exception.FileSystemAccessException; import de.muenchen.refarch.integration.s3.domain.model.FileData; import de.muenchen.refarch.integration.s3.domain.model.PresignedUrl; @@ -11,15 +10,15 @@ * Port describing the main operations on files. */ public interface FileOperationsPresignedUrlInPort { - List getPresignedUrls(List paths, Method action, int expiresInMinutes) throws FileSystemAccessException, FileExistenceException; + List getPresignedUrls(List paths, Method action, int expiresInMinutes) throws FileSystemAccessException; PresignedUrl getPresignedUrl(String path, Method action, int expiresInMinutes) throws FileSystemAccessException; - PresignedUrl getFile(final String pathToFile, final int expiresInMinutes) throws FileExistenceException, FileSystemAccessException; + PresignedUrl getFile(String pathToFile, int expiresInMinutes) throws FileSystemAccessException; - PresignedUrl saveFile(final FileData fileData) throws FileSystemAccessException, FileExistenceException; + PresignedUrl saveFile(FileData fileData) throws FileSystemAccessException; - PresignedUrl updateFile(final FileData fileData) throws FileSystemAccessException; + PresignedUrl updateFile(FileData fileData) throws FileSystemAccessException; - PresignedUrl deleteFile(final String pathToFile, final int expiresInMinutes) throws FileExistenceException, FileSystemAccessException; + PresignedUrl deleteFile(String pathToFile, int expiresInMinutes) throws FileSystemAccessException; } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/port/out/S3OutPort.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/port/out/S3OutPort.java index 98d2273c..b8591f80 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/port/out/S3OutPort.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/port/out/S3OutPort.java @@ -6,15 +6,15 @@ import java.util.Set; public interface S3OutPort { - boolean fileExists(final String path) throws FileSystemAccessException; + boolean fileExists(String path) throws FileSystemAccessException; - Set getFilePathsFromFolder(final String folder) throws FileSystemAccessException; + Set getFilePathsFromFolder(String folder) throws FileSystemAccessException; - void deleteFile(final String pathToFile) throws FileSystemAccessException; + void deleteFile(String pathToFile) throws FileSystemAccessException; - String getPresignedUrl(final String pathToFile, final Method action, final int expiresInMinutes) throws FileSystemAccessException; + String getPresignedUrl(String pathToFile, Method action, int expiresInMinutes) throws FileSystemAccessException; - Map getFileSizesFromFolder(final String folder) throws FileSystemAccessException; + Map getFileSizesFromFolder(String folder) throws FileSystemAccessException; - long getFileSize(final String pathToFile) throws FileSystemAccessException; + long getFileSize(String pathToFile) throws FileSystemAccessException; } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/usecase/CreatePresignedUrlsUseCase.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/usecase/CreatePresignedUrlsUseCase.java index 8457a29e..ab80f73d 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/usecase/CreatePresignedUrlsUseCase.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/usecase/CreatePresignedUrlsUseCase.java @@ -21,7 +21,7 @@ public class CreatePresignedUrlsUseCase implements CreatePresignedUrlsInPort { @Override @NonNull - public List createPresignedUrls(@Valid CreatePresignedUrlEvent event) throws FileSystemAccessException { + public List createPresignedUrls(@Valid final CreatePresignedUrlEvent event) throws FileSystemAccessException { return this.fileHandlingService.getPresignedUrls( List.of(event.path().split(PATH_DELIMITER)), Method.valueOf(event.action()), diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/usecase/FileOperationsPresignedUrlUseCase.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/usecase/FileOperationsPresignedUrlUseCase.java index e29a13a6..e8374758 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/usecase/FileOperationsPresignedUrlUseCase.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/usecase/FileOperationsPresignedUrlUseCase.java @@ -47,13 +47,12 @@ public static String getPathToFolder(final String pathToFile) { * @param expiresInMinutes presigned url expiration time * @return list of pre-signed urls. * @throws FileSystemAccessException on S3 access errors. - * @throws FileExistenceException if file doesn't exist. */ @Override public List getPresignedUrls(final List paths, final Method action, final int expiresInMinutes) - throws FileSystemAccessException, FileExistenceException { + throws FileSystemAccessException { final List presignedUrls = new ArrayList<>(); - for (String p : paths) { + for (final String p : paths) { presignedUrls.addAll(this.getPresignedUrls(p, action, expiresInMinutes)); } return presignedUrls; @@ -78,11 +77,10 @@ public PresignedUrl getPresignedUrl(final String path, final Method action, fina * * @param pathToFile identifies the path to file. * @param expiresInMinutes to define the validity period of the presigned URL. - * @throws FileExistenceException if the file does not exist in the folder. * @throws FileSystemAccessException if the S3 storage cannot be accessed. */ @Override - public PresignedUrl getFile(final String pathToFile, final int expiresInMinutes) throws FileExistenceException, FileSystemAccessException { + public PresignedUrl getFile(final String pathToFile, final int expiresInMinutes) throws FileSystemAccessException { if (!this.fileExists(pathToFile)) { final String message = String.format("The file %s does not exists.", pathToFile); log.error(message); @@ -96,12 +94,11 @@ public PresignedUrl getFile(final String pathToFile, final int expiresInMinutes) * file must not exist yet. * * @param fileData with the file metadata to save. - * @throws FileExistenceException if the file already exists. * @throws FileSystemAccessException if the S3 storage cannot be accessed. */ @Override - public PresignedUrl saveFile(final FileData fileData) throws FileSystemAccessException, FileExistenceException { + public PresignedUrl saveFile(final FileData fileData) throws FileSystemAccessException { if (this.fileExists(fileData.pathToFile())) { final String message = String.format("The file %s does exists.", fileData.pathToFile()); log.error(message); @@ -128,11 +125,10 @@ public PresignedUrl updateFile(final FileData fileData) throws FileSystemAccessE * * @param pathToFile identifies the path to file. * @param expiresInMinutes to define the validity period of the presigned URL. - * @throws FileExistenceException if the file does not exist in the folder. * @throws FileSystemAccessException if the S3 storage cannot be accessed. */ @Override - public PresignedUrl deleteFile(final String pathToFile, final int expiresInMinutes) throws FileExistenceException, FileSystemAccessException { + public PresignedUrl deleteFile(final String pathToFile, final int expiresInMinutes) throws FileSystemAccessException { if (!this.fileExists(pathToFile)) { final String message = String.format("The file %s does not exists.", pathToFile); log.error(message); @@ -154,10 +150,9 @@ private boolean fileExists(final String filePath) throws FileSystemAccessExcepti * @param expiresInMinutes presigned url expiration time * @return list of pre-signed urls. * @throws FileSystemAccessException on S3 access errors. - * @throws FileExistenceException if file doesn't exist. */ private List getPresignedUrls(final String path, final Method action, final int expiresInMinutes) - throws FileSystemAccessException, FileExistenceException { + throws FileSystemAccessException { // special case file creation (POST) // Use method PUT and return a single presignedUrl for the file the user wants to create if (action.equals(Method.POST)) { diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/usecase/FileOperationsUseCase.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/usecase/FileOperationsUseCase.java index 46914a93..566497e3 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/usecase/FileOperationsUseCase.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/application/usecase/FileOperationsUseCase.java @@ -28,7 +28,7 @@ public void deleteFile(final String pathToFile) throws FileSystemAccessException * @throws FileSystemAccessException if the S3 storage cannot be accessed. */ @Override - public FileSize getFileSize(String pathToFile) throws FileSystemAccessException { + public FileSize getFileSize(final String pathToFile) throws FileSystemAccessException { return new FileSize(s3OutPort.getFileSize(pathToFile)); } } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/exception/FileExistenceException.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/exception/FileExistenceException.java index 279ce79d..d36bfeb7 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/exception/FileExistenceException.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/exception/FileExistenceException.java @@ -4,6 +4,7 @@ import lombok.NoArgsConstructor; @NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("PMD.MissingSerialVersionUID") public class FileExistenceException extends RuntimeException { public FileExistenceException(final String message) { super(message); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/exception/FileSystemAccessException.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/exception/FileSystemAccessException.java index cdf14872..805b3363 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/exception/FileSystemAccessException.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/exception/FileSystemAccessException.java @@ -7,6 +7,7 @@ * Represents a technical exception */ @NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("PMD.MissingSerialVersionUID") public class FileSystemAccessException extends Exception { public FileSystemAccessException(final String message) { super(message); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/model/FileSizesInFolder.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/model/FileSizesInFolder.java index 08610923..297043f7 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/model/FileSizesInFolder.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/model/FileSizesInFolder.java @@ -1,7 +1,16 @@ package de.muenchen.refarch.integration.s3.domain.model; +import java.util.Collections; import java.util.Map; public record FileSizesInFolder( Map fileSizes) { + public FileSizesInFolder { + fileSizes = Map.copyOf(fileSizes); + } + + @Override + public Map fileSizes() { + return Collections.unmodifiableMap(fileSizes); + } } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/model/FilesInFolder.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/model/FilesInFolder.java index 9a93332a..1ffc5806 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/model/FilesInFolder.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/main/java/de/muenchen/refarch/integration/s3/domain/model/FilesInFolder.java @@ -1,7 +1,16 @@ package de.muenchen.refarch.integration.s3.domain.model; +import java.util.Collections; import java.util.Set; public record FilesInFolder( Set pathToFiles) { + public FilesInFolder { + pathToFiles = Set.copyOf(pathToFiles); + } + + @Override + public Set pathToFiles() { + return Collections.unmodifiableSet(pathToFiles); + } } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/test/java/de/muenchen/refarch/integration/s3/adapter/out/s3/S3AdapterTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/test/java/de/muenchen/refarch/integration/s3/adapter/out/s3/S3AdapterTest.java index b9e24033..cd8b7296 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/test/java/de/muenchen/refarch/integration/s3/adapter/out/s3/S3AdapterTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/test/java/de/muenchen/refarch/integration/s3/adapter/out/s3/S3AdapterTest.java @@ -1,5 +1,7 @@ package de.muenchen.refarch.integration.s3.adapter.out.s3; +import static org.junit.jupiter.api.Assertions.assertTrue; + import de.muenchen.refarch.integration.s3.domain.exception.FileSystemAccessException; import io.minio.GetPresignedObjectUrlArgs; import io.minio.MinioClient; @@ -14,7 +16,6 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.List; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -29,29 +30,29 @@ */ @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) -public class S3AdapterTest { +class S3AdapterTest { - private final String s3Url = "http://localhost:9000"; - private final String filePath = "test/image.png"; - private final List actions = List.of(Method.GET, Method.POST, Method.PUT, Method.DELETE); - private final int expiresInMinutes = 5; + private final static String S3_URL = "http://localhost:9000"; + private final static String FILE_PATH = "test/image.png"; + private final static List ACTIONS = List.of(Method.GET, Method.POST, Method.PUT, Method.DELETE); + private final static int EXPIRES_IN_MINUTES = 5; private S3Adapter s3Adapter; @Mock private MinioClient client; @BeforeEach - public void beforeEach() throws FileSystemAccessException { - this.s3Adapter = new S3Adapter("test-bucket", this.client, false); + void beforeEach() throws FileSystemAccessException { + this.s3Adapter = new S3Adapter("test-bucket", this.client); } @Test - public void testGetPresignedUrl() + void testGetPresignedUrl() throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, FileSystemAccessException { - Mockito.when(this.client.getPresignedObjectUrl(Mockito.any(GetPresignedObjectUrlArgs.class))).thenReturn(this.s3Url + "/some-url/..."); - for (final Method action : this.actions) { - final String presignedUrl = this.s3Adapter.getPresignedUrl(this.filePath, action, this.expiresInMinutes); - Assertions.assertTrue(presignedUrl.contains(this.s3Url)); + Mockito.when(this.client.getPresignedObjectUrl(Mockito.any(GetPresignedObjectUrlArgs.class))).thenReturn(this.S3_URL + "/some-url/..."); + for (final Method action : this.ACTIONS) { + final String presignedUrl = this.s3Adapter.getPresignedUrl(this.FILE_PATH, action, this.EXPIRES_IN_MINUTES); + assertTrue(presignedUrl.contains(this.S3_URL)); } } } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/test/java/de/muenchen/refarch/integration/s3/application/usecase/FileOperationsPresignedUrlUseCaseTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/test/java/de/muenchen/refarch/integration/s3/application/usecase/FileOperationsPresignedUrlUseCaseTest.java index da64f082..cddf7f57 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/test/java/de/muenchen/refarch/integration/s3/application/usecase/FileOperationsPresignedUrlUseCaseTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/test/java/de/muenchen/refarch/integration/s3/application/usecase/FileOperationsPresignedUrlUseCaseTest.java @@ -1,6 +1,9 @@ package de.muenchen.refarch.integration.s3.application.usecase; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import de.muenchen.refarch.integration.s3.adapter.out.s3.S3Adapter; import de.muenchen.refarch.integration.s3.application.port.in.FileOperationsPresignedUrlInPort; @@ -26,63 +29,60 @@ @MockitoSettings(strictness = Strictness.LENIENT) class FileOperationsPresignedUrlUseCaseTest { + public static final String TEST_TXT_PATH = "folder/test.txt"; + public static final String EXAMPLE_PRESIGNED_URL = "some-presigned-url"; + public static final String PATH_TO_FOLDER = "folder"; @Mock private S3Adapter s3Adapter; private FileOperationsPresignedUrlInPort fileOperations; @BeforeEach - public void beforeEach() { + void beforeEach() { this.fileOperations = new FileOperationsPresignedUrlUseCase(this.s3Adapter); Mockito.reset(this.s3Adapter); } @Test - void getPresignedUrl() { - final String pathToFile = "folder/test.txt"; + void testGetPresignedUrl() { final int expiresInMinutes = 5; final List actions = List.of(Method.GET, Method.POST, Method.PUT, Method.DELETE); - final String examplePresignedUrl = "some-presigned-url"; - - actions.forEach(action -> { + for (final Method action : actions) { try { - Mockito.when(this.s3Adapter.getPresignedUrl(pathToFile, action, expiresInMinutes)).thenReturn(examplePresignedUrl); + Mockito.when(this.s3Adapter.getPresignedUrl(TEST_TXT_PATH, action, expiresInMinutes)).thenReturn(EXAMPLE_PRESIGNED_URL); - final PresignedUrl presignedUrl = fileOperations.getPresignedUrl(pathToFile, action, expiresInMinutes); + final PresignedUrl presignedUrl = fileOperations.getPresignedUrl(TEST_TXT_PATH, action, expiresInMinutes); - Assertions.assertEquals(examplePresignedUrl, presignedUrl.url()); - Assertions.assertEquals(action.toString(), presignedUrl.action()); - Assertions.assertEquals(pathToFile, presignedUrl.path()); + assertEquals(EXAMPLE_PRESIGNED_URL, presignedUrl.url()); + assertEquals(action.toString(), presignedUrl.action()); + assertEquals(TEST_TXT_PATH, presignedUrl.path()); } catch (final FileSystemAccessException e) { Assertions.fail(e.getMessage()); } - }); + } } @Test - void getPresignedUrlForFile() throws FileSystemAccessException, FileExistenceException { - final String pathToFile = "folder/test.txt"; + void testGetPresignedUrlForFile() throws FileSystemAccessException { final int expiresInMinutes = 5; final List actions = List.of(Method.GET, Method.PUT, Method.DELETE); - final String examplePresignedUrl = "some-presigned-url"; - // GET, PUT, DELETE actions.forEach(action -> { try { - Mockito.when(this.s3Adapter.fileExists(pathToFile)).thenReturn(true); - Mockito.when(this.s3Adapter.getFilePathsFromFolder(pathToFile)).thenReturn(Set.of(pathToFile)); - Mockito.when(this.s3Adapter.getPresignedUrl(pathToFile, action, expiresInMinutes)).thenReturn(examplePresignedUrl); + Mockito.when(this.s3Adapter.fileExists(TEST_TXT_PATH)).thenReturn(true); + Mockito.when(this.s3Adapter.getFilePathsFromFolder(TEST_TXT_PATH)).thenReturn(Set.of(TEST_TXT_PATH)); + Mockito.when(this.s3Adapter.getPresignedUrl(TEST_TXT_PATH, action, expiresInMinutes)).thenReturn(EXAMPLE_PRESIGNED_URL); - final List presignedUrls = this.fileOperations.getPresignedUrls(List.of(pathToFile), action, expiresInMinutes); + final List presignedUrls = this.fileOperations.getPresignedUrls(List.of(TEST_TXT_PATH), action, expiresInMinutes); - Assertions.assertEquals(1, presignedUrls.size()); + assertEquals(1, presignedUrls.size()); presignedUrls.forEach(presignedUrl -> { - Assertions.assertEquals(presignedUrl.url(), examplePresignedUrl); - Assertions.assertEquals(presignedUrl.action(), action.toString()); - Assertions.assertEquals(presignedUrl.path(), pathToFile); + assertEquals(presignedUrl.url(), EXAMPLE_PRESIGNED_URL); + assertEquals(presignedUrl.action(), action.toString()); + assertEquals(presignedUrl.path(), TEST_TXT_PATH); }); Mockito.reset(); } catch (final FileExistenceException | FileSystemAccessException e) { @@ -92,42 +92,40 @@ void getPresignedUrlForFile() throws FileSystemAccessException, FileExistenceExc // POST // special case POST is converted to PUT - Mockito.when(this.s3Adapter.getPresignedUrl(pathToFile, Method.PUT, expiresInMinutes)).thenReturn(examplePresignedUrl); + Mockito.when(this.s3Adapter.getPresignedUrl(TEST_TXT_PATH, Method.PUT, expiresInMinutes)).thenReturn(EXAMPLE_PRESIGNED_URL); - final List presignedUrls = this.fileOperations.getPresignedUrls(List.of(pathToFile), Method.POST, expiresInMinutes); + final List presignedUrls = this.fileOperations.getPresignedUrls(List.of(TEST_TXT_PATH), Method.POST, expiresInMinutes); - Assertions.assertEquals(1, presignedUrls.size()); + assertEquals(1, presignedUrls.size()); presignedUrls.forEach(presignedUrl -> { - Assertions.assertEquals(presignedUrl.url(), examplePresignedUrl); - Assertions.assertEquals(presignedUrl.action(), Method.PUT.toString()); - Assertions.assertEquals(presignedUrl.path(), pathToFile); + assertEquals(presignedUrl.url(), EXAMPLE_PRESIGNED_URL); + assertEquals(presignedUrl.action(), Method.PUT.toString()); + assertEquals(presignedUrl.path(), TEST_TXT_PATH); }); } @Test - void getPresignedUrlsForDirectory() throws FileSystemAccessException, FileExistenceException { + void testGetPresignedUrlsForDirectory() throws FileSystemAccessException { final String pathToDirectory = "folder/"; - final Set files = Set.of("folder/test.txt", "folder/test1.txt"); + final Set files = Set.of(TEST_TXT_PATH, "folder/test1.txt"); final int expiresInMinutes = 5; final List actions = List.of(Method.GET, Method.PUT, Method.DELETE); - final String examplePresignedUrl = "some-presigned-url"; - // GET, PUT, DELETE actions.forEach(action -> { try { Mockito.when(this.s3Adapter.getFilePathsFromFolder(pathToDirectory)).thenReturn(files); for (final String file : files) { - Mockito.when(this.s3Adapter.getPresignedUrl(file, action, expiresInMinutes)).thenReturn(examplePresignedUrl); + Mockito.when(this.s3Adapter.getPresignedUrl(file, action, expiresInMinutes)).thenReturn(EXAMPLE_PRESIGNED_URL); } final List presignedUrls = this.fileOperations.getPresignedUrls(List.of(pathToDirectory), action, expiresInMinutes); - Assertions.assertEquals(2, presignedUrls.size()); + assertEquals(2, presignedUrls.size()); presignedUrls.forEach(presignedUrl -> { - Assertions.assertEquals(presignedUrl.url(), examplePresignedUrl); - Assertions.assertEquals(presignedUrl.action(), action.toString()); - Assertions.assertTrue(files.stream().anyMatch(file -> file.equals(presignedUrl.path()))); + assertEquals(presignedUrl.url(), EXAMPLE_PRESIGNED_URL); + assertEquals(presignedUrl.action(), action.toString()); + assertTrue(files.stream().anyMatch(file -> file.equals(presignedUrl.path()))); }); Mockito.reset(); } catch (final FileExistenceException | FileSystemAccessException e) { @@ -137,40 +135,38 @@ void getPresignedUrlsForDirectory() throws FileSystemAccessException, FileExiste // POST // special case POST is converted to PUT - Mockito.when(this.s3Adapter.getPresignedUrl(pathToDirectory, Method.PUT, expiresInMinutes)).thenReturn(examplePresignedUrl); + Mockito.when(this.s3Adapter.getPresignedUrl(pathToDirectory, Method.PUT, expiresInMinutes)).thenReturn(EXAMPLE_PRESIGNED_URL); final List presignedUrls = this.fileOperations.getPresignedUrls(List.of(pathToDirectory), Method.POST, expiresInMinutes); - Assertions.assertEquals(1, presignedUrls.size()); + assertEquals(1, presignedUrls.size()); presignedUrls.forEach(presignedUrl -> { - Assertions.assertEquals(presignedUrl.url(), examplePresignedUrl); - Assertions.assertEquals(presignedUrl.action(), Method.PUT.toString()); - Assertions.assertEquals(presignedUrl.path(), pathToDirectory); + assertEquals(presignedUrl.url(), EXAMPLE_PRESIGNED_URL); + assertEquals(presignedUrl.action(), Method.PUT.toString()); + assertEquals(presignedUrl.path(), pathToDirectory); }); } @Test - void getPresignedUrlsForMultipleFiles() throws FileSystemAccessException, FileExistenceException { + void testGetPresignedUrlsForMultipleFiles() throws FileSystemAccessException { final List pathToFiles = List.of("folder/first.txt", "folder/second.txt", "folder/third.txt"); final int expiresInMinutes = 5; final List actions = List.of(Method.GET, Method.PUT, Method.DELETE); - final String examplePresignedUrl = "some-presigned-url"; - // GET, PUT, DELETE actions.forEach(action -> { try { - for (String file : pathToFiles) { + for (final String file : pathToFiles) { Mockito.when(this.s3Adapter.getFilePathsFromFolder(file)).thenReturn(Set.of(file)); - Mockito.when(this.s3Adapter.getPresignedUrl(file, action, expiresInMinutes)).thenReturn(examplePresignedUrl); + Mockito.when(this.s3Adapter.getPresignedUrl(file, action, expiresInMinutes)).thenReturn(EXAMPLE_PRESIGNED_URL); } final List presignedUrls = this.fileOperations.getPresignedUrls(pathToFiles, action, expiresInMinutes); - Assertions.assertEquals(3, presignedUrls.size()); + assertEquals(3, presignedUrls.size()); presignedUrls.forEach(presignedUrl -> { - Assertions.assertEquals(presignedUrl.url(), examplePresignedUrl); - Assertions.assertEquals(presignedUrl.action(), action.toString()); + assertEquals(presignedUrl.url(), EXAMPLE_PRESIGNED_URL); + assertEquals(presignedUrl.action(), action.toString()); }); Mockito.reset(); } catch (final FileExistenceException | FileSystemAccessException e) { @@ -180,102 +176,90 @@ void getPresignedUrlsForMultipleFiles() throws FileSystemAccessException, FileEx // POST // special case POST is converted to PUT - for (String file : pathToFiles) { - Mockito.when(this.s3Adapter.getPresignedUrl(file, Method.PUT, expiresInMinutes)).thenReturn(examplePresignedUrl); + for (final String file : pathToFiles) { + Mockito.when(this.s3Adapter.getPresignedUrl(file, Method.PUT, expiresInMinutes)).thenReturn(EXAMPLE_PRESIGNED_URL); } final List presignedUrls = this.fileOperations.getPresignedUrls(pathToFiles, Method.POST, expiresInMinutes); - Assertions.assertEquals(3, presignedUrls.size()); + assertEquals(3, presignedUrls.size()); presignedUrls.forEach(presignedUrl -> { - Assertions.assertEquals(presignedUrl.url(), examplePresignedUrl); - Assertions.assertEquals(presignedUrl.action(), Method.PUT.toString()); - Assertions.assertTrue(pathToFiles.stream().anyMatch(file -> file.equals(presignedUrl.path()))); + assertEquals(presignedUrl.url(), EXAMPLE_PRESIGNED_URL); + assertEquals(presignedUrl.action(), Method.PUT.toString()); + assertTrue(pathToFiles.stream().anyMatch(file -> file.equals(presignedUrl.path()))); }); } @Test - void getFileException() throws Exception { - final String pathToFile = "folder/test.txt"; - final String pathToFolder = "folder"; + void testGetFileException() throws Exception { final int expiresInMinutes = 5; - Mockito.when(this.s3Adapter.getFilePathsFromFolder(pathToFolder)).thenReturn(new HashSet<>()); - Assertions.assertThrows(FileExistenceException.class, () -> this.fileOperations.getFile(pathToFile, expiresInMinutes)); + Mockito.when(this.s3Adapter.getFilePathsFromFolder(PATH_TO_FOLDER)).thenReturn(new HashSet<>()); + assertThrows(FileExistenceException.class, () -> this.fileOperations.getFile(TEST_TXT_PATH, expiresInMinutes)); } @Test - void getFile() throws FileSystemAccessException, FileExistenceException { - final String pathToFile = "folder/test.txt"; - final String pathToFolder = "folder"; + void testGetFile() throws FileSystemAccessException { final int expiresInMinutes = 5; final String presignedUrl = "THE_PRESIGNED_URL"; - Mockito.when(this.s3Adapter.fileExists(pathToFile)).thenReturn(true); - Mockito.when(this.s3Adapter.getFilePathsFromFolder(pathToFolder)).thenReturn(new HashSet<>(List.of(pathToFile))); - Mockito.when(this.s3Adapter.getPresignedUrl(pathToFile, Method.GET, expiresInMinutes)).thenReturn(presignedUrl); + Mockito.when(this.s3Adapter.fileExists(TEST_TXT_PATH)).thenReturn(true); + Mockito.when(this.s3Adapter.getFilePathsFromFolder(PATH_TO_FOLDER)).thenReturn(new HashSet<>(List.of(TEST_TXT_PATH))); + Mockito.when(this.s3Adapter.getPresignedUrl(TEST_TXT_PATH, Method.GET, expiresInMinutes)).thenReturn(presignedUrl); - final PresignedUrl result = this.fileOperations.getFile(pathToFile, expiresInMinutes); + final PresignedUrl result = this.fileOperations.getFile(TEST_TXT_PATH, expiresInMinutes); - final PresignedUrl expected = new PresignedUrl(presignedUrl, pathToFile, "GET"); + final PresignedUrl expected = new PresignedUrl(presignedUrl, TEST_TXT_PATH, "GET"); assertThat(result).isEqualTo(expected); } @Test void saveFile() throws FileSystemAccessException { - final String pathToFile = "folder/test.txt"; - final String pathToFolder = "folder"; + final FileData fileData = new FileData(TEST_TXT_PATH, 5); - final FileData fileData = new FileData(pathToFile, 5); - - Mockito.when(this.s3Adapter.fileExists(pathToFile)).thenReturn(true); - Mockito.when(this.s3Adapter.getFilePathsFromFolder(pathToFolder)).thenReturn(new HashSet<>(List.of(pathToFile))); - Assertions.assertThrows(FileExistenceException.class, () -> this.fileOperations.saveFile(fileData)); + Mockito.when(this.s3Adapter.fileExists(TEST_TXT_PATH)).thenReturn(true); + Mockito.when(this.s3Adapter.getFilePathsFromFolder(PATH_TO_FOLDER)).thenReturn(new HashSet<>(List.of(TEST_TXT_PATH))); + assertThrows(FileExistenceException.class, () -> this.fileOperations.saveFile(fileData)); // happy path is tested in updateFile } @Test void updateFile() throws FileSystemAccessException { - final String pathToFile = "folder/test.txt"; - - final FileData fileData = new FileData(pathToFile, 5); + final FileData fileData = new FileData(TEST_TXT_PATH, 5); // File not in Database this.fileOperations.updateFile(fileData); - Mockito.verify(this.s3Adapter, Mockito.times(1)).getPresignedUrl(pathToFile, Method.PUT, fileData.expiresInMinutes()); + Mockito.verify(this.s3Adapter, Mockito.times(1)).getPresignedUrl(TEST_TXT_PATH, Method.PUT, fileData.expiresInMinutes()); // File already in Database with older end of life Mockito.reset(this.s3Adapter); this.fileOperations.updateFile(fileData); - Mockito.verify(this.s3Adapter, Mockito.times(1)).getPresignedUrl(pathToFile, Method.PUT, fileData.expiresInMinutes()); + Mockito.verify(this.s3Adapter, Mockito.times(1)).getPresignedUrl(TEST_TXT_PATH, Method.PUT, fileData.expiresInMinutes()); // File already in Database with older and of life Mockito.reset(this.s3Adapter); this.fileOperations.updateFile(fileData); - Mockito.verify(this.s3Adapter, Mockito.times(1)).getPresignedUrl(pathToFile, Method.PUT, fileData.expiresInMinutes()); + Mockito.verify(this.s3Adapter, Mockito.times(1)).getPresignedUrl(TEST_TXT_PATH, Method.PUT, fileData.expiresInMinutes()); } @Test void deleteFileException() throws FileSystemAccessException { - final String pathToFile = "folder/test.txt"; - final String pathToFolder = "folder"; final int expiresInMinutes = 5; Mockito.reset(this.s3Adapter); - Mockito.when(this.s3Adapter.getFilePathsFromFolder(pathToFolder)).thenReturn(new HashSet<>()); - Assertions.assertThrows(FileExistenceException.class, () -> this.fileOperations.deleteFile(pathToFile, expiresInMinutes)); + Mockito.when(this.s3Adapter.getFilePathsFromFolder(PATH_TO_FOLDER)).thenReturn(new HashSet<>()); + assertThrows(FileExistenceException.class, () -> this.fileOperations.deleteFile(TEST_TXT_PATH, expiresInMinutes)); } @Test - void deleteFile() throws FileSystemAccessException, FileExistenceException { - final String pathToFile = "folder/test.txt"; + void deleteFile() throws FileSystemAccessException { final int expiresInMinutes = 5; Mockito.reset(this.s3Adapter); - Mockito.when(this.s3Adapter.fileExists(pathToFile)).thenReturn(true); - this.fileOperations.deleteFile(pathToFile, expiresInMinutes); - Mockito.verify(this.s3Adapter, Mockito.times(1)).getPresignedUrl(pathToFile, Method.DELETE, expiresInMinutes); - Mockito.verify(this.s3Adapter, Mockito.times(1)).fileExists(pathToFile); + Mockito.when(this.s3Adapter.fileExists(TEST_TXT_PATH)).thenReturn(true); + this.fileOperations.deleteFile(TEST_TXT_PATH, expiresInMinutes); + Mockito.verify(this.s3Adapter, Mockito.times(1)).getPresignedUrl(TEST_TXT_PATH, Method.DELETE, expiresInMinutes); + Mockito.verify(this.s3Adapter, Mockito.times(1)).fileExists(TEST_TXT_PATH); } @Test diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/test/java/de/muenchen/refarch/integration/s3/application/usecase/FolderOperationsUseCaseTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/test/java/de/muenchen/refarch/integration/s3/application/usecase/FolderOperationsUseCaseTest.java index e7e24587..490ed318 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/test/java/de/muenchen/refarch/integration/s3/application/usecase/FolderOperationsUseCaseTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-core/src/test/java/de/muenchen/refarch/integration/s3/application/usecase/FolderOperationsUseCaseTest.java @@ -1,12 +1,12 @@ package de.muenchen.refarch.integration.s3.application.usecase; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import de.muenchen.refarch.integration.s3.adapter.out.s3.S3Adapter; import de.muenchen.refarch.integration.s3.domain.exception.FileSystemAccessException; import java.util.HashSet; import java.util.List; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -38,7 +38,7 @@ void deleteFolder() throws FileSystemAccessException { final String pathToFolderWithSeparator = pathToFolder + "/"; Mockito.when(this.s3Adapter.getFilePathsFromFolder(pathToFolderWithSeparator)).thenReturn(new HashSet<>(List.of(pathToFile))); - Assertions.assertDoesNotThrow(() -> this.folderHandlingService.deleteFolder(pathToFolder)); + assertDoesNotThrow(() -> this.folderHandlingService.deleteFolder(pathToFolder)); Mockito.verify(this.s3Adapter, Mockito.times(1)).deleteFile(pathToFile); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java index 16701c5a..d0ea873c 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java @@ -44,6 +44,7 @@ public class S3IntegrationClientAutoConfiguration { */ @Bean @ConditionalOnBean(SupportedFileExtensions.class) + @SuppressWarnings("PMD.LooseCoupling") public FileValidationService fileService(final SupportedFileExtensions supportedFileExtensions) { return new FileValidationService(supportedFileExtensions, this.s3IntegrationClientProperties.getMaxFileSize(), this.s3IntegrationClientProperties.getMaxBatchSize()); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/properties/S3IntegrationClientProperties.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/properties/S3IntegrationClientProperties.java index a0a15e81..c9308e97 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/properties/S3IntegrationClientProperties.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/properties/S3IntegrationClientProperties.java @@ -1,6 +1,6 @@ package de.muenchen.refarch.integration.s3.client.properties; -import de.muenchen.refarch.integration.s3.client.domain.model.SupportedFileExtensions; +import java.util.Map; import lombok.Getter; import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -17,6 +17,6 @@ public class S3IntegrationClientProperties { */ private DataSize maxBatchSize = DataSize.ofBytes(0L); /** Supported file extensions. */ - private SupportedFileExtensions supportedFileExtensions; + private Map supportedFileExtensions; } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileJavaRepository.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileJavaRepository.java index 2631b6b3..be1e86b2 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileJavaRepository.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileJavaRepository.java @@ -18,7 +18,7 @@ public DocumentStorageFileJavaRepository(final PresignedUrlRepository presignedU } @Override - public Long getFileSize(String pathToFile) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { + public Long getFileSize(final String pathToFile) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { return fileOperationsInPort.getFileSize(pathToFile).fileSize(); } catch (FileSystemAccessException e) { diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderJavaRepository.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderJavaRepository.java index 626e1529..4771df2d 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderJavaRepository.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderJavaRepository.java @@ -14,7 +14,8 @@ public class DocumentStorageFolderJavaRepository implements DocumentStorageFolde private final FolderOperationsInPort folderOperationsInPort; @Override - public void deleteFolder(String pathToFolder) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { + public void deleteFolder(final String pathToFolder) + throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { folderOperationsInPort.deleteFolder(pathToFolder); } catch (FileSystemAccessException e) { @@ -23,7 +24,7 @@ public void deleteFolder(String pathToFolder) throws DocumentStorageClientErrorE } @Override - public Set getAllFilesInFolderRecursively(String pathToFolder) + public Set getAllFilesInFolderRecursively(final String pathToFolder) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { return folderOperationsInPort.getAllFilesInFolderRecursively(pathToFolder).pathToFiles(); @@ -33,7 +34,7 @@ public Set getAllFilesInFolderRecursively(String pathToFolder) } @Override - public Map getAllFileSizesInFolderRecursively(String pathToFolder) + public Map getAllFileSizesInFolderRecursively(final String pathToFolder) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { return folderOperationsInPort.getAllFileSizesInFolderRecursively(pathToFolder).fileSizes(); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlJavaRepository.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlJavaRepository.java index 21a29001..cd57ba44 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlJavaRepository.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-java/refarch-s3-integration-java-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlJavaRepository.java @@ -13,7 +13,7 @@ public class PresignedUrlJavaRepository implements PresignedUrlRepository { private final FileOperationsPresignedUrlInPort fileOperationsPresignedUrlInPort; @Override - public String getPresignedUrlGetFile(String pathToFile, int expireInMinutes) + public String getPresignedUrlGetFile(final String pathToFile, final int expireInMinutes) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { return fileOperationsPresignedUrlInPort.getFile(pathToFile, expireInMinutes).url(); @@ -23,7 +23,7 @@ public String getPresignedUrlGetFile(String pathToFile, int expireInMinutes) } @Override - public String getPresignedUrlSaveFile(String pathToFile, int expireInMinutes) + public String getPresignedUrlSaveFile(final String pathToFile, final int expireInMinutes) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { return fileOperationsPresignedUrlInPort.saveFile(new FileData(pathToFile, expireInMinutes)).url(); @@ -33,7 +33,7 @@ public String getPresignedUrlSaveFile(String pathToFile, int expireInMinutes) } @Override - public String getPresignedUrlUpdateFile(String pathToFile, int expireInMinutes) + public String getPresignedUrlUpdateFile(final String pathToFile, final int expireInMinutes) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { return fileOperationsPresignedUrlInPort.updateFile(new FileData(pathToFile, expireInMinutes)).url(); @@ -43,7 +43,7 @@ public String getPresignedUrlUpdateFile(String pathToFile, int expireInMinutes) } @Override - public String getPresignedUrlDeleteFile(String pathToFile, int expireInMinutes) + public String getPresignedUrlDeleteFile(final String pathToFile, final int expireInMinutes) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { return fileOperationsPresignedUrlInPort.deleteFile(pathToFile, expireInMinutes).url(); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java index 1b7c3f8f..e4f3501f 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java @@ -23,12 +23,10 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; import org.springframework.security.oauth2.client.AuthorizedClientServiceOAuth2AuthorizedClientManager; import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction; -import org.springframework.util.ResourceUtils; import org.springframework.web.reactive.function.client.WebClient; @Configuration @@ -54,7 +52,7 @@ public void init() { @ConditionalOnProperty(prefix = "refarch.s3.client", name = "enable-security", havingValue = "true") public ApiClient securedApiClient(final ClientRegistrationRepository clientRegistrationRepository, final OAuth2AuthorizedClientService authorizedClientService) { - final var apiClient = new ApiClient( + final ApiClient apiClient = new ApiClient( this.authenticatedWebClient(clientRegistrationRepository, authorizedClientService)); apiClient.setBasePath(this.s3IntegrationClientProperties.getDocumentStorageUrl()); return apiClient; @@ -63,7 +61,7 @@ public ApiClient securedApiClient(final ClientRegistrationRepository clientRegis @Bean @ConditionalOnProperty(prefix = "refarch.s3.client", name = "enable-security", havingValue = "false", matchIfMissing = true) public ApiClient apiClient() { - final var apiClient = new ApiClient( + final ApiClient apiClient = new ApiClient( WebClient.builder().build()); apiClient.setBasePath(this.s3IntegrationClientProperties.getDocumentStorageUrl()); return apiClient; @@ -72,7 +70,7 @@ public ApiClient apiClient() { private WebClient authenticatedWebClient( final ClientRegistrationRepository clientRegistrationRepository, final OAuth2AuthorizedClientService authorizedClientService) { - final var oauth = new ServletOAuth2AuthorizedClientExchangeFilterFunction( + final ServletOAuth2AuthorizedClientExchangeFilterFunction oauth = new ServletOAuth2AuthorizedClientExchangeFilterFunction( new AuthorizedClientServiceOAuth2AuthorizedClientManager( clientRegistrationRepository, authorizedClientService)); oauth.setDefaultClientRegistrationId("s3"); @@ -90,6 +88,7 @@ private WebClient authenticatedWebClient( */ @Bean @ConditionalOnBean(SupportedFileExtensions.class) + @SuppressWarnings("PMD.LooseCoupling") public FileValidationService fileService(final SupportedFileExtensions supportedFileExtensions) { return new FileValidationService(supportedFileExtensions, this.s3IntegrationClientProperties.getMaxFileSize(), this.s3IntegrationClientProperties.getMaxBatchSize()); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/properties/S3IntegrationClientProperties.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/properties/S3IntegrationClientProperties.java index 1e946130..12cbaf68 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/properties/S3IntegrationClientProperties.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/properties/S3IntegrationClientProperties.java @@ -1,6 +1,6 @@ package de.muenchen.refarch.integration.s3.client.properties; -import de.muenchen.refarch.integration.s3.client.domain.model.SupportedFileExtensions; +import java.util.Map; import lombok.Getter; import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -21,6 +21,6 @@ public class S3IntegrationClientProperties { */ private DataSize maxBatchSize = DataSize.ofBytes(0L); /** Supported file extensions. */ - private SupportedFileExtensions supportedFileExtensions; + private Map supportedFileExtensions; } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRestRepository.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRestRepository.java index a8ad31f1..19f09756 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRestRepository.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRestRepository.java @@ -44,7 +44,7 @@ public String getPresignedUrlGetFile(final String pathToFile, final int expireIn public String getPresignedUrlSaveFile(final String pathToFile, final int expireInMinutes) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { - final var fileDataDto = new FileDataDto(); + final FileDataDto fileDataDto = new FileDataDto(); fileDataDto.setPathToFile(pathToFile); fileDataDto.setExpiresInMinutes(expireInMinutes); final Mono presignedUrlDto = fileApi.save(fileDataDto); @@ -68,7 +68,7 @@ public String getPresignedUrlSaveFile(final String pathToFile, final int expireI public String getPresignedUrlUpdateFile(final String pathToFile, final int expireInMinutes) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { - final var fileDataDto = new FileDataDto(); + final FileDataDto fileDataDto = new FileDataDto(); fileDataDto.setPathToFile(pathToFile); fileDataDto.setExpiresInMinutes(expireInMinutes); final Mono presignedUrlDto = fileApi.update(fileDataDto); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRestRepositoryTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRestRepositoryTest.java index 850da071..33b46677 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRestRepositoryTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRestRepositoryTest.java @@ -4,6 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -18,7 +20,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; @@ -31,6 +32,8 @@ @MockitoSettings(strictness = Strictness.STRICT_STUBS) class DocumentStorageFileRestRepositoryTest { + public static final String PATH_TO_FILE = "folder/file.txt"; + public static final String PRESIGNED_URL = "the_presignedUrl"; @Mock private PresignedUrlRestRepository presignedUrlRestRepository; @@ -46,25 +49,23 @@ class DocumentStorageFileRestRepositoryTest { public void beforeEach() { this.documentStorageFileRestRepository = new DocumentStorageFileRestRepository(this.presignedUrlRestRepository, this.s3FileTransferRepository, this.fileApi); - Mockito.reset(this.presignedUrlRestRepository, this.s3FileTransferRepository, this.fileApi); + reset(this.presignedUrlRestRepository, this.s3FileTransferRepository, this.fileApi); } @Test - void getFile() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String pathToFile = "folder/file.txt"; + void testGetFile() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final int expireInMinutes = 10; - final String presignedUrl = "the_presignedUrl"; - when(this.presignedUrlRestRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes)).thenReturn(presignedUrl); - when(this.s3FileTransferRepository.getFile(presignedUrl)).thenReturn(new byte[] {}); - this.documentStorageFileRestRepository.getFile(pathToFile, expireInMinutes); + when(this.presignedUrlRestRepository.getPresignedUrlGetFile(PATH_TO_FILE, expireInMinutes)).thenReturn(PRESIGNED_URL); + when(this.s3FileTransferRepository.getFile(PRESIGNED_URL)).thenReturn(new byte[] {}); + this.documentStorageFileRestRepository.getFile(PATH_TO_FILE, expireInMinutes); - verify(this.presignedUrlRestRepository, Mockito.times(1)).getPresignedUrlGetFile(pathToFile, expireInMinutes); - verify(this.s3FileTransferRepository, Mockito.times(1)).getFile(presignedUrl); + verify(this.presignedUrlRestRepository, times(1)).getPresignedUrlGetFile(PATH_TO_FILE, expireInMinutes); + verify(this.s3FileTransferRepository, times(1)).getFile(PRESIGNED_URL); } @Test - void getFileSize() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { + void testGetFileSize() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final FileSizeDto fileSizeDto = new FileSizeDto(); fileSizeDto.setFileSize(123L); final String pathToFile = "path/to/file"; @@ -72,66 +73,60 @@ void getFileSize() throws DocumentStorageException, DocumentStorageClientErrorEx when(fileApi.getFileSize(anyString())).thenReturn(Mono.just(fileSizeDto)); final Long result = documentStorageFileRestRepository.getFileSize(pathToFile); assertEquals(123L, result); - verify(fileApi, Mockito.times(1)).getFileSize(pathToFile); + verify(fileApi, times(1)).getFileSize(pathToFile); - Mockito.reset(this.fileApi); + reset(this.fileApi); when(fileApi.getFileSize(anyString())).thenThrow(HttpClientErrorException.class); assertThrows(DocumentStorageClientErrorException.class, () -> documentStorageFileRestRepository.getFileSize(pathToFile)); - verify(fileApi, Mockito.times(1)).getFileSize(pathToFile); + verify(fileApi, times(1)).getFileSize(pathToFile); - Mockito.reset(this.fileApi); + reset(this.fileApi); when(fileApi.getFileSize(anyString())).thenThrow(HttpServerErrorException.class); assertThrows(DocumentStorageServerErrorException.class, () -> documentStorageFileRestRepository.getFileSize(pathToFile)); - verify(fileApi, Mockito.times(1)).getFileSize(pathToFile); + verify(fileApi, times(1)).getFileSize(pathToFile); - Mockito.reset(this.fileApi); + reset(this.fileApi); when(fileApi.getFileSize(anyString())).thenThrow(RestClientException.class); assertThrows(DocumentStorageException.class, () -> documentStorageFileRestRepository.getFileSize(pathToFile)); - verify(fileApi, Mockito.times(1)).getFileSize(pathToFile); + verify(fileApi, times(1)).getFileSize(pathToFile); } @Test void saveFile() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String pathToFile = "folder/file.txt"; - final byte[] file = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; + final byte[] file = { 1, 2, 3, 4, 5, 6, 7 }; final int expireInMinutes = 10; - final String presignedUrl = "the_presignedUrl"; - when(this.presignedUrlRestRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes)).thenReturn(presignedUrl); - doNothing().when(this.s3FileTransferRepository).saveFile(presignedUrl, file); - this.documentStorageFileRestRepository.saveFile(pathToFile, file, expireInMinutes); + when(this.presignedUrlRestRepository.getPresignedUrlSaveFile(PATH_TO_FILE, expireInMinutes)).thenReturn(PRESIGNED_URL); + doNothing().when(this.s3FileTransferRepository).saveFile(PRESIGNED_URL, file); + this.documentStorageFileRestRepository.saveFile(PATH_TO_FILE, file, expireInMinutes); - verify(this.presignedUrlRestRepository, Mockito.times(1)).getPresignedUrlSaveFile(pathToFile, expireInMinutes); - verify(this.s3FileTransferRepository, Mockito.times(1)).saveFile(presignedUrl, file); + verify(this.presignedUrlRestRepository, times(1)).getPresignedUrlSaveFile(PATH_TO_FILE, expireInMinutes); + verify(this.s3FileTransferRepository, times(1)).saveFile(PRESIGNED_URL, file); } @Test void updateFile() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String pathToFile = "folder/file.txt"; - final byte[] file = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; + final byte[] file = { 1, 2, 3, 4, 5, 6, 7 }; final int expireInMinutes = 10; - final String presignedUrl = "the_presignedUrl"; - when(this.presignedUrlRestRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes)).thenReturn(presignedUrl); - doNothing().when(this.s3FileTransferRepository).updateFile(presignedUrl, file); - this.documentStorageFileRestRepository.updateFile(pathToFile, file, expireInMinutes); + when(this.presignedUrlRestRepository.getPresignedUrlUpdateFile(PATH_TO_FILE, expireInMinutes)).thenReturn(PRESIGNED_URL); + doNothing().when(this.s3FileTransferRepository).updateFile(PRESIGNED_URL, file); + this.documentStorageFileRestRepository.updateFile(PATH_TO_FILE, file, expireInMinutes); - verify(this.presignedUrlRestRepository, Mockito.times(1)).getPresignedUrlUpdateFile(pathToFile, expireInMinutes); - verify(this.s3FileTransferRepository, Mockito.times(1)).updateFile(presignedUrl, file); + verify(this.presignedUrlRestRepository, times(1)).getPresignedUrlUpdateFile(PATH_TO_FILE, expireInMinutes); + verify(this.s3FileTransferRepository, times(1)).updateFile(PRESIGNED_URL, file); } @Test void deleteFile() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String pathToFile = "folder/file.txt"; final int expireInMinutes = 10; - final String presignedUrl = "the_presignedUrl"; - when(this.presignedUrlRestRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes)).thenReturn(presignedUrl); - doNothing().when(this.s3FileTransferRepository).deleteFile(presignedUrl); - this.documentStorageFileRestRepository.deleteFile(pathToFile, expireInMinutes); + when(this.presignedUrlRestRepository.getPresignedUrlDeleteFile(PATH_TO_FILE, expireInMinutes)).thenReturn(PRESIGNED_URL); + doNothing().when(this.s3FileTransferRepository).deleteFile(PRESIGNED_URL); + this.documentStorageFileRestRepository.deleteFile(PATH_TO_FILE, expireInMinutes); - verify(this.presignedUrlRestRepository, Mockito.times(1)).getPresignedUrlDeleteFile(pathToFile, expireInMinutes); - verify(this.s3FileTransferRepository, Mockito.times(1)).deleteFile(presignedUrl); + verify(this.presignedUrlRestRepository, times(1)).getPresignedUrlDeleteFile(PATH_TO_FILE, expireInMinutes); + verify(this.s3FileTransferRepository, times(1)).deleteFile(PRESIGNED_URL); } } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderRestRepositoryTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderRestRepositoryTest.java index 6be37746..9ae456ee 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderRestRepositoryTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderRestRepositoryTest.java @@ -3,6 +3,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -19,7 +21,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; @@ -47,51 +48,51 @@ public void beforeEach() { void deleteFolder() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final String pathToFolder = "folder"; - Mockito.reset(this.folderApi); + reset(this.folderApi); when(this.folderApi.delete(pathToFolder)).thenReturn(Mono.empty()); this.documentStorageFolderRestRepository.deleteFolder(pathToFolder); verify(this.folderApi, times(1)).delete(pathToFolder); - Mockito.reset(this.folderApi); - Mockito.doThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)).when(this.folderApi).delete(pathToFolder); + reset(this.folderApi); + doThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)).when(this.folderApi).delete(pathToFolder); assertThrows(DocumentStorageClientErrorException.class, () -> this.documentStorageFolderRestRepository.deleteFolder(pathToFolder)); verify(this.folderApi, times(1)).delete(pathToFolder); - Mockito.reset(this.folderApi); - Mockito.doThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)).when(this.folderApi).delete(pathToFolder); + reset(this.folderApi); + doThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)).when(this.folderApi).delete(pathToFolder); assertThrows(DocumentStorageServerErrorException.class, () -> this.documentStorageFolderRestRepository.deleteFolder(pathToFolder)); verify(this.folderApi, times(1)).delete(pathToFolder); - Mockito.reset(this.folderApi); - Mockito.doThrow(new RestClientException("Something happened")).when(this.folderApi).delete(pathToFolder); + reset(this.folderApi); + doThrow(new RestClientException("Something happened")).when(this.folderApi).delete(pathToFolder); assertThrows(DocumentStorageException.class, () -> this.documentStorageFolderRestRepository.deleteFolder(pathToFolder)); verify(this.folderApi, times(1)).delete(pathToFolder); } @Test - void getAllFilesInFolderRecursively() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { + void testGetAllFilesInFolderRecursively() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final String pathToFolder = "folder"; final FilesInFolderDto filesInFolderDto = new FilesInFolderDto(); filesInFolderDto.setPathToFiles(Set.of("folder/file.txt")); - Mockito.reset(this.folderApi); + reset(this.folderApi); when(this.folderApi.getAllFilesInFolderRecursively(pathToFolder)).thenReturn(Mono.just(filesInFolderDto)); this.documentStorageFolderRestRepository.getAllFilesInFolderRecursively(pathToFolder); verify(this.folderApi, times(1)).getAllFilesInFolderRecursively(pathToFolder); - Mockito.reset(this.folderApi); - Mockito.doThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)).when(this.folderApi).getAllFilesInFolderRecursively(pathToFolder); + reset(this.folderApi); + doThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)).when(this.folderApi).getAllFilesInFolderRecursively(pathToFolder); assertThrows(DocumentStorageClientErrorException.class, () -> this.documentStorageFolderRestRepository.getAllFilesInFolderRecursively(pathToFolder)); verify(this.folderApi, times(1)).getAllFilesInFolderRecursively(pathToFolder); - Mockito.reset(this.folderApi); - Mockito.doThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)).when(this.folderApi).getAllFilesInFolderRecursively(pathToFolder); + reset(this.folderApi); + doThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)).when(this.folderApi).getAllFilesInFolderRecursively(pathToFolder); assertThrows(DocumentStorageServerErrorException.class, () -> this.documentStorageFolderRestRepository.getAllFilesInFolderRecursively(pathToFolder)); verify(this.folderApi, times(1)).getAllFilesInFolderRecursively(pathToFolder); - Mockito.reset(this.folderApi); - Mockito.doThrow(new RestClientException("Something happened")).when(this.folderApi).getAllFilesInFolderRecursively(pathToFolder); + reset(this.folderApi); + doThrow(new RestClientException("Something happened")).when(this.folderApi).getAllFilesInFolderRecursively(pathToFolder); assertThrows(DocumentStorageException.class, () -> this.documentStorageFolderRestRepository.getAllFilesInFolderRecursively(pathToFolder)); verify(this.folderApi, times(1)).getAllFilesInFolderRecursively(pathToFolder); } @@ -100,25 +101,25 @@ void getAllFilesInFolderRecursively() throws DocumentStorageException, DocumentS void testGetAllFileSizesInFolderRecursively() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final String pathToFolder = "path/to/folder"; - FileSizesInFolderDto fileSizesInFolderDto = new FileSizesInFolderDto(); + final FileSizesInFolderDto fileSizesInFolderDto = new FileSizesInFolderDto(); fileSizesInFolderDto.setFileSizes(Map.of("file1", 100L, "file2", 200L)); when(folderApi.getAllFileSizesInFolderRecursively(anyString())).thenReturn(Mono.just(fileSizesInFolderDto)); - Map result = documentStorageFolderRestRepository.getAllFileSizesInFolderRecursively(pathToFolder); + final Map result = documentStorageFolderRestRepository.getAllFileSizesInFolderRecursively(pathToFolder); assertEquals(Map.of("file1", 100L, "file2", 200L), result); verify(this.folderApi, times(1)).getAllFileSizesInFolderRecursively(pathToFolder); - Mockito.reset(this.folderApi); + reset(this.folderApi); when(folderApi.getAllFileSizesInFolderRecursively(anyString())).thenThrow(HttpClientErrorException.class); assertThrows(DocumentStorageClientErrorException.class, () -> documentStorageFolderRestRepository.getAllFileSizesInFolderRecursively(pathToFolder)); verify(this.folderApi, times(1)).getAllFileSizesInFolderRecursively(pathToFolder); - Mockito.reset(this.folderApi); + reset(this.folderApi); when(folderApi.getAllFileSizesInFolderRecursively(anyString())).thenThrow(HttpServerErrorException.class); assertThrows(DocumentStorageServerErrorException.class, () -> documentStorageFolderRestRepository.getAllFileSizesInFolderRecursively(pathToFolder)); verify(this.folderApi, times(1)).getAllFileSizesInFolderRecursively(pathToFolder); - Mockito.reset(this.folderApi); + reset(this.folderApi); when(folderApi.getAllFileSizesInFolderRecursively(anyString())).thenThrow(RestClientException.class); assertThrows(DocumentStorageException.class, () -> documentStorageFolderRestRepository.getAllFileSizesInFolderRecursively(pathToFolder)); verify(this.folderApi, times(1)).getAllFileSizesInFolderRecursively(pathToFolder); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRestRepositoryTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRestRepositoryTest.java index 96b1569f..a1fc0a89 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRestRepositoryTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRestRepositoryTest.java @@ -2,6 +2,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertThrows; import de.muenchen.refarch.integration.s3.client.api.FileApiApi; import de.muenchen.refarch.integration.s3.client.exception.DocumentStorageClientErrorException; @@ -9,7 +10,6 @@ import de.muenchen.refarch.integration.s3.client.exception.DocumentStorageServerErrorException; import de.muenchen.refarch.integration.s3.client.model.FileDataDto; import de.muenchen.refarch.integration.s3.client.model.PresignedUrlDto; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -28,6 +28,9 @@ @MockitoSettings(strictness = Strictness.STRICT_STUBS) class PresignedUrlRestRepositoryTest { + public static final String PATH_TO_FILE = "folder/file.txt"; + public static final String PRESIGNED_URL = "the_presignedUrl"; + public static final String SOMETHING_HAPPENED = "Something happened"; @Mock private FileApiApi fileApi; @@ -40,183 +43,175 @@ public void beforeEach() { } @Test - void getPresignedUrlGetFile() + void testGetPresignedUrlGetFile() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String pathToFile = "folder/file.txt"; final int expireInMinutes = 10; final PresignedUrlDto expected = new PresignedUrlDto(); - expected.setUrl("the_presignedUrl"); + expected.setUrl(PRESIGNED_URL); Mockito.reset(this.fileApi); - Mockito.when(this.fileApi.get(pathToFile, expireInMinutes)).thenReturn(Mono.just(expected)); - final String result = this.presignedUrlRestRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes); - Mockito.verify(this.fileApi, Mockito.times(1)).get(pathToFile, expireInMinutes); + Mockito.when(this.fileApi.get(PATH_TO_FILE, expireInMinutes)).thenReturn(Mono.just(expected)); + final String result = this.presignedUrlRestRepository.getPresignedUrlGetFile(PATH_TO_FILE, expireInMinutes); + Mockito.verify(this.fileApi, Mockito.times(1)).get(PATH_TO_FILE, expireInMinutes); assertThat(result, is(expected.getUrl())); Mockito.reset(this.fileApi); } @Test - void getPresignedUrlGetFileException() { - final String pathToFile = "folder/file.txt"; + void testGetPresignedUrlGetFileException() { final int expireInMinutes = 10; Mockito.reset(this.fileApi); - Mockito.when(this.fileApi.get(pathToFile, expireInMinutes)).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); - Assertions.assertThrows(DocumentStorageClientErrorException.class, - () -> this.presignedUrlRestRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes)); - Mockito.verify(this.fileApi, Mockito.times(1)).get(pathToFile, expireInMinutes); + Mockito.when(this.fileApi.get(PATH_TO_FILE, expireInMinutes)).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); + assertThrows(DocumentStorageClientErrorException.class, + () -> this.presignedUrlRestRepository.getPresignedUrlGetFile(PATH_TO_FILE, expireInMinutes)); + Mockito.verify(this.fileApi, Mockito.times(1)).get(PATH_TO_FILE, expireInMinutes); Mockito.reset(this.fileApi); - Mockito.when(this.fileApi.get(pathToFile, expireInMinutes)).thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); - Assertions.assertThrows(DocumentStorageServerErrorException.class, - () -> this.presignedUrlRestRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes)); - Mockito.verify(this.fileApi, Mockito.times(1)).get(pathToFile, expireInMinutes); + Mockito.when(this.fileApi.get(PATH_TO_FILE, expireInMinutes)).thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); + assertThrows(DocumentStorageServerErrorException.class, + () -> this.presignedUrlRestRepository.getPresignedUrlGetFile(PATH_TO_FILE, expireInMinutes)); + Mockito.verify(this.fileApi, Mockito.times(1)).get(PATH_TO_FILE, expireInMinutes); Mockito.reset(this.fileApi); - Mockito.when(this.fileApi.get(pathToFile, expireInMinutes)).thenThrow(new RestClientException("Something happened")); - Assertions.assertThrows(DocumentStorageException.class, - () -> this.presignedUrlRestRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes)); - Mockito.verify(this.fileApi, Mockito.times(1)).get(pathToFile, expireInMinutes); + Mockito.when(this.fileApi.get(PATH_TO_FILE, expireInMinutes)).thenThrow(new RestClientException(SOMETHING_HAPPENED)); + assertThrows(DocumentStorageException.class, + () -> this.presignedUrlRestRepository.getPresignedUrlGetFile(PATH_TO_FILE, expireInMinutes)); + Mockito.verify(this.fileApi, Mockito.times(1)).get(PATH_TO_FILE, expireInMinutes); } @Test - void getPresignedUrlSaveFile() + void testGetPresignedUrlSaveFile() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String pathToFile = "folder/file.txt"; final int expireInMinutes = 10; final FileDataDto fileDataDto = new FileDataDto(); - fileDataDto.setPathToFile(pathToFile); + fileDataDto.setPathToFile(PATH_TO_FILE); fileDataDto.setExpiresInMinutes(expireInMinutes); final PresignedUrlDto expected = new PresignedUrlDto(); - expected.setUrl("the_presignedUrl"); + expected.setUrl(PRESIGNED_URL); Mockito.reset(this.fileApi); Mockito.when(this.fileApi.save(fileDataDto)).thenReturn(Mono.just(expected)); - final String result = this.presignedUrlRestRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes); + final String result = this.presignedUrlRestRepository.getPresignedUrlSaveFile(PATH_TO_FILE, expireInMinutes); Mockito.verify(this.fileApi, Mockito.times(1)).save(fileDataDto); assertThat(result, is(expected.getUrl())); } @Test - void getPresignedUrlSaveFileException() { - final String pathToFile = "folder/file.txt"; + void testGetPresignedUrlSaveFileException() { final int expireInMinutes = 10; final FileDataDto fileDataDto = new FileDataDto(); - fileDataDto.setPathToFile(pathToFile); + fileDataDto.setPathToFile(PATH_TO_FILE); fileDataDto.setExpiresInMinutes(expireInMinutes); Mockito.reset(this.fileApi); Mockito.when(this.fileApi.save(fileDataDto)).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); - Assertions.assertThrows(DocumentStorageClientErrorException.class, - () -> this.presignedUrlRestRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes)); + assertThrows(DocumentStorageClientErrorException.class, + () -> this.presignedUrlRestRepository.getPresignedUrlSaveFile(PATH_TO_FILE, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).save(fileDataDto); Mockito.reset(this.fileApi); Mockito.when(this.fileApi.save(fileDataDto)).thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); - Assertions.assertThrows(DocumentStorageServerErrorException.class, - () -> this.presignedUrlRestRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes)); + assertThrows(DocumentStorageServerErrorException.class, + () -> this.presignedUrlRestRepository.getPresignedUrlSaveFile(PATH_TO_FILE, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).save(fileDataDto); Mockito.reset(this.fileApi); - Mockito.when(this.fileApi.save(fileDataDto)).thenThrow(new RestClientException("Something happened")); - Assertions.assertThrows(DocumentStorageException.class, - () -> this.presignedUrlRestRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes)); + Mockito.when(this.fileApi.save(fileDataDto)).thenThrow(new RestClientException(SOMETHING_HAPPENED)); + assertThrows(DocumentStorageException.class, + () -> this.presignedUrlRestRepository.getPresignedUrlSaveFile(PATH_TO_FILE, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).save(fileDataDto); } @Test - void getPresignedUrlUpdateFile() + void testGetPresignedUrlUpdateFile() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String pathToFile = "folder/file.txt"; final int expireInMinutes = 10; final FileDataDto fileDataDto = new FileDataDto(); - fileDataDto.setPathToFile(pathToFile); + fileDataDto.setPathToFile(PATH_TO_FILE); fileDataDto.setExpiresInMinutes(expireInMinutes); final PresignedUrlDto expected = new PresignedUrlDto(); - expected.setUrl("the_presignedUrl"); + expected.setUrl(PRESIGNED_URL); Mockito.reset(this.fileApi); Mockito.when(this.fileApi.update(fileDataDto)).thenReturn(Mono.just(expected)); - final String result = this.presignedUrlRestRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes); + final String result = this.presignedUrlRestRepository.getPresignedUrlUpdateFile(PATH_TO_FILE, expireInMinutes); Mockito.verify(this.fileApi, Mockito.times(1)).update(fileDataDto); assertThat(result, is(expected.getUrl())); } @Test - void getPresignedUrlUpdateFileException() { - final String pathToFile = "folder/file.txt"; + void testGetPresignedUrlUpdateFileException() { final int expireInMinutes = 10; final FileDataDto fileDataDto = new FileDataDto(); - fileDataDto.setPathToFile(pathToFile); + fileDataDto.setPathToFile(PATH_TO_FILE); fileDataDto.setExpiresInMinutes(expireInMinutes); Mockito.reset(this.fileApi); Mockito.when(this.fileApi.update(fileDataDto)).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); - Assertions.assertThrows(DocumentStorageClientErrorException.class, - () -> this.presignedUrlRestRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes)); + assertThrows(DocumentStorageClientErrorException.class, + () -> this.presignedUrlRestRepository.getPresignedUrlUpdateFile(PATH_TO_FILE, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).update(fileDataDto); Mockito.reset(this.fileApi); Mockito.when(this.fileApi.update(fileDataDto)).thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); - Assertions.assertThrows(DocumentStorageServerErrorException.class, - () -> this.presignedUrlRestRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes)); + assertThrows(DocumentStorageServerErrorException.class, + () -> this.presignedUrlRestRepository.getPresignedUrlUpdateFile(PATH_TO_FILE, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).update(fileDataDto); Mockito.reset(this.fileApi); - Mockito.when(this.fileApi.update(fileDataDto)).thenThrow(new RestClientException("Something happened")); - Assertions.assertThrows(DocumentStorageException.class, - () -> this.presignedUrlRestRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes)); + Mockito.when(this.fileApi.update(fileDataDto)).thenThrow(new RestClientException(SOMETHING_HAPPENED)); + assertThrows(DocumentStorageException.class, + () -> this.presignedUrlRestRepository.getPresignedUrlUpdateFile(PATH_TO_FILE, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).update(fileDataDto); } @Test - void getPresignedUrlDeleteFile() + void testGetPresignedUrlDeleteFile() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String pathToFile = "folder/file.txt"; final int expireInMinutes = 10; final PresignedUrlDto expected = new PresignedUrlDto(); - expected.setUrl("the_presignedUrl"); + expected.setUrl(PRESIGNED_URL); Mockito.reset(this.fileApi); - Mockito.when(this.fileApi.delete1(pathToFile, expireInMinutes)).thenReturn(Mono.just(expected)); + Mockito.when(this.fileApi.delete1(PATH_TO_FILE, expireInMinutes)).thenReturn(Mono.just(expected)); - final String result = this.presignedUrlRestRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes); - Mockito.verify(this.fileApi, Mockito.times(1)).delete1(pathToFile, expireInMinutes); + final String result = this.presignedUrlRestRepository.getPresignedUrlDeleteFile(PATH_TO_FILE, expireInMinutes); + Mockito.verify(this.fileApi, Mockito.times(1)).delete1(PATH_TO_FILE, expireInMinutes); assertThat(result, is(expected.getUrl())); } @Test - void getPresignedUrlDeleteFileException() { - final String pathToFile = "folder/file.txt"; + void testGetPresignedUrlDeleteFileException() { final int expireInMinutes = 10; Mockito.reset(this.fileApi); - Mockito.when(this.fileApi.delete1(pathToFile, expireInMinutes)).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); - Assertions.assertThrows(DocumentStorageClientErrorException.class, - () -> this.presignedUrlRestRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes)); - Mockito.verify(this.fileApi, Mockito.times(1)).delete1(pathToFile, expireInMinutes); + Mockito.when(this.fileApi.delete1(PATH_TO_FILE, expireInMinutes)).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); + assertThrows(DocumentStorageClientErrorException.class, + () -> this.presignedUrlRestRepository.getPresignedUrlDeleteFile(PATH_TO_FILE, expireInMinutes)); + Mockito.verify(this.fileApi, Mockito.times(1)).delete1(PATH_TO_FILE, expireInMinutes); Mockito.reset(this.fileApi); - Mockito.when(this.fileApi.delete1(pathToFile, expireInMinutes)).thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); - Assertions.assertThrows(DocumentStorageServerErrorException.class, - () -> this.presignedUrlRestRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes)); - Mockito.verify(this.fileApi, Mockito.times(1)).delete1(pathToFile, expireInMinutes); + Mockito.when(this.fileApi.delete1(PATH_TO_FILE, expireInMinutes)).thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); + assertThrows(DocumentStorageServerErrorException.class, + () -> this.presignedUrlRestRepository.getPresignedUrlDeleteFile(PATH_TO_FILE, expireInMinutes)); + Mockito.verify(this.fileApi, Mockito.times(1)).delete1(PATH_TO_FILE, expireInMinutes); Mockito.reset(this.fileApi); - Mockito.when(this.fileApi.delete1(pathToFile, expireInMinutes)).thenThrow(new RestClientException("Something happened")); - Assertions.assertThrows(DocumentStorageException.class, - () -> this.presignedUrlRestRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes)); - Mockito.verify(this.fileApi, Mockito.times(1)).delete1(pathToFile, expireInMinutes); + Mockito.when(this.fileApi.delete1(PATH_TO_FILE, expireInMinutes)).thenThrow(new RestClientException(SOMETHING_HAPPENED)); + assertThrows(DocumentStorageException.class, + () -> this.presignedUrlRestRepository.getPresignedUrlDeleteFile(PATH_TO_FILE, expireInMinutes)); + Mockito.verify(this.fileApi, Mockito.times(1)).delete1(PATH_TO_FILE, expireInMinutes); } } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/FileController.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/FileController.java index 559c6c7b..447811f3 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/FileController.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/FileController.java @@ -60,11 +60,11 @@ public ResponseEntity get(@RequestParam @NotEmpty @Size(max = F final PresignedUrlDto presignedUrlDto = this.presignedUrlMapper.model2Dto(fileResponse); return ResponseEntity.ok(presignedUrlDto); } catch (final FileSystemAccessException exception) { - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage(), exception); } catch (final FileExistenceException exception) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, exception.getMessage(), exception); } catch (final Exception exception) { - throw new ResponseStatusException(HttpStatus.BAD_REQUEST, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, exception.getMessage(), exception); } } @@ -78,11 +78,11 @@ public ResponseEntity getFileSize( final FileSizeDto fileSizeDto = this.fileSizeMapper.model2dto(fileSize); return ResponseEntity.ok(fileSizeDto); } catch (final FileSystemAccessException exception) { - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage(), exception); } catch (final FileExistenceException exception) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, exception.getMessage(), exception); } catch (final Exception exception) { - throw new ResponseStatusException(HttpStatus.BAD_REQUEST, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, exception.getMessage(), exception); } } @@ -95,9 +95,9 @@ public ResponseEntity save(@RequestBody @NotNull @Valid final F final PresignedUrlDto presignedUrlDto = this.presignedUrlMapper.model2Dto(presignedUrl); return ResponseEntity.ok(presignedUrlDto); } catch (final FileExistenceException exception) { - throw new ResponseStatusException(HttpStatus.CONFLICT, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.CONFLICT, exception.getMessage(), exception); } catch (final Exception exception) { - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage(), exception); } } @@ -110,7 +110,7 @@ public ResponseEntity update(@RequestBody @NotNull @Valid final final PresignedUrlDto presignedUrlDto = this.presignedUrlMapper.model2Dto(presignedUrl); return ResponseEntity.ok(presignedUrlDto); } catch (final Exception exception) { - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage(), exception); } } @@ -124,11 +124,11 @@ public ResponseEntity delete(@RequestParam @NotEmpty @Size(max final PresignedUrlDto presignedUrlDto = this.presignedUrlMapper.model2Dto(presignedUrl); return ResponseEntity.ok(presignedUrlDto); } catch (final FileSystemAccessException exception) { - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage(), exception); } catch (final FileExistenceException exception) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, exception.getMessage(), exception); } catch (final Exception exception) { - throw new ResponseStatusException(HttpStatus.BAD_REQUEST, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, exception.getMessage(), exception); } } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/FolderController.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/FolderController.java index b04082f6..508446ef 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/FolderController.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/FolderController.java @@ -40,7 +40,7 @@ public ResponseEntity delete(@RequestParam @NotEmpty final String pathToFo folderOperations.deleteFolder(pathToFolder); return ResponseEntity.noContent().build(); } catch (final Exception exception) { - throw new ResponseStatusException(HttpStatus.BAD_REQUEST, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, exception.getMessage(), exception); } } @@ -53,7 +53,7 @@ public ResponseEntity getAllFilesInFolderRecursively(@RequestP final FilesInFolderDto filesInFolderDto = this.filesInFolderMapper.model2Dto(filesInFolder); return ResponseEntity.ok(filesInFolderDto); } catch (final Exception exception) { - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage(), exception); } } @@ -66,7 +66,7 @@ public ResponseEntity getAllFileSizesInFolderRecursively(@ final FileSizesInFolderDto filesizesInFolderDto = this.fileSizesInFolderMapper.model2Dto(fileSizesInFolder); return ResponseEntity.ok(filesizesInFolderDto); } catch (final Exception exception) { - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage()); + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage(), exception); } } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/RestExceptionMapping.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/RestExceptionMapping.java index adcedb60..2d177bd3 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/RestExceptionMapping.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/RestExceptionMapping.java @@ -9,7 +9,7 @@ public class RestExceptionMapping { @ExceptionHandler - public ResponseEntity handleFileExistenceException(FileExistenceException exception) { + public ResponseEntity handleFileExistenceException(final FileExistenceException exception) { return ResponseEntity.badRequest().body(exception.getMessage()); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/mapper/FileDataMapper.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/mapper/FileDataMapper.java index 20d0001c..bfa9e7d3 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/mapper/FileDataMapper.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/mapper/FileDataMapper.java @@ -8,6 +8,6 @@ @Mapper(config = MapstructConfiguration.class) public interface FileDataMapper { - FileData dto2Model(final FileDataDto fileDataDto); + FileData dto2Model(FileDataDto fileDataDto); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/mapper/FilesInFolderMapper.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/mapper/FilesInFolderMapper.java index bcf534b7..37763f9e 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/mapper/FilesInFolderMapper.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/mapper/FilesInFolderMapper.java @@ -8,6 +8,6 @@ @Mapper(config = MapstructConfiguration.class) public interface FilesInFolderMapper { - FilesInFolderDto model2Dto(final FilesInFolder filesInFolder); + FilesInFolderDto model2Dto(FilesInFolder filesInFolder); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/mapper/PresignedUrlMapper.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/mapper/PresignedUrlMapper.java index d228482d..20a6934c 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/mapper/PresignedUrlMapper.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-core/src/main/java/de/muenchen/refarch/integration/s3/adapter/in/rest/mapper/PresignedUrlMapper.java @@ -9,8 +9,8 @@ @Mapper(config = MapstructConfiguration.class) public interface PresignedUrlMapper { - PresignedUrlDto model2Dto(final PresignedUrl fileResponse); + PresignedUrlDto model2Dto(PresignedUrl fileResponse); - List models2Dtos(final List presignedUrls); + List models2Dtos(List presignedUrls); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/S3IntegrationApplication.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/S3IntegrationApplication.java index e9a74395..b4a8b8f0 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/S3IntegrationApplication.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/S3IntegrationApplication.java @@ -9,9 +9,9 @@ */ @SpringBootApplication @EnableScheduling +@SuppressWarnings("PMD.UseUtilityClass") public class S3IntegrationApplication { - - public static void main(String[] args) { + public static void main(final String[] args) { SpringApplication.run(S3IntegrationApplication.class, args); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/CacheControlConfiguration.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/CacheControlConfiguration.java index 665e831b..3433aace 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/CacheControlConfiguration.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/CacheControlConfiguration.java @@ -24,7 +24,7 @@ public class CacheControlConfiguration { @Bean public FilterRegistrationBean cacheControlFilter() { - FilterRegistrationBean registration = new FilterRegistrationBean<>(); + final FilterRegistrationBean registration = new FilterRegistrationBean<>(); registration.setFilter(new CacheControlFilter()); registration.addUrlPatterns("/*"); return registration; @@ -50,9 +50,9 @@ public static class CacheControlFilter extends OncePerRequestFilter { * ServletRequest and ServletResponse ones. */ @Override - protected void doFilterInternal(@NotNull HttpServletRequest request, - HttpServletResponse response, - @NotNull FilterChain filterChain) throws ServletException, IOException { + protected void doFilterInternal(@NotNull final HttpServletRequest request, + final HttpServletResponse response, + @NotNull final FilterChain filterChain) throws ServletException, IOException { final String cacheControlHeaderValue = response.getHeader(HttpHeaders.CACHE_CONTROL); if (StringUtils.isBlank(cacheControlHeaderValue)) { diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/JwtUserInfoAuthenticationConverter.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/JwtUserInfoAuthenticationConverter.java index 9fa7162d..e843618a 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/JwtUserInfoAuthenticationConverter.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/JwtUserInfoAuthenticationConverter.java @@ -16,12 +16,12 @@ public class JwtUserInfoAuthenticationConverter implements Converter customizer.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)) .authorizeHttpRequests(requests -> requests.requestMatchers(AntPathRequestMatcher.antMatcher("/**")) diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/SecurityConfiguration.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/SecurityConfiguration.java index 1b0165ae..8643de60 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/SecurityConfiguration.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/SecurityConfiguration.java @@ -31,7 +31,7 @@ public class SecurityConfiguration { private String userInfoUri; @Bean - public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + public SecurityFilterChain filterChain(final HttpSecurity http) throws Exception { http .authorizeHttpRequests((requests) -> requests.requestMatchers( // allow access to /actuator/info diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/UserInfoAuthoritiesService.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/UserInfoAuthoritiesService.java index e52e6269..87ba1a3e 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/UserInfoAuthoritiesService.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/UserInfoAuthoritiesService.java @@ -19,6 +19,7 @@ import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.oauth2.jwt.Jwt; +import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; import org.springframework.web.client.RestTemplate; @@ -38,7 +39,7 @@ public class UserInfoAuthoritiesService { private final RestTemplate restTemplate; private final Cache cache; - public UserInfoAuthoritiesService(String userInfoUri, RestTemplateBuilder restTemplateBuilder) { + public UserInfoAuthoritiesService(final String userInfoUri, final RestTemplateBuilder restTemplateBuilder) { this.userInfoUri = userInfoUri; this.restTemplate = restTemplateBuilder.build(); this.cache = new CaffeineCache(NAME_AUTHENTICATION_CACHE, @@ -48,14 +49,15 @@ public UserInfoAuthoritiesService(String userInfoUri, RestTemplateBuilder restTe .build()); } - private static List asAuthorities(Object object) { - List authorities = new ArrayList<>(); + private static List asAuthorities(final Object object) { + final List authorities = new ArrayList<>(); + Object internalObject = object; if (object instanceof Collection collection) { - object = collection.toArray(new Object[0]); + internalObject = collection.toArray(new Object[0]); } - if (ObjectUtils.isArray(object)) { + if (ObjectUtils.isArray(internalObject)) { authorities.addAll( - Stream.of(((Object[]) object)) + Stream.of((Object[]) internalObject) .map(Object::toString) .map(SimpleGrantedAuthority::new) .toList()); @@ -70,25 +72,25 @@ private static List asAuthorities(Object object) { * @return the {@link GrantedAuthority}s according to the "authorities" claim of the /userinfo * endpoint */ - public Collection loadAuthorities(Jwt jwt) { - ValueWrapper valueWrapper = this.cache.get(jwt.getSubject()); + public Collection loadAuthorities(final Jwt jwt) { + final ValueWrapper valueWrapper = this.cache.get(jwt.getSubject()); if (valueWrapper != null) { // value present in cache @SuppressWarnings("unchecked") - Collection authorities = (Collection) valueWrapper.get(); + final Collection authorities = (Collection) valueWrapper.get(); log.debug("Resolved authorities (from cache): {}", authorities); return authorities; } log.debug("Fetching user-info for token subject: {}", jwt.getSubject()); - final HttpHeaders headers = new HttpHeaders(); + final MultiValueMap headers = new HttpHeaders(); headers.set(HttpHeaders.AUTHORIZATION, "Bearer " + jwt.getTokenValue()); final HttpEntity entity = new HttpEntity<>(headers); Collection authorities = new ArrayList<>(); try { @SuppressWarnings("unchecked") - Map map = restTemplate.exchange(this.userInfoUri, HttpMethod.GET, entity, + final Map map = restTemplate.exchange(this.userInfoUri, HttpMethod.GET, entity, Map.class).getBody(); log.debug("Response from user-info Endpoint: {}", map); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcHelper.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcHelper.java index f9be5d67..9baec35a 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcHelper.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcHelper.java @@ -64,7 +64,7 @@ public static StringBuffer nfcConverter(final StringBuffer in) { * @see #nfcConverter(String) * @see Normalizer#normalize(CharSequence, Normalizer.Form) */ - public static String[] nfcConverter(final String[] original) { + public static String[] nfcConverter(final String... original) { return Arrays.stream(original) .map(NfcHelper::nfcConverter) .toArray(String[]::new); @@ -79,7 +79,7 @@ public static String[] nfcConverter(final String[] original) { * @see Normalizer#normalize(CharSequence, Normalizer.Form) */ public static Map nfcConverter(final Map original) { - final HashMap nfcConverted = new HashMap<>(original.size()); + final Map nfcConverted = new HashMap<>(original.size()); original.forEach((nfdKey, nfdValueArray) -> nfcConverted.put( nfcConverter(nfdKey), nfcConverter(nfdValueArray))); @@ -94,12 +94,12 @@ public static Map nfcConverter(final Map ori * @see #nfcConverter(String) * @see Normalizer#normalize(CharSequence, Normalizer.Form) */ - public static Cookie nfcConverter(Cookie original) { - final Cookie nfcCookie = new Cookie(NfcHelper.nfcConverter(original.getName()), NfcHelper.nfcConverter(original.getValue())); + public static Cookie nfcConverter(final Cookie original) { + final Cookie nfcCookie = new Cookie(nfcConverter(original.getName()), nfcConverter(original.getValue())); if (original.getDomain() != null) { - nfcCookie.setDomain(NfcHelper.nfcConverter(original.getDomain())); + nfcCookie.setDomain(nfcConverter(original.getDomain())); } - nfcCookie.setPath(NfcHelper.nfcConverter(original.getPath())); + nfcCookie.setPath(nfcConverter(original.getPath())); return nfcCookie; } @@ -111,9 +111,9 @@ public static Cookie nfcConverter(Cookie original) { * @see #nfcConverter(String) * @see Normalizer#normalize(CharSequence, Normalizer.Form) */ - public static Cookie[] nfcConverter(final Cookie[] original) { + public static Cookie[] nfcConverter(final Cookie... original) { if (original == null) { - return null; + return new Cookie[] {}; } return Arrays.stream(original) .map(NfcHelper::nfcConverter) @@ -132,7 +132,7 @@ public static Cookie[] nfcConverter(final Cookie[] original) { public static Map> nfcConverterForHeadersFromOriginalRequest(final HttpServletRequest originalRequest) { final Map> converted = new CaseInsensitiveMap<>(); Collections.list(originalRequest.getHeaderNames()).forEach(nfdHeaderName -> { - final String nfcHeaderName = NfcHelper.nfcConverter(nfdHeaderName); + final String nfcHeaderName = nfcConverter(nfdHeaderName); final List nfcHeaderEntries = Collections.list(originalRequest.getHeaders(nfdHeaderName)).stream() .map(NfcHelper::nfcConverter) .collect(Collectors.toList()); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcReader.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcReader.java index af740530..4dec746e 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcReader.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcReader.java @@ -29,8 +29,8 @@ public class NfcReader extends Reader { private CharArrayReader converted; public NfcReader(final Reader original) { + super(); this.original = original; - this.converted = null; } private void convert() { @@ -58,7 +58,7 @@ public int read() throws IOException { } @Override - public int read(@NotNull char[] cbuf, int off, int len) throws IOException { + public int read(@NotNull final char[] cbuf, final int off, final int len) throws IOException { convert(); return converted.read(cbuf, off, len); } @@ -69,7 +69,7 @@ public void close() { } @Override - public long skip(long n) throws IOException { + public long skip(final long n) throws IOException { convert(); return converted.skip(n); } @@ -87,7 +87,7 @@ public boolean markSupported() { } @Override - public void mark(int readAheadLimit) throws IOException { + public void mark(final int readAheadLimit) throws IOException { convert(); converted.mark(readAheadLimit); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcRequest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcRequest.java index 92e5bcab..9d78efd4 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcRequest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcRequest.java @@ -10,6 +10,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; @@ -36,9 +37,6 @@ public class NfcRequest extends HttpServletRequestWrapper implements HttpServlet public NfcRequest(final HttpServletRequest request, final Set contentTypes) { super(request); - this.params = null; - this.cookies = null; - this.headers = null; this.contentTypes = contentTypes; } @@ -54,7 +52,7 @@ private void convert() { @Override public Cookie[] getCookies() { convert(); - return this.cookies; + return Arrays.copyOf(cookies, cookies.length); } @Override @@ -131,7 +129,7 @@ public StringBuffer getRequestURL() { * Only the username is converted to nfc. Password won't be touched! */ @Override - public void login(String username, String password) throws ServletException { + public void login(final String username, final String password) throws ServletException { getOriginalRequest().login(NfcHelper.nfcConverter(username), password); } @@ -188,8 +186,8 @@ public ServletInputStream getInputStream() throws IOException { final String encoding = getOriginalRequest().getCharacterEncoding(); - String content; - try (final InputStream is = getOriginalRequest().getInputStream()) { + final String content; + try (InputStream is = getOriginalRequest().getInputStream()) { content = new String(IOUtils.toByteArray(is), encoding); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcRequestFilter.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcRequestFilter.java index 95ebdc21..d5644a88 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcRequestFilter.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcRequestFilter.java @@ -78,7 +78,7 @@ public void setContentTypes(final String contentTypes) { } @Override - protected void doFilterInternal(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull FilterChain filterChain) + protected void doFilterInternal(final HttpServletRequest request, @NotNull final HttpServletResponse response, @NotNull final FilterChain filterChain) throws ServletException, IOException { log.debug("Request-Type={}", request.getClass().getName()); diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcServletInputStream.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcServletInputStream.java index 6df80692..51c27269 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcServletInputStream.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcServletInputStream.java @@ -13,6 +13,7 @@ public class NfcServletInputStream extends ServletInputStream { private final ByteArrayInputStream buffer; public NfcServletInputStream(final ByteArrayInputStream buffer) { + super(); this.buffer = buffer; } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/security/AuthUtils.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/security/AuthUtils.java index 5fdff270..f86fac3c 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/security/AuthUtils.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/security/AuthUtils.java @@ -8,7 +8,7 @@ /** * Utilities for authentication data. */ -public class AuthUtils { +public final class AuthUtils { public static final String NAME_UNAUTHENTICATED_USER = "unauthenticated"; @@ -24,7 +24,7 @@ private AuthUtils() { * @return the username or "unauthenticated", if no {@link Authentication} exists */ public static String getUsername() { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication instanceof JwtAuthenticationToken jwtAuth) { return (String) jwtAuth.getTokenAttributes().getOrDefault(TOKEN_USER_NAME, null); } else if (authentication instanceof UsernamePasswordAuthenticationToken usernameAuth) { diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/security/RequestResponseLoggingFilter.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/security/RequestResponseLoggingFilter.java index 75bea288..5582bc3f 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/security/RequestResponseLoggingFilter.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/main/java/de/muenchen/refarch/integration/s3/security/RequestResponseLoggingFilter.java @@ -80,9 +80,9 @@ public void destroy() { * @param httpServletRequest The request to check for logging. * @return True if logging should be done otherwise false. */ - private boolean checkForLogging(HttpServletRequest httpServletRequest) { - return requestLoggingMode.equals(REQUEST_LOGGING_MODE_ALL) - || (requestLoggingMode.equals(REQUEST_LOGGING_MODE_CHANGING) + private boolean checkForLogging(final HttpServletRequest httpServletRequest) { + return REQUEST_LOGGING_MODE_ALL.equals(requestLoggingMode) + || (REQUEST_LOGGING_MODE_CHANGING.equals(requestLoggingMode) && CHANGING_METHODS.contains(httpServletRequest.getMethod())); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/test/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcConverterTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/test/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcConverterTest.java index 1e69340b..3cf42b57 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/test/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcConverterTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/test/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcConverterTest.java @@ -37,7 +37,7 @@ @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) -public class NfcConverterTest { +class NfcConverterTest { // Für Stellen der API an denen Strings bestimmten Regeln genügen müssen. public static final String TOKEN = "token"; @@ -61,7 +61,7 @@ public class NfcConverterTest { // Test, das Request mit konfigriertem ContentType auf NFC normalisiert wird. // @Test - public void testFilterIfContenttypeInWhitelist() throws ServletException, IOException { + void testFilterIfContenttypeInWhitelist() throws ServletException, IOException { mockRequest("text/plain"); filter.setContentTypes("text/plain;text/html;application/json"); @@ -71,7 +71,7 @@ public void testFilterIfContenttypeInWhitelist() throws ServletException, IOExce // // Check // - ArgumentCaptor reqCaptor = ArgumentCaptor.forClass(HttpServletRequest.class); + final ArgumentCaptor reqCaptor = ArgumentCaptor.forClass(HttpServletRequest.class); Mockito.verify(chain, Mockito.times(1)).doFilter(reqCaptor.capture(), Mockito.any(ServletResponse.class)); assertEquals(VALUE_NFC, reqCaptor.getValue().getParameter(NAME_NFC)); @@ -90,7 +90,7 @@ public void testFilterIfContenttypeInWhitelist() throws ServletException, IOExce // auf NFC normalisiert wird. // @Test - public void testSkipFilterIfContenttypeNotInWhitelist() throws ServletException, IOException { + void testSkipFilterIfContenttypeNotInWhitelist() throws ServletException, IOException { mockRequest("application/postscript"); filter.setContentTypes("text/plain;text/html"); @@ -100,7 +100,7 @@ public void testSkipFilterIfContenttypeNotInWhitelist() throws ServletException, // // Check // - ArgumentCaptor reqCaptor = ArgumentCaptor.forClass(HttpServletRequest.class); + final ArgumentCaptor reqCaptor = ArgumentCaptor.forClass(HttpServletRequest.class); Mockito.verify(chain, Mockito.times(1)).doFilter(reqCaptor.capture(), Mockito.any(ServletResponse.class)); assertEquals(VALUE_NFD, reqCaptor.getValue().getParameter(NAME_NFD)); @@ -118,19 +118,19 @@ private void mockRequest(final String contentType) throws IOException, ServletEx Mockito.when(req.getContentType()).thenReturn(contentType); Mockito.when(req.getRequestURI()).thenReturn("/index.html?type=" + contentType); - Map baseMapParams = new HashMap<>(); + final Map baseMapParams = new HashMap<>(); baseMapParams.put(NAME_NFD, new String[] { VALUE_NFD, VALUE2_NFD }); final Map params = UnmodifiableMap.unmodifiableMap(baseMapParams); Mockito.when(req.getParameter(NAME_NFD)).thenReturn(params.get(NAME_NFD)[0]); Mockito.when(req.getParameterMap()).thenReturn(params); - Map baseMapHeaders = new HashMap<>(); + final Map baseMapHeaders = new HashMap<>(); baseMapHeaders.put(NAME_NFD, VALUE_NFD); final Map headers = UnmodifiableMap.unmodifiableMap(baseMapHeaders); Mockito.when(req.getHeaderNames()).thenReturn(Collections.enumeration(headers.keySet())); Mockito.when(req.getHeader(NAME_NFD)).thenReturn(headers.get(NAME_NFD)); - List baseListvalues = new ArrayList<>(); + final List baseListvalues = new ArrayList<>(); baseListvalues.add(VALUE_NFD); - final UnmodifiableList values = new UnmodifiableList<>(baseListvalues); + final List values = new UnmodifiableList<>(baseListvalues); Mockito.when(req.getHeaders(NAME_NFD)).thenReturn(Collections.enumeration(values)); Mockito.when(req.getCookies()).thenReturn(mockCookies()); @@ -149,9 +149,9 @@ private Cookie[] mockCookies() { } private List mockParts() throws IOException { - Part part = Mockito.mock(Part.class); + final Part part = Mockito.mock(Part.class); Mockito.when(part.getInputStream()).thenReturn(new ByteArrayInputStream(VALUE_NFD.getBytes(UTF8))); - List baseListParts = new ArrayList<>(); + final List baseListParts = new ArrayList<>(); baseListParts.add(part); return new UnmodifiableList<>(baseListParts); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/test/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcHelperTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/test/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcHelperTest.java index bd2be80a..0b2572ac 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/test/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcHelperTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service/src/test/java/de/muenchen/refarch/integration/s3/configuration/nfcconverter/NfcHelperTest.java @@ -8,10 +8,9 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class NfcHelperTest { +class NfcHelperTest { public static final String FIRST_NFD = "\u017f\u0307"; @@ -25,9 +24,9 @@ public class NfcHelperTest { public static final String THIRD_NFC = "\u1e69"; - public static final String[] NFD_INPUT = new String[] { FIRST_NFD, SECOND_NFD, THIRD_NFD }; + public static final String[] NFD_INPUT = { FIRST_NFD, SECOND_NFD, THIRD_NFD }; - public static final String[] NFC_OUTPUT_EXPECTED = new String[] { FIRST_NFC, SECOND_NFC, THIRD_NFC }; + public static final String[] NFC_OUTPUT_EXPECTED = { FIRST_NFC, SECOND_NFC, THIRD_NFC }; private static Cookie createNfdCookie() { final Cookie nfdCookie = new Cookie(NfcConverterTest.TOKEN, Arrays.toString(NFD_INPUT)); @@ -37,8 +36,8 @@ private static Cookie createNfdCookie() { } @Test - public void nfcConverterString() { - Assertions.assertEquals(FIRST_NFC, NfcHelper.nfcConverter(FIRST_NFD)); + void nfcConverterString() { + assertEquals(FIRST_NFC, NfcHelper.nfcConverter(FIRST_NFD)); assertEquals(FIRST_NFC.length(), NfcHelper.nfcConverter(FIRST_NFD).length()); assertEquals(SECOND_NFC, NfcHelper.nfcConverter(SECOND_NFD)); @@ -49,7 +48,7 @@ public void nfcConverterString() { } @Test - public void nfcConverterStringBuffer() { + void nfcConverterStringBuffer() { assertEquals(FIRST_NFC, NfcHelper.nfcConverter(new StringBuffer(FIRST_NFD)).toString()); assertEquals(FIRST_NFC.length(), NfcHelper.nfcConverter(new StringBuffer(FIRST_NFD)).length()); @@ -61,13 +60,13 @@ public void nfcConverterStringBuffer() { } @Test - public void nfcConverterStringArray() { + void nfcConverterStringArray() { assertArrayEquals(NFC_OUTPUT_EXPECTED, NfcHelper.nfcConverter(NFD_INPUT)); assertEquals(NFC_OUTPUT_EXPECTED.length, NfcHelper.nfcConverter(NFD_INPUT).length); } @Test - public void nfcConverterMapOfStrings() { + void nfcConverterMapOfStrings() { final Map nfdInput = new HashMap<>(); nfdInput.put(FIRST_NFD, NFD_INPUT); nfdInput.put(SECOND_NFD, NFD_INPUT); @@ -81,7 +80,7 @@ public void nfcConverterMapOfStrings() { } @Test - public void nfcConverterCookie() { + void nfcConverterCookie() { final Cookie nfcCookie = NfcHelper.nfcConverter(createNfdCookie()); assertEquals(NfcConverterTest.TOKEN, nfcCookie.getName()); @@ -91,7 +90,8 @@ public void nfcConverterCookie() { } @Test - public void nfcConverterCookieArray() { + @SuppressWarnings("PMD.UnitTestShouldIncludeAssert") + void nfcConverterCookieArray() { final Cookie[] nfdCookies = Collections.nCopies(3, createNfdCookie()).toArray(new Cookie[3]); final Cookie[] nfcCookies = NfcHelper.nfcConverter(nfdCookies); Arrays.asList(nfcCookies).forEach(nfcCookie -> { diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-starter/src/main/java/de/muenchen/refarch/integration/s3/configuration/S3IntegrationAutoConfiguration.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-starter/src/main/java/de/muenchen/refarch/integration/s3/configuration/S3IntegrationAutoConfiguration.java index daa6f80a..a87d6935 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-starter/src/main/java/de/muenchen/refarch/integration/s3/configuration/S3IntegrationAutoConfiguration.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-starter/src/main/java/de/muenchen/refarch/integration/s3/configuration/S3IntegrationAutoConfiguration.java @@ -13,7 +13,6 @@ import de.muenchen.refarch.integration.s3.properties.S3IntegrationProperties; import io.minio.MinioClient; import lombok.RequiredArgsConstructor; -import org.apache.commons.lang3.BooleanUtils; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -30,20 +29,24 @@ public class S3IntegrationAutoConfiguration { @ConditionalOnMissingBean @Bean + @SuppressWarnings("PMD.CloseResource") public S3Adapter s3Adapter() throws FileSystemAccessException { final MinioClient minioClient = MinioClient.builder() .endpoint(this.s3IntegrationProperties.getUrl()) .credentials(this.s3IntegrationProperties.getAccessKey(), this.s3IntegrationProperties.getSecretKey()) .build(); - return new S3Adapter( + final S3Adapter adapter = new S3Adapter( this.s3IntegrationProperties.getBucketName(), - minioClient, - BooleanUtils.isNotFalse(this.s3IntegrationProperties.getInitialConnectionTest())); + minioClient); + if (this.s3IntegrationProperties.getInitialConnectionTest()) { + adapter.testConnection(); + } + return adapter; } @ConditionalOnMissingBean @Bean - public CreatePresignedUrlsInPort createPresignedUrlsInPort(FileOperationsPresignedUrlUseCase fileHandlingService) { + public CreatePresignedUrlsInPort createPresignedUrlsInPort(final FileOperationsPresignedUrlUseCase fileHandlingService) { return new CreatePresignedUrlsUseCase( fileHandlingService, this.s3IntegrationProperties.getPresignedUrlExpiresInMinutes()); @@ -51,13 +54,13 @@ public CreatePresignedUrlsInPort createPresignedUrlsInPort(FileOperationsPresign @ConditionalOnMissingBean @Bean - public FileOperationsInPort fileOperationsInPort(S3Adapter s3Adapter) { + public FileOperationsInPort fileOperationsInPort(final S3Adapter s3Adapter) { return new FileOperationsUseCase(s3Adapter); } @ConditionalOnMissingBean @Bean - public FileOperationsPresignedUrlUseCase fileOperationsPresignedUrlUseCase(S3Adapter s3Adapter) { + public FileOperationsPresignedUrlUseCase fileOperationsPresignedUrlUseCase(final S3Adapter s3Adapter) { return new FileOperationsPresignedUrlUseCase(s3Adapter); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-starter/src/main/java/de/muenchen/refarch/integration/s3/properties/S3IntegrationProperties.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-starter/src/main/java/de/muenchen/refarch/integration/s3/properties/S3IntegrationProperties.java index cab690e5..fa4fcfff 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-starter/src/main/java/de/muenchen/refarch/integration/s3/properties/S3IntegrationProperties.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-starter/src/main/java/de/muenchen/refarch/integration/s3/properties/S3IntegrationProperties.java @@ -26,5 +26,5 @@ public class S3IntegrationProperties { private Boolean initialConnectionTest; - private int presignedUrlExpiresInMinutes = 10080; // 7 days + private int presignedUrlExpiresInMinutes = 7 * 24 * 60; // 7 days }