Skip to content

Commit

Permalink
Config models (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavetok authored Oct 21, 2023
1 parent 0c82dde commit 64c4f60
Show file tree
Hide file tree
Showing 87 changed files with 476 additions and 540 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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.MessagingDm.MappingMode.SPRING_MVC;
import static smecalculus.bezmen.configuration.StorageDm.MappingMode.MY_BATIS;
import static smecalculus.bezmen.configuration.StorageDm.MappingMode.SPRING_DATA;

import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Bean;
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;
Expand All @@ -37,7 +37,7 @@ public static void main(String[] args) {
}

@Bean
@ConditionalOnMessageMappingModes(SPRING_MVC)
@ConditionalOnMessagingMappingModes(SPRING_MVC)
SepulkaController sepulkaControllerSpringMvc(SepulkaClient client) {
return new SepulkaController(client);
}
Expand All @@ -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);
}

Expand All @@ -68,13 +68,13 @@ SepulkaStateMapper sepulkaStateMapper() {
}

@Bean
@ConditionalOnStateMappingMode(SPRING_DATA)
@ConditionalOnStorageMappingMode(SPRING_DATA)
SepulkaDaoSpringData sepulkaDaoSpringData(SepulkaStateMapper mapper, SepulkaRepository repository) {
return new SepulkaDaoSpringData(mapper, repository);
}

@Bean
@ConditionalOnStateMappingMode(MY_BATIS)
@ConditionalOnStorageMappingMode(MY_BATIS)
SepulkaDaoMyBatis sepulkaDaoMyBatis(SepulkaStateMapper recMapper, SepulkaSqlMapper sqlMapper) {
return new SepulkaDaoMyBatis(recMapper, sqlMapper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@
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.MessageDm.PreviewRequest;
import smecalculus.bezmen.core.MessageDm.PreviewResponse;
import smecalculus.bezmen.core.MessageDm.RegistrationRequest;
import smecalculus.bezmen.core.MessageDm.RegistrationResponse;
import smecalculus.bezmen.storage.SepulkaDao;

@RequiredArgsConstructor
public class SepulkaServiceImpl implements SepulkaService {

@NonNull
private SepulkaSliceMapper mapper;
private SepulkaMapper mapper;

@NonNull
private SepulkaDao dao;

@Override
public RegistrationResponse register(RegistrationRequest request) {
var now = LocalDateTime.now();
var sepulkaCreated = mapper.toServer(request)
var sepulkaCreated = mapper.toState(request)
.internalId(randomUUID())
.revision(0)
.createdAt(now)
.updatedAt(now)
.build();
var sepulkaSaved = dao.add(sepulkaCreated);
return mapper.toClient(sepulkaSaved).build();
return mapper.toMessage(sepulkaSaved).build();
}

@Override
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.MessageEm.RegistrationRequest;
import smecalculus.bezmen.messaging.MessageEm.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.MessageEm.RegistrationRequest;
import smecalculus.bezmen.messaging.MessageEm.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.StateDm.AggregateState;
import smecalculus.bezmen.core.StateDm.ExistenceState;
import smecalculus.bezmen.core.StateDm.PreviewState;
import smecalculus.bezmen.core.StateDm.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.StateDm.AggregateState;
import smecalculus.bezmen.core.StateDm.ExistenceState;
import smecalculus.bezmen.core.StateDm.PreviewState;
import smecalculus.bezmen.core.StateDm.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.StateDm;
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 StateDm.AggregateState add(@NonNull StateDm.AggregateState state) {
var stateEdge = repository.save(mapper.toEdge(state));
return mapper.toDomain(stateEdge);
}

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

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

@Override
public void updateBy(ServerSide.TouchState state, UUID internalId) {
public void updateBy(StateDm.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.StateDm;
import smecalculus.bezmen.mapping.EdgeMapper;

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

ServerSide.AggregateState toDomain(EdgeSide.AggregateState state);
StateDm.AggregateState toDomain(StateEm.AggregateState state);

EdgeSide.TouchState toEdge(ServerSide.TouchState state);
StateEm.TouchState toEdge(StateDm.TouchState state);

ServerSide.ExistenceState toDomain(EdgeSide.ExistenceState state);
StateDm.ExistenceState toDomain(StateEm.ExistenceState state);

EdgeSide.PreviewState toEdge(ServerSide.PreviewState state);
StateEm.PreviewState toEdge(StateDm.PreviewState state);

ServerSide.PreviewState toDomain(EdgeSide.PreviewState state);
StateDm.PreviewState toDomain(StateEm.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 StateEm {
@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.StateEm.AggregateState;
import smecalculus.bezmen.storage.StateEm.ExistenceState;
import smecalculus.bezmen.storage.StateEm.PreviewState;
import smecalculus.bezmen.storage.StateEm.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.StateEm.AggregateState;
import smecalculus.bezmen.storage.StateEm.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.StorageProps;
import smecalculus.bezmen.configuration.StorageDm.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.StorageProtocolMode.H2;
import static smecalculus.bezmen.configuration.StorageProtocolMode.POSTGRES;
import static smecalculus.bezmen.configuration.StorageDm.MappingMode.MY_BATIS;
import static smecalculus.bezmen.configuration.StorageDm.MappingMode.SPRING_DATA;
import static smecalculus.bezmen.configuration.StorageDm.ProtocolMode.H2;
import static smecalculus.bezmen.configuration.StorageDm.ProtocolMode.POSTGRES;

import org.springframework.context.annotation.Bean;
import smecalculus.bezmen.configuration.StorageProps;
import smecalculus.bezmen.configuration.StoragePropsEg;
import smecalculus.bezmen.configuration.StorageDm.StorageProps;
import smecalculus.bezmen.configuration.StorageDmEg;

public class StoragePropsBeans {

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

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

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

public static class MyBatisH2 {
@Bean
public StorageProps storageProps() {
return StoragePropsEg.storageProps(MY_BATIS, H2).build();
return StorageDmEg.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.MessageDm.RegistrationRequest;
import smecalculus.bezmen.core.MessageDmEg;
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 = MessageEmEg.registrationRequest(externalId);
// and
when(serviceMock.register(any(RegistrationRequest.class)))
.thenReturn(ClientSideEg.registrationResponse(externalId).build());
.thenReturn(MessageDmEg.registrationResponse(externalId).build());
// and
var expectedResponse = EdgeSideEg.registrationResponse(externalId);
var expectedResponse = MessageEmEg.registrationResponse(externalId);
// when
var actualResponse = externalClient.register(request);
// then
Expand Down
Loading

0 comments on commit 64c4f60

Please sign in to comment.