Search in sources :

Example 16 with Reference

use of org.geotoolkit.wps.xml.v200.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 17 with Reference

use of org.geotoolkit.wps.xml.v200.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 18 with Reference

use of org.geotoolkit.wps.xml.v200.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)

Example 19 with Reference

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

the class ComplexAdaptor method toWPS2Input.

/**
 * Convert java object to WPS-2 input.
 *
 * <p>
 * Default implementation of this method only support objects of type Reference.
 * </p>
 *
 * @param candidate
 * @return
 */
@Override
public DataInput toWPS2Input(T candidate) throws UnconvertibleObjectException {
    if (candidate instanceof ReferenceProxy) {
        final Reference reference = ((ReferenceProxy) candidate).getReference();
        final Reference ref;
        if (reference instanceof Reference) {
            ref = (Reference) reference;
        } else {
            ref = new Reference();
            ref.setHref(reference.getHref());
            ref.setEncoding(reference.getEncoding());
            ref.setMimeType(reference.getMimeType());
            ref.setSchema(reference.getSchema());
            ref.setBody(reference.getBody());
        }
        final DataInput dit = new DataInput();
        dit.setReference(ref);
        return dit;
    }
    throw new UnconvertibleObjectException("Unsupported value.");
}
Also used : ReferenceProxy(org.geotoolkit.wps.xml.ReferenceProxy) DataInput(org.geotoolkit.wps.xml.v200.DataInput) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Reference(org.geotoolkit.wps.xml.v200.Reference)

Example 20 with Reference

use of org.geotoolkit.wps.xml.v200.Reference in project eclipselink by eclipse-ee4j.

the class MetadataResource method buildEntitySchemaResponse.

private Response buildEntitySchemaResponse(String version, String persistenceUnit, String entityName, UriInfo uriInfo) {
    JPARSLogger.entering(CLASS_NAME, "buildEntitySchemaResponse", new Object[] { "GET", version, persistenceUnit, uriInfo.getRequestUri().toASCIIString() });
    final String result;
    try {
        final PersistenceContext context = getPersistenceContext(persistenceUnit, null, uriInfo.getBaseUri(), version, null);
        final ClassDescriptor descriptor = context.getServerSession().getDescriptorForAlias(entityName);
        if (descriptor == null) {
            JPARSLogger.error(context.getSessionLog(), "jpars_could_not_find_entity_type", new Object[] { entityName, persistenceUnit });
            throw JPARSException.classOrClassDescriptorCouldNotBeFoundForEntity(entityName, persistenceUnit);
        } else {
            final ResourceSchema schema = new ResourceSchema();
            schema.setTitle(descriptor.getAlias());
            schema.setSchema(HrefHelper.buildEntityMetadataHref(context, descriptor.getAlias()) + "#");
            schema.addAllOf(new Reference(HrefHelper.buildBaseRestSchemaRef("#/singularResource")));
            // Properties
            for (DatabaseMapping databaseMapping : descriptor.getMappings()) {
                schema.addProperty(databaseMapping.getAttributeName(), buildProperty(context, databaseMapping));
            }
            // Links
            final String instancesHref = HrefHelper.buildEntityDescribesHref(context, descriptor.getAlias());
            schema.setLinks((new ItemLinksBuilder()).addDescribedBy(HrefHelper.buildEntityMetadataHref(context, descriptor.getAlias())).addFind(instancesHref + "/{primaryKey}").addCreate(instancesHref).addUpdate(instancesHref).addDelete(instancesHref + "/{primaryKey}").getList());
            result = marshallMetadata(schema, MediaType.APPLICATION_JSON);
        }
    } catch (JAXBException e) {
        throw JPARSException.exceptionOccurred(e);
    }
    return Response.ok(new StreamingOutputMarshaller(null, result, AbstractResource.APPLICATION_SCHEMA_JSON_TYPE)).build();
}
Also used : ItemLinksBuilder(org.eclipse.persistence.jpa.rs.features.ItemLinksBuilder) ResourceSchema(org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.ResourceSchema) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Reference(org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference) JAXBException(jakarta.xml.bind.JAXBException) PersistenceContext(org.eclipse.persistence.jpa.rs.PersistenceContext) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) StreamingOutputMarshaller(org.eclipse.persistence.jpa.rs.util.StreamingOutputMarshaller)

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