Skip to content

Commit

Permalink
Storing state stored via business repository (#423)
Browse files Browse the repository at this point in the history
* Storing state stored via business repository

* Fixes
  • Loading branch information
dgafka authored Dec 22, 2024
1 parent 58f238f commit c53973b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 48 deletions.
89 changes: 45 additions & 44 deletions packages/Ecotone/src/Modelling/Config/AggregrateHandlerModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,36 @@ private function registerAggregateCommandHandler(Configuration $configuration, I
}
}

private function registerSaveAggregate(ClassDefinition $aggregateClassDefinition, Configuration $configuration, MessageProcessorActivatorBuilder $chainMessageHandlerBuilder, InterfaceToCallRegistry $interfaceToCallRegistry, BaseEventSourcingConfiguration $baseEventSourcingConfiguration, string $inputChannelName): void
{
/** @TODO do not require method name in save service */
$methodName = $aggregateClassDefinition->getPublicMethodNames() ? $aggregateClassDefinition->getPublicMethodNames()[0] : '__construct';

$saveAggregateBuilder = $chainMessageHandlerBuilder
->chain(ResolveAggregateEventsServiceBuilder::create($aggregateClassDefinition, $methodName, $interfaceToCallRegistry))
->chain(
SaveAggregateServiceBuilder::create(
$aggregateClassDefinition,
$methodName,
$interfaceToCallRegistry,
$baseEventSourcingConfiguration
)
->withAggregateRepositoryFactories($this->aggregateRepositoryReferenceNames)
)
;

if ($configuration->isRunningForTest()) {
$saveAggregateBuilderWithTestState = clone $saveAggregateBuilder;
$configuration->registerMessageHandler(
$saveAggregateBuilderWithTestState
->withInputChannelName($saveAggregateBuilderWithTestState->getInputMessageChannelName() . '.test_setup_state')
);
}

$saveAggregateBuilder = $saveAggregateBuilder->chain(PublishAggregateEventsServiceBuilder::create($aggregateClassDefinition, $methodName));
$configuration->registerMessageHandler($saveAggregateBuilder);
}

private function registerAggregateQueryHandler(AnnotatedFinding $registration, InterfaceToCallRegistry $interfaceToCallRegistry, ParameterConverterAnnotationFactory $parameterConverterAnnotationFactory, Configuration $configuration): void
{
/** @var QueryHandler $annotationForMethod */
Expand Down Expand Up @@ -348,26 +378,6 @@ private function registerAggregateQueryHandler(AnnotatedFinding $registration, I
);
}

public function getModulePackageName(): string
{
return ModulePackageList::CORE_PACKAGE;
}

public static function getRegisterAggregateLoadRepositoryInputChannel(string $className, bool $allowNulls): string
{
return self::getAggregateRepositoryInputChannel($className, '.will_load', false, $allowNulls);
}

public static function getRegisterAggregateSaveRepositoryInputChannel(string $className): string
{
return self::getAggregateRepositoryInputChannel($className, '.will_save', true, false);
}

public static function getAggregateRepositoryInputChannel(string $className, string $methodName1, bool $isSave, bool $canReturnNull): string
{
return $className . $methodName1 . ($isSave ? '.save' : '.load' . ($canReturnNull ? '.nullable' : ''));
}

private function registerLoadAggregate(ClassDefinition $aggregateClassDefinition, bool $canReturnNull, Configuration $configuration, MessageProcessorActivatorBuilder $chainMessageHandlerBuilder, InterfaceToCallRegistry $interfaceToCallRegistry): void
{
/** @TODO do not require method name in save service */
Expand All @@ -384,34 +394,24 @@ private function registerLoadAggregate(ClassDefinition $aggregateClassDefinition
);
}

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

$saveAggregateBuilder = $chainMessageHandlerBuilder
->chain(ResolveAggregateEventsServiceBuilder::create($aggregateClassDefinition, $methodName, $interfaceToCallRegistry))
->chain(
SaveAggregateServiceBuilder::create(
$aggregateClassDefinition,
$methodName,
$interfaceToCallRegistry,
$baseEventSourcingConfiguration
)
->withAggregateRepositoryFactories($this->aggregateRepositoryReferenceNames)
)
;
public static function getRegisterAggregateLoadRepositoryInputChannel(string $className, bool $allowNulls): string
{
return self::getAggregateRepositoryInputChannel($className, '.will_load', false, $allowNulls);
}

if ($configuration->isRunningForTest()) {
$saveAggregateBuilderWithTestState = clone $saveAggregateBuilder;
$configuration->registerMessageHandler(
$saveAggregateBuilderWithTestState
->withInputChannelName($saveAggregateBuilderWithTestState->getInputMessageChannelName() . '.test_setup_state')
);
}
public static function getRegisterAggregateSaveRepositoryInputChannel(string $className): string
{
return self::getAggregateRepositoryInputChannel($className, '.will_save', true, false);
}

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

private function initialization(Configuration $messagingConfiguration): void
Expand Down Expand Up @@ -526,6 +526,7 @@ public function registerBusinessRepositories(InterfaceToCallRegistry $interfaceT
$gatewayParameterConverters = [
GatewayHeaderBuilder::create($interface->getFirstParameter()->getName(), AggregateMessage::CALLED_AGGREGATE_OBJECT),
GatewayHeaderBuilder::create($interface->getFirstParameter()->getName(), AggregateMessage::RESULT_AGGREGATE_OBJECT),
GatewayPayloadBuilder::create($interface->getFirstParameter()->getName())
];
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,7 @@ public function test_fetch_nulls_on_non_null_business_repository()
$repository->get(123);
}

/**
* @TODO
*/
public function todo_test_storing_standard_aggregate_via_business_repository(): void
public function test_storing_standard_aggregate_via_business_repository(): void
{
$ecotoneLite = EcotoneLite::bootstrapFlowTesting(
[Appointment::class, AppointmentStandardRepository::class, AppointmentRepositoryInterface::class],
Expand Down

0 comments on commit c53973b

Please sign in to comment.