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());
}
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());
}
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;
}
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.");
}
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();
}
}
Aggregations