From 870d258e6d7aa6d664c4c9cdeee42395914262c8 Mon Sep 17 00:00:00 2001 From: Pavel Vetokhin Date: Sat, 21 Oct 2023 14:55:12 +0300 Subject: [PATCH] Storage config models --- .../smecalculus/bezmen/construction/App.java | 10 +-- .../bezmen/core/SepulkaServiceImpl.java | 2 +- .../bezmen/construction/SepulkaDaoBeans.java | 2 +- .../construction/StoragePropsBeans.java | 12 ++-- ...lkaSliceMapper.java => SepulkaMapper.java} | 2 +- .../bezmen/configuration/EdgeSide.java | 68 +++++++++++++++++++ .../bezmen/configuration/EdgeSideEg.java | 30 ++++++++ .../bezmen/configuration/H2Props.java | 8 --- .../bezmen/configuration/H2PropsEdge.java | 17 ----- .../bezmen/configuration/PostgresProps.java | 9 --- .../configuration/PostgresPropsEdge.java | 19 ------ .../bezmen/configuration/ServerSide.java | 25 +++++++ .../bezmen/configuration/ServerSideEg.java | 51 ++++++++++++++ .../configuration/StateMappingProps.java | 7 -- .../configuration/StateMappingPropsEdge.java | 11 --- .../configuration/StateMappingPropsEg.java | 23 ------- .../bezmen/configuration/StorageProps.java | 7 -- .../configuration/StoragePropsEdge.java | 14 ---- .../bezmen/configuration/StoragePropsEg.java | 31 --------- .../configuration/StoragePropsMapper.java | 6 +- .../configuration/StorageProtocolProps.java | 8 --- .../StorageProtocolPropsEdge.java | 18 ----- .../configuration/StorageProtocolPropsEg.java | 32 --------- .../construction/MappingSpringDataBeans.java | 2 +- .../StateMappingModeCondition.java | 2 +- .../bezmen/construction/StorageBeans.java | 6 +- .../construction/StorageConfigBeans.java | 8 +-- .../construction/StorageConfigBeansIT.java | 4 +- .../construction/StorageConfigBeansTest.java | 8 +-- .../postgres/sepulkarium/owner/sepulkas.sql | 4 +- 30 files changed, 208 insertions(+), 238 deletions(-) rename libs/abstraction/src/main/java/smecalculus/bezmen/core/{SepulkaSliceMapper.java => SepulkaMapper.java} (91%) create mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/EdgeSide.java create mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/EdgeSideEg.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/H2Props.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/H2PropsEdge.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresProps.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresPropsEdge.java create mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/ServerSide.java create mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/ServerSideEg.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingProps.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEdge.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEg.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProps.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEdge.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEg.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolProps.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEdge.java delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEg.java diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/construction/App.java b/apps/sepuling/src/main/java/smecalculus/bezmen/construction/App.java index b17288d6..1955d18b 100644 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/construction/App.java +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/construction/App.java @@ -9,10 +9,10 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.PropertySource; +import smecalculus.bezmen.core.SepulkaMapper; +import smecalculus.bezmen.core.SepulkaMapperImpl; import smecalculus.bezmen.core.SepulkaService; import smecalculus.bezmen.core.SepulkaServiceImpl; -import smecalculus.bezmen.core.SepulkaSliceMapper; -import smecalculus.bezmen.core.SepulkaSliceMapperImpl; import smecalculus.bezmen.messaging.SepulkaClient; import smecalculus.bezmen.messaging.SepulkaClientImpl; import smecalculus.bezmen.messaging.SepulkaMessageMapper; @@ -53,12 +53,12 @@ SepulkaClient sepulkaClient(EdgeValidator validator, SepulkaMessageMapper mapper } @Bean - SepulkaSliceMapper sepulkaSliceMapper() { - return new SepulkaSliceMapperImpl(); + SepulkaMapper sepulkaMapper() { + return new SepulkaMapperImpl(); } @Bean - SepulkaService sepulkaService(SepulkaSliceMapper mapper, SepulkaDao dao) { + SepulkaService sepulkaService(SepulkaMapper mapper, SepulkaDao dao) { return new SepulkaServiceImpl(mapper, dao); } diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/core/SepulkaServiceImpl.java b/apps/sepuling/src/main/java/smecalculus/bezmen/core/SepulkaServiceImpl.java index 496df4e4..7eb3e05b 100644 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/core/SepulkaServiceImpl.java +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/core/SepulkaServiceImpl.java @@ -17,7 +17,7 @@ public class SepulkaServiceImpl implements SepulkaService { @NonNull - private SepulkaSliceMapper mapper; + private SepulkaMapper mapper; @NonNull private SepulkaDao dao; diff --git a/apps/sepuling/src/test/java/smecalculus/bezmen/construction/SepulkaDaoBeans.java b/apps/sepuling/src/test/java/smecalculus/bezmen/construction/SepulkaDaoBeans.java index be47a817..7078360b 100644 --- a/apps/sepuling/src/test/java/smecalculus/bezmen/construction/SepulkaDaoBeans.java +++ b/apps/sepuling/src/test/java/smecalculus/bezmen/construction/SepulkaDaoBeans.java @@ -10,7 +10,7 @@ import org.springframework.context.annotation.Import; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; -import smecalculus.bezmen.configuration.StorageProps; +import smecalculus.bezmen.configuration.ServerSide.StorageProps; import smecalculus.bezmen.storage.SepulkaDao; import smecalculus.bezmen.storage.SepulkaDaoMyBatis; import smecalculus.bezmen.storage.SepulkaDaoSpringData; diff --git a/apps/sepuling/src/test/java/smecalculus/bezmen/construction/StoragePropsBeans.java b/apps/sepuling/src/test/java/smecalculus/bezmen/construction/StoragePropsBeans.java index 7a35cf3f..4eeb1f5d 100644 --- a/apps/sepuling/src/test/java/smecalculus/bezmen/construction/StoragePropsBeans.java +++ b/apps/sepuling/src/test/java/smecalculus/bezmen/construction/StoragePropsBeans.java @@ -6,36 +6,36 @@ import static smecalculus.bezmen.configuration.StorageProtocolMode.POSTGRES; import org.springframework.context.annotation.Bean; -import smecalculus.bezmen.configuration.StorageProps; -import smecalculus.bezmen.configuration.StoragePropsEg; +import smecalculus.bezmen.configuration.ServerSide.StorageProps; +import smecalculus.bezmen.configuration.ServerSideEg; public class StoragePropsBeans { public static class SpringDataPostgres { @Bean public StorageProps storageProps() { - return StoragePropsEg.storageProps(SPRING_DATA, POSTGRES).build(); + return ServerSideEg.storageProps(SPRING_DATA, POSTGRES).build(); } } public static class SpringDataH2 { @Bean public StorageProps storageProps() { - return StoragePropsEg.storageProps(SPRING_DATA, H2).build(); + return ServerSideEg.storageProps(SPRING_DATA, H2).build(); } } public static class MyBatisPostgres { @Bean public StorageProps storageProps() { - return StoragePropsEg.storageProps(MY_BATIS, POSTGRES).build(); + return ServerSideEg.storageProps(MY_BATIS, POSTGRES).build(); } } public static class MyBatisH2 { @Bean public StorageProps storageProps() { - return StoragePropsEg.storageProps(MY_BATIS, H2).build(); + return ServerSideEg.storageProps(MY_BATIS, H2).build(); } } } diff --git a/libs/abstraction/src/main/java/smecalculus/bezmen/core/SepulkaSliceMapper.java b/libs/abstraction/src/main/java/smecalculus/bezmen/core/SepulkaMapper.java similarity index 91% rename from libs/abstraction/src/main/java/smecalculus/bezmen/core/SepulkaSliceMapper.java rename to libs/abstraction/src/main/java/smecalculus/bezmen/core/SepulkaMapper.java index 2b15f84f..39cea092 100644 --- a/libs/abstraction/src/main/java/smecalculus/bezmen/core/SepulkaSliceMapper.java +++ b/libs/abstraction/src/main/java/smecalculus/bezmen/core/SepulkaMapper.java @@ -6,7 +6,7 @@ import smecalculus.bezmen.core.ServerSide.AggregateState; @Mapper -public interface SepulkaSliceMapper { +public interface SepulkaMapper { AggregateState.Builder toServer(RegistrationRequest request); RegistrationResponse.Builder toClient(AggregateState state); diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/EdgeSide.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/EdgeSide.java new file mode 100644 index 00000000..dde8c8d8 --- /dev/null +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/EdgeSide.java @@ -0,0 +1,68 @@ +package smecalculus.bezmen.configuration; + +import com.typesafe.config.Optional; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import lombok.ToString; +import smecalculus.bezmen.validation.ValueOfEnum; + +public abstract class EdgeSide { + + @Data + public static class StorageProps { + + @NotNull + StorageProtocolProps protocol; + + @NotNull + StateMappingProps mapping; + } + + @Data + public static class StorageProtocolProps { + + @ValueOfEnum(StorageProtocolMode.class) + String mode; + + @Optional + H2Props h2; + + @Optional + PostgresProps postgres; + } + + @Data + public static class StateMappingProps { + + @ValueOfEnum(StateMappingMode.class) + private String mode; + } + + @Data + public static class PostgresProps { + + @NotBlank + String url; + + @NotBlank + String username; + + @NotBlank + @ToString.Exclude + String password; + } + + @Data + public static class H2Props { + + @NotBlank + String url; + + @NotBlank + String username; + + @NotBlank + String password; + } +} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/EdgeSideEg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/EdgeSideEg.java new file mode 100644 index 00000000..5ca4f12f --- /dev/null +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/EdgeSideEg.java @@ -0,0 +1,30 @@ +package smecalculus.bezmen.configuration; + +import static smecalculus.bezmen.configuration.StateMappingMode.SPRING_DATA; +import static smecalculus.bezmen.configuration.StorageProtocolMode.H2; + +import smecalculus.bezmen.configuration.EdgeSide.StateMappingProps; +import smecalculus.bezmen.configuration.EdgeSide.StorageProps; +import smecalculus.bezmen.configuration.EdgeSide.StorageProtocolProps; + +public abstract class EdgeSideEg { + + public static StorageProps storageProps() { + var propsEdge = new StorageProps(); + propsEdge.setMapping(stateMappingProps()); + propsEdge.setProtocol(storageProtocolProps()); + return propsEdge; + } + + public static StateMappingProps stateMappingProps() { + var propsEdge = new StateMappingProps(); + propsEdge.setMode(SPRING_DATA.name()); + return propsEdge; + } + + public static StorageProtocolProps storageProtocolProps() { + var propsEdge = new StorageProtocolProps(); + propsEdge.setMode(H2.name()); + return propsEdge; + } +} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/H2Props.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/H2Props.java deleted file mode 100644 index a16d6945..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/H2Props.java +++ /dev/null @@ -1,8 +0,0 @@ -package smecalculus.bezmen.configuration; - -import lombok.Builder; -import lombok.NonNull; -import lombok.ToString; - -@Builder -public record H2Props(@NonNull String url, @NonNull String username, @NonNull @ToString.Exclude String password) {} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/H2PropsEdge.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/H2PropsEdge.java deleted file mode 100644 index 0a3e4ff7..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/H2PropsEdge.java +++ /dev/null @@ -1,17 +0,0 @@ -package smecalculus.bezmen.configuration; - -import jakarta.validation.constraints.NotBlank; -import lombok.Data; - -@Data -public class H2PropsEdge { - - @NotBlank - String url; - - @NotBlank - String username; - - @NotBlank - String password; -} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresProps.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresProps.java deleted file mode 100644 index b80f1901..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresProps.java +++ /dev/null @@ -1,9 +0,0 @@ -package smecalculus.bezmen.configuration; - -import lombok.Builder; -import lombok.NonNull; -import lombok.ToString; - -@Builder -public record PostgresProps( - @NonNull String url, @NonNull String username, @NonNull @ToString.Exclude String password) {} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresPropsEdge.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresPropsEdge.java deleted file mode 100644 index 65a3ff2a..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresPropsEdge.java +++ /dev/null @@ -1,19 +0,0 @@ -package smecalculus.bezmen.configuration; - -import jakarta.validation.constraints.NotBlank; -import lombok.Data; -import lombok.ToString; - -@Data -public class PostgresPropsEdge { - - @NotBlank - String url; - - @NotBlank - String username; - - @NotBlank - @ToString.Exclude - String password; -} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/ServerSide.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/ServerSide.java new file mode 100644 index 00000000..bb97e4ce --- /dev/null +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/ServerSide.java @@ -0,0 +1,25 @@ +package smecalculus.bezmen.configuration; + +import lombok.Builder; +import lombok.NonNull; +import lombok.ToString; + +public abstract class ServerSide { + + @Builder + public record StorageProps(@NonNull StorageProtocolProps protocolProps, @NonNull StateMappingProps mappingProps) {} + + @Builder + public record StorageProtocolProps( + @NonNull StorageProtocolMode protocolMode, H2Props h2Props, PostgresProps postgresProps) {} + + @Builder + public record StateMappingProps(@NonNull StateMappingMode mappingMode) {} + + @Builder + public record H2Props(@NonNull String url, @NonNull String username, @NonNull String password) {} + + @Builder + public record PostgresProps( + @NonNull String url, @NonNull String username, @NonNull @ToString.Exclude String password) {} +} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/ServerSideEg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/ServerSideEg.java new file mode 100644 index 00000000..42c5e35e --- /dev/null +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/ServerSideEg.java @@ -0,0 +1,51 @@ +package smecalculus.bezmen.configuration; + +import static smecalculus.bezmen.configuration.StateMappingMode.SPRING_DATA; +import static smecalculus.bezmen.configuration.StorageProtocolMode.H2; + +import smecalculus.bezmen.configuration.ServerSide.H2Props; +import smecalculus.bezmen.configuration.ServerSide.PostgresProps; +import smecalculus.bezmen.configuration.ServerSide.StateMappingProps; +import smecalculus.bezmen.configuration.ServerSide.StorageProps; +import smecalculus.bezmen.configuration.ServerSide.StorageProtocolProps; + +public abstract class ServerSideEg { + public static StorageProps.Builder storageProps() { + return StorageProps.builder() + .protocolProps(storageProtocolProps().build()) + .mappingProps(stateMappingProps().build()); + } + + public static StorageProps.Builder storageProps(StateMappingMode mappingMode, StorageProtocolMode protocolMode) { + return storageProps() + .protocolProps(storageProtocolProps(protocolMode).build()) + .mappingProps(stateMappingProps(mappingMode).build()); + } + + public static StateMappingProps.Builder stateMappingProps() { + return StateMappingProps.builder().mappingMode(SPRING_DATA); + } + + public static StateMappingProps.Builder stateMappingProps(StateMappingMode mode) { + return stateMappingProps().mappingMode(mode); + } + + public static StorageProtocolProps.Builder storageProtocolProps() { + return StorageProtocolProps.builder() + .protocolMode(H2) + .h2Props(H2Props.builder() + .url("jdbc:h2:mem:bezmen;DB_CLOSE_DELAY=-1") + .username("sa") + .password("sa") + .build()) + .postgresProps(PostgresProps.builder() + .url("jdbc:postgresql://localhost:5432/bezmen") + .username("bezmen") + .password("bezmen") + .build()); + } + + public static StorageProtocolProps.Builder storageProtocolProps(StorageProtocolMode mode) { + return storageProtocolProps().protocolMode(mode); + } +} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingProps.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingProps.java deleted file mode 100644 index a54b9cf8..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingProps.java +++ /dev/null @@ -1,7 +0,0 @@ -package smecalculus.bezmen.configuration; - -import lombok.Builder; -import lombok.NonNull; - -@Builder -public record StateMappingProps(@NonNull StateMappingMode mappingMode) {} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEdge.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEdge.java deleted file mode 100644 index ace84796..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEdge.java +++ /dev/null @@ -1,11 +0,0 @@ -package smecalculus.bezmen.configuration; - -import lombok.Data; -import smecalculus.bezmen.validation.ValueOfEnum; - -@Data -public class StateMappingPropsEdge { - - @ValueOfEnum(StateMappingMode.class) - private String mode; -} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEg.java deleted file mode 100644 index 6d1b712c..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEg.java +++ /dev/null @@ -1,23 +0,0 @@ -package smecalculus.bezmen.configuration; - -import static smecalculus.bezmen.configuration.StateMappingMode.SPRING_DATA; - -public class StateMappingPropsEg { - public static class Pojos { - public static StateMappingPropsEdge stateMappingPropsEdge() { - var propsEdge = new StateMappingPropsEdge(); - propsEdge.setMode(SPRING_DATA.name()); - return propsEdge; - } - } - - public static class Builders { - public static StateMappingProps.Builder stateMappingProps() { - return StateMappingProps.builder().mappingMode(SPRING_DATA); - } - - public static StateMappingProps.Builder stateMappingProps(StateMappingMode mode) { - return stateMappingProps().mappingMode(mode); - } - } -} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProps.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProps.java deleted file mode 100644 index d5b13b05..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProps.java +++ /dev/null @@ -1,7 +0,0 @@ -package smecalculus.bezmen.configuration; - -import lombok.Builder; -import lombok.NonNull; - -@Builder -public record StorageProps(@NonNull StorageProtocolProps protocolProps, @NonNull StateMappingProps mappingProps) {} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEdge.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEdge.java deleted file mode 100644 index 0a7f6626..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEdge.java +++ /dev/null @@ -1,14 +0,0 @@ -package smecalculus.bezmen.configuration; - -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -@Data -public class StoragePropsEdge { - - @NotNull - StorageProtocolPropsEdge protocol; - - @NotNull - StateMappingPropsEdge mapping; -} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEg.java deleted file mode 100644 index cd48ed64..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEg.java +++ /dev/null @@ -1,31 +0,0 @@ -package smecalculus.bezmen.configuration; - -import static smecalculus.bezmen.configuration.StateMappingPropsEg.Builders.stateMappingProps; -import static smecalculus.bezmen.configuration.StateMappingPropsEg.Pojos.stateMappingPropsEdge; -import static smecalculus.bezmen.configuration.StorageProtocolPropsEg.Builders.storageProtocolProps; -import static smecalculus.bezmen.configuration.StorageProtocolPropsEg.Pojos.storageProtocolPropsEdge; - -public class StoragePropsEg { - public static class Pojos { - public static StoragePropsEdge storagePropsEdge() { - var propsEdge = new StoragePropsEdge(); - propsEdge.setProtocol(storageProtocolPropsEdge()); - propsEdge.setMapping(stateMappingPropsEdge()); - return propsEdge; - } - } - - public static class Builders { - public static StorageProps.Builder storageProps() { - return StorageProps.builder() - .protocolProps(storageProtocolProps().build()) - .mappingProps(stateMappingProps().build()); - } - } - - public static StorageProps.Builder storageProps(StateMappingMode mappingMode, StorageProtocolMode protocolMode) { - return Builders.storageProps() - .protocolProps(storageProtocolProps(protocolMode).build()) - .mappingProps(stateMappingProps(mappingMode).build()); - } -} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsMapper.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsMapper.java index e56d61ac..416025e8 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsMapper.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsMapper.java @@ -9,15 +9,15 @@ public interface StoragePropsMapper extends EdgeMapper { @Mapping(source = "protocol", target = "protocolProps") @Mapping(source = "mapping", target = "mappingProps") - StorageProps toDomain(StoragePropsEdge propsEdge); + ServerSide.StorageProps toServer(EdgeSide.StorageProps propsEdge); @Mapping(source = "mode", target = "protocolMode") @Mapping(source = "h2", target = "h2Props") @Mapping(source = "postgres", target = "postgresProps") - StorageProtocolProps toDomain(StorageProtocolPropsEdge propsEdge); + ServerSide.StorageProtocolProps toServer(EdgeSide.StorageProtocolProps propsEdge); @Mapping(source = "mode", target = "mappingMode") - StateMappingProps toDomain(StateMappingPropsEdge propsEdge); + ServerSide.StateMappingProps toServer(EdgeSide.StateMappingProps propsEdge); default StorageProtocolMode toProtocolMode(String mode) { return StorageProtocolMode.valueOf(mode.toUpperCase()); diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolProps.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolProps.java deleted file mode 100644 index f4b6c40b..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolProps.java +++ /dev/null @@ -1,8 +0,0 @@ -package smecalculus.bezmen.configuration; - -import lombok.Builder; -import lombok.NonNull; - -@Builder -public record StorageProtocolProps( - @NonNull StorageProtocolMode protocolMode, H2Props h2Props, PostgresProps postgresProps) {} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEdge.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEdge.java deleted file mode 100644 index 1ba82b09..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEdge.java +++ /dev/null @@ -1,18 +0,0 @@ -package smecalculus.bezmen.configuration; - -import com.typesafe.config.Optional; -import lombok.Data; -import smecalculus.bezmen.validation.ValueOfEnum; - -@Data -public class StorageProtocolPropsEdge { - - @ValueOfEnum(StorageProtocolMode.class) - String mode; - - @Optional - H2PropsEdge h2; - - @Optional - PostgresPropsEdge postgres; -} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEg.java deleted file mode 100644 index 43aeaf79..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEg.java +++ /dev/null @@ -1,32 +0,0 @@ -package smecalculus.bezmen.configuration; - -public class StorageProtocolPropsEg { - public static class Pojos { - public static StorageProtocolPropsEdge storageProtocolPropsEdge() { - var propsEdge = new StorageProtocolPropsEdge(); - propsEdge.setMode(StorageProtocolMode.H2.name()); - return propsEdge; - } - } - - public static class Builders { - public static StorageProtocolProps.Builder storageProtocolProps() { - return StorageProtocolProps.builder() - .protocolMode(StorageProtocolMode.H2) - .h2Props(H2Props.builder() - .url("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1") - .username("sa") - .password("sa") - .build()) - .postgresProps(PostgresProps.builder() - .url("jdbc:postgresql://localhost:5432/bezmen") - .username("bezmen") - .password("bezmen") - .build()); - } - - public static StorageProtocolProps.Builder storageProtocolProps(StorageProtocolMode mode) { - return storageProtocolProps().protocolMode(mode); - } - } -} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingSpringDataBeans.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingSpringDataBeans.java index 674f9e97..cd914f41 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingSpringDataBeans.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingSpringDataBeans.java @@ -21,7 +21,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.transaction.PlatformTransactionManager; -import smecalculus.bezmen.configuration.StorageProps; +import smecalculus.bezmen.configuration.ServerSide.StorageProps; @ConditionalOnStateMappingMode(SPRING_DATA) @EnableJdbcRepositories("smecalculus.bezmen.storage.springdata") diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/StateMappingModeCondition.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/StateMappingModeCondition.java index 669192d3..fb5eb11a 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/StateMappingModeCondition.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/StateMappingModeCondition.java @@ -6,8 +6,8 @@ import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.ConfigurationCondition; import org.springframework.core.type.AnnotatedTypeMetadata; +import smecalculus.bezmen.configuration.ServerSide.StorageProps; import smecalculus.bezmen.configuration.StateMappingMode; -import smecalculus.bezmen.configuration.StorageProps; class StateMappingModeCondition implements ConfigurationCondition { diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageBeans.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageBeans.java index 0f6cdb5a..7759da8b 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageBeans.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageBeans.java @@ -5,9 +5,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.jdbc.datasource.DriverManagerDataSource; -import smecalculus.bezmen.configuration.H2Props; -import smecalculus.bezmen.configuration.PostgresProps; -import smecalculus.bezmen.configuration.StorageProps; +import smecalculus.bezmen.configuration.ServerSide.H2Props; +import smecalculus.bezmen.configuration.ServerSide.PostgresProps; +import smecalculus.bezmen.configuration.ServerSide.StorageProps; @Import({StorageConfigBeans.class, MappingMyBatisBeans.class, MappingSpringDataBeans.class}) @Configuration(proxyBeanMethods = false) diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java index b5b97f7b..09610c59 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java @@ -5,9 +5,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; +import smecalculus.bezmen.configuration.EdgeSide; import smecalculus.bezmen.configuration.PropsKeeper; -import smecalculus.bezmen.configuration.StorageProps; -import smecalculus.bezmen.configuration.StoragePropsEdge; +import smecalculus.bezmen.configuration.ServerSide.StorageProps; import smecalculus.bezmen.configuration.StoragePropsMapper; import smecalculus.bezmen.configuration.StoragePropsMapperImpl; import smecalculus.bezmen.validation.EdgeValidator; @@ -25,9 +25,9 @@ StoragePropsMapper storagePropsMapper() { @Bean StorageProps storageProps(PropsKeeper keeper, EdgeValidator validator, StoragePropsMapper mapper) { - var propsEdge = keeper.read("bezmen.storage", StoragePropsEdge.class); + var propsEdge = keeper.read("bezmen.storage", EdgeSide.StorageProps.class); validator.validate(propsEdge); LOG.info("Read {}", propsEdge); - return mapper.toDomain(propsEdge); + return mapper.toServer(propsEdge); } } diff --git a/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansIT.java b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansIT.java index 62de9f65..f5018437 100644 --- a/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansIT.java +++ b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansIT.java @@ -1,14 +1,14 @@ package smecalculus.bezmen.construction; import static org.assertj.core.api.Assertions.assertThat; -import static smecalculus.bezmen.configuration.StoragePropsEg.Builders.storageProps; +import static smecalculus.bezmen.configuration.ServerSideEg.storageProps; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; -import smecalculus.bezmen.configuration.StorageProps; +import smecalculus.bezmen.configuration.ServerSide.StorageProps; @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {StorageConfigBeans.class, ConfigBeans.class, ValidationBeans.class}) diff --git a/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java index 3651f064..652d4b23 100644 --- a/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java +++ b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java @@ -3,12 +3,12 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static smecalculus.bezmen.configuration.StoragePropsEg.Pojos.storagePropsEdge; +import static smecalculus.bezmen.configuration.EdgeSideEg.storageProps; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import smecalculus.bezmen.configuration.EdgeSide.StorageProps; import smecalculus.bezmen.configuration.PropsKeeper; -import smecalculus.bezmen.configuration.StoragePropsEdge; import smecalculus.bezmen.configuration.StoragePropsMapper; import smecalculus.bezmen.configuration.StoragePropsMapperImpl; import smecalculus.bezmen.validation.EdgeValidator; @@ -29,9 +29,9 @@ void setUp() { @Test void shouldValidateConf() { // given - StoragePropsEdge expectedProps = storagePropsEdge(); + StorageProps expectedProps = storageProps(); // and - when(keeperMock.read("bezmen.storage", StoragePropsEdge.class)).thenReturn(expectedProps); + when(keeperMock.read("bezmen.storage", StorageProps.class)).thenReturn(expectedProps); // when config.storageProps(keeperMock, validatorMock, mapper); // then diff --git a/schemas/postgres/sepulkarium/owner/sepulkas.sql b/schemas/postgres/sepulkarium/owner/sepulkas.sql index 7293d961..46138426 100644 --- a/schemas/postgres/sepulkarium/owner/sepulkas.sql +++ b/schemas/postgres/sepulkarium/owner/sepulkas.sql @@ -2,6 +2,6 @@ CREATE TABLE sepulkas ( internal_id uuid UNIQUE, external_id character varying (64) UNIQUE, revision integer, - created_at TIMESTAMP (6), - updated_at TIMESTAMP (6) + created_at timestamp (6), + updated_at timestamp (6) );