Search in sources :

Example 16 with Reference

use of com.google.api.expr.v1alpha1.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 17 with Reference

use of com.google.api.expr.v1alpha1.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)

Example 18 with Reference

use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.

the class CoverageToReferenceConverter method convert.

/**
 * {@inheritDoc}
 */
@Override
public Reference convert(final GridCoverage 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();
    final String encodingStr = (String) params.get(ENCODING);
    final String mimeStr = (String) params.get(MIME) != null ? (String) params.get(MIME) : WPSMimeType.IMG_GEOTIFF.val();
    final WPSMimeType mime = WPSMimeType.customValueOf(mimeStr);
    reference.setMimeType(mimeStr);
    reference.setEncoding(encodingStr);
    reference.setSchema((String) params.get(SCHEMA));
    final String formatName;
    final String[] formatNames = XImageIO.getFormatNamesByMimeType(mimeStr, true, true);
    formatName = (formatNames.length < 1) ? "GEOTIFF" : formatNames[0];
    final String randomFileName = UUID.randomUUID().toString();
    try {
        final Path imageFile = buildPath(params, randomFileName);
        if (encodingStr != null && encodingStr.equals(WPSEncoding.BASE64.getValue())) {
            try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
                CoverageIO.write(source, formatName, baos);
                baos.flush();
                byte[] bytesOut = baos.toByteArray();
                IOUtilities.writeString(Base64.getEncoder().encodeToString(bytesOut), imageFile);
            }
        } else {
            // Note : do not do OutputStream out = Files.newOutputStream(imageFile, StandardOpenOption.CREATE, WRITE, TRUNCATE_EXISTING)
            // Most coverage writer do not support stream writing properly, it is better to work with a file.
            // This also avoid keeping large files in memory if byte buffer seeking is needed by the writer.
            Files.deleteIfExists(imageFile);
            CoverageIO.write(source, formatName, imageFile);
        }
        final String relLoc = getRelativeLocation(imageFile, params);
        reference.setHref((String) params.get(TMP_DIR_URL) + "/" + relLoc);
    } catch (IOException | DataStoreException ex) {
        throw new UnconvertibleObjectException("Error during writing the coverage in the output file.", ex);
    }
    return reference;
}
Also used : Path(java.nio.file.Path) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) DataStoreException(org.apache.sis.storage.DataStoreException) WPSMimeType(org.geotoolkit.wps.io.WPSMimeType) Reference(org.geotoolkit.wps.xml.v200.Reference) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 19 with Reference

use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.

the class WPSConvertersUtils method featureToParameterGroup.

/**
 * Convert a feature into a ParameterValueGroup.
 *
 * This function will try to convert objects if their types doesn't match between feature and parameter.
 * Then fill a ParameterValueGroup which contains data of the feature in parameter.
 *
 * @param version WPS version
 * @param toConvert The feature to transform.
 * @param toFill The descriptor of the ParameterValueGroup which will be created.
 */
public static void featureToParameterGroup(String version, Feature toConvert, ParameterValueGroup toFill) throws UnconvertibleObjectException {
    ArgumentChecks.ensureNonNull("feature", toConvert);
    ArgumentChecks.ensureNonNull("ParameterGroup", toFill);
    final WPSConverterRegistry registry = WPSConverterRegistry.getInstance();
    final Parameters toFill2 = Parameters.castOrWrap(toFill);
    for (final GeneralParameterDescriptor gpd : toFill.getDescriptor().descriptors()) {
        if (gpd instanceof ParameterDescriptor) {
            final Property prop = toConvert.getProperty(gpd.getName().getCode());
            if (prop == null && gpd.getMinimumOccurs() > 0) {
                throw new UnconvertibleObjectException("A mandatory attribute can't be found");
            }
            final ParameterDescriptor desc = (ParameterDescriptor) gpd;
            if (prop.getValue().getClass().isAssignableFrom(desc.getValueClass()) || desc.getValueClass().isAssignableFrom(prop.getValue().getClass())) {
                toFill2.getOrCreate(desc).setValue(prop.getValue());
            } else {
                if (prop.getValue().getClass().isAssignableFrom(URI.class)) {
                    Reference type = UriToReference(version, (URI) prop.getValue(), WPSIO.IOType.INPUT, null);
                    WPSObjectConverter converter = registry.getConverter(type.getClass(), desc.getValueClass());
                    toFill2.getOrCreate(desc).setValue(converter.convert(type, null));
                }
            }
        } else if (gpd instanceof ParameterDescriptorGroup) {
            final Collection<Feature> propCollection = (Collection<Feature>) toConvert.getPropertyValue(gpd.getName().getCode());
            int filledGroups = 0;
            for (Feature complex : propCollection) {
                ParameterValueGroup childGroup = toFill.addGroup(gpd.getName().getCode());
                featureToParameterGroup(version, complex, childGroup);
                filledGroups++;
            }
            if (filledGroups < gpd.getMinimumOccurs()) {
                throw new UnconvertibleObjectException("Not enough attributes have been found.");
            }
        } else {
            throw new UnconvertibleObjectException("Parameter type is not managed.");
        }
    }
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Parameters(org.apache.sis.parameter.Parameters) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Reference(org.geotoolkit.wps.xml.v200.Reference) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ParameterDescriptor(org.opengis.parameter.ParameterDescriptor) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) Property(org.opengis.feature.Property) Feature(org.opengis.feature.Feature)

Example 20 with Reference

use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.

the class GMLAdaptor method fromWPS2Input.

@Override
public Object fromWPS2Input(DataOutput candidate) throws UnconvertibleObjectException {
    final Reference ref = candidate.getReference();
    if (ref != null) {
        return WPSConvertersUtils.convertFromReference(ref, FeatureSet.class);
    }
    final Data data = candidate.getData();
    if (data != null) {
        return WPSConvertersUtils.convertFromComplex(gmlVersion, data, FeatureSet.class);
    }
    throw new UnconvertibleObjectException("Niether reference or data is filled.");
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Reference(org.geotoolkit.wps.xml.v200.Reference) Data(org.geotoolkit.wps.xml.v200.Data) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData)

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 Geometry (org.locationtech.jts.geom.Geometry)4 Type (com.google.api.expr.v1alpha1.Type)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 DataStoreException (org.apache.sis.storage.DataStoreException)3 Reference (org.dishevelled.bio.assembly.gfa1.Reference)3 Traversal (org.dishevelled.bio.assembly.gfa1.Traversal)3 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)2 Decl (com.google.api.expr.v1alpha1.Decl)2