FINERACT-1834: Remove dependency on configuration service from content repository factory
This commit is contained in:
committed by
Arnold Gálovics
parent
69c25c282b
commit
4d5dce0309
+2
@@ -174,6 +174,7 @@ public class FineractProperties {
|
|||||||
@Setter
|
@Setter
|
||||||
public static class FineractContentFilesystemProperties {
|
public static class FineractContentFilesystemProperties {
|
||||||
|
|
||||||
|
private Boolean enabled;
|
||||||
private String rootFolder;
|
private String rootFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +182,7 @@ public class FineractProperties {
|
|||||||
@Setter
|
@Setter
|
||||||
public static class FineractContentS3Properties {
|
public static class FineractContentS3Properties {
|
||||||
|
|
||||||
|
private Boolean enabled;
|
||||||
private String bucketName;
|
private String bucketName;
|
||||||
private String accessKey;
|
private String accessKey;
|
||||||
private String secretKey;
|
private String secretKey;
|
||||||
|
|||||||
+15
-7
@@ -20,7 +20,7 @@ package org.apache.fineract.infrastructure.documentmanagement.contentrepository;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
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.apache.fineract.infrastructure.documentmanagement.domain.StorageType;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -28,18 +28,26 @@ import org.springframework.stereotype.Component;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ContentRepositoryFactory {
|
public class ContentRepositoryFactory {
|
||||||
|
|
||||||
// TODO: all configuration should be really moved to application.properties
|
private final FineractProperties fineractProperties;
|
||||||
private final ConfigurationDomainService configurationService;
|
|
||||||
private final List<ContentRepository> contentRepositories;
|
private final List<ContentRepository> contentRepositories;
|
||||||
|
|
||||||
public ContentRepository getRepository() {
|
public ContentRepository getRepository() {
|
||||||
if (configurationService.isAmazonS3Enabled()) {
|
if (fineractProperties.getContent() != null) {
|
||||||
return getRepository(StorageType.S3);
|
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) {
|
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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user