The Extractionservice Beginning with yuuvis RAD version 9.0, the Extraction Service can be extended by plugins.
This is based on the framework PF4J: https://pf4j.org/
Inside the extractionservice the plugins are loaded via PF4J-Spring:
https://github.com/pf4j/pf4j-spring
This means that the plugins a plugin must comply with this interface. . In particular, this is a constructor with a PluginWrapper as a parameter:
Code Block | ||
---|---|---|
| ||
public PgnFilePlugin(PluginWrapper wrapper) { super(wrapper); } |
Necessary steps (not chronological)
It follows the description of what to set up and configure for creating a new plugin, deploying, and checking it.
1.
...
Include the library provided by Optimal Systems for the definition of the plugin interface
The library "extractionservice-plugin-interface" is available as a jar file and must be added to the project. This defines the interface for the extraction service and also brings the plugin capability of PF4J.
...
Code Block | ||
---|---|---|
| ||
<dependency> <groupId>com.os.enaio.services.extraction</groupId> <artifactId>extractionservice-plugin-interface</artifactId> <version>9.0.2</version> <scope>provided</scope> </dependency> |
2.
...
Implement the plugin
As an example for of a plugin the library "extractionservice-plugin-demo" is also available as a jar-file:
...
View file | ||
---|---|---|
|
Plugin example code:
Code Block | ||
---|---|---|
| ||
package com.os.services.extraction.plugin.demo; import com.os.services.extraction.plugin.ExtractionDriver; import com.os.services.extraction.plugin.ExtractionInfo; import org.apache.commons.io.IOUtils; import org.pf4j.Extension; import org.pf4j.Plugin; import org.pf4j.PluginWrapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileInputStream; import java.util.HashMap; import java.util.Map; public class PgnFilePlugin extends Plugin { /** * Constructor to be used by plugin manager for plugin instantiation. * Your plugins have to provide constructor with this exact signature to * be successfully loaded by manager. * * @param wrapper */ public PgnFilePlugin(PluginWrapper wrapper) { super(wrapper); } private final static Logger LOGGER = LoggerFactory.getLogger(PgnFilePlugin.class); @Override public void start() { LOGGER.info("Start"); } @Override public void stop() { LOGGER.info("Stop"); } @Extension public static class PgnFileProcessor implements ExtractionDriver { private final static Logger LOGGER = LoggerFactory.getLogger(PgnFileProcessor.class); private static final String PREFIX = "PGNFILE"; @Override public ExtractionInfo info() { return null; } @Override public String getExtractionDriverName() { return "PgnFile"; } @Override public String getExtractionNamespace() { return PREFIX; } @Override public boolean isApplicable (File file) { if (file.getName().endsWith(".pgn")) { return true; } return false; } @Override public Map<String, String> extractData( File file ) { Map<String, String> result = new HashMap<>(); try { String str = IOUtils.toString(new FileInputStream(file), "UTF-8"); String[] tokens = str.split("]"); if (tokens != null) { for (String token : tokens) { token = token.trim(); if (token.startsWith("[")) { String[] tag = token.substring(1).split("\""); if (tag.length >= 2) { //do not add prefix to key //it will be set by extractionservice String key = tag[0].trim(); String value = tag[1].trim(); if (key.endsWith("Date")) { value = value.replaceAll("\\?{2}", "01") .replaceAll("\\.", "\\-") + "T12:00:00+01:00"; } result.put(key, value); } if (tag.length == 1) { //do not add prefix to key //it will be set by extractionservice String key = tag[0].trim(); result.put(key, ""); } } } } } catch (Exception e) { LOGGER.error(e.getMessage()); } return result; } } } |
3.
...
Build the jar-file
If the plugin is packaged in a jar file, there are important points to note:
The following attributes must be specified in the MANIFEST.MF file (in the example plugin):
...
This generated jar file can now be placed in the appropriately configured directory of the Extractionservice.4
4.
...
Configure the extraction service
By default, the use of plugins is disabled. In the extraction-prod.yml file, these settings can be adjusted:
...
The jar file of the plugin must then be stored in the specified directory and is read in when the Extractionservice Extraction Service is restarted.
Any number of plugin files can be stored in this directory.
5. Check the logging of the plugin
When the extraction service is restarted, available plug-ins are read in. Information about this is output in the log.
...