use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.
the class ReferenceToGridCoverage2DConverterTest method testConversion.
@Test
@org.junit.Ignore("Fails randomly because of GeoTIFF reader not found.")
public void testConversion() throws UnconvertibleObjectException, IOException {
final WPSObjectConverter<Reference, GridCoverage> converter = WPSConverterRegistry.getInstance().getConverter(Reference.class, GridCoverage.class);
final URL coverage = ReferenceToRenderedImageConverterTest.class.getResource("/inputs/coverage.tiff");
assertNotNull(coverage);
final Map<String, Object> parameters = new HashMap<>();
parameters.put(AbstractReferenceInputConverter.IOTYPE, WPSIO.IOType.INPUT);
parameters.put(AbstractReferenceInputConverter.MIME, "image/geotiff");
final Reference reference = new Reference();
reference.setHref(coverage.toString());
reference.setMimeType("image/x-geotiff");
reference.setEncoding(null);
final GridCoverage convertedCvg = converter.convert(reference, parameters);
assertNotNull(convertedCvg);
final GridCoverage expectedCvg = ConvertersTestUtils.makeCoverage();
final Envelope convertedEnvelope = convertedCvg.getGridGeometry().getEnvelope();
final Envelope expectedEnvelope = expectedCvg.getGridGeometry().getEnvelope();
assertTrue(Utilities.equalsIgnoreMetadata(expectedEnvelope.getCoordinateReferenceSystem(), convertedEnvelope.getCoordinateReferenceSystem()));
assertTrue(expectedEnvelope.getMinimum(0) == convertedEnvelope.getMinimum(0));
assertTrue(expectedEnvelope.getMinimum(1) == convertedEnvelope.getMinimum(1));
assertTrue(expectedEnvelope.getMaximum(0) == convertedEnvelope.getMaximum(0));
assertTrue(expectedEnvelope.getMaximum(1) == convertedEnvelope.getMaximum(1));
Assert.assertRasterEquals(expectedCvg.render(null), convertedCvg.render(null));
}
use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.
the class ReferenceToRenderedImageConverterTest method testConversionBase64.
@Test
public void testConversionBase64() throws UnconvertibleObjectException, IOException {
final WPSObjectConverter<Reference, RenderedImage> converter = WPSConverterRegistry.getInstance().getConverter(Reference.class, RenderedImage.class);
final URL imageBase64 = ReferenceToRenderedImageConverterTest.class.getResource("/inputs/image_tiff_base64");
assertNotNull(imageBase64);
final Map<String, Object> parameters = new HashMap<>();
parameters.put(AbstractReferenceInputConverter.IOTYPE, WPSIO.IOType.INPUT);
parameters.put(AbstractReferenceInputConverter.ENCODING, "base64");
final Reference reference = new Reference();
reference.setHref(imageBase64.toString());
reference.setMimeType("image/tiff");
reference.setEncoding("base64");
final RenderedImage convertedImage = converter.convert(reference, parameters);
assertNotNull(convertedImage);
final RenderedImage expectedImage = ConvertersTestUtils.makeRendredImage();
assertRasterEquals(expectedImage, convertedImage);
}
use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.
the class GeometryArrayToReferenceConverterTest method testJSONConversion.
@Test
public void testJSONConversion() throws IOException, FactoryException, URISyntaxException, DataStoreException {
// Get test resource
final Object testResource = ConvertersTestUtils.loadTestResource("/inputs/geometrycollection.json");
final 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());
final Geometry[] geometryArray = ConvertersTestUtils.getGeometryArrayFromInputStream(new FileInputStream(new File(new URL(reference.getHref()).toURI())));
ConvertersTestUtils.assertGeometryArrayIsValid((Geometry[]) testResource);
ConvertersTestUtils.assertGeometryArrayIsValid(geometryArray);
}
use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.
the class UrlConnectionToReferenceConverterTest method convert.
@Test
public void convert() throws Exception {
final WPSObjectConverter<URLConnection, Reference> converter = WPSConverterRegistry.getInstance().getConverter(URLConnection.class, Reference.class);
final URL url = new URL("https://toto.titi/tata");
URLConnection conn = url.openConnection();
Reference ref = converter.convert(conn, Collections.singletonMap(WPSObjectConverter.IOTYPE, (Object) WPSIO.IOType.OUTPUT.name()));
Assert.assertEquals("Href differs !", url.toExternalForm(), ref.getHref());
}
use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.
the class FeatureCollectionToReferenceConverter method convert.
/**
* {@inheritDoc}
*/
@Override
public Reference convert(final FeatureCollection 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 (params.get(TMP_DIR_URL) == null) {
throw new UnconvertibleObjectException("The output directory URL should be defined.");
}
if (source == null) {
throw new UnconvertibleObjectException("The output data should be defined.");
}
// TODO : useless test, null test above is all we need, fix this and other converters
if (!(source instanceof FeatureCollection)) {
throw new UnconvertibleObjectException("The requested output data is not an instance of FeatureCollection.");
}
Reference reference = new Reference();
reference.setMimeType((String) params.get(MIME));
reference.setEncoding((String) params.get(ENCODING));
final FeatureType ft = source.getType();
final String namespace = NamesExt.getNamespace(ft.getName());
final Map<String, String> schemaLocation = new HashMap<>();
final String randomFileName = UUID.randomUUID().toString();
if (WPSMimeType.APP_GEOJSON.val().equalsIgnoreCase(reference.getMimeType())) {
// create file
final Path dataFile = buildPath(params, randomFileName + ".json");
try (OutputStream fos = Files.newOutputStream(dataFile, CREATE, TRUNCATE_EXISTING, WRITE);
GeoJSONStreamWriter writer = new GeoJSONStreamWriter(fos, ft, WPSConvertersUtils.FRACTION_DIGITS);
Stream<Feature> st = source.features(false)) {
Iterator<Feature> iterator = st.iterator();
while (iterator.hasNext()) {
Feature next = iterator.next();
Feature neww = writer.next();
FeatureExt.copy(next, neww, false);
writer.write();
}
} catch (DataStoreException e) {
throw new UnconvertibleObjectException("Can't write Feature into GeoJSON output stream.", e);
} catch (IOException e) {
throw new UnconvertibleObjectException(e);
}
final String relLoc = getRelativeLocation(dataFile, params);
reference.setHref(params.get(TMP_DIR_URL) + "/" + relLoc);
reference.setSchema(null);
} else if (WPSMimeType.APP_GML.val().equalsIgnoreCase(reference.getMimeType()) || WPSMimeType.TEXT_XML.val().equalsIgnoreCase(reference.getMimeType()) || WPSMimeType.TEXT_GML.val().equalsIgnoreCase(reference.getMimeType())) {
try {
reference.setSchema(WPSConvertersUtils.writeSchema(ft, params));
schemaLocation.put(namespace, reference.getSchema());
} catch (JAXBException ex) {
throw new UnconvertibleObjectException("Can't write FeatureType into xsd schema.", ex);
} catch (IOException ex) {
throw new UnconvertibleObjectException("Can't create xsd schema file.", ex);
}
// Write Feature
final JAXPStreamFeatureWriter featureWriter = new JAXPStreamFeatureWriter(schemaLocation);
// create file
final Path dataFile = buildPath(params, randomFileName + ".xml");
try (final OutputStream dataStream = Files.newOutputStream(dataFile);
final AutoCloseable xmlCloser = () -> featureWriter.dispose()) {
// Write feature in file
featureWriter.write(source, dataStream);
final String relLoc = getRelativeLocation(dataFile, params);
reference.setHref(params.get(TMP_DIR_URL) + "/" + relLoc);
} catch (XMLStreamException ex) {
throw new UnconvertibleObjectException("Stax exception while writing the feature collection", ex);
} catch (DataStoreException ex) {
throw new UnconvertibleObjectException("FeatureStore exception while writing the feature collection", ex);
} catch (FeatureStoreRuntimeException ex) {
throw new UnconvertibleObjectException("FeatureStoreRuntimeException exception while writing the feature collection", ex);
} catch (Exception ex) {
throw new UnconvertibleObjectException(ex);
}
} else {
throw new UnconvertibleObjectException("Unsupported mime-type for " + this.getClass().getName() + " : " + reference.getMimeType());
}
return reference;
}
Aggregations