paulcwarren/spring-content

Events emitted twice

Closed this issue · 2 comments

Describe the bug
Event seems to be emitted twice.

To Reproduce

  1. Configure a new project using a filesystem storage
  2. Write a very simple event handler like this:
@Component
@StoreEventHandler
public class PocFileContentStoreEventHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(PocFileContentStoreEventHandler.class);

   @HandleAfterGetResource
    public void handleAfterGetResource(PocFile pocFile) {
        LOGGER.debug("PocFile {} resource has been fetched", pocFile.getId());
    }
}

and an API with these rows:

LOGGER.debug(pocFile.getId());
pocFileContentStore.getResource(pocFile);
  1. call the API
  2. here's the output:
2024-03-21T10:37:39.271+01:00 DEBUG 7672 --- [Spring Content Poc] [nio-8080-exec-2] i.i.s.api.FileApiDelegateImpl            : 14
2024-03-21T10:37:39.397+01:00 DEBUG 7672 --- [Spring Content Poc] [nio-8080-exec-2] i.i.s.c.PocFileContentStoreEventHandler  : PocFile 14 resource has been fetched
2024-03-21T10:37:39.399+01:00 DEBUG 7672 --- [Spring Content Poc] [nio-8080-exec-2] i.i.s.c.PocFileContentStoreEventHandler  : PocFile 14 resource has been fetched

Expected behavior
One row only wrote for PocFileContentStoreEventHandler class.

Thanks @RuudGianesini , I'll take a look as soon as I can

OK. I see the issue. It's to do with the compatibility layer that I put in to support the old org.springframework.content.commons.repository.ContentStore interface alongside the newer org.springframework.content.commons.store.ContentStore.

I have identified a pretty simple fix. Shouldn't take too long.