使用事件¶
从GeoNetwork3.0.x开始,您可以在Java代码上收听许多事件。
启用事件侦听器¶
要在Maven项目上启用此功能,必须添加事件依赖项。编辑文件 custom/pom.xml
并添加依赖项标记:
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>events</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
然后创建文件custom/src/main/resources/config spring-地理网络.xml告诉Spring加载自定义bean,添加以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<bean class="org.fao.geonet.events.listeners.MyCustomListener" ></bean>
</beans>
此文件应包含一个列表,其中列出了在geonnetwork作用域内侦听事件的所有类。
简单实例¶
我们可以添加这样一个简单的示例监听器,它将在每次删除元数据时打印一个字符串。
例如,我们可以调用一个外部REST API,它在每次删除或更新元数据时都会被触发。
地理网络API¶
还有一个新的API可用于从外部脚本与geonnetwork交互。查看更多信息 API指南 .