Compare commits

..

No commits in common. "main" and "0.9.0" have entirely different histories.
main ... 0.9.0

12 changed files with 124 additions and 62 deletions

1
.gitignore vendored
View File

@ -40,4 +40,3 @@ gradle/
**/.gradle
**/build
.DS_Store

View File

@ -18,5 +18,4 @@ deploy:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_BRANCH =~ /^release/
- if: $CI_COMMIT_BRANCH =~ /^feature/
- if: $CI_COMMIT_TAG

View File

@ -1,6 +1,7 @@
plugins {
`java-library`
`maven-publish`
`kotlin-dsl`
pmd
checkstyle
jacoco
@ -24,11 +25,10 @@ repositories {
val springBootVersion = "3.1.5"
dependencies {
api("com.knecon.fforesight:tenant-commons:0.31.0")
api("org.liquibase:liquibase-core:4.29.2")
api("org.liquibase.ext:liquibase-mongodb:4.29.2")
api("com.knecon.fforesight:tenant-commons:0.24.0")
api("org.liquibase:liquibase-core:4.20.0")
api("org.liquibase.ext:liquibase-mongodb:4.20.0")
api("org.springframework.boot:spring-boot-starter-data-mongodb:${springBootVersion}")
api("org.springframework.boot:spring-boot-starter-validation:${springBootVersion}")
api("org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}")
api("org.projectlombok:lombok:1.18.28")
runtimeOnly("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
@ -83,7 +83,7 @@ tasks.named<Test>("test") {
sonarqube {
properties {
providers.gradleProperty("sonarToken").getOrNull()?.let { property("sonar.login", it) }
property("sonar.login", providers.gradleProperty("sonarToken").getOrNull())
property("sonar.host.url", "https://sonarqube.knecon.com")
}
}
@ -103,4 +103,4 @@ tasks.jacocoTestReport {
java {
withJavadocJar()
}
}

View File

@ -0,0 +1,59 @@
package com.knecon.fforesight.mongo.database.commons;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import com.knecon.fforesight.mongo.database.commons.liquibase.EnableMongoLiquibaseCondition;
import lombok.RequiredArgsConstructor;
@Configuration
@RequiredArgsConstructor
@Conditional(EnableMongoLiquibaseCondition.class)
public class MongoTenantMessagingConfiguration {
@Value("${fforesight.mongo.multitenancy.tenant-created-queue:mongo-tenant-created}")
private String mongoTenantCreatedEventQueue;
@Value("${fforesight.mongo.multitenancy.tenant-created-dlq:mongo-tenant-created-dlq}")
private String mongoTenantCreatedDLQ;
@Bean(name = "mongoTenantExchange")
TopicExchange mongoTenantExchange(@Value("${fforesight.tenant-exchange.name:tenants-exchange}") String tenantExchangeName) {
return new TopicExchange(tenantExchangeName);
}
@Bean("persistenceServiceMongoTenantCreatedQueue")
public Queue persistenceServiceMongoTenantCreatedQueue() {
return QueueBuilder.durable(mongoTenantCreatedEventQueue)
.withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", mongoTenantCreatedDLQ).build();
}
@Bean("persistenceServiceMongoTenantDLQ")
public Queue persistenceServiceMongoTenantDLQ() {
return QueueBuilder.durable(mongoTenantCreatedDLQ).build();
}
@Bean("mongoTenantExchangeBinding")
public Binding mongoTenantExchangeBinding(@Qualifier("persistenceServiceMongoTenantCreatedQueue") Queue persistenceServiceTenantCreatedQueue,
@Qualifier("mongoTenantExchange") TopicExchange tenantExchange) {
return BindingBuilder.bind(persistenceServiceTenantCreatedQueue).to(tenantExchange).with("tenant.created");
}
}

View File

@ -1,20 +1,15 @@
package com.knecon.fforesight.mongo.database.commons.config;
import java.util.List;
import java.util.concurrent.TimeUnit;
import jakarta.validation.constraints.NotNull;
import org.bson.Document;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.conversions.Bson;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
import com.knecon.fforesight.mongo.database.commons.service.MongoDataSources;
import com.mongodb.ClientSessionOptions;
import com.mongodb.ReadConcern;
import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
import com.mongodb.client.ChangeStreamIterable;
import com.mongodb.client.ClientSession;
import com.mongodb.client.ListDatabasesIterable;
@ -45,7 +40,6 @@ public class MultiTenantMongoDBFactory extends SimpleMongoClientDatabaseFactory
private static MongoClient getBootstrapMongoClient() {
return new MongoClient() {
@Override
public MongoDatabase getDatabase(String s) {

View File

@ -2,12 +2,11 @@ package com.knecon.fforesight.mongo.database.commons.liquibase;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import jakarta.validation.constraints.NotNull;
public class EnableMongoLiquibaseCondition implements Condition {
@Override

View File

@ -23,7 +23,7 @@ public class MongoLiquibaseConfig {
@Bean
public TenantMongoLiquibaseExecutor tenantMongoLiquibaseExecutor(EncryptionDecryptionService encryptionService,
public TenantMongoLiquibaseExecutor tenantLiquibase(EncryptionDecryptionService encryptionService,
TenantProvider tenantProvider,
@Qualifier("tenantMongoLiquibaseProperties") LiquibaseProperties mongoLiquibaseProperties) {

View File

@ -0,0 +1,14 @@
package com.knecon.fforesight.mongo.database.commons.liquibase;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MongoTenantCreatedEvent {
private String tenantId;
}

View File

@ -0,0 +1,39 @@
package com.knecon.fforesight.mongo.database.commons.liquibase;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Service;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
@RequiredArgsConstructor
@Conditional(EnableMongoLiquibaseCondition.class)
public class MongoTenantCreatedListener {
private final TenantMongoLiquibaseExecutor tenantMongoLiquibaseExecutor;
@Value("${fforesight.multitenancy.mongo.tenant-created-queue:mongo-tenant-created}")
private String tenantCreatedQueue;
@PostConstruct
public void postConstruct() {
log.info("Listener for tenant-created started for queue: {}", tenantCreatedQueue);
}
@SneakyThrows
@RabbitListener(queues = "${fforesight.multitenancy.mongo.tenant-created-queue:mongo-tenant-created}")
public void createTenant(MongoTenantCreatedEvent tenantRequest) {
tenantMongoLiquibaseExecutor.initializeTenant(tenantRequest.getTenantId());
}
}

View File

@ -1,33 +0,0 @@
package com.knecon.fforesight.mongo.database.commons.liquibase;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Service;
import com.knecon.fforesight.tenantcommons.listener.ITenantEventHandler;
import com.knecon.fforesight.tenantcommons.model.TenantCreatedEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
@RequiredArgsConstructor
@Conditional(EnableMongoLiquibaseCondition.class)
public class TenantCreatedMongoEventHandler implements ITenantEventHandler<TenantCreatedEvent> {
private final TenantMongoLiquibaseExecutor tenantMongoLiquibaseExecutor;
@Override
public void handle(TenantCreatedEvent tenantCreatedEvent) {
tenantMongoLiquibaseExecutor.initializeTenant(tenantCreatedEvent.getTenantId());
}
@Override
public Class<TenantCreatedEvent> getEventClass() {
return TenantCreatedEvent.class;
}
}

View File

@ -1,8 +1,6 @@
package com.knecon.fforesight.mongo.database.commons.liquibase;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
@ -98,12 +96,6 @@ public class TenantMongoLiquibaseExecutor implements InitializingBean, ResourceL
liquibase.setChangeLog(tenantMongoLiquibaseProperties.getChangeLog());
liquibase.setContexts(tenantMongoLiquibaseProperties.getContexts());
liquibase.setClearCheckSums(tenantMongoLiquibaseProperties.isClearChecksums());
String databaseName = database.getConnection().getCatalog(); // or getDatabaseName() depending on your implementation
Map<String, String> changeLogParameters = new HashMap<>();
changeLogParameters.put("databaseName", databaseName);
liquibase.setChangeLogParameters(changeLogParameters);
liquibase.afterPropertiesSet();
}

View File

@ -2,6 +2,7 @@ package com.knecon.fforesight.mongo.database.commons.service;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@ -15,7 +16,6 @@ import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import jakarta.annotation.PostConstruct;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
@ -43,7 +43,7 @@ public class MongoClientCache {
var mongoDBConnection = mongoConnectionProvider.getMongoDBConnection(key);
if (mongoDBConnection != null) {
return new MongoClientConnection(mongoDBConnection.getDatabase(), buildMongoClient(mongoDBConnection));
return new MongoClientConnection(key, buildMongoClient(mongoDBConnection));
}
throw new RuntimeException("No Connection provided");
}
@ -70,4 +70,4 @@ public class MongoClientCache {
return clients.get(tenantId);
}
}
}