You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ar...@apache.org on 2022/12/15 22:20:29 UTC

[fineract] branch develop updated: FINERACT-1834: Remove dependency on configuration service from content repository factory

This is an automated email from the ASF dual-hosted git repository.

arnold pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 4d5dce030 FINERACT-1834: Remove dependency on configuration service from content repository factory
4d5dce030 is described below

commit 4d5dce030917c5885b3becb23eda3042c8d030ac
Author: Aleks <al...@apache.org>
AuthorDate: Wed Dec 14 04:48:05 2022 +0100

    FINERACT-1834: Remove dependency on configuration service from content repository factory
---
 .../core/config/FineractProperties.java            |  2 ++
 .../ContentRepositoryFactory.java                  | 22 +++++++++++++++-------
 2 files changed, 17 insertions(+), 7 deletions(-)

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<ContentRepository> 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)));
     }
 }