Search in sources :

Example 1 with ReferenceProxy

use of org.geotoolkit.wps.xml.ReferenceProxy in project geotoolkit by Geomatys.

the class GMLAdaptor method toWPS2Input.

@Override
public DataInput toWPS2Input(Object candidate) throws UnconvertibleObjectException {
    if (candidate instanceof ReferenceProxy)
        return super.toWPS2Input(candidate);
    final ComplexData cdt = new ComplexData();
    cdt.getContent().add(new org.geotoolkit.wps.xml.v200.Format(encoding, mimeType, schema, null));
    final JAXPStreamFeatureWriter writer = new JAXPStreamFeatureWriter(gmlVersion, null, null);
    try {
        if (ENC_BASE64.equalsIgnoreCase(encoding)) {
            final ByteArrayOutputStream out = new ByteArrayOutputStream();
            writer.write(candidate, out);
            out.flush();
            String base64 = Base64.getEncoder().encodeToString(out.toByteArray());
            cdt.getContent().add(base64);
        } else if (ENC_UTF8.equalsIgnoreCase(encoding)) {
            final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
            final DocumentBuilder constructeur = fabrique.newDocumentBuilder();
            final Document document = constructeur.newDocument();
            final DOMResult domResult = new DOMResult(document);
            writer.write(candidate, domResult);
            cdt.getContent().add(document.getDocumentElement());
        }
    } catch (IOException | XMLStreamException | DataStoreException | ParserConfigurationException ex) {
        throw new UnconvertibleObjectException(ex.getMessage(), ex);
    }
    final Data data = new Data();
    data.getContent().add(cdt);
    final DataInput dit = new DataInput();
    dit.setData(data);
    return dit;
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DOMResult(javax.xml.transform.dom.DOMResult) Data(org.geotoolkit.wps.xml.v200.Data) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JAXPStreamFeatureWriter(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureWriter) Document(org.w3c.dom.Document) ReferenceProxy(org.geotoolkit.wps.xml.ReferenceProxy) Format(org.geotoolkit.wps.xml.v200.Format) DataInput(org.geotoolkit.wps.xml.v200.DataInput) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) XMLStreamException(javax.xml.stream.XMLStreamException) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with ReferenceProxy

use of org.geotoolkit.wps.xml.ReferenceProxy in project geotoolkit by Geomatys.

the class OctetStreamAdaptor method toWPS2Input.

@Override
public DataInput toWPS2Input(Path candidate) throws UnconvertibleObjectException {
    if (candidate instanceof ReferenceProxy)
        return super.toWPS2Input(candidate);
    final byte[] bytes;
    try {
        bytes = Files.readAllBytes(candidate);
    } catch (IOException ex) {
        throw new UnconvertibleObjectException(ex.getMessage(), ex);
    }
    final String base64 = Base64.getEncoder().encodeToString(bytes);
    final DataInput dit = new DataInput();
    final Data data = new Data();
    data.setEncoding("base64");
    data.getContent().add(base64);
    dit.setData(data);
    return dit;
}
Also used : ReferenceProxy(org.geotoolkit.wps.xml.ReferenceProxy) DataInput(org.geotoolkit.wps.xml.v200.DataInput) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Data(org.geotoolkit.wps.xml.v200.Data) IOException(java.io.IOException)

Example 3 with ReferenceProxy

use of org.geotoolkit.wps.xml.ReferenceProxy in project geotoolkit by Geomatys.

the class WKTAdaptor method toWPS2Input.

@Override
public DataInput toWPS2Input(Object candidate) throws UnconvertibleObjectException {
    if (candidate instanceof ReferenceProxy)
        return super.toWPS2Input(candidate);
    final ComplexData cdt = new ComplexData();
    cdt.getContent().add(new org.geotoolkit.wps.xml.v200.Format(encoding, mimeType, null, null));
    Geometry geom = (Geometry) candidate;
    int srid = 0;
    int dimension = 2;
    try {
        CoordinateReferenceSystem crs = Geometries.wrap(geom).get().getCoordinateReferenceSystem();
        if (crs != null) {
            dimension = crs.getCoordinateSystem().getDimension();
            final IdentifiedObjectFinder finder = IdentifiedObjects.newFinder("EPSG");
            // TODO: Ensure no project strongly rely on that, then remove. It's pure non-sense/madness.
            // Note: If you read this after march 2020: do not ask : delete.
            finder.setIgnoringAxes(true);
            final CoordinateReferenceSystem epsgcrs = (CoordinateReferenceSystem) finder.findSingleton(crs);
            if (epsgcrs != null) {
                srid = IdentifiedObjects.lookupEPSG(epsgcrs);
                // force geometry in longitude first
                final CoordinateReferenceSystem crs2 = ((AbstractCRS) crs).forConvention(AxesConvention.RIGHT_HANDED);
                if (crs2 != crs) {
                    geom = org.apache.sis.internal.feature.jts.JTS.transform(geom, crs2);
                }
                if (crs2 != null)
                    dimension = crs2.getCoordinateSystem().getDimension();
            }
        }
    } catch (FactoryException | MismatchedDimensionException | TransformException ex) {
        throw new UnconvertibleObjectException(ex.getMessage(), ex);
    }
    // String wkt = geom.toText();
    WKTWriter writer = new WKTWriter(dimension);
    String wkt = writer.write(geom);
    if (srid > 0) {
        wkt = "SRID=" + srid + ";" + wkt;
    }
    cdt.getContent().add(wkt);
    final Data data = new Data();
    data.getContent().add(cdt);
    final DataInput dit = new DataInput();
    dit.setData(data);
    return dit;
}
Also used : IdentifiedObjectFinder(org.apache.sis.referencing.factory.IdentifiedObjectFinder) WKTWriter(org.locationtech.jts.io.WKTWriter) FactoryException(org.opengis.util.FactoryException) AbstractCRS(org.apache.sis.referencing.crs.AbstractCRS) TransformException(org.opengis.referencing.operation.TransformException) Data(org.geotoolkit.wps.xml.v200.Data) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) ReferenceProxy(org.geotoolkit.wps.xml.ReferenceProxy) Format(org.geotoolkit.wps.xml.v200.Format) Geometry(org.locationtech.jts.geom.Geometry) DataInput(org.geotoolkit.wps.xml.v200.DataInput) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 4 with ReferenceProxy

use of org.geotoolkit.wps.xml.ReferenceProxy in project geotoolkit by Geomatys.

the class XMLAdaptor method toWPS2Input.

@Override
public DataInput toWPS2Input(Node candidate) throws UnconvertibleObjectException {
    if (candidate instanceof ReferenceProxy) {
        return super.toWPS2Input(candidate);
    }
    final ComplexData cdt = new ComplexData();
    cdt.getContent().add(new org.geotoolkit.wps.xml.v200.Format(encoding, mimeType, schema, null));
    if (candidate instanceof Document) {
        candidate = ((Document) candidate).getDocumentElement();
    }
    cdt.getContent().add(candidate);
    final Data data = new Data();
    data.getContent().add(cdt);
    final DataInput dit = new DataInput();
    dit.setData(data);
    return dit;
}
Also used : ReferenceProxy(org.geotoolkit.wps.xml.ReferenceProxy) Format(org.geotoolkit.wps.xml.v200.Format) DataInput(org.geotoolkit.wps.xml.v200.DataInput) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) Data(org.geotoolkit.wps.xml.v200.Data) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) Document(org.w3c.dom.Document)

Example 5 with ReferenceProxy

use of org.geotoolkit.wps.xml.ReferenceProxy in project geotoolkit by Geomatys.

the class ComplexAdaptor method toWPS2Input.

/**
 * Convert java object to WPS-2 input.
 *
 * <p>
 * Default implementation of this method only support objects of type Reference.
 * </p>
 *
 * @param candidate
 * @return
 */
@Override
public DataInput toWPS2Input(T candidate) throws UnconvertibleObjectException {
    if (candidate instanceof ReferenceProxy) {
        final Reference reference = ((ReferenceProxy) candidate).getReference();
        final Reference ref;
        if (reference instanceof Reference) {
            ref = (Reference) reference;
        } else {
            ref = new Reference();
            ref.setHref(reference.getHref());
            ref.setEncoding(reference.getEncoding());
            ref.setMimeType(reference.getMimeType());
            ref.setSchema(reference.getSchema());
            ref.setBody(reference.getBody());
        }
        final DataInput dit = new DataInput();
        dit.setReference(ref);
        return dit;
    }
    throw new UnconvertibleObjectException("Unsupported value.");
}
Also used : ReferenceProxy(org.geotoolkit.wps.xml.ReferenceProxy) DataInput(org.geotoolkit.wps.xml.v200.DataInput) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Reference(org.geotoolkit.wps.xml.v200.Reference)

Aggregations

ReferenceProxy (org.geotoolkit.wps.xml.ReferenceProxy)10 DataInput (org.geotoolkit.wps.xml.v200.DataInput)10 Data (org.geotoolkit.wps.xml.v200.Data)9 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)7 IOException (java.io.IOException)5 ComplexData (org.geotoolkit.wps.xml.v200.ComplexData)5 Format (org.geotoolkit.wps.xml.v200.Format)5 Document (org.w3c.dom.Document)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 DOMResult (javax.xml.transform.dom.DOMResult)1 AbstractCRS (org.apache.sis.referencing.crs.AbstractCRS)1 IdentifiedObjectFinder (org.apache.sis.referencing.factory.IdentifiedObjectFinder)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 JAXPStreamFeatureWriter (org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureWriter)1 Reference (org.geotoolkit.wps.xml.v200.Reference)1 Geometry (org.locationtech.jts.geom.Geometry)1