public ExecuteResponseType build() {
ExecuteRequest helper = new ExecuteRequest(request);
// build the response
Wps10Factory f = Wps10Factory.eINSTANCE;
ExecuteResponseType response = f.createExecuteResponseType();
response.setLang("en");
if (request.getBaseUrl() != null) {
response.setServiceInstance(ResponseUtils.appendQueryString(
ResponseUtils.buildURL(request.getBaseUrl(), "ows", null, URLType.SERVICE), ""));
}
// process
Name processName = helper.getProcessName();
ProcessFactory pf = GeoServerProcessors.createProcessFactory(processName);
final ProcessBriefType process = f.createProcessBriefType();
response.setProcess(process);
// damn blasted EMF changes the state of request if we set its identifier on
// another object! (I guess, following some strict ownership rule...)
process.setIdentifier((CodeType) EMFUtils.clone(request.getIdentifier(),
Ows11Factory.eINSTANCE, true));
process.setProcessVersion(pf.getVersion(processName));
process.setTitle(Ows11Util.languageString(pf.getTitle(processName)));
process.setAbstract(Ows11Util.languageString(pf.getDescription(processName)));
// status
response.setStatus(f.createStatusType());
XMLGregorianCalendar gc = Converters.convert(created, XMLGregorianCalendar.class);
response.getStatus().setCreationTime(gc);
if (status == null) {
if (exception != null) {
setResponseFailed(response, getException(ProcessState.COMPLETED));
} else if (outputs == null) {
response.getStatus().setProcessAccepted("Process accepted.");
} else {
response.getStatus().setProcessSucceeded("Process succeeded.");
}
} else {
if (status.getPhase() == ProcessState.QUEUED) {
response.getStatus().setProcessAccepted("Process accepted.");
} else if (status.getPhase() == ProcessState.RUNNING) {
ProcessStartedType startedType = f.createProcessStartedType();
int progressPercent = Math.round(status.getProgress());
if(progressPercent < 0) {
LOGGER.warning("Progress reported is below zero, fixing it to 0: " + progressPercent);
progressPercent = 0;
} else if(progressPercent > 100) {
LOGGER.warning("Progress reported is above 100, fixing it to 100: " + progressPercent);
progressPercent = 100;
}
startedType.setPercentCompleted(new BigInteger(String.valueOf(progressPercent)));
startedType.setValue(status.getTask());
response.getStatus().setProcessStarted(startedType);
} else if (status.getPhase() == ProcessState.COMPLETED) {
response.getStatus().setProcessSucceeded("Process succeeded.");
} else {
ServiceException reportException = getException(status.getPhase());
setResponseFailed(response, reportException);
}
}
// status location, if asynch
if (helper.isAsynchronous() && request.getBaseUrl() != null && executionId != null) {
Map<String, String> kvp = new LinkedHashMap<String, String>();
kvp.put("service", "WPS");
kvp.put("version", "1.0.0");
kvp.put("request", "GetExecutionStatus");
kvp.put("executionId", executionId);
response.setStatusLocation(ResponseUtils.buildURL(request.getBaseUrl(), "ows", kvp, URLType.SERVICE));
}
// lineage, should be included only if requested, the response should contain it
// even if the process is not done computing. From the spec:
// * If lineage is "true" the server shall include in the execute response a complete copy
// of
// the DataInputs and OutputDefinition elements _as received in the execute request_.
// *If lineage is "false" then/ these elements shall be omitted from the response
if (helper.isLineageRequested()) {
// inputs
if (request.getDataInputs() != null && request.getDataInputs().getInput().size() > 0) {
response.setDataInputs(f.createDataInputsType1());
for (Iterator i = request.getDataInputs().getInput().iterator(); i.hasNext();) {
InputType input = (InputType) i.next();
response.getDataInputs().getInput().add(EMFUtils.clone(input, f, true));
}
}
// output definitions, if any was requested explicitly
List<DocumentOutputDefinitionType> outputList = helper.getRequestedOutputs();
if (outputList != null) {
OutputDefinitionsType outputs = f.createOutputDefinitionsType();
response.setOutputDefinitions(outputs);
for (DocumentOutputDefinitionType output : outputList) {
outputs.getOutput().add(EMFUtils.clone(output, f, true));
}
}
}
// process outputs
if (exception == null && outputs != null) {
ProcessOutputsType1 processOutputs = f.createProcessOutputsType1();
response.setProcessOutputs(processOutputs);
Map<String, Parameter<?>> resultInfo = pf.getResultInfo(processName, null);
if (request.getResponseForm() != null