From ed87e00548d2c89b704d5c9572d78d522514012b Mon Sep 17 00:00:00 2001 From: Vincenzo Ingenito Date: Mon, 2 Oct 2023 21:24:02 +0200 Subject: [PATCH] feat: Update props --- .../config/mongo/MongoDatabaseCFG.java | 24 +++++++++++++++---- .../config/mongo/MongoPropertiesDataCFG.java | 3 +++ src/main/resources/application-dev.properties | 1 + src/main/resources/application.properties | 1 + .../resources/application-test.properties | 2 ++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/config/mongo/MongoDatabaseCFG.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/config/mongo/MongoDatabaseCFG.java index a2478ae..a43297a 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/config/mongo/MongoDatabaseCFG.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/config/mongo/MongoDatabaseCFG.java @@ -29,6 +29,10 @@ import org.springframework.data.mongodb.core.convert.MappingMongoConverter; import org.springframework.data.mongodb.core.mapping.MongoMappingContext; +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; +import com.mongodb.client.MongoClients; + import net.javacrumbs.shedlock.core.LockProvider; import net.javacrumbs.shedlock.provider.mongo.MongoLockProvider; @@ -55,19 +59,31 @@ public class MongoDatabaseCFG { @Primary @Qualifier("mongo-factory-data") public MongoDatabaseFactory mongoDatabaseFactoryData() { - return new SimpleMongoClientDatabaseFactory(mongoData.getUri()); + ConnectionString connectionString = new ConnectionString(mongoData.getUri()); + MongoClientSettings mongoClientSettings = MongoClientSettings.builder() + .applyConnectionString(connectionString) + .build(); + return new SimpleMongoClientDatabaseFactory(MongoClients.create(mongoClientSettings), mongoData.getSchemaName()); } @Bean @Qualifier("mongo-factory-transaction") public MongoDatabaseFactory mongoDatabaseFactoryTransactions() { - return new SimpleMongoClientDatabaseFactory(mongoTransactions.getUri()); + ConnectionString connectionString = new ConnectionString(mongoTransactions.getUri()); + MongoClientSettings mongoClientSettings = MongoClientSettings.builder() + .applyConnectionString(connectionString) + .build(); + return new SimpleMongoClientDatabaseFactory(MongoClients.create(mongoClientSettings), mongoData.getSchemaName()); } @Bean @Qualifier("mongo-factory-valdoc") public MongoDatabaseFactory mongoDatabaseFactoryFse() { - return new SimpleMongoClientDatabaseFactory(mongoFse.getUri()); + ConnectionString connectionString = new ConnectionString(mongoFse.getUri()); + MongoClientSettings mongoClientSettings = MongoClientSettings.builder() + .applyConnectionString(connectionString) + .build(); + return new SimpleMongoClientDatabaseFactory(MongoClients.create(mongoClientSettings), mongoData.getSchemaName()); } @Bean @@ -79,7 +95,7 @@ public MongoTemplate mongoTemplateData() { } @Bean -// @Primary + // @Primary @Qualifier("mongo-template-transaction") public MongoTemplate mongoTemplateTransactions() { final MongoDatabaseFactory factory = mongoDatabaseFactoryTransactions(); diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/config/mongo/MongoPropertiesDataCFG.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/config/mongo/MongoPropertiesDataCFG.java index 5c664fb..3243091 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/config/mongo/MongoPropertiesDataCFG.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/config/mongo/MongoPropertiesDataCFG.java @@ -27,5 +27,8 @@ public class MongoPropertiesDataCFG { @Value("${data.mongodb.uri}") private String uri; + + @Value("${data.mongodb.schema-name}") + private String schemaName; } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 0706ffa..0f0d25d 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -8,6 +8,7 @@ data.mongodb.uri=mongodb://mongoadmin:secret@localhost:27888/fse transactions.mongodb.uri=mongodb://mongoadmin:secret@localhost:27888/fse valdoc.mongodb.uri=mongodb://mongoadmin:secret@localhost:27888/fse rules.mongodb.uri=mongodb://mongoadmin:secret@localhost:27888/fse +data.mongodb.schema-name=FSE_GTW ####################################### # DATA RETENTION RULES diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ec1f7c3..e492ef2 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -41,6 +41,7 @@ data.mongodb.uri=- transactions.mongodb.uri=- valdoc.mongodb.uri=- rules.mongodb.uri=- +data.mongodb.schema-name=${MONGO_DBNAME} ####################################### # DATA RETENTION RULES diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 950cd4b..2e174bd 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -7,6 +7,8 @@ management.server.port=8019 data.mongodb.uri=mongodb://mongoadmin:secret@localhost:27888/fse transactions.mongodb.uri=mongodb://mongoadmin:secret@localhost:27888/fse valdoc.mongodb.uri=mongodb://mongoadmin:secret@localhost:27888/fse +data.mongodb.schema-name=FSE_GTW + ####################################### # DATA RETENTION RULES #######################################