Skip to content

Commit

Permalink
adds support for rich 'aggregate' modeling (working)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangsa committed Mar 30, 2024
1 parent b87d3fb commit cdeb2ad
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class EventsProducerInMemoryContext {
{{#each services as |service|}}
private {{service.apiClassName}}Captor {{asInstanceName service.apiClassName}}Captor = new {{service.apiClassName}}Captor();

public <T extends I{{service.apiClassName}}> T {{asInstanceName service.apiClassName}}() {
return (T) {{asInstanceName service.apiClassName}}Captor;
public {{service.apiClassName}}Captor {{asInstanceName service.apiClassName}}() {
return {{asInstanceName service.apiClassName}}Captor;
}
{{/each}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public {{abstractClass event}} class {{event.className}} {{addExtends event}} im
private static final long serialVersionUID = 1L;

{{#each event.fields as |field|}}
{{#each field.validations as |validation|~}}
// @{{validation.name}}("{{validation.value}}")
{{~/each}}
{{{fieldValidationAnnotations field}}}
private {{{fieldType field}}} {{field.name}};
{{/each}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
// aggregates commands
{{{logMethodCall method}}}
{{~#if (eq (size aggregateCommandsForMethod.aggregatesCommandsForMethod) 1)}}
{{~assign 'aggregateCommand' aggregateCommandsForMethod.aggregatesCommandsForMethod.0}}
{{~#if method.paramId}}
var {{asInstanceName aggregateCommand.aggregate.className}} = {{aggregateCommand.entity.instanceName}}Repository.find{{aggregateCommand.aggregate.className}}ById({{method.paramId}}).orElseThrow();
{{~else}}
var {{asInstanceName aggregateCommand.aggregate.className}} = new {{aggregateCommand.aggregate.className}}();
{{~/if}}
{{asInstanceName aggregateCommand.aggregate.className}}.{{aggregateCommand.command.name}}({{#if method.parameter}}input{{/if}});
persistAndEmitEvents({{asInstanceName aggregateCommand.aggregate.className}});
{{~#if method.returnType}}
{{~#if (eq aggregateCommand.aggregate.className method.returnType)}}
return {{asInstanceName aggregateCommand.aggregate.className}};
{{~else if (eq aggregateCommand.aggregate.aggregateRoot method.returnType)}}
return {{asInstanceName aggregateCommand.aggregate.className}}.getRootEntity();
{{~else}}
return {{asInstanceName service.name}}Mapper.as{{returnType}}({{asInstanceName aggregateCommand.aggregate.className}}.getRootEntity());
{{~/if}}
{{~/if}}
{{~else}}
{{~#each aggregateCommandsForMethod.aggregatesCommandsForMethod as |aggregateCommand| }}
{{~#if method.paramId}}
var {{asInstanceName aggregate.className}} = {{entity.instanceName}}Repository.find{{aggregate.className}}ById({{method.paramId}}).orElseThrow();
{{~else}}
var {{asInstanceName aggregate.className}} = new {{aggregate.className}}();
{{~/if}}
{{asInstanceName aggregate.className}}.{{command.name}}({{#if method.parameter}}input{{/if}});
persistAndEmitEvents({{asInstanceName aggregate.className}});
{{~/each}}
{{~#if method.returnType}}
{{~#if (eq aggregate.className method.returnType)}}
return {{asInstanceName aggregate.className}};
{{~else if (eq aggregate.aggregateRoot method.returnType)}}
return {{asInstanceName aggregate.className}}.getRootEntity();
{{~else}}
return null;
{{~/if}}
{{~/if}}
{{~/if}}
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{{{logMethodCall method}}}
// void
{{~#if method.returnType}}
return null;
{{~/if}}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{assign 'entity' aggregateCommandsForMethod.entity }}
{{~assign 'entity' aggregateCommandsForMethod.entity }}
{{~#if (isCrudMethod 'create' method=method entity=entity )}}
log.debug("[CRUD] Request to save {{entity.className}}: {}", input);
var {{entity.instanceName}} = {{asInstanceName service.name}}Mapper.update(new {{entity.className}}(), {{{mapperInputCallSignature method.parameter}}});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{assign 'aggregateCommandsForMethod' (findAggregateCommandsForMethod method)}}
{{~assign 'aggregateCommandsForMethod' (findAggregateCommandsForMethod method)}}
{{~> (partial aggregateCommandsForMethod.templateFile)}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{#if (eq (size aggregateCommandsForMethod.aggregatesCommandsForMethod) 1)}}
{{{logMethodCall method}}}
{{~#if (eq (size aggregateCommandsForMethod.aggregatesCommandsForMethod) 1)}}
{{~assign 'aggregateCommand' aggregateCommandsForMethod.aggregatesCommandsForMethod.0}}
{{~#if method.paramId}}
var {{asInstanceName aggregateCommand.aggregate.className}} = {{aggregateCommand.entity.instanceName}}Repository.find{{aggregateCommand.aggregate.className}}ById({{method.paramId}}).orElseThrow();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{assign 'aggregateCommandsForMethod' (findAggregateCommandsForMethod method)}}
{{~assign 'aggregateCommandsForMethod' (findAggregateCommandsForMethod method)}}
{{~> (partial aggregateCommandsForMethod.templateFile)}}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public class ServicesInMemoryConfig extends RepositoriesInMemoryConfig {
}

{{~#if (includeEmitEventsImplementation service)}}
public EventsProducerInMemoryContext getEventsProducerInMemoryContext() {
return eventsProducerInMemoryContext;
}

private List<Object> publishedEvents = new ArrayList<>();

public List<Object> getPublishedEvents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class TestDataLoader {

public TestDataLoader(List<? extends Class<?>> mongoManagedTypes) {
this.mongoManagedTypes = mongoManagedTypes;
mappingConverter = mappingConverter();
}

public <T> List<T> loadCollectionTestDataAsObjects(Class<T> collectionClass) {
Expand Down Expand Up @@ -67,7 +68,7 @@ public class TestDataLoader {
return mappingConverter.read(type, org.bson.Document.parse(json));
}

MappingMongoConverter mappingConverter = mappingConverter();
MappingMongoConverter mappingConverter;

MappingMongoConverter mappingConverter() {
MappingMongoConverter mappingConverter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mongoMappingContext());
Expand Down

0 comments on commit cdeb2ad

Please sign in to comment.