Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: poc mongo #274

Draft
wants to merge 10 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<module>queen-domain-pilotage</module>
<module>queen-infra-pilotage</module>
<module>queen-infra-depositproof</module>
<module>queen-infra-mongo</module>
</modules>

<dependencies>
Expand Down
35 changes: 21 additions & 14 deletions queen-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<guava.version>33.3.1-jre</guava.version>
<json-schema-validator.version>1.5.3</json-schema-validator.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
Expand All @@ -46,6 +47,20 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-database-spring-test</artifactId>
<version>${zonky-spring.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-postgres</artifactId>
<version>${zonky-postgres.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>fr.insee.queen</groupId>
<artifactId>queen-domain-depositproof</artifactId>
Expand All @@ -70,6 +85,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>fr.insee.queen</groupId>
<artifactId>queen-infra-mongo</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -95,20 +116,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-database-spring-test</artifactId>
<version>${zonky-spring.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-postgres</artifactId>
<version>${zonky-postgres.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

import fr.insee.queen.application.PropertiesLogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.event.EventListener;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;


@SpringBootApplication(scanBasePackages = "fr.insee.queen")
@Configuration
@ComponentScan(excludeFilters = {
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "fr.insee.queen.infrastructure.mongo.*"),
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "fr.insee.queen.infrastructure.db.*")
}
)
@EnableAutoConfiguration
@EnableTransactionManagement
@ConfigurationPropertiesScan
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fr.insee.queen.application.configuration.db;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@ConditionalOnProperty(name = "feature.mongo.enabled", havingValue = "false")
@EnableTransactionManagement
@ComponentScan(basePackages = {"fr.insee.queen.infrastructure.db"})
@EnableJpaRepositories(basePackages = {"fr.insee.queen.infrastructure.db"})
@Slf4j
public class JpaConfiguration {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package fr.insee.queen.application.configuration.db;

import com.mongodb.ReadConcern;
import com.mongodb.ReadPreference;
import com.mongodb.TransactionOptions;
import com.mongodb.WriteConcern;
import fr.insee.queen.domain.campaign.gateway.CampaignRepository;
import fr.insee.queen.domain.campaign.gateway.NomenclatureRepository;
import fr.insee.queen.domain.campaign.gateway.QuestionnaireModelRepository;
import fr.insee.queen.domain.paradata.gateway.ParadataEventRepository;
import fr.insee.queen.domain.surveyunit.gateway.StateDataRepository;
import fr.insee.queen.domain.surveyunit.gateway.SurveyUnitRepository;
import fr.insee.queen.domain.surveyunittempzone.gateway.SurveyUnitTempZoneRepository;
import fr.insee.queen.infrastructure.mongo.paradata.dao.ParadataEventMongoDao;
import fr.insee.queen.infrastructure.mongo.questionnaire.dao.CampaignMongoDao;
import fr.insee.queen.infrastructure.mongo.questionnaire.dao.NomenclatureMongoDao;
import fr.insee.queen.infrastructure.mongo.questionnaire.dao.QuestionnaireModelMongoDao;
import fr.insee.queen.infrastructure.mongo.surveyunit.dao.StateDataMongoDao;
import fr.insee.queen.infrastructure.mongo.surveyunit.dao.SurveyUnitMongoDao;
import fr.insee.queen.infrastructure.mongo.surveyunittempzone.dao.SurveyUnitTempZoneMongoDao;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.*;
import org.springframework.data.mongodb.MongoTransactionManager;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@ConditionalOnProperty(name = "feature.mongo.enabled", havingValue = "true")
@ComponentScan(basePackages = {"fr.insee.queen.infrastructure.mongo"})
@EnableMongoRepositories(basePackages = {"fr.insee.queen.infrastructure.mongo"})
@EnableTransactionManagement
@RequiredArgsConstructor
@Slf4j
public class MongoConfiguration {

private final ParadataEventMongoDao paradataEventMongoDao;
private final CampaignMongoDao campaignMongoDao;
private final QuestionnaireModelMongoDao questionnaireModelDao;
private final NomenclatureMongoDao nomenclatureMongoDao;
private final SurveyUnitMongoDao surveyUnitMongoDao;
private final StateDataMongoDao stateDataMongoDao;
private final SurveyUnitTempZoneMongoDao surveyUnitTempZoneMongoDao;

@Bean
public MongoTransactionManager transactionManager(MongoTemplate mongoTemplate) {
TransactionOptions transactionalOptions = TransactionOptions.builder()
.readConcern(ReadConcern.MAJORITY)
.readPreference(ReadPreference.primary())
.writeConcern(WriteConcern.MAJORITY.withJournal(true))
.build();
return new MongoTransactionManager(mongoTemplate.getMongoDatabaseFactory(), transactionalOptions);
}

@Bean
@Primary
public ParadataEventRepository paradataEventRepository() {
return paradataEventMongoDao;
}

@Bean
@Primary
public CampaignRepository campaignRepository() {
return campaignMongoDao;
}

@Bean
@Primary
public QuestionnaireModelRepository questionnaireModelRepository() {
return questionnaireModelDao;
}

@Bean
@Primary
public NomenclatureRepository nomenclatureRepository() {
return nomenclatureMongoDao;
}

@Bean
@Primary
public SurveyUnitRepository surveyUnitRepository() {
return surveyUnitMongoDao;
}

@Bean
@Primary
public StateDataRepository stateDataRepository() {
return stateDataMongoDao;
}

@Bean
@Primary
public SurveyUnitTempZoneRepository surveyUnitTempZoneRepository() {
return surveyUnitTempZoneMongoDao;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import fr.insee.queen.domain.pilotage.service.exception.PilotageApiException;
import fr.insee.queen.domain.surveyunit.service.exception.MetadataValueNotFoundException;
import fr.insee.queen.domain.surveyunit.service.exception.StateDataInvalidDateException;
import fr.insee.queen.infrastructure.db.surveyunit.repository.exception.UpdateCollectedDataException;
import fr.insee.queen.domain.surveyunit.service.exception.UpdateCollectedDataException;
import fr.insee.queen.infrastructure.depositproof.exception.DepositProofException;
import jakarta.validation.ConstraintViolationException;
import lombok.RequiredArgsConstructor;
Expand Down
118 changes: 118 additions & 0 deletions queen-application/src/main/resources/application.mongo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
application:
public-urls:
- /swagger-ui/**
- /v3/api-docs/**
- /v3/*.json
- /api/healthcheck
- /
roles:
interviewer:
reviewer:
admin:
webclient:
reviewer-alternative:
survey-unit:
corsOrigins:
# Folder where to store temp files.
# DO NOT USE THE DEFAULT TEMP DIRECTORY OF THE OS as it adresses some vulnerabilities.
# Use a folder with permissions for the app only
temp-folder:

feature:
oidc:
enabled: true
auth-server-host: https://auth-server.host
auth-server-url: ${feature.oidc.auth-server-host}/auth
client-id: my-client-id
realm: my-realm
principal-attribute: id-claim
role-claim:
dataset:
# create demo dataset on startup
load-on-start: false
# display api endpoint to create dataset
display-endpoint: false
swagger:
enabled: false
pilotage:
enabled: true
url:
alternative-habilitation:
url: http://alternative.url
campaignids-regex: ((edt)|(EDT))(\d|\S){1,}
cache:
enabled: true
comments:
enabled: false
interviewer-mode:
enabled: false
mongo:
enabled: true

spring:
jpa:
enabled: false
data:
mongodb:
host:
port:
database:
replica-set-name:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: ${feature.oidc.auth-server-url}/realms/${feature.oidc.realm}
liquibase:
enabled: false
profiles:
group:
cache-testing: test,test-cache
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
- org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration

mongock:
enabled: true
transaction-enabled: true
migration-scan-package:
- fr.insee.queen.infrastructure.mongo.configuration.migration.changelog
- fr.insee.queen.infrastructure.mongo.configuration.migration.data

springdoc:
swagger-ui:
oauth:
client-id: ${feature.oidc.client-id}
# /!\ when injecting this property from env var, cannot convert KCIDPHINT env var to kc_idp_hint otherwise
# This property is a hint for spring-boot to map the env var to this property
additionalQueryStringParams:
kc_idp_hint: my-idp
path: /
syntax-highlight:
activated: false
tagsSorter: alpha
doc-expansion: none
api-docs:
version: OPENAPI_3_1
#Actuator Metrics
management:
endpoints:
enabled-by-default: false
web:
discovery:
enabled: false
logging:
appender: console
level:
root: INFO
fr:
insee:
queen: INFO
pattern:
console: "%d{YYYY-MM-dd HH:mm:ss.SSS} [%X{id}][%X{user}][%X{method} %X{path}] [%thread] %-5level %logger{36} - %htmlEncode{%m}%n"
file: ${logging.pattern.console}
logback:
rollingpolicy:
max-history: 90
10 changes: 8 additions & 2 deletions queen-application/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ feature:
enabled: false
interviewer-mode:
enabled: false
mongo:
enabled: false

spring:
main:
allow-bean-definition-overriding: true
datasource:
url:
username:
Expand Down Expand Up @@ -89,6 +89,11 @@ spring:
profiles:
group:
cache-testing: test,test-cache
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration
- org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration
- org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration

springdoc:
swagger-ui:
Expand All @@ -113,6 +118,7 @@ management:
discovery:
enabled: false
logging:
appender: ROLLING_FILE # ROLLING_FILE | CONSOLE
level:
root: INFO
fr:
Expand Down
Loading
Loading