public void startDiscussionInitiation(StartDiscussionInitiationCommand aCommand) {
ApplicationServiceLifeCycle.begin();
try {
Product product =
this.productRepository()
.productOfId(
new TenantId(aCommand.getTenantId()),
new ProductId(aCommand.getProductId()));
if (product == null) {
throw new IllegalStateException(
"Unknown product of tenant id: "
+ aCommand.getTenantId()
+ " and product id: "
+ aCommand.getProductId());
}
String timedOutEventName =
ProductDiscussionRequestTimedOut.class.getName();
TimeConstrainedProcessTracker tracker =
new TimeConstrainedProcessTracker(
product.tenantId().id(),
ProcessId.newProcessId(),
"Create discussion for product: "
+ product.name(),
new Date(),
5L * 60L * 1000L, // retries every 5 minutes
3, // 3 total retries
timedOutEventName);
this.processTrackerRepository().save(tracker);
product.startDiscussionInitiation(tracker.processId().id());
this.productRepository().save(product);
ApplicationServiceLifeCycle.success();