Class WpsScriptWrapper
java.lang.Object
org.noise_planet.noisemodelling.webserver.script.WpsScriptWrapper
The `WpsScriptWrapper` class provides functionalities to manage, organize, and process
Groovy scripts for use in a Web Processing Service (WPS) environment. It includes methods
for loading scripts, parsing their metadata, grouping them into categories, and generating
WPS-compliant XML documents.
The class relies on the directory structure of Groovy script files to organize them into
groups, and it provides mechanisms for extracting script information, such as inputs,
outputs, descriptions, and other metadata. These capabilities facilitate the integration
of scripts into a WPS framework by generating necessary XML representations.
-
Constructor Summary
ConstructorsConstructorDescriptionWpsScriptWrapper(Path scriptDir) Default constructor for the WpsScriptWrapper class. -
Method Summary
Modifier and TypeMethodDescriptionstatic Map<String, ScriptMetadata> scanScriptsGrouped(ClassLoader loader, String scriptDirectoryName) Scans a predefined directory structure containing Groovy scripts and organizes them into groups.static voidwalkUri(Map<String, ScriptMetadata> grouped, org.slf4j.Logger logger, URI resourcesScriptUri, String scriptDirectoryName) Walks through the contents of a given URI, which can point to either a directory in the file system or a location within a JAR file, to find and process Groovy script files.
-
Constructor Details
-
WpsScriptWrapper
Default constructor for the WpsScriptWrapper class. This constructor initializes the WpsScriptWrapper instance by setting the `scriptsRoot` field to point to the default directory containing Groovy script files. The directory is resolved relative to the current working directory of the application and is expected to exist at: "noisemodelling-scripts/src/main/groovy/org/noise_planet/noisemodelling/scripts".
-
-
Method Details
-
scanScriptsGrouped
public static Map<String,ScriptMetadata> scanScriptsGrouped(ClassLoader loader, String scriptDirectoryName) throws IOException Scans a predefined directory structure containing Groovy scripts and organizes them into groups.This method traverses the directory structure rooted at the `scriptsRoot` location recursively. It identifies Groovy script files (files ending with the `.groovy` extension), extracts their names (excluding the file extension), and groups them into categories based on the directory structure. Each group corresponds to a directory path relative to the root directory.
If the root directory does not exist or contains no valid files, an empty map is returned.
- Returns:
- a map where the keys are group names (relative directory paths) and the values are lists of script metadata
- Throws:
IOException
-
walkUri
public static void walkUri(Map<String, ScriptMetadata> grouped, org.slf4j.Logger logger, URI resourcesScriptUri, String scriptDirectoryName) throws IOExceptionWalks through the contents of a given URI, which can point to either a directory in the file system or a location within a JAR file, to find and process Groovy script files.- Parameters:
grouped- a map to store the metadata of found scripts, where the key is a unique identifier for each script and the value is a ScriptMetadata object containing details about the scriptlogger- a Logger instance for logging information and warnings during the script discovery processresourcesScriptUri- a URI pointing to the location to be scanned for Groovy script files; this can be a file system path or a JAR file pathscriptDirectoryName- the name of the script directory being scanned, used for logging purposes and to ensure correct path handling within JAR files- Throws:
IOException- if an I/O error occurs while accessing the URI or reading script files, or if the URI is malformed and cannot be processed correctly
-