contextualInformation.put(ContextualInventoryService.ORDER_KEY, processContext.getSeedData().getOrder());
if (inventoryToIncrement != null && !inventoryToIncrement.isEmpty()) {
try {
inventoryService.incrementInventory(inventoryToIncrement, contextualInformation);
} catch (Exception ex) {
RollbackFailureException rfe = new RollbackFailureException("An unexpected error occured in the error handler of the checkout workflow trying to compensate for inventory. This happend for order ID: " +
orderId + ". This should be corrected manually!", ex);
rfe.setActivity(activity);
rfe.setProcessContext(processContext);
rfe.setStateItems(stateConfiguration);
throw rfe;
}
}
if (inventoryToDecrement != null && !inventoryToDecrement.isEmpty()) {
try {
inventoryService.decrementInventory(inventoryToDecrement, contextualInformation);
} catch (InventoryUnavailableException e) {
//This is an awkward, unlikely state. I just added some inventory, but something happened, and I want to remove it, but it's already gone!
RollbackFailureException rfe = new RollbackFailureException("While trying roll back (decrement) inventory, we found that there was none left decrement.", e);
rfe.setActivity(activity);
rfe.setProcessContext(processContext);
rfe.setStateItems(stateConfiguration);
throw rfe;
} catch (RuntimeException ex) {
LOG.error("An unexpected error occured in the error handler of the checkout workflow trying to compensate for inventory. This happend for order ID: " +
orderId + ". This should be corrected manually!", ex);
RollbackFailureException rfe = new RollbackFailureException("An unexpected error occured in the error handler of the checkout workflow " +
"trying to compensate for inventory. This happend for order ID: " +
orderId + ". This should be corrected manually!", ex);
rfe.setActivity(activity);
rfe.setProcessContext(processContext);
rfe.setStateItems(stateConfiguration);
throw rfe;
}
}
}
}