diff --git a/src/main/java/org/folio/linked/data/integration/ResourceModificationEventListener.java b/src/main/java/org/folio/linked/data/integration/ResourceModificationEventListener.java index 407402b0..1f871fdd 100644 --- a/src/main/java/org/folio/linked/data/integration/ResourceModificationEventListener.java +++ b/src/main/java/org/folio/linked/data/integration/ResourceModificationEventListener.java @@ -49,9 +49,11 @@ public void afterUpdate(ResourceUpdatedEvent resourceUpdatedEvent) { @TransactionalEventListener public void afterReplace(ResourceReplacedEvent resourceReplacedEvent) { log.info("ResourceReplacedEvent received [{}]", resourceReplacedEvent); - replaceMessageSenders.forEach( - sender -> sender.produce(resourceReplacedEvent.previous(), resourceReplacedEvent.current()) - ); + resourceRepository.findById(resourceReplacedEvent.current().getId()) + .ifPresent(resource -> replaceMessageSenders.forEach( + sender -> sender.produce(resourceReplacedEvent.previous(), resource) + ) + ); } @TransactionalEventListener