Search in sources :

Example 11 with Data

use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project geotoolkit by Geomatys.

the class WPSConvertersUtils method geojsonContentAsString.

/**
 * Extract the GeoJSON content of a complex and return it as a String.
 *
 * Pre-condition : the complex must have exactly one content element
 * Pre-condition : the content must be either of the type GeoJSONType, String
 * or Node
 *
 * @param objContent the complex to read
 * @return the complex content as a String
 */
public static String geojsonContentAsString(final Object objContent) {
    ArgumentChecks.ensureNonNull("Data", objContent);
    Object content = objContent;
    if (content instanceof Data) {
        List<Object> contents = ((Data) content).getContent();
        if (contents == null || contents.isEmpty()) {
            content = "";
        } else if (contents.size() > 1) {
            throw new UnconvertibleObjectException("We search for a single text content, but given data contains " + contents.size());
        } else {
            content = contents.get(0);
        }
    }
    // Data can contain a literal value, so we test it after
    if (content instanceof LiteralValue) {
        content = ((LiteralValue) content).getValue();
    } else if (content instanceof Node) {
        // Otherwise, data could contain a Dom node (rarely), so we also test it
        content = ((Node) content).getTextContent();
    }
    if (content instanceof String)
        // TODO: remove CDATA ?
        return (String) content;
    throw new UnconvertibleObjectException("Cannot extract text content from source " + objContent.getClass().getName());
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Node(org.w3c.dom.Node) GeoJSONObject(org.geotoolkit.internal.geojson.binding.GeoJSONObject) Data(org.geotoolkit.wps.xml.v200.Data) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) LiteralValue(org.geotoolkit.wps.xml.v200.LiteralValue)

Example 12 with Data

use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project geotoolkit by Geomatys.

the class AbstractComplexInputConverter method fromXml.

private static Stream<FeatureSet> fromXml(final Data source) {
    final XmlFeatureReader fcollReader;
    try {
        fcollReader = WPSIO.getFeatureReader(source.getSchema());
    } catch (MalformedURLException ex) {
        throw new UnconvertibleObjectException("Unable to reach the schema url.", ex);
    }
    List<Object> content = new ArrayList<>();
    // extract feature nodes from gml unmarshalled feature collection
    for (Object o : source.getContent()) {
        if (o instanceof JAXBElement) {
            o = ((JAXBElement) o).getValue();
        }
        if (o instanceof FeatureCollection) {
            FeatureCollection fc = (FeatureCollection) o;
            for (FeatureProperty fp : fc.getFeatureMember()) {
                if (fp.getUnknowFeature() != null) {
                    content.add(fp.getUnknowFeature());
                } else {
                    throw new UnconvertibleObjectException("Unabel to read feature from XML.");
                }
            }
        } else {
            content.add(o);
        }
    }
    final Stream<FeatureSet> result = content.stream().map(in -> {
        try {
            return fcollReader.read(in);
        } catch (XMLStreamException | IOException ex) {
            throw new UnconvertibleObjectException("Unable to read feature from nodes.", ex);
        }
    }).map(ReferenceToFeatureCollectionConverter::castOrWrap);
    return result.onClose(() -> fcollReader.dispose());
}
Also used : ReferenceToFeatureCollectionConverter(org.geotoolkit.wps.converters.inputs.references.ReferenceToFeatureCollectionConverter) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) JAXBElement(javax.xml.bind.JAXBElement) ArgumentChecks(org.apache.sis.util.ArgumentChecks) WPSConvertersUtils(org.geotoolkit.wps.converters.WPSConvertersUtils) IOException(java.io.IOException) FeatureProperty(org.geotoolkit.gml.xml.FeatureProperty) ArrayList(java.util.ArrayList) List(java.util.List) Stream(java.util.stream.Stream) FeatureSet(org.apache.sis.storage.FeatureSet) Map(java.util.Map) XMLStreamException(javax.xml.stream.XMLStreamException) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) FeatureCollection(org.geotoolkit.gml.xml.FeatureCollection) WPSDefaultConverter(org.geotoolkit.wps.converters.WPSDefaultConverter) Data(org.geotoolkit.wps.xml.v200.Data) DataStoreException(org.apache.sis.storage.DataStoreException) WPSIO(org.geotoolkit.wps.io.WPSIO) WPSMimeType(org.geotoolkit.wps.io.WPSMimeType) Path(java.nio.file.Path) XmlFeatureReader(org.geotoolkit.feature.xml.XmlFeatureReader) MalformedURLException(java.net.MalformedURLException) ReferenceToFeatureCollectionConverter(org.geotoolkit.wps.converters.inputs.references.ReferenceToFeatureCollectionConverter) XmlFeatureReader(org.geotoolkit.feature.xml.XmlFeatureReader) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) FeatureProperty(org.geotoolkit.gml.xml.FeatureProperty) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) FeatureCollection(org.geotoolkit.gml.xml.FeatureCollection) FeatureSet(org.apache.sis.storage.FeatureSet)

Example 13 with Data

use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project geotoolkit by Geomatys.

the class GMLAdaptor method toWPS2Input.

@Override
public DataInput toWPS2Input(Object candidate) throws UnconvertibleObjectException {
    if (candidate instanceof ReferenceProxy)
        return super.toWPS2Input(candidate);
    final ComplexData cdt = new ComplexData();
    cdt.getContent().add(new org.geotoolkit.wps.xml.v200.Format(encoding, mimeType, schema, null));
    final JAXPStreamFeatureWriter writer = new JAXPStreamFeatureWriter(gmlVersion, null, null);
    try {
        if (ENC_BASE64.equalsIgnoreCase(encoding)) {
            final ByteArrayOutputStream out = new ByteArrayOutputStream();
            writer.write(candidate, out);
            out.flush();
            String base64 = Base64.getEncoder().encodeToString(out.toByteArray());
            cdt.getContent().add(base64);
        } else if (ENC_UTF8.equalsIgnoreCase(encoding)) {
            final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
            final DocumentBuilder constructeur = fabrique.newDocumentBuilder();
            final Document document = constructeur.newDocument();
            final DOMResult domResult = new DOMResult(document);
            writer.write(candidate, domResult);
            cdt.getContent().add(document.getDocumentElement());
        }
    } catch (IOException | XMLStreamException | DataStoreException | ParserConfigurationException ex) {
        throw new UnconvertibleObjectException(ex.getMessage(), ex);
    }
    final Data data = new Data();
    data.getContent().add(cdt);
    final DataInput dit = new DataInput();
    dit.setData(data);
    return dit;
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DOMResult(javax.xml.transform.dom.DOMResult) Data(org.geotoolkit.wps.xml.v200.Data) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JAXPStreamFeatureWriter(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureWriter) Document(org.w3c.dom.Document) ReferenceProxy(org.geotoolkit.wps.xml.ReferenceProxy) Format(org.geotoolkit.wps.xml.v200.Format) DataInput(org.geotoolkit.wps.xml.v200.DataInput) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) XMLStreamException(javax.xml.stream.XMLStreamException) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 14 with Data

use of com.microsoft.applicationinsights.smoketest.schemav2.Data 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 15 with Data

use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project geotoolkit by Geomatys.

the class ImageAdaptor method fromWPS2Input.

@Override
public RenderedImage fromWPS2Input(DataOutput candidate) throws UnconvertibleObjectException {
    if (candidate.getReference() != null) {
        return super.fromWPS2Input(candidate);
    }
    final Data data = candidate.getData();
    if (data == null)
        throw new UnconvertibleObjectException();
    final String mimeType = data.getMimeType();
    if (mimeType == null)
        throw new UnconvertibleObjectException();
    if (data.getContent().size() != 1)
        throw new UnconvertibleObjectException();
    Object cdt = data.getContent().get(0);
    if (cdt instanceof String) {
        // base64 encoded image
        byte[] rawData = Base64.getDecoder().decode(cdt.toString());
        try {
            return ImageIO.read(new ByteArrayInputStream(rawData));
        } catch (IOException ex) {
            throw new UnconvertibleObjectException(ex.getMessage(), ex);
        }
    } else {
        throw new UnconvertibleObjectException();
    }
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) ByteArrayInputStream(java.io.ByteArrayInputStream) Data(org.geotoolkit.wps.xml.v200.Data) IOException(java.io.IOException)

Aggregations

Test (org.junit.Test)65 Envelope (com.microsoft.applicationinsights.smoketest.schemav2.Envelope)53 RequestData (com.microsoft.applicationinsights.smoketest.schemav2.RequestData)45 Data (org.geotoolkit.wps.xml.v200.Data)42 RemoteDependencyData (com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData)26 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)20 IOException (java.io.IOException)16 DataInput (org.geotoolkit.wps.xml.v200.DataInput)15 Format (org.geotoolkit.wps.xml.v200.Format)12 AiSmokeTest (com.microsoft.applicationinsights.smoketest.AiSmokeTest)10 TargetUri (com.microsoft.applicationinsights.smoketest.TargetUri)10 MessageData (com.microsoft.applicationinsights.smoketest.schemav2.MessageData)10 ComplexData (org.geotoolkit.wps.xml.v200.ComplexData)10 ExceptionData (com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData)9 ReferenceProxy (org.geotoolkit.wps.xml.ReferenceProxy)9 Data (com.microsoft.applicationinsights.smoketest.schemav2.Data)8 DataStoreException (org.apache.sis.storage.DataStoreException)8 LiteralValue (org.geotoolkit.wps.xml.v200.LiteralValue)7 EventData (com.microsoft.applicationinsights.smoketest.schemav2.EventData)6 MetricData (com.microsoft.applicationinsights.smoketest.schemav2.MetricData)6