-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added emd citizen first implementation
- Loading branch information
1 parent
17a5cc5
commit c5cb94d
Showing
29 changed files
with
552 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/it/gov/pagopa/common/configuration/CustomReactiveMongoHealthIndicator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package it.gov.pagopa.common.configuration; | ||
|
||
import org.bson.Document; | ||
import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate; | ||
import org.springframework.util.Assert; | ||
import reactor.core.publisher.Mono; | ||
|
||
public class CustomReactiveMongoHealthIndicator extends AbstractReactiveHealthIndicator { | ||
|
||
private final ReactiveMongoTemplate reactiveMongoTemplate; | ||
|
||
public CustomReactiveMongoHealthIndicator(ReactiveMongoTemplate reactiveMongoTemplate) { | ||
super("Mongo health check failed"); | ||
Assert.notNull(reactiveMongoTemplate, "ReactiveMongoTemplate must not be null"); | ||
this.reactiveMongoTemplate = reactiveMongoTemplate; | ||
} | ||
|
||
@Override | ||
protected Mono<Health> doHealthCheck(Health.Builder builder) { | ||
Mono<Document> buildInfo = this.reactiveMongoTemplate.executeCommand("{ isMaster: 1 }"); | ||
return buildInfo.map(document -> builderUp(builder, document)); | ||
} | ||
private Health builderUp(Health.Builder builder, Document document) { | ||
return builder.up().withDetail("maxWireVersion", document.getInteger("maxWireVersion")).build(); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
src/main/java/it/gov/pagopa/common/configuration/MongoConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package it.gov.pagopa.common.configuration; | ||
|
||
import com.mongodb.lang.NonNull; | ||
import it.gov.pagopa.common.utils.CommonConstants; | ||
import lombok.Setter; | ||
import org.bson.types.Decimal128; | ||
import org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCustomizer; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.data.convert.ReadingConverter; | ||
import org.springframework.data.convert.WritingConverter; | ||
import org.springframework.data.mongodb.core.convert.MongoCustomConversions; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.OffsetDateTime; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Configuration | ||
public class MongoConfig { | ||
|
||
@Configuration | ||
@ConfigurationProperties(prefix = "spring.data.mongodb.config") | ||
public static class MongoDbCustomProperties { | ||
@Setter | ||
ConnectionPoolSettings connectionPool; | ||
|
||
@Setter | ||
static class ConnectionPoolSettings { | ||
int maxSize; | ||
int minSize; | ||
long maxWaitTimeMS; | ||
long maxConnectionLifeTimeMS; | ||
long maxConnectionIdleTimeMS; | ||
int maxConnecting; | ||
} | ||
|
||
} | ||
|
||
@Bean | ||
public MongoClientSettingsBuilderCustomizer customizer(MongoDbCustomProperties mongoDbCustomProperties) { | ||
return builder -> builder.applyToConnectionPoolSettings( | ||
connectionPool -> { | ||
connectionPool.maxSize(mongoDbCustomProperties.connectionPool.maxSize); | ||
connectionPool.minSize(mongoDbCustomProperties.connectionPool.minSize); | ||
connectionPool.maxWaitTime(mongoDbCustomProperties.connectionPool.maxWaitTimeMS, TimeUnit.MILLISECONDS); | ||
connectionPool.maxConnectionLifeTime(mongoDbCustomProperties.connectionPool.maxConnectionLifeTimeMS, TimeUnit.MILLISECONDS); | ||
connectionPool.maxConnectionIdleTime(mongoDbCustomProperties.connectionPool.maxConnectionIdleTimeMS, TimeUnit.MILLISECONDS); | ||
connectionPool.maxConnecting(mongoDbCustomProperties.connectionPool.maxConnecting); | ||
}); | ||
} | ||
|
||
@Bean | ||
public MongoCustomConversions mongoCustomConversions() { | ||
return new MongoCustomConversions(Arrays.asList( | ||
// BigDecimal support | ||
new BigDecimalDecimal128Converter(), | ||
new Decimal128BigDecimalConverter(), | ||
|
||
// OffsetDateTime support | ||
new OffsetDateTimeWriteConverter(), | ||
new OffsetDateTimeReadConverter() | ||
)); | ||
} | ||
|
||
@WritingConverter | ||
private static class BigDecimalDecimal128Converter implements Converter<BigDecimal, Decimal128> { | ||
|
||
@Override | ||
public Decimal128 convert(@NonNull BigDecimal source) { | ||
return new Decimal128(source); | ||
} | ||
} | ||
|
||
@ReadingConverter | ||
private static class Decimal128BigDecimalConverter implements Converter<Decimal128, BigDecimal> { | ||
|
||
@Override | ||
public BigDecimal convert(@NonNull Decimal128 source) { | ||
return source.bigDecimalValue(); | ||
} | ||
|
||
} | ||
|
||
@WritingConverter | ||
public static class OffsetDateTimeWriteConverter implements Converter<OffsetDateTime, Date> { | ||
@Override | ||
public Date convert(OffsetDateTime offsetDateTime) { | ||
return Date.from(offsetDateTime.toInstant()); | ||
} | ||
} | ||
|
||
@ReadingConverter | ||
public static class OffsetDateTimeReadConverter implements Converter<Date, OffsetDateTime> { | ||
@Override | ||
public OffsetDateTime convert(Date date) { | ||
return date.toInstant().atZone(CommonConstants.ZONEID).toOffsetDateTime(); | ||
} | ||
} | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
src/main/java/it/gov/pagopa/common/configuration/MongoHealthConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package it.gov.pagopa.common.configuration; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate; | ||
|
||
@Configuration | ||
public class MongoHealthConfig { | ||
@Bean | ||
public CustomReactiveMongoHealthIndicator customMongoHealthIndicator(ReactiveMongoTemplate reactiveMongoTemplate) { | ||
return new CustomReactiveMongoHealthIndicator(reactiveMongoTemplate); | ||
} | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
src/main/java/it/gov/pagopa/common/utils/CommonConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package it.gov.pagopa.common.utils; | ||
|
||
import java.time.ZoneId; | ||
|
||
public class CommonConstants { | ||
|
||
|
||
public static final class ExceptionCode { | ||
public static final String GENERIC_ERROR = "GENERIC_ERROR"; | ||
private ExceptionCode() {} | ||
} | ||
|
||
public static final ZoneId ZONEID = ZoneId.of("Europe/Rome"); | ||
|
||
private CommonConstants(){} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...eption/custom/EmdEncryptionException.java → ...web/exception/EmdEncryptionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.