Skip to content

Commit de33204

Browse files
committed
Storing state stored via business repository
1 parent 58f238f commit de33204

File tree

2 files changed

+47
-48
lines changed

2 files changed

+47
-48
lines changed

packages/Ecotone/src/Modelling/Config/AggregrateHandlerModule.php

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,37 @@ private function registerAggregateCommandHandler(Configuration $configuration, I
309309
}
310310
}
311311

312+
private function registerSaveAggregate(ClassDefinition $aggregateClassDefinition, Configuration $configuration, MessageProcessorActivatorBuilder $chainMessageHandlerBuilder, InterfaceToCallRegistry $interfaceToCallRegistry, BaseEventSourcingConfiguration $baseEventSourcingConfiguration, string $inputChannelName): void
313+
{
314+
/** @TODO do not require method name in save service */
315+
$methodName = $aggregateClassDefinition->getPublicMethodNames() ? $aggregateClassDefinition->getPublicMethodNames()[0] : '__construct';
316+
317+
$saveAggregateBuilder = $chainMessageHandlerBuilder
318+
->chain(ResolveAggregateEventsServiceBuilder::create($aggregateClassDefinition, $methodName, $interfaceToCallRegistry))
319+
->chain(ResolveAggregateServiceBuilder::create($aggregateClassDefinition, $methodName, $interfaceToCallRegistry))
320+
->chain(
321+
SaveAggregateServiceBuilder::create(
322+
$aggregateClassDefinition,
323+
$methodName,
324+
$interfaceToCallRegistry,
325+
$baseEventSourcingConfiguration
326+
)
327+
->withAggregateRepositoryFactories($this->aggregateRepositoryReferenceNames)
328+
)
329+
;
330+
331+
if ($configuration->isRunningForTest()) {
332+
$saveAggregateBuilderWithTestState = clone $saveAggregateBuilder;
333+
$configuration->registerMessageHandler(
334+
$saveAggregateBuilderWithTestState
335+
->withInputChannelName($saveAggregateBuilderWithTestState->getInputMessageChannelName() . '.test_setup_state')
336+
);
337+
}
338+
339+
$saveAggregateBuilder = $saveAggregateBuilder->chain(PublishAggregateEventsServiceBuilder::create($aggregateClassDefinition, $methodName));
340+
$configuration->registerMessageHandler($saveAggregateBuilder);
341+
}
342+
312343
private function registerAggregateQueryHandler(AnnotatedFinding $registration, InterfaceToCallRegistry $interfaceToCallRegistry, ParameterConverterAnnotationFactory $parameterConverterAnnotationFactory, Configuration $configuration): void
313344
{
314345
/** @var QueryHandler $annotationForMethod */
@@ -348,26 +379,6 @@ private function registerAggregateQueryHandler(AnnotatedFinding $registration, I
348379
);
349380
}
350381

351-
public function getModulePackageName(): string
352-
{
353-
return ModulePackageList::CORE_PACKAGE;
354-
}
355-
356-
public static function getRegisterAggregateLoadRepositoryInputChannel(string $className, bool $allowNulls): string
357-
{
358-
return self::getAggregateRepositoryInputChannel($className, '.will_load', false, $allowNulls);
359-
}
360-
361-
public static function getRegisterAggregateSaveRepositoryInputChannel(string $className): string
362-
{
363-
return self::getAggregateRepositoryInputChannel($className, '.will_save', true, false);
364-
}
365-
366-
public static function getAggregateRepositoryInputChannel(string $className, string $methodName1, bool $isSave, bool $canReturnNull): string
367-
{
368-
return $className . $methodName1 . ($isSave ? '.save' : '.load' . ($canReturnNull ? '.nullable' : ''));
369-
}
370-
371382
private function registerLoadAggregate(ClassDefinition $aggregateClassDefinition, bool $canReturnNull, Configuration $configuration, MessageProcessorActivatorBuilder $chainMessageHandlerBuilder, InterfaceToCallRegistry $interfaceToCallRegistry): void
372383
{
373384
/** @TODO do not require method name in save service */
@@ -384,34 +395,24 @@ private function registerLoadAggregate(ClassDefinition $aggregateClassDefinition
384395
);
385396
}
386397

387-
private function registerSaveAggregate(ClassDefinition $aggregateClassDefinition, Configuration $configuration, MessageProcessorActivatorBuilder $chainMessageHandlerBuilder, InterfaceToCallRegistry $interfaceToCallRegistry, BaseEventSourcingConfiguration $baseEventSourcingConfiguration, string $inputChannelName): void
398+
public function getModulePackageName(): string
388399
{
389-
/** @TODO do not require method name in save service */
390-
$methodName = $aggregateClassDefinition->getPublicMethodNames() ? $aggregateClassDefinition->getPublicMethodNames()[0] : '__construct';
400+
return ModulePackageList::CORE_PACKAGE;
401+
}
391402

392-
$saveAggregateBuilder = $chainMessageHandlerBuilder
393-
->chain(ResolveAggregateEventsServiceBuilder::create($aggregateClassDefinition, $methodName, $interfaceToCallRegistry))
394-
->chain(
395-
SaveAggregateServiceBuilder::create(
396-
$aggregateClassDefinition,
397-
$methodName,
398-
$interfaceToCallRegistry,
399-
$baseEventSourcingConfiguration
400-
)
401-
->withAggregateRepositoryFactories($this->aggregateRepositoryReferenceNames)
402-
)
403-
;
403+
public static function getRegisterAggregateLoadRepositoryInputChannel(string $className, bool $allowNulls): string
404+
{
405+
return self::getAggregateRepositoryInputChannel($className, '.will_load', false, $allowNulls);
406+
}
404407

405-
if ($configuration->isRunningForTest()) {
406-
$saveAggregateBuilderWithTestState = clone $saveAggregateBuilder;
407-
$configuration->registerMessageHandler(
408-
$saveAggregateBuilderWithTestState
409-
->withInputChannelName($saveAggregateBuilderWithTestState->getInputMessageChannelName() . '.test_setup_state')
410-
);
411-
}
408+
public static function getRegisterAggregateSaveRepositoryInputChannel(string $className): string
409+
{
410+
return self::getAggregateRepositoryInputChannel($className, '.will_save', true, false);
411+
}
412412

413-
$saveAggregateBuilder = $saveAggregateBuilder->chain(PublishAggregateEventsServiceBuilder::create($aggregateClassDefinition, $methodName));
414-
$configuration->registerMessageHandler($saveAggregateBuilder);
413+
public static function getAggregateRepositoryInputChannel(string $className, string $methodName1, bool $isSave, bool $canReturnNull): string
414+
{
415+
return $className . $methodName1 . ($isSave ? '.save' : '.load' . ($canReturnNull ? '.nullable' : ''));
415416
}
416417

417418
private function initialization(Configuration $messagingConfiguration): void
@@ -526,6 +527,7 @@ public function registerBusinessRepositories(InterfaceToCallRegistry $interfaceT
526527
$gatewayParameterConverters = [
527528
GatewayHeaderBuilder::create($interface->getFirstParameter()->getName(), AggregateMessage::CALLED_AGGREGATE_OBJECT),
528529
GatewayHeaderBuilder::create($interface->getFirstParameter()->getName(), AggregateMessage::RESULT_AGGREGATE_OBJECT),
530+
GatewayPayloadBuilder::create($interface->getFirstParameter()->getName())
529531
];
530532
}
531533
} else {

packages/Ecotone/tests/Modelling/Unit/LoadAggregateServiceBuilderTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,7 @@ public function test_fetch_nulls_on_non_null_business_repository()
228228
$repository->get(123);
229229
}
230230

231-
/**
232-
* @TODO
233-
*/
234-
public function todo_test_storing_standard_aggregate_via_business_repository(): void
231+
public function test_storing_standard_aggregate_via_business_repository(): void
235232
{
236233
$ecotoneLite = EcotoneLite::bootstrapFlowTesting(
237234
[Appointment::class, AppointmentStandardRepository::class, AppointmentRepositoryInterface::class],

0 commit comments

Comments
 (0)