diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java index c10e3ddd4..46dd0c2af 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java @@ -174,6 +174,7 @@ public class FineractProperties { @Setter public static class FineractContentFilesystemProperties { + private Boolean enabled; private String rootFolder; } @@ -181,6 +182,7 @@ public class FineractProperties { @Setter public static class FineractContentS3Properties { + private Boolean enabled; private String bucketName; private String accessKey; private String secretKey; diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/contentrepository/ContentRepositoryFactory.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/contentrepository/ContentRepositoryFactory.java index 5c8fa8f90..b17803e02 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/contentrepository/ContentRepositoryFactory.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/contentrepository/ContentRepositoryFactory.java @@ -20,7 +20,7 @@ package org.apache.fineract.infrastructure.documentmanagement.contentrepository; import java.util.List; import lombok.RequiredArgsConstructor; -import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; +import org.apache.fineract.infrastructure.core.config.FineractProperties; import org.apache.fineract.infrastructure.documentmanagement.domain.StorageType; import org.springframework.stereotype.Component; @@ -28,18 +28,26 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class ContentRepositoryFactory { - // TODO: all configuration should be really moved to application.properties - private final ConfigurationDomainService configurationService; + private final FineractProperties fineractProperties; private final List contentRepositories; public ContentRepository getRepository() { - if (configurationService.isAmazonS3Enabled()) { - return getRepository(StorageType.S3); + if (fineractProperties.getContent() != null) { + if (fineractProperties.getContent().getFilesystem() != null + && Boolean.TRUE.equals(fineractProperties.getContent().getFilesystem().getEnabled())) { + return getRepository(StorageType.FILE_SYSTEM); + } else if (fineractProperties.getContent().getS3() != null + && Boolean.TRUE.equals(fineractProperties.getContent().getS3().getEnabled())) { + return getRepository(StorageType.S3); + } } - return getRepository(StorageType.FILE_SYSTEM); + + throw new RuntimeException( + "No content repository enabled. Please set either 'fineract.content.filesystem.enabled=true' or 'fineract.content.s3.enabled=true' in your application.properties."); } public ContentRepository getRepository(StorageType storageType) { - return contentRepositories.stream().filter(cr -> cr.getStorageType().equals(storageType)).findFirst().orElseThrow(); + return contentRepositories.stream().filter(cr -> cr.getStorageType().equals(storageType)).findFirst().orElseThrow( + () -> new RuntimeException(String.format("No content repository implementation found for storage type: %s", storageType))); } }