Search in sources :

Example 11 with Reference

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

the class GeometryToReferenceConverter method convert.

/**
 * {@inheritDoc}
 */
@Override
public Reference convert(final Geometry source, final Map<String, Object> params) throws UnconvertibleObjectException {
    if (params.get(TMP_DIR_PATH) == null) {
        throw new UnconvertibleObjectException("The output directory should be defined.");
    }
    if (source == null) {
        throw new UnconvertibleObjectException("The output data should be defined.");
    }
    if (!(source instanceof Geometry)) {
        throw new UnconvertibleObjectException("The geometry is not an JTS geometry.");
    }
    Reference reference = new Reference();
    reference.setMimeType((String) params.get(MIME));
    reference.setEncoding((String) params.get(ENCODING));
    reference.setSchema((String) params.get(SCHEMA));
    String gmlVersion = (String) params.get(GMLVERSION);
    if (gmlVersion == null) {
        gmlVersion = "3.1.1";
    }
    final String randomPathName = UUID.randomUUID().toString() + getFileExtension(reference.getMimeType());
    final Path geometryFile = buildPath(params, randomPathName);
    final String tmpDirUrl = (String) params.get(TMP_DIR_URL);
    OutputStream geometryStream = null;
    try {
        geometryStream = Files.newOutputStream(geometryFile);
        if (WPSMimeType.APP_GML.val().equalsIgnoreCase(reference.getMimeType()) || WPSMimeType.TEXT_XML.val().equalsIgnoreCase(reference.getMimeType()) || WPSMimeType.TEXT_GML.val().equalsIgnoreCase(reference.getMimeType()) || reference.getMimeType() == null) {
            // default to XML
            final Marshaller m = WPSMarshallerPool.getInstance().acquireMarshaller();
            m.marshal(JTStoGeometry.toGML(gmlVersion, source), geometryStream);
            final String relLoc = getRelativeLocation(geometryFile, params);
            reference.setHref(tmpDirUrl + '/' + relLoc.replace('\\', '/'));
            WPSMarshallerPool.getInstance().recycle(m);
        } else if (WPSMimeType.APP_GEOJSON.val().equalsIgnoreCase(reference.getMimeType())) {
            GeoJSONStreamWriter.writeSingleGeometry(geometryStream, source, JsonEncoding.UTF8, WPSConvertersUtils.FRACTION_DIGITS, true);
            final String relLoc = getRelativeLocation(geometryFile, params);
            reference.setHref(tmpDirUrl + '/' + relLoc.replace('\\', '/'));
        } else {
            throw new UnconvertibleObjectException("Unsupported mime-type for " + this.getClass().getName() + " : " + reference.getMimeType());
        }
    } catch (FactoryException ex) {
        throw new UnconvertibleObjectException("Can't convert the JTS geometry to OpenGIS.", ex);
    } catch (FileNotFoundException ex) {
        throw new UnconvertibleObjectException("Can't create output reference file.", ex);
    } catch (JAXBException ex) {
        throw new UnconvertibleObjectException("JAXB exception while writing the geometry", ex);
    } catch (IOException ex) {
        throw new UnconvertibleObjectException(ex);
    } finally {
        try {
            if (geometryStream != null)
                geometryStream.close();
        } catch (IOException ex) {
            throw new UnconvertibleObjectException("Can't close the output reference file stream.", ex);
        }
    }
    return reference;
}
Also used : JTStoGeometry(org.geotoolkit.gml.JTStoGeometry) Geometry(org.locationtech.jts.geom.Geometry) Path(java.nio.file.Path) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Marshaller(javax.xml.bind.Marshaller) FactoryException(org.opengis.util.FactoryException) Reference(org.geotoolkit.wps.xml.v200.Reference) JAXBException(javax.xml.bind.JAXBException)

Example 12 with Reference

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

the class NumberToReferenceConverter method convert.

@Override
public Reference convert(final Number source, final Map<String, Object> params) throws UnconvertibleObjectException {
    if (params.get(TMP_DIR_PATH) == null) {
        throw new UnconvertibleObjectException("The output directory should be defined.");
    }
    if (source == null) {
        throw new UnconvertibleObjectException("The output data should be defined.");
    }
    Reference reference = new Reference();
    reference.setMimeType((String) params.get(MIME));
    reference.setEncoding((String) params.get(ENCODING));
    reference.setSchema((String) params.get(SCHEMA));
    reference.setMimeType("text/plain");
    reference.setEncoding("UTF-8");
    reference.setSchema(null);
    final String randomFileName = UUID.randomUUID().toString();
    try {
        // create file
        final Path literalFile = buildPath(params, randomFileName);
        IOUtilities.writeString(String.valueOf(source), literalFile);
        final String relLoc = getRelativeLocation(literalFile, params);
        reference.setHref((String) params.get(TMP_DIR_URL) + "/" + relLoc);
    } catch (IOException ex) {
        throw new UnconvertibleObjectException("Error occurs during string writing.", ex);
    }
    return reference;
}
Also used : Path(java.nio.file.Path) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Reference(org.geotoolkit.wps.xml.v200.Reference) IOException(java.io.IOException)

Example 13 with Reference

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

the class UriToReferenceConverter method convert.

@Override
public Reference convert(URI source, Map<String, Object> params) throws UnconvertibleObjectException {
    if (source == null)
        return null;
    final Reference reference = new Reference();
    reference.setHref(source.toString());
    mapParameters(reference, params);
    return reference;
}
Also used : Reference(org.geotoolkit.wps.xml.v200.Reference)

Example 14 with Reference

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

the class UrlConnectionToReferenceConverter method convert.

@Override
public Reference convert(URLConnection source, Map<String, Object> params) throws UnconvertibleObjectException {
    final Reference reference = new Reference();
    reference.setHref(source.getURL().toString());
    mapParameters(reference, params);
    return reference;
}
Also used : Reference(org.geotoolkit.wps.xml.v200.Reference)

Example 15 with Reference

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

the class UrlToReferenceConverter method convert.

@Override
public Reference convert(URL source, Map<String, Object> params) throws UnconvertibleObjectException {
    final Reference reference = new Reference();
    reference.setHref(source.toString());
    mapParameters(reference, params);
    return reference;
}
Also used : Reference(org.geotoolkit.wps.xml.v200.Reference)

Aggregations

Reference (org.geotoolkit.wps.xml.v200.Reference)34 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)17 Path (java.nio.file.Path)14 Test (org.junit.Test)11 IOException (java.io.IOException)9 URL (java.net.URL)9 HashMap (java.util.HashMap)9 JAXBException (javax.xml.bind.JAXBException)6 AbstractWPSConverterTest (org.geotoolkit.wps.converters.AbstractWPSConverterTest)6 ArrayList (java.util.ArrayList)5 Feature (org.opengis.feature.Feature)5 BufferedReader (java.io.BufferedReader)4 DataStoreException (org.apache.sis.storage.DataStoreException)4 Geometry (org.locationtech.jts.geom.Geometry)4 RenderedImage (java.awt.image.RenderedImage)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 Reference (org.dishevelled.bio.assembly.gfa1.Reference)3 Traversal (org.dishevelled.bio.assembly.gfa1.Traversal)3 Reference (com.google.api.expr.v1alpha1.Reference)2 HashBasedTable (com.google.common.collect.HashBasedTable)2