.. _tuto-hookcustomizations-events:
Using Events
############
From GeoNetwork 3.0.x on, there are a number of events you can listen to on your Java code.
Enabling Event Listeners
========================
To enable this on your Maven project, you have to add the event dependencies. Edit the file :file:`custom/pom.xml` and add the dependencies tag:
.. code:: xml
${project.groupId}
events
${project.version}
${project.groupId}
core
${project.version}
Then create the file custom/src/main/resources/config-spring-geonetwork.xml to tell Spring to load your custom beans adding the following content:
.. code:: xml
This file should contain a list of all the classes that listen to events inside GeoNetwork scope.
Simple Example
==============
We can add a simple example listener like this one, which will print a string every time a metadata gets removed.
.. code:: java
package org.fao.geonet.events.listeners;
import org.fao.geonet.domain.*;
import org.fao.geonet.events.md.MetadataRemove;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
@Component
public class MyCustomListener implements ApplicationListener {
@Override
public void onApplicationEvent(MetadataRemove event) {
System.out.println("REMOVED");
}
}
For example, we can call an external REST API that gets triggered every time a Metadata gets removed or updated.
GeoNetwork API
==============
There is also a new API you can use to interact with GeoNetwork from an external script. See more on :ref:`api-guide`.