Search in sources :

Example 1 with Contents

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

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

the class WPSProcessingRegistry method checkDescriptors.

/**
 * @param loadDescription force loading all descriptor
 */
private synchronized void checkDescriptors(boolean loadDescription) {
    if (descriptors != null && !loadDescription)
        return;
    if (descriptors == null)
        descriptors = new ConcurrentHashMap<>();
    final Capabilities capabilities;
    try {
        capabilities = client.getServiceCapabilities();
    } catch (CapabilitiesException ex) {
        // it should not happen since we called a getCapabilities at registry creation
        throw new RuntimeException(ex);
    }
    final Contents contents = capabilities.getContents();
    if (contents == null) {
        return;
    }
    final List<ProcessSummary> processBrief = contents.getProcessSummary();
    if (loadDescription) {
        final ExecutorService exec = Executors.newFixedThreadPool(8);
        for (final ProcessSummary processBriefType : processBrief) {
            final String processId = processBriefType.getIdentifier().getValue();
            if (descriptors.get(processId) instanceof ProcessDescriptor)
                continue;
            exec.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        final ProcessDescriptor processDesc = toProcessDescriptor(processId);
                        descriptors.put(processDesc.getIdentifier().getCode(), processDesc);
                    } catch (Throwable ex) {
                        LOGGER.log(Level.WARNING, ex.getMessage(), ex);
                    }
                }
            });
        }
        exec.shutdown();
        try {
            // TODO: better timeout management
            exec.awaitTermination(10, TimeUnit.MINUTES);
        } catch (InterruptedException ex) {
            LOGGER.log(Level.WARNING, ex.getMessage(), ex);
        }
    } else {
        for (final ProcessSummary processBriefType : processBrief) {
            descriptors.put(processBriefType.getIdentifier().getValue(), processBriefType);
        }
    }
}
Also used : ProcessSummary(org.geotoolkit.wps.xml.v200.ProcessSummary) Contents(org.geotoolkit.wps.xml.v200.Contents) Capabilities(org.geotoolkit.wps.xml.v200.Capabilities) ExecutorService(java.util.concurrent.ExecutorService) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CapabilitiesException(org.geotoolkit.client.CapabilitiesException)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)1 CapabilitiesException (org.geotoolkit.client.CapabilitiesException)1 GeoJSONObject (org.geotoolkit.internal.geojson.binding.GeoJSONObject)1 ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)1 Capabilities (org.geotoolkit.wps.xml.v200.Capabilities)1 ComplexData (org.geotoolkit.wps.xml.v200.ComplexData)1 Contents (org.geotoolkit.wps.xml.v200.Contents)1 Data (org.geotoolkit.wps.xml.v200.Data)1 LiteralValue (org.geotoolkit.wps.xml.v200.LiteralValue)1 ProcessSummary (org.geotoolkit.wps.xml.v200.ProcessSummary)1 Node (org.w3c.dom.Node)1