Extending AbstractAnnotatedAlgorithm

In this tutorial, we will show you, how you can implement a WPS algorithm (or process) in Java, the native language of th 52°North WPS, with very little effort. Tasks like the creation of the ProcessDescription and the (un-)marshalling of inputs and outputs are done by the framework.

The base class AbstractAnnotatedAlgorithm introduces an annotation mechanism, the available annotations are described in the following.

An exemplary Maven project that contains the necessary dependencies and allows to to start programming rightaway is available on GitHub: https://github.com/52North/WPS-Extension-Skeleton

The @Algorithm annotation

With this annotation you can specify some base elements of your algorithm, like the version, title and abstract.

@Algorithm(version = "1.0.0", abstrakt="This algorithm creates a buffers around a JTS geometry using the build-in buffer-method.")
public class JTSBufferAlgorithm extends AbstractAnnotatedAlgorithm {

The following are the supported parameters:

String identifier() default ""; // the algorithm identifier, if not specified, the fully qualified class name is used
String title() default ""; // the algorithm title
String abstrakt() default ""; // the abstract of this algorithm, 'abstract' is java reserved keyword
String version(); // the version for internal use (you can currently not request a specific algorithm version)
boolean storeSupported() default true; // specifies, whether the results can be stored in the WPS database
boolean statusSupported() default true; // specifies, whether the status of the algorithm can be queried

The @LiteralDataInput annotation

With this annotation you can specify literal inputs of your algorithm, e.g. Strings or integers:

@LiteralDataInput(identifier="endCapStyle", abstrakt="CAP_ROUND = 1, CAP_FLAT = 2, CAP_SQUARE = 3", allowedValues={"1","2","3"}, defaultValue = ""+ BufferParameters.CAP_ROUND, minOccurs=0)
public void setEndCapStyle(int endCapStyle) {
 this.endCapStyle = endCapStyle;
}

The following are the supported parameters:

String identifier(); // identifier of the input
String title() default ""; // title of the input
String abstrakt() default ""; // abstract of the input 'abstract' is java reserved keyword
int minOccurs() default 1; // specifies, whether this input is mandatory (1) or not (0)
int maxOccurs() default 1; //specifies the maximum number of occurrences of this input
String defaultValue() default ""; // specifies the default value of this input
String[] allowedValues() default {}; // specifies the allowed values of this input
Class <? extends ILiteralData> binding() default ILiteralData.class; // specifies the class of this input. The class must implement ILiteralData. If not specified, the class is resolved automatically

The @ComplexDataInput annotation

With this annotation you can specify complex inputs of your algorithm, e.g. Geotools FeatureCollections or raster images:

@ComplexDataInput(identifier = "data", binding = JTSGeometryBinding.class, minOccurs=1)
public void setData(Geometry data) {
this.data = data;
}

The parameters are basically the same as those of literal data, however, no defaulf or allowed values can be specified. Two more differences:

int maximumMegaBytes() default 0; // this can be specified to restrict the size of the complex data
Class <? extends IComplexData> binding(); // specifies the class of this input. if not specified. The class must implement IComplexData.

The @ComplexDataOutput annotation

With this annotation, you can specify complex data outputs of your algorithm:

@ComplexDataOutput(identifier = "result", binding = JTSGeometryBinding.class)
public Geometry getResult() {
 return result;
}

The parameters are the same as those of complex input, however, maximum MB and min/max-occurs can not be specified.

The @LiteralDataOutput annotation

With this annotation, you can specify literal output of your algorithm:

@LiteralDataOutput(identifier = "output")
public String getOutput() {
 return this.output;
}

Parameters are the same as those of complex data output, except the class must be implementing ILiteralData. If not specified, it will be automatically resolved.

The @Execute annotation

This annotation is used to mark the run-method of the algorithm. It has no further parameters.

@Execute
public void runAlgorithm() {
 result = data.buffer(distance, quadrantSegments, endCapStyle);
}

In the run-method you can directly access the input parameters of the algorithm and allocate values for the output parameters.

You can also directly update messages that will be displayed if the client pulls the status of the process. Simply add calls to

this.update(Object state)

anywhere in the run-method.

You can download the complete Java class here.

Deploy the process

See here.

Execute the process

See here.
Topic revision: r9 - 16 Jan 2019, BenjaminPross
Legal Notice | Privacy Statement


This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Wiki? Send feedback