Search in sources :

Example 41 with Reference

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

the class GeometryToReferenceConverterTest method testJSONConversion.

@Test
public void testJSONConversion() throws DataStoreException, IOException, URISyntaxException, FactoryException {
    // Get test resource
    final Object testResource = ConvertersTestUtils.loadTestResource("/inputs/geometry.json");
    Reference reference = ConvertersTestUtils.initAndRunOutputConversion(Geometry.class, Reference.class, testResource, WPSMimeType.APP_GEOJSON.val(), WPSEncoding.UTF8.getValue());
    // Test reference
    assertEquals(WPSMimeType.APP_GEOJSON.val(), reference.getMimeType());
    assertEquals(WPSEncoding.UTF8.getValue(), reference.getEncoding());
    assertNull(reference.getSchema());
    assertNotNull(reference.getHref());
    Geometry geometry = ConvertersTestUtils.getGeometryFromGeoJsonContent(Paths.get(URI.create(reference.getHref())));
    ConvertersTestUtils.assertGeometryIsValid((Geometry) testResource);
    ConvertersTestUtils.assertGeometryIsValid(geometry);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Reference(org.geotoolkit.wps.xml.v200.Reference) Test(org.junit.Test)

Example 42 with Reference

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

the class ReferenceToRenderedImageConverterTest method testConversion.

@Test
public void testConversion() throws UnconvertibleObjectException, IOException {
    final WPSObjectConverter<Reference, RenderedImage> converter = WPSConverterRegistry.getInstance().getConverter(Reference.class, RenderedImage.class);
    final URL image = ReferenceToRenderedImageConverterTest.class.getResource("/inputs/image.tiff");
    assertNotNull(image);
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put(AbstractReferenceInputConverter.IOTYPE, WPSIO.IOType.INPUT);
    final Reference reference = new Reference();
    reference.setHref(image.toString());
    reference.setMimeType("image/tiff");
    reference.setEncoding(null);
    final RenderedImage convertedImage = converter.convert(reference, parameters);
    assertNotNull(convertedImage);
    final RenderedImage expectedImage = ConvertersTestUtils.makeRendredImage();
    assertRasterEquals(expectedImage, convertedImage);
}
Also used : HashMap(java.util.HashMap) Reference(org.geotoolkit.wps.xml.v200.Reference) RenderedImage(java.awt.image.RenderedImage) URL(java.net.URL) AbstractWPSConverterTest(org.geotoolkit.wps.converters.AbstractWPSConverterTest) Test(org.junit.Test)

Example 43 with Reference

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

the class ReferenceToUrlConnectionConverterTest method convert.

@Test
public void convert() throws Exception {
    final WPSObjectConverter<Reference, URLConnection> converter = WPSConverterRegistry.getInstance().getConverter(Reference.class, URLConnection.class);
    final Reference ref = new Reference();
    ref.setHref("https://my.domain/context");
    final Reference.Header header = new Reference.Header();
    header.setKey("myKey");
    header.setValue("myValue");
    ref.getHeader().add(header);
    final URLConnection con = converter.convert(ref, Collections.singletonMap(WPSObjectConverter.IOTYPE, (Object) WPSIO.IOType.INPUT.name()));
    Assert.assertEquals("HRef differs !", ref.getHref(), con.getURL().toExternalForm());
    Assert.assertEquals("No header has been copied !", header.getValue(), con.getRequestProperty(header.getKey()));
}
Also used : Reference(org.geotoolkit.wps.xml.v200.Reference) URLConnection(java.net.URLConnection) AbstractWPSConverterTest(org.geotoolkit.wps.converters.AbstractWPSConverterTest) Test(org.junit.Test)

Example 44 with Reference

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

the class AbstractReferenceInputConverter method connect.

protected static URLConnection connect(final Reference ref) throws UnconvertibleObjectException {
    final String brutHref;
    if (ref == null || (brutHref = ref.getHref()) == null) {
        throw new UnconvertibleObjectException("Null reference given.");
    }
    final URL href;
    try {
        final String decoded = URLDecoder.decode(brutHref, "UTF-8");
        href = new URL(decoded);
    } catch (UnsupportedEncodingException | MalformedURLException ex) {
        throw new UnconvertibleObjectException("Invalid reference href: " + brutHref, ex);
    }
    final URLConnection connection;
    try {
        connection = href.openConnection();
    } catch (IOException ex) {
        throw new UnconvertibleObjectException("Cannot connect to reference url:" + href, ex);
    }
    for (final Reference.Header header : ref.getHeader()) {
        connection.addRequestProperty(header.getKey(), header.getValue());
    }
    addBody(connection, ref.getBody(), ref.getBodyReference());
    return connection;
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) MalformedURLException(java.net.MalformedURLException) Reference(org.geotoolkit.wps.xml.v200.Reference) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 45 with Reference

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

the class BooleanToReferenceConverter method convert.

@Override
public Reference convert(final Boolean 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 occure during image 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)

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