use of org.geotoolkit.wps.adaptor.ComplexAdaptor in project geotoolkit by Geomatys.
the class WPS2Process method createRequest.
/**
* Make a WPS Execute request from {@link ParameterValueGroup values}.
*/
private ExecuteRequest createRequest() throws ProcessException {
try {
final ParameterValueGroup inputs = getInput();
final List<GeneralParameterDescriptor> inputParamDesc = inputs.getDescriptor().descriptors();
final List<GeneralParameterDescriptor> outputParamDesc = descriptor.getOutputDescriptor().descriptors();
final List<DataInput> wpsIN = new ArrayList<>();
final List<OutputDefinition> wpsOUT = new ArrayList<>();
final String processId = descriptor.getIdentifier().getCode();
for (final GeneralParameterValue inputValue : inputs.values()) {
GeneralParameterDescriptor inputGeneDesc = inputValue.getDescriptor();
if (inputGeneDesc instanceof ParameterDescriptor) {
final ParameterDescriptor inputDesc = (ParameterDescriptor) inputGeneDesc;
final DataAdaptor adaptor = (DataAdaptor) ((ExtendedParameterDescriptor) inputDesc).getUserObject().get(DataAdaptor.USE_ADAPTOR);
final Object value = ((ParameterValue) inputValue).getValue();
if (value == null)
continue;
final DataInput dataInput;
if (adaptor instanceof LiteralAdaptor) {
dataInput = ((LiteralAdaptor) adaptor).toWPS2Input(value, rawLiteralData);
} else {
dataInput = adaptor.toWPS2Input(value);
}
dataInput.setId(inputDesc.getName().getCode());
wpsIN.add(dataInput);
}
}
/*
* OUTPUTS
*/
for (final GeneralParameterDescriptor outputGeneDesc : outputParamDesc) {
if (outputGeneDesc instanceof ParameterDescriptor) {
final ParameterDescriptor outputDesc = (ParameterDescriptor) outputGeneDesc;
final DataAdaptor adaptor = (DataAdaptor) ((ExtendedParameterDescriptor) outputDesc).getUserObject().get(DataAdaptor.USE_ADAPTOR);
final String outputIdentifier = outputDesc.getName().getCode();
String mime = null;
String encoding = null;
String schema = null;
if (adaptor instanceof ComplexAdaptor) {
final ComplexAdaptor cadaptor = (ComplexAdaptor) adaptor;
mime = cadaptor.getMimeType();
encoding = cadaptor.getEncoding();
schema = cadaptor.getSchema();
}
final OutputDefinition out = new OutputDefinition(outputIdentifier, asReference);
out.setEncoding(encoding);
out.setMimeType(mime);
out.setSchema(schema);
wpsOUT.add(out);
} else if (outputGeneDesc instanceof ParameterDescriptorGroup) {
final ParameterDescriptorGroup outputDesc = (ParameterDescriptorGroup) outputGeneDesc;
final OutputDefinition out = new OutputDefinition(outputDesc.getName().getCode(), asReference);
wpsOUT.add(out);
}
}
final ExecuteRequest request = registry.getClient().createExecute();
request.setClientSecurity(security);
final Execute execute = request.getContent();
execute.setIdentifier(processId);
final Execute.Mode mode = executionMode == null ? Execute.Mode.auto : executionMode;
execute.setMode(mode);
execute.setResponse(rawOutput ? Execute.Response.raw : Execute.Response.document);
execute.getInput().addAll(wpsIN);
execute.getOutput().addAll(wpsOUT);
WPSProcessingRegistry.LOGGER.log(Level.FINER, "Execute request created for {0} in {1} mode.", new Object[] { processId, mode });
return request;
} catch (UnconvertibleObjectException ex) {
throw new ProcessException("Error during conversion step.", null, ex);
}
}
Aggregations