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