Search in sources :

Example 1 with LiteralValue

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

the class LiteralAdaptorTest method stringWPS2.

@Test
public void stringWPS2() {
    final DomainMetadataType metaType = new DomainMetadataType("String", "http://www.w3.org/TR/xmlschema-2/#string");
    final LiteralDataDomain domain = new LiteralDataDomain();
    domain.setDataType(metaType);
    final LiteralAdaptor adaptor = LiteralAdaptor.create(domain);
    assertEquals(String.class, adaptor.getValueClass());
    final DataOutput output = new DataOutput();
    final LiteralValue lit = new LiteralValue();
    lit.setValue("hello world");
    final Data data = new Data(lit);
    output.setData(data);
    final Object result = adaptor.fromWPS2Input(output);
    assertEquals("hello world", result);
}
Also used : DomainMetadataType(org.geotoolkit.ows.xml.v200.DomainMetadataType) DataOutput(org.geotoolkit.wps.xml.v200.DataOutput) LiteralValue(org.geotoolkit.wps.xml.v200.LiteralValue) Data(org.geotoolkit.wps.xml.v200.Data) LiteralDataDomain(org.geotoolkit.wps.xml.v200.LiteralDataDomain) Test(org.junit.Test)

Example 2 with LiteralValue

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

the class LiteralAdaptorTest method booleanWPS2.

@Test
public void booleanWPS2() {
    final DomainMetadataType metaType = new DomainMetadataType(null, "xs:boolean");
    final LiteralDataDomain domain = new LiteralDataDomain();
    domain.setDataType(metaType);
    final LiteralAdaptor adaptor = LiteralAdaptor.create(domain);
    assertEquals(Boolean.class, adaptor.getValueClass());
    final DataOutput output = new DataOutput();
    final LiteralValue lit = new LiteralValue();
    lit.setValue("true");
    final Data data = new Data(lit);
    output.setData(data);
    final Object result = adaptor.fromWPS2Input(output);
    assertEquals(true, result);
}
Also used : DomainMetadataType(org.geotoolkit.ows.xml.v200.DomainMetadataType) DataOutput(org.geotoolkit.wps.xml.v200.DataOutput) LiteralValue(org.geotoolkit.wps.xml.v200.LiteralValue) Data(org.geotoolkit.wps.xml.v200.Data) LiteralDataDomain(org.geotoolkit.wps.xml.v200.LiteralDataDomain) Test(org.junit.Test)

Example 3 with LiteralValue

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

the class WPSConvertersUtils method geojsonContentAsString.

/**
 * Extract the GeoJSON content of a complex and return it as a String.
 *
 * Pre-condition : the complex must have exactly one content element
 * Pre-condition : the content must be either of the type GeoJSONType, String
 * or Node
 *
 * @param objContent the complex to read
 * @return the complex content as a String
 */
public static String geojsonContentAsString(final Object objContent) {
    ArgumentChecks.ensureNonNull("Data", objContent);
    Object content = objContent;
    if (content instanceof Data) {
        List<Object> contents = ((Data) content).getContent();
        if (contents == null || contents.isEmpty()) {
            content = "";
        } else if (contents.size() > 1) {
            throw new UnconvertibleObjectException("We search for a single text content, but given data contains " + contents.size());
        } else {
            content = contents.get(0);
        }
    }
    // Data can contain a literal value, so we test it after
    if (content instanceof LiteralValue) {
        content = ((LiteralValue) content).getValue();
    } else if (content instanceof Node) {
        // Otherwise, data could contain a Dom node (rarely), so we also test it
        content = ((Node) content).getTextContent();
    }
    if (content instanceof String)
        // TODO: remove CDATA ?
        return (String) content;
    throw new UnconvertibleObjectException("Cannot extract text content from source " + objContent.getClass().getName());
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Node(org.w3c.dom.Node) GeoJSONObject(org.geotoolkit.internal.geojson.binding.GeoJSONObject) Data(org.geotoolkit.wps.xml.v200.Data) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) LiteralValue(org.geotoolkit.wps.xml.v200.LiteralValue)

Example 4 with LiteralValue

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

the class LiteralAdaptor method fromWPS2Input.

@Override
public T fromWPS2Input(DataOutput candidate) {
    final Data data = candidate.getData();
    final LiteralValue literalData = data.getLiteralData();
    final String value = literalData.getValue();
    return convert(value);
}
Also used : Data(org.geotoolkit.wps.xml.v200.Data) LiteralValue(org.geotoolkit.wps.xml.v200.LiteralValue)

Example 5 with LiteralValue

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

the class LiteralAdaptorTest method doubleWPS2.

@Test
public void doubleWPS2() {
    final DomainMetadataType metaType = new DomainMetadataType(null, "xs:double");
    final LiteralDataDomain domain = new LiteralDataDomain();
    domain.setDataType(metaType);
    final LiteralAdaptor adaptor = LiteralAdaptor.create(domain);
    assertEquals(Double.class, adaptor.getValueClass());
    final DataOutput output = new DataOutput();
    final LiteralValue lit = new LiteralValue();
    lit.setValue("3.14");
    final Data data = new Data(lit);
    output.setData(data);
    final Object result = adaptor.fromWPS2Input(output);
    assertEquals(3.14, (Double) result, DELTA);
}
Also used : DomainMetadataType(org.geotoolkit.ows.xml.v200.DomainMetadataType) DataOutput(org.geotoolkit.wps.xml.v200.DataOutput) LiteralValue(org.geotoolkit.wps.xml.v200.LiteralValue) Data(org.geotoolkit.wps.xml.v200.Data) LiteralDataDomain(org.geotoolkit.wps.xml.v200.LiteralDataDomain) Test(org.junit.Test)

Aggregations

Data (org.geotoolkit.wps.xml.v200.Data)7 LiteralValue (org.geotoolkit.wps.xml.v200.LiteralValue)7 Test (org.junit.Test)4 DomainMetadataType (org.geotoolkit.ows.xml.v200.DomainMetadataType)3 DataOutput (org.geotoolkit.wps.xml.v200.DataOutput)3 LiteralDataDomain (org.geotoolkit.wps.xml.v200.LiteralDataDomain)3 DataInput (org.geotoolkit.wps.xml.v200.DataInput)2 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)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 GeoJSONObject (org.geotoolkit.internal.geojson.binding.GeoJSONObject)1 BoundingBoxType (org.geotoolkit.ows.xml.v200.BoundingBoxType)1 ExecuteRequest (org.geotoolkit.wps.client.ExecuteRequest)1 WebProcessingClient (org.geotoolkit.wps.client.WebProcessingClient)1 ComplexData (org.geotoolkit.wps.xml.v200.ComplexData)1