Search in sources :

Example 1 with OutputDefinition

use of org.geotoolkit.wps.xml.v200.OutputDefinition in project geotoolkit by Geomatys.

the class ExecuteTest method testRequestAndMarshall.

@Test
public void testRequestAndMarshall() throws Exception {
    final WebProcessingClient client = new WebProcessingClient(new URL("http://test.com"), null, WPSVersion.v100);
    final ExecuteRequest request = client.createExecute();
    final Execute execute = request.getContent();
    final GeographicCRS epsg4326 = CommonCRS.WGS84.geographic();
    final GeneralEnvelope env = new GeneralEnvelope(epsg4326);
    env.setRange(0, 10, 10);
    env.setRange(1, 10, 10);
    execute.setIdentifier("identifier");
    final List<DataInput> inputs = execute.getInput();
    inputs.add(new DataInput("literal", new Data(new LiteralValue("10", null, null))));
    inputs.add(new DataInput("bbox", new Data(new BoundingBoxType(env))));
    inputs.add(new DataInput("complex", new Data(new Format("UTF-8", WPSMimeType.APP_GML.val(), WPSSchema.OGC_GML_3_1_1.getValue(), null), new PointType(new DirectPosition2D(epsg4326, 0, 0)))));
    inputs.add(new DataInput("reference", new Reference("http://link.to/reference/", null, null)));
    execute.getOutput().add(new OutputDefinition("output", false));
    assertEquals("WPS", execute.getService());
    assertEquals("1.0.0", execute.getVersion().toString());
    assertEquals(execute.getIdentifier().getValue(), "identifier");
    final StringWriter stringWriter = new StringWriter();
    final Marshaller marshaller = WPSMarshallerPool.getInstance().acquireMarshaller();
    marshaller.marshal(execute, stringWriter);
    String result = stringWriter.toString();
    try (final InputStream expected = expectedRequest()) {
        assertXmlEquals(expected, result, "xmlns:*", "crs", "srsName");
    }
    WPSMarshallerPool.getInstance().recycle(marshaller);
}
Also used : Marshaller(javax.xml.bind.Marshaller) Execute(org.geotoolkit.wps.xml.v200.Execute) Reference(org.geotoolkit.wps.xml.v200.Reference) InputStream(java.io.InputStream) Data(org.geotoolkit.wps.xml.v200.Data) LiteralValue(org.geotoolkit.wps.xml.v200.LiteralValue) WebProcessingClient(org.geotoolkit.wps.client.WebProcessingClient) DirectPosition2D(org.apache.sis.geometry.DirectPosition2D) URL(java.net.URL) DataInput(org.geotoolkit.wps.xml.v200.DataInput) BoundingBoxType(org.geotoolkit.ows.xml.v200.BoundingBoxType) ExecuteRequest(org.geotoolkit.wps.client.ExecuteRequest) Format(org.geotoolkit.wps.xml.v200.Format) StringWriter(java.io.StringWriter) PointType(org.geotoolkit.gml.xml.v321.PointType) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) OutputDefinition(org.geotoolkit.wps.xml.v200.OutputDefinition) Test(org.junit.Test)

Example 2 with OutputDefinition

use of org.geotoolkit.wps.xml.v200.OutputDefinition in project geotoolkit by Geomatys.

the class WPS2Process method createRequest.

/**
 * Make a WPS Execute request from {@link ParameterValueGroup values}.
 */
private ExecuteRequest createRequest() throws ProcessException {
    try {
        final ParameterValueGroup inputs = getInput();
        final List<GeneralParameterDescriptor> inputParamDesc = inputs.getDescriptor().descriptors();
        final List<GeneralParameterDescriptor> outputParamDesc = descriptor.getOutputDescriptor().descriptors();
        final List<DataInput> wpsIN = new ArrayList<>();
        final List<OutputDefinition> wpsOUT = new ArrayList<>();
        final String processId = descriptor.getIdentifier().getCode();
        for (final GeneralParameterValue inputValue : inputs.values()) {
            GeneralParameterDescriptor inputGeneDesc = inputValue.getDescriptor();
            if (inputGeneDesc instanceof ParameterDescriptor) {
                final ParameterDescriptor inputDesc = (ParameterDescriptor) inputGeneDesc;
                final DataAdaptor adaptor = (DataAdaptor) ((ExtendedParameterDescriptor) inputDesc).getUserObject().get(DataAdaptor.USE_ADAPTOR);
                final Object value = ((ParameterValue) inputValue).getValue();
                if (value == null)
                    continue;
                final DataInput dataInput;
                if (adaptor instanceof LiteralAdaptor) {
                    dataInput = ((LiteralAdaptor) adaptor).toWPS2Input(value, rawLiteralData);
                } else {
                    dataInput = adaptor.toWPS2Input(value);
                }
                dataInput.setId(inputDesc.getName().getCode());
                wpsIN.add(dataInput);
            }
        }
        /*
             * OUTPUTS
             */
        for (final GeneralParameterDescriptor outputGeneDesc : outputParamDesc) {
            if (outputGeneDesc instanceof ParameterDescriptor) {
                final ParameterDescriptor outputDesc = (ParameterDescriptor) outputGeneDesc;
                final DataAdaptor adaptor = (DataAdaptor) ((ExtendedParameterDescriptor) outputDesc).getUserObject().get(DataAdaptor.USE_ADAPTOR);
                final String outputIdentifier = outputDesc.getName().getCode();
                String mime = null;
                String encoding = null;
                String schema = null;
                if (adaptor instanceof ComplexAdaptor) {
                    final ComplexAdaptor cadaptor = (ComplexAdaptor) adaptor;
                    mime = cadaptor.getMimeType();
                    encoding = cadaptor.getEncoding();
                    schema = cadaptor.getSchema();
                }
                final OutputDefinition out = new OutputDefinition(outputIdentifier, asReference);
                out.setEncoding(encoding);
                out.setMimeType(mime);
                out.setSchema(schema);
                wpsOUT.add(out);
            } else if (outputGeneDesc instanceof ParameterDescriptorGroup) {
                final ParameterDescriptorGroup outputDesc = (ParameterDescriptorGroup) outputGeneDesc;
                final OutputDefinition out = new OutputDefinition(outputDesc.getName().getCode(), asReference);
                wpsOUT.add(out);
            }
        }
        final ExecuteRequest request = registry.getClient().createExecute();
        request.setClientSecurity(security);
        final Execute execute = request.getContent();
        execute.setIdentifier(processId);
        final Execute.Mode mode = executionMode == null ? Execute.Mode.auto : executionMode;
        execute.setMode(mode);
        execute.setResponse(rawOutput ? Execute.Response.raw : Execute.Response.document);
        execute.getInput().addAll(wpsIN);
        execute.getOutput().addAll(wpsOUT);
        WPSProcessingRegistry.LOGGER.log(Level.FINER, "Execute request created for {0} in {1} mode.", new Object[] { processId, mode });
        return request;
    } catch (UnconvertibleObjectException ex) {
        throw new ProcessException("Error during conversion step.", null, ex);
    }
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) LiteralAdaptor(org.geotoolkit.wps.adaptor.LiteralAdaptor) ParameterValue(org.opengis.parameter.ParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) Execute(org.geotoolkit.wps.xml.v200.Execute) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ExtendedParameterDescriptor(org.geotoolkit.utility.parameter.ExtendedParameterDescriptor) ParameterDescriptor(org.opengis.parameter.ParameterDescriptor) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) ArrayList(java.util.ArrayList) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ExtendedParameterDescriptor(org.geotoolkit.utility.parameter.ExtendedParameterDescriptor) ComplexAdaptor(org.geotoolkit.wps.adaptor.ComplexAdaptor) DataInput(org.geotoolkit.wps.xml.v200.DataInput) ExecuteRequest(org.geotoolkit.wps.client.ExecuteRequest) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) ProcessException(org.geotoolkit.process.ProcessException) DismissProcessException(org.geotoolkit.process.DismissProcessException) DataAdaptor(org.geotoolkit.wps.adaptor.DataAdaptor) OutputDefinition(org.geotoolkit.wps.xml.v200.OutputDefinition)

Aggregations

ExecuteRequest (org.geotoolkit.wps.client.ExecuteRequest)2 DataInput (org.geotoolkit.wps.xml.v200.DataInput)2 Execute (org.geotoolkit.wps.xml.v200.Execute)2 OutputDefinition (org.geotoolkit.wps.xml.v200.OutputDefinition)2 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Marshaller (javax.xml.bind.Marshaller)1 DirectPosition2D (org.apache.sis.geometry.DirectPosition2D)1 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)1 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)1 PointType (org.geotoolkit.gml.xml.v321.PointType)1 BoundingBoxType (org.geotoolkit.ows.xml.v200.BoundingBoxType)1 DismissProcessException (org.geotoolkit.process.DismissProcessException)1 ProcessException (org.geotoolkit.process.ProcessException)1 ExtendedParameterDescriptor (org.geotoolkit.utility.parameter.ExtendedParameterDescriptor)1 ComplexAdaptor (org.geotoolkit.wps.adaptor.ComplexAdaptor)1 DataAdaptor (org.geotoolkit.wps.adaptor.DataAdaptor)1 LiteralAdaptor (org.geotoolkit.wps.adaptor.LiteralAdaptor)1