Can I trigger a function when a specific file type is requested?
I have a question that involves a little bit of architecture and may sound a little bit of 'chew this for me cause my teeth didn't grow yet'.
I have the following use case: When a request arrives into Nuxeo (REST API), I want to fetch data from a 3rd party service and answer this data into the response IF a specific document type is part of the set of files that are requested.
For example, suppose you are dealing with Nuxeo for Adobe CC Connector inside Adobe InDesign. It's standard behavior is to fetch all the assets under file document type and retrieve them into the connector's view. This view allows you to insert the assets into the canvas.
Now, suppose that you have a document type registered as myDocumentType and it inherits from file document type. It will be retrieved within the InDesign request for files and attachments. Now, when this happens, when this myDocumentType file is requested, I want it to fire a request to a 3rd party service and, when it answers, I compile the contents of the file which is a .csv and answers the request for the file with these data in it.
One can notice that this use case exists because of this specific requirement: the myDocumentType fresh data needs ALWAYS to be kept in this 3rd party service. There is no other way around it.
Now the questions:
- Can it be done?
- With which approach can it be done? A listener? (I don't really know if it can be done with a listener. With what can it be done?)
- What are the steps that I need to implement to achieve that? (I'm very new and don't know the whole architecture). It would be nice to get an answer like: 1) bootstrap a multi-module project; 2) bootstrap a package; 3) bootstrap a service; 4) Bootstrap a listener; 5) write method into the listener; etc.
Sorry for this long post and question, but am really looking forward to get my hands on Nuxeo and this will give me a great taste of the experience and probably will understand a great part of its features, serving as an enhanced 'helloworld'.
It sounds like a listener would be your best bet as it would give you a lot of flexibility in terms of logic.
In point 3, you have the basic idea already - you may want to consider creating a custom marketplace package which is easy to scaffold via the nuxeo cli bootstrap command. Check out this documentation for how to contribute your own listener: https://doc.nuxeo.com/nxdoc/events-and-messages/#registering-an-event-listener
I'd also recommend checking out university.nuxeo.com and in particular the Developer learning track