From ba73128494c88f1967ada7a516c64a4415d8e041 Mon Sep 17 00:00:00 2001 From: Simon Hirtreiter Date: Mon, 12 Aug 2024 07:46:29 +0200 Subject: [PATCH 1/5] :fire: s3-client rm url override --- .../S3IntegrationClientAutoConfiguration.java | 45 +++------- .../DocumentStorageFileRepository.java | 50 +++++------ .../DocumentStorageFolderRepository.java | 16 +--- .../presignedurl/PresignedUrlRepository.java | 21 ++--- .../s3/client/service/ApiClientFactory.java | 30 ------- .../s3/client/service/S3DomainProvider.java | 19 ---- .../client/service/S3StorageUrlProvider.java | 64 -------------- .../DocumentStorageFileRepositoryTest.java | 50 +++++------ .../DocumentStorageFolderRepositoryTest.java | 64 +++++--------- .../PresignedUrlRepositoryTest.java | 88 +++++++------------ .../service/S3StorageUrlProviderTest.java | 56 ------------ 11 files changed, 122 insertions(+), 381 deletions(-) delete mode 100644 refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/service/ApiClientFactory.java delete mode 100644 refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/service/S3DomainProvider.java delete mode 100644 refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/service/S3StorageUrlProvider.java delete mode 100644 refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/service/S3StorageUrlProviderTest.java diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java index 5d7509b8..d98ebbf9 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java @@ -5,10 +5,7 @@ import de.muenchen.refarch.integration.s3.client.api.FolderApiApi; import de.muenchen.refarch.integration.s3.client.domain.model.SupportedFileExtensions; import de.muenchen.refarch.integration.s3.client.properties.S3IntegrationClientProperties; -import de.muenchen.refarch.integration.s3.client.service.ApiClientFactory; import de.muenchen.refarch.integration.s3.client.service.FileService; -import de.muenchen.refarch.integration.s3.client.service.S3DomainProvider; -import de.muenchen.refarch.integration.s3.client.service.S3StorageUrlProvider; import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -62,20 +59,20 @@ public void init() { @Bean @ConditionalOnProperty(prefix = "refarch.s3.client", name = "enable-security", havingValue = "true") - public ApiClientFactory securedApiClientFactory(final ClientRegistrationRepository clientRegistrationRepository, + public ApiClient securedApiClientFactory(final ClientRegistrationRepository clientRegistrationRepository, final OAuth2AuthorizedClientService authorizedClientService) { - return new ApiClientFactory( - this.webClient(clientRegistrationRepository, authorizedClientService)); + return new ApiClient( + this.authenticatedWebClient(clientRegistrationRepository, authorizedClientService)); } @Bean @ConditionalOnProperty(prefix = "refarch.s3.client", name = "enable-security", havingValue = "false", matchIfMissing = true) - public ApiClientFactory apiClientFactory() { - return new ApiClientFactory( + public ApiClient apiClientFactory() { + return new ApiClient( WebClient.builder().build()); } - private WebClient webClient( + private WebClient authenticatedWebClient( final ClientRegistrationRepository clientRegistrationRepository, final OAuth2AuthorizedClientService authorizedClientService) { final var oauth = new ServletOAuth2AuthorizedClientExchangeFilterFunction( @@ -101,8 +98,7 @@ public FileService fileService(final SupportedFileExtensions supportedFileExtens } /** - * Instance of a {@link FileService} containing supported file extensions configured within in the - * 'de.muenchen.oss.digiwf.s3' scope. + * Instance of a {@link FileService} containing supported file extensions configured within in the 'de.muenchen.refarch.s3' scope. * * @return {@link FileService} for managing file extensions. */ @@ -113,30 +109,15 @@ public FileService fileServiceFromS3IntegrationClientProperties() { this.s3IntegrationClientProperties.getMaxBatchSize()); } - /** - * Instance of an {@link S3StorageUrlProvider} containing an externally created - * {@link S3DomainProvider} for retrieving the S3 storage URL. - * - * @param s3DomainProvider Provider of domain specific S3 storages configured in process - * configurations. - * @return Provider of the S3 storage URL. - */ @Bean - @ConditionalOnBean(S3DomainProvider.class) - public S3StorageUrlProvider s3StorageUrlProvider(final S3DomainProvider s3DomainProvider) { - return new S3StorageUrlProvider(s3DomainProvider, this.s3IntegrationClientProperties.getDocumentStorageUrl()); + @ConditionalOnMissingBean + public FileApiApi fileApiApi(final ApiClient apiClient) { + return new FileApiApi(apiClient); } - /** - * Instance of an {@link S3StorageUrlProvider} containing a default {@link S3DomainProvider}. The - * instance will only return the default S3 URL. - * - * @return Provider of the S3 storage URL. - */ @Bean - @ConditionalOnMissingBean(S3DomainProvider.class) - public S3StorageUrlProvider s3StorageUrlProviderWithoutDomainProvider() { - return new S3StorageUrlProvider(this.s3IntegrationClientProperties.getDocumentStorageUrl()); + @ConditionalOnMissingBean + public FolderApiApi folderApiApi(final ApiClient apiClient) { + return new FolderApiApi(apiClient); } - } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRepository.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRepository.java index b104e844..e7030920 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRepository.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRepository.java @@ -7,7 +7,6 @@ import de.muenchen.refarch.integration.s3.client.model.FileSizeDto; import de.muenchen.refarch.integration.s3.client.repository.presignedurl.PresignedUrlRepository; import de.muenchen.refarch.integration.s3.client.repository.transfer.S3FileTransferRepository; -import de.muenchen.refarch.integration.s3.client.service.ApiClientFactory; import java.io.InputStream; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -26,14 +25,13 @@ public class DocumentStorageFileRepository { private final S3FileTransferRepository s3FileTransferRepository; - private final ApiClientFactory apiClientFactory; + private final FileApiApi fileApi; /** * Gets the file specified in the parameter from the document storage. * * @param pathToFile defines the path to the file. * @param expireInMinutes the expiration time of the presignedURL in minutes. - * @param documentStorageUrl to define to which document storage the request goes. * @return the file. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the S3 storage or document @@ -41,9 +39,9 @@ public 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(final String pathToFile, final int expireInMinutes, final String documentStorageUrl) + public byte[] getFile(final String pathToFile, final int expireInMinutes) throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final Mono presignedUrl = this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes, documentStorageUrl); + final Mono presignedUrl = this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes); return this.s3FileTransferRepository.getFile(presignedUrl.block()); } @@ -51,7 +49,6 @@ public byte[] getFile(final String pathToFile, final int expireInMinutes, final * Retrieves the file size of a file specified in the parameter from the document storage. * * @param pathToFile defines the path to the file. - * @param documentStorageUrl defines to which document storage the request goes. * @return the file size. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the S3 storage or document @@ -59,10 +56,9 @@ public byte[] getFile(final String pathToFile, final int expireInMinutes, final * @throws DocumentStorageException if the problem cannot be assigned to either the client or the S3 * storage or the document storage. */ - public Mono getFileSize(final String pathToFile, final String documentStorageUrl) + public Mono getFileSize(final String pathToFile) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { - final FileApiApi fileApi = this.apiClientFactory.getFileApiForDocumentStorageUrl(documentStorageUrl); return fileApi.getFileSize(pathToFile).mapNotNull(FileSizeDto::getFileSize); } catch (final HttpClientErrorException exception) { final String message = String.format("The request to get file size failed %s.", exception.getStatusCode()); @@ -84,7 +80,6 @@ public Mono getFileSize(final String pathToFile, final String documentStor * * @param pathToFile defines the path to the file. * @param expireInMinutes the expiration time of the presignedURL in minutes. - * @param documentStorageUrl to define to which document storage the request goes. * @return the InputStream for the file. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the S3 storage or document @@ -92,9 +87,9 @@ public Mono getFileSize(final String pathToFile, final String documentStor * @throws DocumentStorageException if the problem cannot be assigned to either the client or the S3 * storage or the document storage. */ - public InputStream getFileInputStream(final String pathToFile, final int expireInMinutes, final String documentStorageUrl) + public InputStream getFileInputStream(final String pathToFile, final int expireInMinutes) throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final Mono presignedUrl = this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes, documentStorageUrl); + final Mono presignedUrl = this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes); return this.s3FileTransferRepository.getFileInputStream(presignedUrl.block()); } @@ -104,16 +99,15 @@ public InputStream getFileInputStream(final String pathToFile, final int expireI * @param pathToFile defines the path to the file. * @param file to save. * @param expireInMinutes the expiration time of the presignedURL in minutes. - * @param documentStorageUrl to define to which document storage the request goes. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the S3 storage or document * storage. * @throws DocumentStorageException if the problem cannot be assigned to either the client or the S3 * storage or the document storage. */ - public void saveFile(final String pathToFile, final byte[] file, final int expireInMinutes, - final String documentStorageUrl) throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String presignedUrl = this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes, documentStorageUrl); + public void saveFile(final String pathToFile, final byte[] file, final int expireInMinutes) + throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { + final String presignedUrl = this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes); this.s3FileTransferRepository.saveFile(presignedUrl, file); } @@ -123,16 +117,15 @@ public void saveFile(final String pathToFile, final byte[] file, final int expir * @param pathToFile defines the path to the file. * @param file to save. * @param expireInMinutes the expiration time of the presignedURL in minutes. - * @param documentStorageUrl to define to which document storage the request goes. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the S3 storage or document * storage. * @throws DocumentStorageException if the problem cannot be assigned to either the client or the S3 * storage or the document storage. */ - public void saveFileInputStream(final String pathToFile, final InputStream file, final int expireInMinutes, - final String documentStorageUrl) throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String presignedUrl = this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes, documentStorageUrl); + public void saveFileInputStream(final String pathToFile, final InputStream file, final int expireInMinutes) + throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { + final String presignedUrl = this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes); this.s3FileTransferRepository.saveFileInputStream(presignedUrl, file); } @@ -142,16 +135,15 @@ public void saveFileInputStream(final String pathToFile, final InputStream file, * @param pathToFile defines the path to the file. * @param file which overwrites the file in the document storage. * @param expireInMinutes the expiration time of the presignedURL in minutes. - * @param documentStorageUrl to define to which document storage the request goes. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the S3 storage or document * storage. * @throws DocumentStorageException if the problem cannot be assigned to either the client or the S3 * storage or the document storage. */ - public void updateFile(final String pathToFile, final byte[] file, final int expireInMinutes, - final String documentStorageUrl) throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String presignedUrl = this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes, documentStorageUrl); + public void updateFile(final String pathToFile, final byte[] file, final int expireInMinutes) + throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { + final String presignedUrl = this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes); this.s3FileTransferRepository.updateFile(presignedUrl, file); } @@ -161,16 +153,15 @@ public void updateFile(final String pathToFile, final byte[] file, final int exp * @param pathToFile defines the path to the file. * @param file which overwrites the file in the document storage. * @param expireInMinutes the expiration time of the presignedURL in minutes. - * @param documentStorageUrl to define to which document storage the request goes. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the S3 storage or document * storage. * @throws DocumentStorageException if the problem cannot be assigned to either the client or the S3 * storage or the document storage. */ - public void updateFileInputStream(final String pathToFile, final InputStream file, final int expireInMinutes, - final String documentStorageUrl) throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String presignedUrl = this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes, documentStorageUrl); + public void updateFileInputStream(final String pathToFile, final InputStream file, final int expireInMinutes) + throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { + final String presignedUrl = this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes); this.s3FileTransferRepository.updateFileInputStream(presignedUrl, file); } @@ -179,16 +170,15 @@ public void updateFileInputStream(final String pathToFile, final InputStream fil * * @param pathToFile defines the path to the file. * @param expireInMinutes the expiration time of the presignedURL in minutes. - * @param documentStorageUrl to define to which document storage the request goes. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the S3 storage or document * storage. * @throws DocumentStorageException if the problem cannot be assigned to either the client or the S3 * storage or the document storage. */ - public void deleteFile(final String pathToFile, final int expireInMinutes, final String documentStorageUrl) + public void deleteFile(final String pathToFile, final int expireInMinutes) throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { - final String presignedUrl = this.presignedUrlRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes, documentStorageUrl); + final String presignedUrl = this.presignedUrlRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes); this.s3FileTransferRepository.deleteFile(presignedUrl); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderRepository.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderRepository.java index 4df00db2..64b8e0ce 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderRepository.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderRepository.java @@ -6,7 +6,6 @@ import de.muenchen.refarch.integration.s3.client.exception.DocumentStorageServerErrorException; import de.muenchen.refarch.integration.s3.client.model.FileSizesInFolderDto; import de.muenchen.refarch.integration.s3.client.model.FilesInFolderDto; -import de.muenchen.refarch.integration.s3.client.service.ApiClientFactory; import java.util.Map; import java.util.Set; import lombok.RequiredArgsConstructor; @@ -21,23 +20,20 @@ @Repository @RequiredArgsConstructor public class DocumentStorageFolderRepository { - - private final ApiClientFactory apiClientFactory; + private final FolderApiApi folderApi; /** * Deletes the folder with all containing files on document storage. * * @param pathToFolder which defines the folder in the document storage. - * @param documentStorageUrl to define to which document storage the request goes. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the document storage. * @throws DocumentStorageException if the problem cannot be assigned directly to the document * storage. */ - public void deleteFolder(final String pathToFolder, final String documentStorageUrl) + public void deleteFolder(final String pathToFolder) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { - final FolderApiApi folderApi = this.apiClientFactory.getFolderApiForDocumentStorageUrl(documentStorageUrl); folderApi.delete(pathToFolder); } catch (final HttpClientErrorException exception) { final String message = String.format("The request to delete a folder failed %s.", exception.getStatusCode()); @@ -58,16 +54,14 @@ public void deleteFolder(final String pathToFolder, final String documentStorage * Returns all files within a folder given in the parameter from document storage. * * @param pathToFolder which defines the folder in the document storage. - * @param documentStorageUrl to define to which document storage the request goes. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the document storage. * @throws DocumentStorageException if the problem cannot be assigned directly to the document * storage. */ - public Mono> getAllFilesInFolderRecursively(final String pathToFolder, final String documentStorageUrl) + public Mono> getAllFilesInFolderRecursively(final String pathToFolder) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { - final FolderApiApi folderApi = this.apiClientFactory.getFolderApiForDocumentStorageUrl(documentStorageUrl); final Mono filesInFolderDto = folderApi.getAllFilesInFolderRecursively(pathToFolder); return filesInFolderDto.mapNotNull(FilesInFolderDto::getPathToFiles); } catch (final HttpClientErrorException exception) { @@ -89,17 +83,15 @@ public Mono> getAllFilesInFolderRecursively(final String pathToFolde * Returns all file sizes of files within a folder given in the parameter from document storage. * * @param pathToFolder defines the folder in the document storage. - * @param documentStorageUrl defines to which document storage the request goes. * @return file paths with their file sizes. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the document storage. * @throws DocumentStorageException if the problem cannot be assigned directly to the document * storage. */ - public Mono> getAllFileSizesInFolderRecursively(final String pathToFolder, final String documentStorageUrl) + public Mono> getAllFileSizesInFolderRecursively(final String pathToFolder) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { - final FolderApiApi folderApi = this.apiClientFactory.getFolderApiForDocumentStorageUrl(documentStorageUrl); final Mono fileSizesInFolderDtoMono = folderApi.getAllFileSizesInFolderRecursively(pathToFolder); return fileSizesInFolderDtoMono.mapNotNull(FileSizesInFolderDto::getFileSizes); } catch (final HttpClientErrorException exception) { diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRepository.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRepository.java index 5e21e73a..145e93e7 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRepository.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRepository.java @@ -6,7 +6,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 de.muenchen.refarch.integration.s3.client.service.ApiClientFactory; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Repository; @@ -20,7 +19,7 @@ @RequiredArgsConstructor public class PresignedUrlRepository { - private final ApiClientFactory apiClientFactory; + private final FileApiApi fileApi; /** * Fetches a presignedURL for the file named in the parameter to get a file from the document @@ -28,17 +27,15 @@ public class PresignedUrlRepository { * * @param pathToFile defines the path to the file. * @param expireInMinutes the expiration time of the presignedURL in minutes. - * @param documentStorageUrl to define to which document storage the request goes. * @return the presignedURL. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the document storage. * @throws DocumentStorageException if the problem cannot be assigned to either the client or the * document storage. */ - public Mono getPresignedUrlGetFile(final String pathToFile, final int expireInMinutes, final String documentStorageUrl) + public Mono getPresignedUrlGetFile(final String pathToFile, final int expireInMinutes) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { - final FileApiApi fileApi = this.apiClientFactory.getFileApiForDocumentStorageUrl(documentStorageUrl); final Mono presignedUrlDto = fileApi.get(pathToFile, expireInMinutes); return presignedUrlDto.mapNotNull(PresignedUrlDto::getUrl); } catch (final HttpClientErrorException exception) { @@ -62,17 +59,15 @@ public Mono getPresignedUrlGetFile(final String pathToFile, final int ex * * @param pathToFile defines the path to the file. * @param expireInMinutes the expiration time of the presignedURL in minutes. - * @param documentStorageUrl to define to which document storage the request goes. * @return the presignedURL. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the document storage. * @throws DocumentStorageException if the problem cannot be assigned to either the client or the * document storage. */ - public String getPresignedUrlSaveFile(final String pathToFile, final int expireInMinutes, final String documentStorageUrl) + public String getPresignedUrlSaveFile(final String pathToFile, final int expireInMinutes) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { - final FileApiApi fileApi = this.apiClientFactory.getFileApiForDocumentStorageUrl(documentStorageUrl); final var fileDataDto = new FileDataDto(); fileDataDto.setPathToFile(pathToFile); fileDataDto.setExpiresInMinutes(expireInMinutes); @@ -99,17 +94,15 @@ public String getPresignedUrlSaveFile(final String pathToFile, final int expireI * * @param pathToFile defines the path to the file. * @param expireInMinutes the expiration time of the presignedURL in minutes. - * @param documentStorageUrl to define to which document storage the request goes. * @return the presignedURL. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the document storage. * @throws DocumentStorageException if the problem cannot be assigned to either the client or the * document storage. */ - public String getPresignedUrlUpdateFile(final String pathToFile, final int expireInMinutes, - final String documentStorageUrl) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { + public String getPresignedUrlUpdateFile(final String pathToFile, final int expireInMinutes) + throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { - final FileApiApi fileApi = this.apiClientFactory.getFileApiForDocumentStorageUrl(documentStorageUrl); final var fileDataDto = new FileDataDto(); fileDataDto.setPathToFile(pathToFile); fileDataDto.setExpiresInMinutes(expireInMinutes); @@ -136,17 +129,15 @@ public String getPresignedUrlUpdateFile(final String pathToFile, final int expir * * @param pathToFile defines the path to the file. * @param expireInMinutes the expiration time of the presignedURL in minutes. - * @param documentStorageUrl to define to which document storage the request goes. * @return the presignedURL. * @throws DocumentStorageClientErrorException if the problem is with the client. * @throws DocumentStorageServerErrorException if the problem is with the document storage. * @throws DocumentStorageException if the problem cannot be assigned to either the client or the * document storage. */ - public String getPresignedUrlDeleteFile(final String pathToFile, final int expireInMinutes, final String documentStorageUrl) + public String getPresignedUrlDeleteFile(final String pathToFile, final int expireInMinutes) throws DocumentStorageClientErrorException, DocumentStorageServerErrorException, DocumentStorageException { try { - final FileApiApi fileApi = this.apiClientFactory.getFileApiForDocumentStorageUrl(documentStorageUrl); final Mono presignedUrlDto = fileApi.delete1(pathToFile, expireInMinutes); return presignedUrlDto.block().getUrl(); } catch (final HttpClientErrorException exception) { diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/service/ApiClientFactory.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/service/ApiClientFactory.java deleted file mode 100644 index 8128ffbf..00000000 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/service/ApiClientFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.muenchen.refarch.integration.s3.client.service; - -import de.muenchen.refarch.integration.s3.client.ApiClient; -import de.muenchen.refarch.integration.s3.client.api.FileApiApi; -import de.muenchen.refarch.integration.s3.client.api.FolderApiApi; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.reactive.function.client.WebClient; - -@RequiredArgsConstructor -@Slf4j -public class ApiClientFactory { - - private final WebClient webClient; - - public FileApiApi getFileApiForDocumentStorageUrl(final String documentStorageUrl) { - return new FileApiApi(this.getApiClientForDocumentStorageUrl(documentStorageUrl)); - } - - public FolderApiApi getFolderApiForDocumentStorageUrl(final String documentStorageUrl) { - return new FolderApiApi(this.getApiClientForDocumentStorageUrl(documentStorageUrl)); - } - - private ApiClient getApiClientForDocumentStorageUrl(final String documentStorageUrl) { - final ApiClient apiClient = new ApiClient(this.webClient); - apiClient.setBasePath(documentStorageUrl); - return apiClient; - } - -} diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/service/S3DomainProvider.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/service/S3DomainProvider.java deleted file mode 100644 index be57dca7..00000000 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/service/S3DomainProvider.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.muenchen.refarch.integration.s3.client.service; - -import java.util.Optional; - -/** - * Implementors obtain a function that provides an S3 storage URL if it is configured for a given - * process definition. - */ -@FunctionalInterface -public interface S3DomainProvider { - - /** - * Provides an S3 storage URL if it is configured for a given process definition. - * - * @param processDefinitionId The {@link String} id of a process definition. - * @return An {@link Optional} containing an S3 storage URL if it is configured. - */ - Optional provideDomainSpecificS3StorageUrl(String processDefinitionId); -} diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/service/S3StorageUrlProvider.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/service/S3StorageUrlProvider.java deleted file mode 100644 index e41fb926..00000000 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/main/java/de/muenchen/refarch/integration/s3/client/service/S3StorageUrlProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -package de.muenchen.refarch.integration.s3.client.service; - -import de.muenchen.refarch.integration.s3.client.exception.PropertyNotSetException; -import java.util.Optional; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -/** - * Provides the S3 storage URL either configured in a process configuration of a given process - * definition or the default URL. - */ -@Slf4j -public class S3StorageUrlProvider { - - private final S3DomainProvider s3DomainProvider; - - @Getter - private final String defaultDocumentStorageUrl; - - /** - * Constructor for client users which obtain their own {@link S3DomainProvider}. - * - * @param s3DomainProvider The {@link S3DomainProvider} to use for fetching domain-specific S3 URLs. - * @param defaultDocumentStorageUrl The default S3 storage URL to use if no domain-specific URL is - * available. - */ - public S3StorageUrlProvider(final S3DomainProvider s3DomainProvider, final String defaultDocumentStorageUrl) { - this.s3DomainProvider = s3DomainProvider; - this.defaultDocumentStorageUrl = defaultDocumentStorageUrl; - } - - /** - * Constructor for client users which do not obtain their own {@link S3DomainProvider}. - * - * @param defaultDocumentStorageUrl The default S3 storage URL to use if no domain-specific URL is - * available. - */ - public S3StorageUrlProvider(final String defaultDocumentStorageUrl) { - this(processDefinition -> Optional.empty(), defaultDocumentStorageUrl); - } - - /** - * Provides an S3 storage URL either configured in a process configuration of a given process - * definition or the default URL. - * - * @param processDefinitionId The {@link String} process definition id for which the S3 storage URL - * will be provided. - * @return The S3 storage URL. - * @throws PropertyNotSetException Thrown if the property - * 'de.muenchen.oss.digiwf.s3.document-storage-url' is unset. - */ - public String provideS3StorageUrl(final String processDefinitionId) throws PropertyNotSetException { - final Optional domainSpecificStorageUrl = s3DomainProvider.provideDomainSpecificS3StorageUrl(processDefinitionId); - if (domainSpecificStorageUrl.isPresent()) return domainSpecificStorageUrl.get(); - if (StringUtils.isNotBlank(this.defaultDocumentStorageUrl)) { - return this.defaultDocumentStorageUrl; - } - final String message = "Default document storage is not set. Make sure the property de.muenchen.oss.digiwf.s3.document-storage-url is set."; - log.error(message); - throw new PropertyNotSetException(message); - } - -} diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRepositoryTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRepositoryTest.java index fb9e5f24..3ec95654 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRepositoryTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFileRepositoryTest.java @@ -12,7 +12,6 @@ import de.muenchen.refarch.integration.s3.client.model.FileSizeDto; import de.muenchen.refarch.integration.s3.client.repository.presignedurl.PresignedUrlRepository; import de.muenchen.refarch.integration.s3.client.repository.transfer.S3FileTransferRepository; -import de.muenchen.refarch.integration.s3.client.service.ApiClientFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -30,9 +29,6 @@ @MockitoSettings(strictness = Strictness.STRICT_STUBS) class DocumentStorageFileRepositoryTest { - @Mock - private ApiClientFactory apiClientFactory; - @Mock private PresignedUrlRepository presignedUrlRepository; @@ -47,8 +43,8 @@ class DocumentStorageFileRepositoryTest { @BeforeEach public void beforeEach() { this.documentStorageFileRepository = new DocumentStorageFileRepository(this.presignedUrlRepository, this.s3FileTransferRepository, - this.apiClientFactory); - Mockito.reset(this.presignedUrlRepository, this.s3FileTransferRepository, this.fileApi, this.apiClientFactory); + this.fileApi); + Mockito.reset(this.presignedUrlRepository, this.s3FileTransferRepository, this.fileApi); } @Test @@ -57,11 +53,11 @@ void getFile() throws DocumentStorageException, DocumentStorageClientErrorExcept final int expireInMinutes = 10; final String presignedUrl = "the_presignedUrl"; - when(this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes, "url")).thenReturn(Mono.just(presignedUrl)); + when(this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes)).thenReturn(Mono.just(presignedUrl)); when(this.s3FileTransferRepository.getFile(presignedUrl)).thenReturn(new byte[] {}); - this.documentStorageFileRepository.getFile(pathToFile, expireInMinutes, "url"); + this.documentStorageFileRepository.getFile(pathToFile, expireInMinutes); - verify(this.presignedUrlRepository, Mockito.times(1)).getPresignedUrlGetFile(pathToFile, expireInMinutes, "url"); + verify(this.presignedUrlRepository, Mockito.times(1)).getPresignedUrlGetFile(pathToFile, expireInMinutes); verify(this.s3FileTransferRepository, Mockito.times(1)).getFile(presignedUrl); } @@ -71,28 +67,24 @@ void getFileSize() throws DocumentStorageException, DocumentStorageClientErrorEx fileSizeDto.setFileSize(123L); final String pathToFile = "path/to/file"; - when(apiClientFactory.getFileApiForDocumentStorageUrl(anyString())).thenReturn(fileApi); when(fileApi.getFileSize(anyString())).thenReturn(Mono.just(fileSizeDto)); - final Mono result = documentStorageFileRepository.getFileSize(pathToFile, "url"); + final Mono result = documentStorageFileRepository.getFileSize(pathToFile); assertEquals(123L, result.block()); verify(fileApi, Mockito.times(1)).getFileSize(pathToFile); - Mockito.reset(this.fileApi, this.apiClientFactory); - when(apiClientFactory.getFileApiForDocumentStorageUrl(anyString())).thenReturn(fileApi); + Mockito.reset(this.fileApi); when(fileApi.getFileSize(anyString())).thenThrow(HttpClientErrorException.class); - assertThrows(DocumentStorageClientErrorException.class, () -> documentStorageFileRepository.getFileSize(pathToFile, "url")); + assertThrows(DocumentStorageClientErrorException.class, () -> documentStorageFileRepository.getFileSize(pathToFile)); verify(fileApi, Mockito.times(1)).getFileSize(pathToFile); - Mockito.reset(this.fileApi, this.apiClientFactory); - when(apiClientFactory.getFileApiForDocumentStorageUrl(anyString())).thenReturn(fileApi); + Mockito.reset(this.fileApi); when(fileApi.getFileSize(anyString())).thenThrow(HttpServerErrorException.class); - assertThrows(DocumentStorageServerErrorException.class, () -> documentStorageFileRepository.getFileSize(pathToFile, "url")); + assertThrows(DocumentStorageServerErrorException.class, () -> documentStorageFileRepository.getFileSize(pathToFile)); verify(fileApi, Mockito.times(1)).getFileSize(pathToFile); - Mockito.reset(this.fileApi, this.apiClientFactory); - when(apiClientFactory.getFileApiForDocumentStorageUrl(anyString())).thenReturn(fileApi); + Mockito.reset(this.fileApi); when(fileApi.getFileSize(anyString())).thenThrow(RestClientException.class); - assertThrows(DocumentStorageException.class, () -> documentStorageFileRepository.getFileSize(pathToFile, "url")); + assertThrows(DocumentStorageException.class, () -> documentStorageFileRepository.getFileSize(pathToFile)); verify(fileApi, Mockito.times(1)).getFileSize(pathToFile); } @@ -103,11 +95,11 @@ void saveFile() throws DocumentStorageException, DocumentStorageClientErrorExcep final int expireInMinutes = 10; final String presignedUrl = "the_presignedUrl"; - when(this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes, "url")).thenReturn(presignedUrl); + when(this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes)).thenReturn(presignedUrl); doNothing().when(this.s3FileTransferRepository).saveFile(presignedUrl, file); - this.documentStorageFileRepository.saveFile(pathToFile, file, expireInMinutes, "url"); + this.documentStorageFileRepository.saveFile(pathToFile, file, expireInMinutes); - verify(this.presignedUrlRepository, Mockito.times(1)).getPresignedUrlSaveFile(pathToFile, expireInMinutes, "url"); + verify(this.presignedUrlRepository, Mockito.times(1)).getPresignedUrlSaveFile(pathToFile, expireInMinutes); verify(this.s3FileTransferRepository, Mockito.times(1)).saveFile(presignedUrl, file); } @@ -118,11 +110,11 @@ void updateFile() throws DocumentStorageException, DocumentStorageClientErrorExc final int expireInMinutes = 10; final String presignedUrl = "the_presignedUrl"; - when(this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes, "url")).thenReturn(presignedUrl); + when(this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes)).thenReturn(presignedUrl); doNothing().when(this.s3FileTransferRepository).updateFile(presignedUrl, file); - this.documentStorageFileRepository.updateFile(pathToFile, file, expireInMinutes, "url"); + this.documentStorageFileRepository.updateFile(pathToFile, file, expireInMinutes); - verify(this.presignedUrlRepository, Mockito.times(1)).getPresignedUrlUpdateFile(pathToFile, expireInMinutes, "url"); + verify(this.presignedUrlRepository, Mockito.times(1)).getPresignedUrlUpdateFile(pathToFile, expireInMinutes); verify(this.s3FileTransferRepository, Mockito.times(1)).updateFile(presignedUrl, file); } @@ -132,11 +124,11 @@ void deleteFile() throws DocumentStorageException, DocumentStorageClientErrorExc final int expireInMinutes = 10; final String presignedUrl = "the_presignedUrl"; - when(this.presignedUrlRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes, "url")).thenReturn(presignedUrl); + when(this.presignedUrlRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes)).thenReturn(presignedUrl); doNothing().when(this.s3FileTransferRepository).deleteFile(presignedUrl); - this.documentStorageFileRepository.deleteFile(pathToFile, expireInMinutes, "url"); + this.documentStorageFileRepository.deleteFile(pathToFile, expireInMinutes); - verify(this.presignedUrlRepository, Mockito.times(1)).getPresignedUrlDeleteFile(pathToFile, expireInMinutes, "url"); + verify(this.presignedUrlRepository, Mockito.times(1)).getPresignedUrlDeleteFile(pathToFile, expireInMinutes); verify(this.s3FileTransferRepository, Mockito.times(1)).deleteFile(presignedUrl); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderRepositoryTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderRepositoryTest.java index 0bba2053..6871c32e 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderRepositoryTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/DocumentStorageFolderRepositoryTest.java @@ -11,7 +11,6 @@ import de.muenchen.refarch.integration.s3.client.exception.DocumentStorageServerErrorException; import de.muenchen.refarch.integration.s3.client.model.FileSizesInFolderDto; import de.muenchen.refarch.integration.s3.client.model.FilesInFolderDto; -import de.muenchen.refarch.integration.s3.client.service.ApiClientFactory; import java.util.Map; import java.util.Set; import org.junit.jupiter.api.BeforeEach; @@ -32,9 +31,6 @@ @MockitoSettings(strictness = Strictness.STRICT_STUBS) class DocumentStorageFolderRepositoryTest { - @Mock - private ApiClientFactory apiClientFactory; - @Mock private FolderApiApi folderApi; @@ -42,35 +38,31 @@ class DocumentStorageFolderRepositoryTest { @BeforeEach public void beforeEach() { - this.documentStorageFolderRepository = new DocumentStorageFolderRepository(this.apiClientFactory); + this.documentStorageFolderRepository = new DocumentStorageFolderRepository(this.folderApi); } @Test void deleteFolder() throws DocumentStorageException, DocumentStorageClientErrorException, DocumentStorageServerErrorException { final String pathToFolder = "folder"; - Mockito.reset(this.folderApi, this.apiClientFactory); - when(this.apiClientFactory.getFolderApiForDocumentStorageUrl("url")).thenReturn(this.folderApi); + Mockito.reset(this.folderApi); when(this.folderApi.delete(pathToFolder)).thenReturn(Mono.empty()); - this.documentStorageFolderRepository.deleteFolder(pathToFolder, "url"); + this.documentStorageFolderRepository.deleteFolder(pathToFolder); verify(this.folderApi, times(1)).delete(pathToFolder); - Mockito.reset(this.folderApi, this.apiClientFactory); - when(this.apiClientFactory.getFolderApiForDocumentStorageUrl("url")).thenReturn(this.folderApi); + Mockito.reset(this.folderApi); Mockito.doThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)).when(this.folderApi).delete(pathToFolder); - assertThrows(DocumentStorageClientErrorException.class, () -> this.documentStorageFolderRepository.deleteFolder(pathToFolder, "url")); + assertThrows(DocumentStorageClientErrorException.class, () -> this.documentStorageFolderRepository.deleteFolder(pathToFolder)); verify(this.folderApi, times(1)).delete(pathToFolder); - Mockito.reset(this.folderApi, this.apiClientFactory); - when(this.apiClientFactory.getFolderApiForDocumentStorageUrl("url")).thenReturn(this.folderApi); + Mockito.reset(this.folderApi); Mockito.doThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)).when(this.folderApi).delete(pathToFolder); - assertThrows(DocumentStorageServerErrorException.class, () -> this.documentStorageFolderRepository.deleteFolder(pathToFolder, "url")); + assertThrows(DocumentStorageServerErrorException.class, () -> this.documentStorageFolderRepository.deleteFolder(pathToFolder)); verify(this.folderApi, times(1)).delete(pathToFolder); - Mockito.reset(this.folderApi, this.apiClientFactory); - when(this.apiClientFactory.getFolderApiForDocumentStorageUrl("url")).thenReturn(this.folderApi); + Mockito.reset(this.folderApi); Mockito.doThrow(new RestClientException("Something happened")).when(this.folderApi).delete(pathToFolder); - assertThrows(DocumentStorageException.class, () -> this.documentStorageFolderRepository.deleteFolder(pathToFolder, "url")); + assertThrows(DocumentStorageException.class, () -> this.documentStorageFolderRepository.deleteFolder(pathToFolder)); verify(this.folderApi, times(1)).delete(pathToFolder); } @@ -81,28 +73,24 @@ void getAllFilesInFolderRecursively() throws DocumentStorageException, DocumentS final FilesInFolderDto filesInFolderDto = new FilesInFolderDto(); filesInFolderDto.setPathToFiles(Set.of("folder/file.txt")); - Mockito.reset(this.folderApi, this.apiClientFactory); - when(this.apiClientFactory.getFolderApiForDocumentStorageUrl("url")).thenReturn(this.folderApi); + Mockito.reset(this.folderApi); when(this.folderApi.getAllFilesInFolderRecursively(pathToFolder)).thenReturn(Mono.just(filesInFolderDto)); - this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder, "url"); + this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder); verify(this.folderApi, times(1)).getAllFilesInFolderRecursively(pathToFolder); - Mockito.reset(this.folderApi, this.apiClientFactory); - when(this.apiClientFactory.getFolderApiForDocumentStorageUrl("url")).thenReturn(this.folderApi); + Mockito.reset(this.folderApi); Mockito.doThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)).when(this.folderApi).getAllFilesInFolderRecursively(pathToFolder); - assertThrows(DocumentStorageClientErrorException.class, () -> this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder, "url")); + assertThrows(DocumentStorageClientErrorException.class, () -> this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder)); verify(this.folderApi, times(1)).getAllFilesInFolderRecursively(pathToFolder); - Mockito.reset(this.folderApi, this.apiClientFactory); - when(this.apiClientFactory.getFolderApiForDocumentStorageUrl("url")).thenReturn(this.folderApi); + Mockito.reset(this.folderApi); Mockito.doThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)).when(this.folderApi).getAllFilesInFolderRecursively(pathToFolder); - assertThrows(DocumentStorageServerErrorException.class, () -> this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder, "url")); + assertThrows(DocumentStorageServerErrorException.class, () -> this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder)); verify(this.folderApi, times(1)).getAllFilesInFolderRecursively(pathToFolder); - Mockito.reset(this.folderApi, this.apiClientFactory); - when(this.apiClientFactory.getFolderApiForDocumentStorageUrl("url")).thenReturn(this.folderApi); + Mockito.reset(this.folderApi); Mockito.doThrow(new RestClientException("Something happened")).when(this.folderApi).getAllFilesInFolderRecursively(pathToFolder); - assertThrows(DocumentStorageException.class, () -> this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder, "url")); + assertThrows(DocumentStorageException.class, () -> this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder)); verify(this.folderApi, times(1)).getAllFilesInFolderRecursively(pathToFolder); } @@ -112,29 +100,25 @@ void testGetAllFileSizesInFolderRecursively() final String pathToFolder = "path/to/folder"; FileSizesInFolderDto fileSizesInFolderDto = new FileSizesInFolderDto(); fileSizesInFolderDto.setFileSizes(Map.of("file1", 100L, "file2", 200L)); - when(apiClientFactory.getFolderApiForDocumentStorageUrl(anyString())).thenReturn(folderApi); when(folderApi.getAllFileSizesInFolderRecursively(anyString())).thenReturn(Mono.just(fileSizesInFolderDto)); - Mono> result = documentStorageFolderRepository.getAllFileSizesInFolderRecursively(pathToFolder, "url"); + Mono> result = documentStorageFolderRepository.getAllFileSizesInFolderRecursively(pathToFolder); assertEquals(Map.of("file1", 100L, "file2", 200L), result.block()); verify(this.folderApi, times(1)).getAllFileSizesInFolderRecursively(pathToFolder); - Mockito.reset(this.folderApi, this.apiClientFactory); - when(apiClientFactory.getFolderApiForDocumentStorageUrl(anyString())).thenReturn(folderApi); + Mockito.reset(this.folderApi); when(folderApi.getAllFileSizesInFolderRecursively(anyString())).thenThrow(HttpClientErrorException.class); - assertThrows(DocumentStorageClientErrorException.class, () -> documentStorageFolderRepository.getAllFileSizesInFolderRecursively(pathToFolder, "url")); + assertThrows(DocumentStorageClientErrorException.class, () -> documentStorageFolderRepository.getAllFileSizesInFolderRecursively(pathToFolder)); verify(this.folderApi, times(1)).getAllFileSizesInFolderRecursively(pathToFolder); - Mockito.reset(this.folderApi, this.apiClientFactory); - when(apiClientFactory.getFolderApiForDocumentStorageUrl(anyString())).thenReturn(folderApi); + Mockito.reset(this.folderApi); when(folderApi.getAllFileSizesInFolderRecursively(anyString())).thenThrow(HttpServerErrorException.class); - assertThrows(DocumentStorageServerErrorException.class, () -> documentStorageFolderRepository.getAllFileSizesInFolderRecursively(pathToFolder, "url")); + assertThrows(DocumentStorageServerErrorException.class, () -> documentStorageFolderRepository.getAllFileSizesInFolderRecursively(pathToFolder)); verify(this.folderApi, times(1)).getAllFileSizesInFolderRecursively(pathToFolder); - Mockito.reset(this.folderApi, this.apiClientFactory); - when(apiClientFactory.getFolderApiForDocumentStorageUrl(anyString())).thenReturn(folderApi); + Mockito.reset(this.folderApi); when(folderApi.getAllFileSizesInFolderRecursively(anyString())).thenThrow(RestClientException.class); - assertThrows(DocumentStorageException.class, () -> documentStorageFolderRepository.getAllFileSizesInFolderRecursively(pathToFolder, "url")); + assertThrows(DocumentStorageException.class, () -> documentStorageFolderRepository.getAllFileSizesInFolderRecursively(pathToFolder)); verify(this.folderApi, times(1)).getAllFileSizesInFolderRecursively(pathToFolder); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRepositoryTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRepositoryTest.java index d5fcf49c..b61deecd 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRepositoryTest.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRepositoryTest.java @@ -9,7 +9,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 de.muenchen.refarch.integration.s3.client.service.ApiClientFactory; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -31,9 +30,6 @@ class PresignedUrlRepositoryTest { private static final String DEFAULT_S3_URL = "defaultURL"; - @Mock - private ApiClientFactory apiClientFactory; - @Mock private FileApiApi fileApi; @@ -41,8 +37,8 @@ class PresignedUrlRepositoryTest { @BeforeEach public void beforeEach() { - this.presignedUrlRepository = new PresignedUrlRepository(this.apiClientFactory); - Mockito.reset(this.fileApi, this.apiClientFactory); + this.presignedUrlRepository = new PresignedUrlRepository(this.fileApi); + Mockito.reset(this.fileApi); } @Test @@ -54,10 +50,9 @@ void getPresignedUrlGetFile() final PresignedUrlDto expected = new PresignedUrlDto(); expected.setUrl("the_presignedUrl"); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.get(pathToFile, expireInMinutes)).thenReturn(Mono.just(expected)); - final Mono result = this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes, DEFAULT_S3_URL); + final Mono result = this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes); Mockito.verify(this.fileApi, Mockito.times(1)).get(pathToFile, expireInMinutes); assertThat(result.block(), is(expected.getUrl())); Mockito.reset(this.fileApi); @@ -68,25 +63,22 @@ void getPresignedUrlGetFileException() { final String pathToFile = "folder/file.txt"; final Integer expireInMinutes = 10; - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.get(pathToFile, expireInMinutes)).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); Assertions.assertThrows(DocumentStorageClientErrorException.class, - () -> this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes, DEFAULT_S3_URL)); + () -> this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).get(pathToFile, expireInMinutes); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.get(pathToFile, expireInMinutes)).thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); Assertions.assertThrows(DocumentStorageServerErrorException.class, - () -> this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes, DEFAULT_S3_URL)); + () -> this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).get(pathToFile, expireInMinutes); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.get(pathToFile, expireInMinutes)).thenThrow(new RestClientException("Something happened")); Assertions.assertThrows(DocumentStorageException.class, - () -> this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes, DEFAULT_S3_URL)); + () -> this.presignedUrlRepository.getPresignedUrlGetFile(pathToFile, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).get(pathToFile, expireInMinutes); } @@ -103,11 +95,10 @@ void getPresignedUrlSaveFile() final PresignedUrlDto expected = new PresignedUrlDto(); expected.setUrl("the_presignedUrl"); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.save(fileDataDto)).thenReturn(Mono.just(expected)); - final String result = this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes, DEFAULT_S3_URL); + final String result = this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes); Mockito.verify(this.fileApi, Mockito.times(1)).save(fileDataDto); assertThat(result, is(expected.getUrl())); } @@ -121,25 +112,22 @@ void getPresignedUrlSaveFileException() { fileDataDto.setPathToFile(pathToFile); fileDataDto.setExpiresInMinutes(expireInMinutes); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.save(fileDataDto)).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); Assertions.assertThrows(DocumentStorageClientErrorException.class, - () -> this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes, DEFAULT_S3_URL)); + () -> this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).save(fileDataDto); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.save(fileDataDto)).thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); Assertions.assertThrows(DocumentStorageServerErrorException.class, - () -> this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes, DEFAULT_S3_URL)); + () -> this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).save(fileDataDto); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.save(fileDataDto)).thenThrow(new RestClientException("Something happened")); Assertions.assertThrows(DocumentStorageException.class, - () -> this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes, DEFAULT_S3_URL)); + () -> this.presignedUrlRepository.getPresignedUrlSaveFile(pathToFile, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).save(fileDataDto); } @@ -156,11 +144,10 @@ void getPresignedUrlUpdateFile() final PresignedUrlDto expected = new PresignedUrlDto(); expected.setUrl("the_presignedUrl"); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.update(fileDataDto)).thenReturn(Mono.just(expected)); - final String result = this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes, DEFAULT_S3_URL); + final String result = this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes); Mockito.verify(this.fileApi, Mockito.times(1)).update(fileDataDto); assertThat(result, is(expected.getUrl())); } @@ -174,25 +161,22 @@ void getPresignedUrlUpdateFileException() { fileDataDto.setPathToFile(pathToFile); fileDataDto.setExpiresInMinutes(expireInMinutes); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.update(fileDataDto)).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); Assertions.assertThrows(DocumentStorageClientErrorException.class, - () -> this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes, DEFAULT_S3_URL)); + () -> this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).update(fileDataDto); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.update(fileDataDto)).thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); Assertions.assertThrows(DocumentStorageServerErrorException.class, - () -> this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes, DEFAULT_S3_URL)); + () -> this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).update(fileDataDto); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.update(fileDataDto)).thenThrow(new RestClientException("Something happened")); Assertions.assertThrows(DocumentStorageException.class, - () -> this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes, DEFAULT_S3_URL)); + () -> this.presignedUrlRepository.getPresignedUrlUpdateFile(pathToFile, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).update(fileDataDto); } @@ -205,11 +189,10 @@ void getPresignedUrlDeleteFile() final PresignedUrlDto expected = new PresignedUrlDto(); expected.setUrl("the_presignedUrl"); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.delete1(pathToFile, expireInMinutes)).thenReturn(Mono.just(expected)); - final String result = this.presignedUrlRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes, DEFAULT_S3_URL); + final String result = this.presignedUrlRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes); Mockito.verify(this.fileApi, Mockito.times(1)).delete1(pathToFile, expireInMinutes); assertThat(result, is(expected.getUrl())); } @@ -219,25 +202,22 @@ void getPresignedUrlDeleteFileException() { final String pathToFile = "folder/file.txt"; final int expireInMinutes = 10; - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.delete1(pathToFile, expireInMinutes)).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); Assertions.assertThrows(DocumentStorageClientErrorException.class, - () -> this.presignedUrlRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes, DEFAULT_S3_URL)); + () -> this.presignedUrlRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).delete1(pathToFile, expireInMinutes); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.delete1(pathToFile, expireInMinutes)).thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); Assertions.assertThrows(DocumentStorageServerErrorException.class, - () -> this.presignedUrlRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes, DEFAULT_S3_URL)); + () -> this.presignedUrlRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).delete1(pathToFile, expireInMinutes); - Mockito.reset(this.fileApi, this.apiClientFactory); - Mockito.when(this.apiClientFactory.getFileApiForDocumentStorageUrl(DEFAULT_S3_URL)).thenReturn(this.fileApi); + Mockito.reset(this.fileApi); Mockito.when(this.fileApi.delete1(pathToFile, expireInMinutes)).thenThrow(new RestClientException("Something happened")); Assertions.assertThrows(DocumentStorageException.class, - () -> this.presignedUrlRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes, DEFAULT_S3_URL)); + () -> this.presignedUrlRepository.getPresignedUrlDeleteFile(pathToFile, expireInMinutes)); Mockito.verify(this.fileApi, Mockito.times(1)).delete1(pathToFile, expireInMinutes); } diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/service/S3StorageUrlProviderTest.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/service/S3StorageUrlProviderTest.java deleted file mode 100644 index a5a3c193..00000000 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client/src/test/java/de/muenchen/refarch/integration/s3/client/service/S3StorageUrlProviderTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package de.muenchen.refarch.integration.s3.client.service; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import de.muenchen.refarch.integration.s3.client.exception.PropertyNotSetException; -import de.muenchen.refarch.integration.s3.client.service.S3DomainProvider; -import de.muenchen.refarch.integration.s3.client.service.S3StorageUrlProvider; -import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -class S3StorageUrlProviderTest { - - private static final String DEFAULT_DOCUMENT_STORAGE_URL = "default-storage-url"; - private static final String PROCESS_DEFINITION_ID = "processDefinitionId"; - private static final String DOMAIN_SPECIFIC_STORAGE_URL = "domain-specific-url"; - private final S3DomainProvider s3DomainProvider = mock(S3DomainProvider.class); - private S3StorageUrlProvider s3StorageUrlProviderWithDefault; - private S3StorageUrlProvider s3StorageUrlProviderWithoutDefault; - - @BeforeEach - void setUp() { - s3StorageUrlProviderWithDefault = new S3StorageUrlProvider(s3DomainProvider, DEFAULT_DOCUMENT_STORAGE_URL); - s3StorageUrlProviderWithoutDefault = new S3StorageUrlProvider(s3DomainProvider, null); - } - - @Test - void testProvideS3StorageUrl_DomainSpecificUrl() throws PropertyNotSetException { - when(s3DomainProvider.provideDomainSpecificS3StorageUrl(PROCESS_DEFINITION_ID)) - .thenReturn(Optional.of(DOMAIN_SPECIFIC_STORAGE_URL)); - String result = s3StorageUrlProviderWithDefault.provideS3StorageUrl(PROCESS_DEFINITION_ID); - assertEquals(DOMAIN_SPECIFIC_STORAGE_URL, result); - } - - @Test - void testProvideS3StorageUrl_DefaultUrl() throws PropertyNotSetException { - when(s3DomainProvider.provideDomainSpecificS3StorageUrl(PROCESS_DEFINITION_ID)) - .thenReturn(Optional.empty()); - String result = s3StorageUrlProviderWithDefault.provideS3StorageUrl(PROCESS_DEFINITION_ID); - assertEquals(DEFAULT_DOCUMENT_STORAGE_URL, result); - } - - @Test - void testProvideS3StorageUrl_NoUrls() { - when(s3DomainProvider.provideDomainSpecificS3StorageUrl(PROCESS_DEFINITION_ID)) - .thenReturn(Optional.empty()); - PropertyNotSetException exception = assertThrows(PropertyNotSetException.class, - () -> s3StorageUrlProviderWithoutDefault.provideS3StorageUrl(PROCESS_DEFINITION_ID)); - - assertEquals("Default document storage is not set. Make sure the property de.muenchen.oss.digiwf.s3.document-storage-url is set.", - exception.getMessage()); - } -} From 61132f6d1bdae6b63ad3a4f6b085b20f222ced45 Mon Sep 17 00:00:00 2001 From: Simon Hirtreiter Date: Mon, 12 Aug 2024 07:48:21 +0200 Subject: [PATCH 2/5] :fire: s3-client rm url override --- .../S3IntegrationClientAutoConfiguration.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java index d98ebbf9..e402230b 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java @@ -16,7 +16,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.FilterType; import org.springframework.security.oauth2.client.AuthorizedClientServiceOAuth2AuthorizedClientManager; import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; @@ -27,21 +26,6 @@ @ComponentScan( basePackages = { "de.muenchen.refarch.integration.s3.client" - }, - excludeFilters = { - @ComponentScan.Filter( - type = FilterType.ASSIGNABLE_TYPE, - classes = { - /* - * Exclude to avoid multiple instantiation of multiple beans with same name. - * This class is instantiated in {@link S3IntegrationClientAutoConfiguration} - * to give the bean another name. - */ - ApiClient.class, - FileApiApi.class, - FolderApiApi.class - } - ) } ) @RequiredArgsConstructor From aab3dd276ae28b505e2418c95ca8516550db1ea6 Mon Sep 17 00:00:00 2001 From: Simon Hirtreiter Date: Mon, 12 Aug 2024 07:49:01 +0200 Subject: [PATCH 3/5] :art: s3-client format --- .../configuration/S3IntegrationClientAutoConfiguration.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java index e402230b..97710fdc 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java @@ -82,7 +82,8 @@ public FileService fileService(final SupportedFileExtensions supportedFileExtens } /** - * Instance of a {@link FileService} containing supported file extensions configured within in the 'de.muenchen.refarch.s3' scope. + * Instance of a {@link FileService} containing supported file extensions configured within in the + * 'de.muenchen.refarch.s3' scope. * * @return {@link FileService} for managing file extensions. */ From b25a63af2ab609d09f0d39f6ca29386003bae907 Mon Sep 17 00:00:00 2001 From: Simon Hirtreiter Date: Mon, 12 Aug 2024 08:54:18 +0200 Subject: [PATCH 4/5] :pencil2: s3-integration client starter fix method naming --- .../S3IntegrationClientAutoConfiguration.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java index 97710fdc..4a2f97da 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java @@ -43,7 +43,7 @@ public void init() { @Bean @ConditionalOnProperty(prefix = "refarch.s3.client", name = "enable-security", havingValue = "true") - public ApiClient securedApiClientFactory(final ClientRegistrationRepository clientRegistrationRepository, + public ApiClient securedApiClient(final ClientRegistrationRepository clientRegistrationRepository, final OAuth2AuthorizedClientService authorizedClientService) { return new ApiClient( this.authenticatedWebClient(clientRegistrationRepository, authorizedClientService)); @@ -51,7 +51,7 @@ public ApiClient securedApiClientFactory(final ClientRegistrationRepository clie @Bean @ConditionalOnProperty(prefix = "refarch.s3.client", name = "enable-security", havingValue = "false", matchIfMissing = true) - public ApiClient apiClientFactory() { + public ApiClient apiClient() { return new ApiClient( WebClient.builder().build()); } @@ -82,8 +82,7 @@ public FileService fileService(final SupportedFileExtensions supportedFileExtens } /** - * Instance of a {@link FileService} containing supported file extensions configured within in the - * 'de.muenchen.refarch.s3' scope. + * Instance of a {@link FileService} containing supported file extensions configured within in the 'de.muenchen.refarch.s3' scope. * * @return {@link FileService} for managing file extensions. */ From 3b2c63523264724671f872875bc3fb2f3af35993 Mon Sep 17 00:00:00 2001 From: Simon Hirtreiter Date: Mon, 12 Aug 2024 09:04:09 +0200 Subject: [PATCH 5/5] :art: s3-integration format --- .../configuration/S3IntegrationClientAutoConfiguration.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java index 4a2f97da..645abe6c 100644 --- a/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java +++ b/refarch-integrations/refarch-s3-integration/refarch-s3-integration-client-starter/src/main/java/de/muenchen/refarch/integration/s3/client/configuration/S3IntegrationClientAutoConfiguration.java @@ -82,7 +82,8 @@ public FileService fileService(final SupportedFileExtensions supportedFileExtens } /** - * Instance of a {@link FileService} containing supported file extensions configured within in the 'de.muenchen.refarch.s3' scope. + * Instance of a {@link FileService} containing supported file extensions configured within in the + * 'de.muenchen.refarch.s3' scope. * * @return {@link FileService} for managing file extensions. */