Skip to content

Commit

Permalink
Message config models
Browse files Browse the repository at this point in the history
  • Loading branch information
pavetok committed Oct 21, 2023
1 parent 870d258 commit 605523e
Show file tree
Hide file tree
Showing 66 changed files with 274 additions and 318 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package smecalculus.bezmen.construction;

import static smecalculus.bezmen.configuration.MessageMappingMode.SPRING_MVC;
import static smecalculus.bezmen.configuration.StateMappingMode.MY_BATIS;
import static smecalculus.bezmen.configuration.StateMappingMode.SPRING_DATA;
import static smecalculus.bezmen.configuration.MessagingMappingMode.SPRING_MVC;
import static smecalculus.bezmen.configuration.StorageMappingMode.MY_BATIS;
import static smecalculus.bezmen.configuration.StorageMappingMode.SPRING_DATA;

import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import java.util.List;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import smecalculus.bezmen.core.ClientSide.PreviewRequest;
import smecalculus.bezmen.core.ClientSide.PreviewResponse;
import smecalculus.bezmen.core.ClientSide.RegistrationRequest;
import smecalculus.bezmen.core.ClientSide.RegistrationResponse;
import smecalculus.bezmen.core.MessageDomain.PreviewRequest;
import smecalculus.bezmen.core.MessageDomain.PreviewResponse;
import smecalculus.bezmen.core.MessageDomain.RegistrationRequest;
import smecalculus.bezmen.core.MessageDomain.RegistrationResponse;
import smecalculus.bezmen.storage.SepulkaDao;

@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import smecalculus.bezmen.core.SepulkaService;
import smecalculus.bezmen.messaging.EdgeSide.RegistrationRequest;
import smecalculus.bezmen.messaging.EdgeSide.RegistrationResponse;
import smecalculus.bezmen.messaging.MessageEdge.RegistrationRequest;
import smecalculus.bezmen.messaging.MessageEdge.RegistrationResponse;
import smecalculus.bezmen.validation.EdgeValidator;

@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import smecalculus.bezmen.messaging.EdgeSide.RegistrationRequest;
import smecalculus.bezmen.messaging.EdgeSide.RegistrationResponse;
import smecalculus.bezmen.messaging.MessageEdge.RegistrationRequest;
import smecalculus.bezmen.messaging.MessageEdge.RegistrationResponse;
import smecalculus.bezmen.messaging.SepulkaClient;

@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import java.util.Optional;
import java.util.UUID;
import smecalculus.bezmen.core.ServerSide.AggregateState;
import smecalculus.bezmen.core.ServerSide.ExistenceState;
import smecalculus.bezmen.core.ServerSide.PreviewState;
import smecalculus.bezmen.core.ServerSide.TouchState;
import smecalculus.bezmen.core.StateDomain.AggregateState;
import smecalculus.bezmen.core.StateDomain.ExistenceState;
import smecalculus.bezmen.core.StateDomain.PreviewState;
import smecalculus.bezmen.core.StateDomain.TouchState;

/**
* Port: server side
*/
public interface SepulkaDao {

AggregateState add(AggregateState state);

Optional<ExistenceState> getBy(String externalId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import java.util.UUID;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import smecalculus.bezmen.core.ServerSide.AggregateState;
import smecalculus.bezmen.core.ServerSide.ExistenceState;
import smecalculus.bezmen.core.ServerSide.PreviewState;
import smecalculus.bezmen.core.ServerSide.TouchState;
import smecalculus.bezmen.core.StateDomain.AggregateState;
import smecalculus.bezmen.core.StateDomain.ExistenceState;
import smecalculus.bezmen.core.StateDomain.PreviewState;
import smecalculus.bezmen.core.StateDomain.TouchState;
import smecalculus.bezmen.storage.mybatis.SepulkaSqlMapper;

@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.UUID;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import smecalculus.bezmen.core.ServerSide;
import smecalculus.bezmen.core.StateDomain;
import smecalculus.bezmen.storage.springdata.SepulkaRepository;

@RequiredArgsConstructor
Expand All @@ -17,27 +17,27 @@ public class SepulkaDaoSpringData implements SepulkaDao {
private SepulkaRepository repository;

@Override
public ServerSide.AggregateState add(@NonNull ServerSide.AggregateState state) {
public StateDomain.AggregateState add(@NonNull StateDomain.AggregateState state) {
var stateEdge = repository.save(mapper.toEdge(state));
return mapper.toDomain(stateEdge);
}

@Override
public Optional<ServerSide.ExistenceState> getBy(@NonNull String externalId) {
public Optional<StateDomain.ExistenceState> getBy(@NonNull String externalId) {
return repository
.findByExternalId(externalId, EdgeSide.ExistenceState.class)
.findByExternalId(externalId, StateEdge.ExistenceState.class)
.map(mapper::toDomain);
}

@Override
public Optional<ServerSide.PreviewState> getBy(@NonNull UUID internalId) {
public Optional<StateDomain.PreviewState> getBy(@NonNull UUID internalId) {
return repository
.findByInternalId(internalId.toString(), EdgeSide.PreviewState.class)
.findByInternalId(internalId.toString(), StateEdge.PreviewState.class)
.map(mapper::toDomain);
}

@Override
public void updateBy(ServerSide.TouchState state, UUID internalId) {
public void updateBy(StateDomain.TouchState state, UUID internalId) {
var stateEdge = mapper.toEdge(state);
var matchedCount = repository.updateBy(stateEdge, internalId.toString());
if (matchedCount == 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package smecalculus.bezmen.storage;

import org.mapstruct.Mapper;
import smecalculus.bezmen.core.ServerSide;
import smecalculus.bezmen.core.StateDomain;
import smecalculus.bezmen.mapping.EdgeMapper;

@Mapper
public interface SepulkaStateMapper extends EdgeMapper {
EdgeSide.AggregateState toEdge(ServerSide.AggregateState state);
StateEdge.AggregateState toEdge(StateDomain.AggregateState state);

ServerSide.AggregateState toDomain(EdgeSide.AggregateState state);
StateDomain.AggregateState toDomain(StateEdge.AggregateState state);

EdgeSide.TouchState toEdge(ServerSide.TouchState state);
StateEdge.TouchState toEdge(StateDomain.TouchState state);

ServerSide.ExistenceState toDomain(EdgeSide.ExistenceState state);
StateDomain.ExistenceState toDomain(StateEdge.ExistenceState state);

EdgeSide.PreviewState toEdge(ServerSide.PreviewState state);
StateEdge.PreviewState toEdge(StateDomain.PreviewState state);

ServerSide.PreviewState toDomain(EdgeSide.PreviewState state);
StateDomain.PreviewState toDomain(StateEdge.PreviewState state);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;

public abstract class EdgeSide {

public abstract class StateEdge {
@Data
public static class ExistenceState {
UUID internalId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import smecalculus.bezmen.storage.EdgeSide.AggregateState;
import smecalculus.bezmen.storage.EdgeSide.ExistenceState;
import smecalculus.bezmen.storage.EdgeSide.PreviewState;
import smecalculus.bezmen.storage.EdgeSide.TouchState;
import smecalculus.bezmen.storage.StateEdge.AggregateState;
import smecalculus.bezmen.storage.StateEdge.ExistenceState;
import smecalculus.bezmen.storage.StateEdge.PreviewState;
import smecalculus.bezmen.storage.StateEdge.TouchState;

public interface SepulkaSqlMapper {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.lang.Nullable;
import smecalculus.bezmen.storage.EdgeSide.AggregateState;
import smecalculus.bezmen.storage.EdgeSide.TouchState;
import smecalculus.bezmen.storage.StateEdge.AggregateState;
import smecalculus.bezmen.storage.StateEdge.TouchState;

public interface SepulkaRepository extends CrudRepository<AggregateState, String> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.ServerSide.StorageProps;
import smecalculus.bezmen.configuration.StorageDomain.StorageProps;
import smecalculus.bezmen.storage.SepulkaDao;
import smecalculus.bezmen.storage.SepulkaDaoMyBatis;
import smecalculus.bezmen.storage.SepulkaDaoSpringData;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
package smecalculus.bezmen.construction;

import static smecalculus.bezmen.configuration.StateMappingMode.MY_BATIS;
import static smecalculus.bezmen.configuration.StateMappingMode.SPRING_DATA;
import static smecalculus.bezmen.configuration.StorageMappingMode.MY_BATIS;
import static smecalculus.bezmen.configuration.StorageMappingMode.SPRING_DATA;
import static smecalculus.bezmen.configuration.StorageProtocolMode.H2;
import static smecalculus.bezmen.configuration.StorageProtocolMode.POSTGRES;

import org.springframework.context.annotation.Bean;
import smecalculus.bezmen.configuration.ServerSide.StorageProps;
import smecalculus.bezmen.configuration.ServerSideEg;
import smecalculus.bezmen.configuration.StorageDomain.StorageProps;
import smecalculus.bezmen.configuration.StorageDomainEg;

public class StoragePropsBeans {

public static class SpringDataPostgres {
@Bean
public StorageProps storageProps() {
return ServerSideEg.storageProps(SPRING_DATA, POSTGRES).build();
return StorageDomainEg.storageProps(SPRING_DATA, POSTGRES).build();
}
}

public static class SpringDataH2 {
@Bean
public StorageProps storageProps() {
return ServerSideEg.storageProps(SPRING_DATA, H2).build();
return StorageDomainEg.storageProps(SPRING_DATA, H2).build();
}
}

public static class MyBatisPostgres {
@Bean
public StorageProps storageProps() {
return ServerSideEg.storageProps(MY_BATIS, POSTGRES).build();
return StorageDomainEg.storageProps(MY_BATIS, POSTGRES).build();
}
}

public static class MyBatisH2 {
@Bean
public StorageProps storageProps() {
return ServerSideEg.storageProps(MY_BATIS, H2).build();
return StorageDomainEg.storageProps(MY_BATIS, H2).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import smecalculus.bezmen.construction.SepulkaClientBeans;
import smecalculus.bezmen.core.ClientSide.RegistrationRequest;
import smecalculus.bezmen.core.ClientSideEg;
import smecalculus.bezmen.core.MessageDomain.RegistrationRequest;
import smecalculus.bezmen.core.MessageDomainEg;
import smecalculus.bezmen.core.SepulkaService;

@ExtendWith(SpringExtension.class)
Expand All @@ -30,12 +30,12 @@ void shouldRegisterSepulka() {
// given
var externalId = UUID.randomUUID().toString();
// and
var request = EdgeSideEg.registrationRequest(externalId);
var request = MessageEdgeEg.registrationRequest(externalId);
// and
when(serviceMock.register(any(RegistrationRequest.class)))
.thenReturn(ClientSideEg.registrationResponse(externalId).build());
.thenReturn(MessageDomainEg.registrationResponse(externalId).build());
// and
var expectedResponse = EdgeSideEg.registrationResponse(externalId);
var expectedResponse = MessageEdgeEg.registrationResponse(externalId);
// when
var actualResponse = externalClient.register(request);
// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import smecalculus.bezmen.construction.SepulkaDaoBeans;
import smecalculus.bezmen.core.ServerSideEg;
import smecalculus.bezmen.core.StateDomainEg;

@DirtiesContext
@ExtendWith(SpringExtension.class)
Expand All @@ -24,10 +24,10 @@ abstract class SepulkaDaoIT {
@Test
void shouldAddOneSepulka() {
// given
var expected1 = ServerSideEg.aggregateState().build();
var expected1 = StateDomainEg.aggregateState().build();
// and
var expected2 =
ServerSideEg.creationState().internalId(expected1.internalId()).build();
StateDomainEg.creationState().internalId(expected1.internalId()).build();
// when
var actualSaved = sepulkaDao.add(expected1);
// and
Expand All @@ -41,11 +41,11 @@ void shouldAddOneSepulka() {
@Test
void shouldViewOneSepulka() {
// given
var aggregate = ServerSideEg.aggregateState().build();
var aggregate = StateDomainEg.aggregateState().build();
// and
sepulkaDao.add(aggregate);
// and
var expected = ServerSideEg.previewState(aggregate).build();
var expected = StateDomainEg.previewState(aggregate).build();
// when
var actual = sepulkaDao.getBy(aggregate.internalId());
// then
Expand All @@ -55,13 +55,13 @@ void shouldViewOneSepulka() {
@Test
void shouldUpdateOneSepulka() {
// given
var aggregate = ServerSideEg.aggregateState().build();
var aggregate = StateDomainEg.aggregateState().build();
// and
sepulkaDao.add(aggregate);
// and
var updatedAt = aggregate.updatedAt().plusSeconds(1);
// and
var touch = ServerSideEg.touchState(aggregate).updatedAt(updatedAt).build();
var touch = StateDomainEg.touchState(aggregate).updatedAt(updatedAt).build();
// when
sepulkaDao.updateBy(touch, aggregate.internalId());
// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import jakarta.validation.constraints.Size;
import lombok.Data;

public class EdgeSide {

public abstract class MessageEdge {
@Data
public static class RegistrationRequest {
@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package smecalculus.bezmen.messaging;

import java.util.UUID;
import smecalculus.bezmen.messaging.EdgeSide.RegistrationRequest;
import smecalculus.bezmen.messaging.EdgeSide.RegistrationResponse;

public class EdgeSideEg {
import smecalculus.bezmen.messaging.MessageEdge.RegistrationRequest;
import smecalculus.bezmen.messaging.MessageEdge.RegistrationResponse;

public abstract class MessageEdgeEg {
public static RegistrationRequest registrationRequest() {
var requestEdge = new RegistrationRequest();
requestEdge.setExternalId(UUID.randomUUID().toString());
Expand All @@ -19,12 +18,12 @@ public static RegistrationRequest registrationRequest(String id) {
}

public static RegistrationResponse registrationResponse() {
var responseEdge = new EdgeSide.RegistrationResponse();
var responseEdge = new RegistrationResponse();
responseEdge.setExternalId(UUID.randomUUID().toString());
return responseEdge;
}

public static EdgeSide.RegistrationResponse registrationResponse(String externalId) {
public static RegistrationResponse registrationResponse(String externalId) {
var responseEdge = registrationResponse();
responseEdge.setExternalId(externalId);
return responseEdge;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package smecalculus.bezmen.messaging;

import smecalculus.bezmen.messaging.EdgeSide.RegistrationRequest;
import smecalculus.bezmen.messaging.EdgeSide.RegistrationResponse;
import smecalculus.bezmen.messaging.MessageEdge.RegistrationRequest;
import smecalculus.bezmen.messaging.MessageEdge.RegistrationResponse;

/**
* Port: client side
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import lombok.Builder;
import lombok.NonNull;

public class ClientSide {

public class MessageDomain {
@Builder
public record RegistrationRequest(@NonNull String externalId) {}

Expand Down
Loading

0 comments on commit 605523e

Please sign in to comment.