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);
}
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);
}
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()));
}
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;
}
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;
}
Aggregations