Search in sources :

Example 31 with Reference

use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project cel-java by projectnessie.

the class Checker method setReference.

void setReference(Expr.Builder e, Reference r) {
    Reference old = references.get(e.getId());
    if (old != null && !old.equals(r)) {
        throw new IllegalStateException(String.format("Reference already exists for expression: %s(%d) old:%s, new:%s", e, e.getId(), old, r));
    }
    references.put(e.getId(), r);
}
Also used : Reference(com.google.api.expr.v1alpha1.Reference)

Example 32 with Reference

use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.

the class ConvertersTestUtils method createReference.

/**
 * Helper method that creates a Reference with all its field filled
 * @param mimeType can be null
 * @param encoding can be null
 * @param schema can be null
 * @param url must be set
 * @return the reference with its field filled using the above parameters
 */
public static final Reference createReference(String version, String mimeType, String encoding, String schema, URL url) {
    final Reference reference = new Reference();
    reference.setMimeType(mimeType);
    reference.setEncoding(encoding);
    reference.setSchema(schema);
    reference.setHref(url.toString());
    return reference;
}
Also used : Reference(org.geotoolkit.wps.xml.v200.Reference)

Example 33 with Reference

use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.

the class FeatureSetToReferenceConverter method convert.

/**
 * {@inheritDoc}
 */
@Override
public Reference convert(final FeatureSet 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 FeatureSet)) {
        throw new UnconvertibleObjectException("The requested output data is not an instance of FeatureSet.");
    }
    Reference reference = new Reference();
    reference.setMimeType((String) params.get(MIME));
    reference.setEncoding((String) params.get(ENCODING));
    final FeatureType ft;
    try {
        ft = source.getType();
    } catch (DataStoreException ex) {
        throw new UnconvertibleObjectException("Can't write acess FeatureSet type.", ex);
    }
    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;
}
Also used : Path(java.nio.file.Path) FeatureType(org.opengis.feature.FeatureType) DataStoreException(org.apache.sis.storage.DataStoreException) HashMap(java.util.HashMap) Reference(org.geotoolkit.wps.xml.v200.Reference) JAXBException(javax.xml.bind.JAXBException) JAXPStreamFeatureWriter(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureWriter) Feature(org.opengis.feature.Feature) XMLStreamException(javax.xml.stream.XMLStreamException) DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) JAXBException(javax.xml.bind.JAXBException) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) XMLStreamException(javax.xml.stream.XMLStreamException) GeoJSONStreamWriter(org.geotoolkit.storage.geojson.GeoJSONStreamWriter) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) FeatureSet(org.apache.sis.storage.FeatureSet)

Example 34 with Reference

use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.

the class FileToReferenceConverter method convert.

@Override
public Reference convert(File source, 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));
    final Path targetDirectory = buildPath(params, null);
    final String tmpDir = getTemproraryDirectoryPath(params);
    final String tmpDirUrl = (String) params.get(TMP_DIR_URL);
    try {
        // if the source is already in the temp folder
        if (source.getAbsolutePath().startsWith(tmpDir)) {
            reference.setHref(source.getAbsolutePath().replace(tmpDir, tmpDirUrl));
        // else we create a link from the source file in temp dir
        } else {
            final Path target = targetDirectory.resolve(source.getName());
            Files.createSymbolicLink(target, source.toPath());
            // IOUtilities.copy(source.toPath(),target);
            String suffix = getRelativeLocation(target, tmpDir);
            reference.setHref(tmpDirUrl + "/" + suffix);
        }
    } catch (IOException ex) {
        throw new UnconvertibleObjectException("Error during moving file to output directory.", 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 35 with Reference

use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.

the class GeometryArrayToReferenceConverter method convert.

@Override
public Reference convert(Geometry[] source, 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));
    final String randomFilename = UUID.randomUUID().toString() + ".json";
    final Path geometryArrayFile = buildPath(params, randomFilename);
    try {
        if (WPSMimeType.APP_GEOJSON.val().equalsIgnoreCase(reference.getMimeType())) {
            try (OutputStream geometryStream = Files.newOutputStream(geometryArrayFile)) {
                GeometryFactory geometryFactory = org.geotoolkit.geometry.jts.JTS.getFactory();
                Geometry toWrite = new GeometryCollection(source, geometryFactory);
                GeoJSONStreamWriter.writeSingleGeometry(geometryStream, toWrite, JsonEncoding.UTF8, WPSConvertersUtils.FRACTION_DIGITS, true);
            }
            reference.setHref(geometryArrayFile.toUri().toURL().toString());
            return reference;
        } else
            throw new UnconvertibleObjectException("Unsupported mime-type for " + this.getClass().getName() + " : " + reference.getMimeType());
    } catch (FileNotFoundException ex) {
        throw new UnconvertibleObjectException("Unable to find the reference file");
    } catch (IOException ex) {
        throw new UnconvertibleObjectException(ex);
    }
}
Also used : Path(java.nio.file.Path) Geometry(org.locationtech.jts.geom.Geometry) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Reference(org.geotoolkit.wps.xml.v200.Reference) OutputStream(java.io.OutputStream) FileNotFoundException(java.io.FileNotFoundException) 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