Addressing review suggestions and fixing asynchronous function calls.
This commit addresses @bartvde's review comments, adds more documentation, and fixes asynchronous function calls. Previously, when creating multiple processes with the same identifier, the describe callback would only have been called for the first process. This was fixed to move DescribeProcess handling from WPSProcess to WPSClient.
This commit is contained in:
@@ -8,26 +8,27 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @requires OpenLayers/Events.js
|
||||
* @requires OpenLayers/Geometry.js
|
||||
* @requires OpenLayers/Feature/Vector.js
|
||||
* @requires OpenLayers/Format/WKT.js
|
||||
* @requires OpenLayers/Format/GeoJSON.js
|
||||
* @requires OpenLayers/Format/WPSExecute.js
|
||||
* @requires OpenLayers/Request.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.WPSProcess
|
||||
* Representation of a WPS process. Usually instances of
|
||||
* <OpenLayers.WPSProcess> are created by calling 'getProcess' on an
|
||||
* <OpenLayers.WPSClient> instance.
|
||||
*
|
||||
* Currently <OpenLayers.WPSProcess> supports processes that have geometries
|
||||
* or features as output, using WKT or GeoJSON as output format. It also
|
||||
* supports chaining of processes by using the <output> method to create a
|
||||
* handle that is used as process input instead of a static value.
|
||||
*/
|
||||
OpenLayers.WPSProcess = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* APIProperty: events
|
||||
* {<OpenLayers.Events>}
|
||||
*
|
||||
* Supported event types:
|
||||
* describeprocess - Fires when the process description is available for
|
||||
* the first time.
|
||||
*/
|
||||
events: null,
|
||||
|
||||
/**
|
||||
* Property: client
|
||||
* {<OpenLayers.WPSClient>} The client that manages this process.
|
||||
@@ -52,6 +53,13 @@ OpenLayers.WPSProcess = OpenLayers.Class({
|
||||
*/
|
||||
description: null,
|
||||
|
||||
/**
|
||||
* APIProperty: localWPS
|
||||
* {String} Service endpoint for locally chained WPS processes. Default is
|
||||
* 'http://geoserver/wps'.
|
||||
*/
|
||||
localWPS: 'http://geoserver/wps',
|
||||
|
||||
/**
|
||||
* Property: formats
|
||||
* {Object} OpenLayers.Format instances keyed by mimetype.
|
||||
@@ -60,7 +68,7 @@ OpenLayers.WPSProcess = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* Property: chained
|
||||
* {Integer} Number of chained processes for pending execute reqeusts that
|
||||
* {Integer} Number of chained processes for pending execute requests that
|
||||
* don't have a full configuration yet.
|
||||
*/
|
||||
chained: 0,
|
||||
@@ -79,18 +87,15 @@ OpenLayers.WPSProcess = OpenLayers.Class({
|
||||
* options - {Object} Object whose properties will be set on the instance.
|
||||
*
|
||||
* Avaliable options:
|
||||
* client - {<OpenLayers.WPSClient} Mandatory. Client that manages this
|
||||
* client - {<OpenLayers.WPSClient>} Mandatory. Client that manages this
|
||||
* process.
|
||||
* server - {String} Mandatory. Local client identifier of this process's
|
||||
* server.
|
||||
* identifier - {String} Mandatory. Process identifier known to the server.
|
||||
*/
|
||||
initialize: function(options) {
|
||||
OpenLayers.Util.extend(this, options);
|
||||
|
||||
this.events = new OpenLayers.Events(this);
|
||||
OpenLayers.Util.extend(this, options);
|
||||
this.executeCallbacks = [];
|
||||
|
||||
this.formats = {
|
||||
'application/wkt': new OpenLayers.Format.WKT(),
|
||||
'application/json': new OpenLayers.Format.GeoJSON()
|
||||
@@ -99,12 +104,10 @@ OpenLayers.WPSProcess = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* Method: describe
|
||||
* Issues a DescribeProcess request asynchronously and fires the
|
||||
* 'describeprocess' event as soon as the response is available in
|
||||
* <description>.
|
||||
* Makes the client ssues a DescribeProcess request asynchronously.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} Coniguration for the method call
|
||||
* options - {Object} Configuration for the method call
|
||||
*
|
||||
* Available options:
|
||||
* callback - {Function} Callback to execute when the description is
|
||||
@@ -115,45 +118,21 @@ OpenLayers.WPSProcess = OpenLayers.Class({
|
||||
*/
|
||||
describe: function(options) {
|
||||
options = options || {};
|
||||
function callback() {
|
||||
if (options.callback) {
|
||||
window.setTimeout(function() {
|
||||
options.callback.call(options.scope, this.description);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
var server = this.client.servers[this.server];
|
||||
if (this.description !== null) {
|
||||
callback();
|
||||
return;
|
||||
} else if (server.describeProcessResponse[this.identifier] === null) {
|
||||
// pending request
|
||||
this.events.register('describeprocess', this, callback);
|
||||
return;
|
||||
} else if (this.identifier in server.describeProcessResponse) {
|
||||
// process description already cached on client
|
||||
this.parseDescription();
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
// set to null so we know a describeFeature request is pending
|
||||
server.describeProcessResponse[this.identifier] = null;
|
||||
OpenLayers.Request.GET({
|
||||
url: server.url,
|
||||
params: {
|
||||
SERVICE: 'WPS',
|
||||
VERSION: server.version,
|
||||
REQUEST: 'DescribeProcess',
|
||||
IDENTIFIER: this.identifier
|
||||
},
|
||||
success: function(response) {
|
||||
this.parseDescription(response);
|
||||
if (!this.description) {
|
||||
this.client.describeProcess(this.server, this.identifier, function(description) {
|
||||
if (!this.description) {
|
||||
this.parseDescription(description);
|
||||
}
|
||||
if (options.callback) {
|
||||
options.callback.call(options.scope, this.description);
|
||||
}
|
||||
},
|
||||
scope: this
|
||||
});
|
||||
}, this);
|
||||
} else if (options.callback) {
|
||||
var description = this.description;
|
||||
window.setTimeout(function() {
|
||||
options.callback.call(options.scope, description);
|
||||
}, 0);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -175,25 +154,22 @@ OpenLayers.WPSProcess = OpenLayers.Class({
|
||||
* scope - {Object} Optional scope for the callback.
|
||||
*/
|
||||
configure: function(options) {
|
||||
if (!this.description) {
|
||||
this.describe({
|
||||
callback: function() {
|
||||
this.configure(options);
|
||||
},
|
||||
scope: this
|
||||
});
|
||||
return;
|
||||
}
|
||||
var description = this.description,
|
||||
inputs = options.inputs,
|
||||
input, i, ii;
|
||||
for (i=0, ii=description.dataInputs.length; i<ii; ++i) {
|
||||
input = description.dataInputs[i];
|
||||
this.setInputData(input, inputs[input.identifier]);
|
||||
}
|
||||
if (options.callback) {
|
||||
options.callback.call(options.scope);
|
||||
}
|
||||
this.describe({
|
||||
callback: function() {
|
||||
var description = this.description,
|
||||
inputs = options.inputs,
|
||||
input, i, ii;
|
||||
for (i=0, ii=description.dataInputs.length; i<ii; ++i) {
|
||||
input = description.dataInputs[i];
|
||||
this.setInputData(input, inputs[input.identifier]);
|
||||
}
|
||||
if (options.callback) {
|
||||
options.callback.call(options.scope);
|
||||
}
|
||||
},
|
||||
scope: this
|
||||
});
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -212,10 +188,10 @@ OpenLayers.WPSProcess = OpenLayers.Class({
|
||||
* provided, the first output will be parsed.
|
||||
* success - {Function} Callback to call when the process is complete.
|
||||
* This function is called with an outputs object as argument, which
|
||||
* will have a property with the name of the requested output (e.g.
|
||||
* 'result'). For processes that generate spatial output, the value
|
||||
* will either be a single <OpenLayers.Feature.Vector> or an array of
|
||||
* features.
|
||||
* will have a property with the identifier of the requested output
|
||||
* (or 'result' if output was not configured). For processes that
|
||||
* generate spatial output, the value will be an array of
|
||||
* <OpenLayers.Feature.Vector> instances.
|
||||
* scope - {Object} Optional scope for the success callback.
|
||||
*/
|
||||
execute: function(options) {
|
||||
@@ -248,9 +224,12 @@ OpenLayers.WPSProcess = OpenLayers.Class({
|
||||
);
|
||||
//TODO For now we assume a spatial output
|
||||
var features = me.formats[mimeType].read(response.responseText);
|
||||
if (features instanceof OpenLayers.Feature.Vector) {
|
||||
features = [features];
|
||||
}
|
||||
if (options.success) {
|
||||
var outputs = {};
|
||||
outputs[output.identifier] = features;
|
||||
outputs[options.output || 'result'] = features;
|
||||
options.success.call(options.scope, outputs);
|
||||
}
|
||||
},
|
||||
@@ -298,17 +277,13 @@ OpenLayers.WPSProcess = OpenLayers.Class({
|
||||
* Parses the DescribeProcess response
|
||||
*
|
||||
* Parameters:
|
||||
* response - {Object}
|
||||
* description - {Object}
|
||||
*/
|
||||
parseDescription: function(response) {
|
||||
parseDescription: function(description) {
|
||||
var server = this.client.servers[this.server];
|
||||
if (response) {
|
||||
server.describeProcessResponse[this.identifier] = response.responseText;
|
||||
}
|
||||
this.description = new OpenLayers.Format.WPSDescribeProcess()
|
||||
.read(server.describeProcessResponse[this.identifier])
|
||||
.read(server.processDescription[this.identifier])
|
||||
.processDescriptions[this.identifier];
|
||||
this.events.triggerEvent('describeprocess');
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -331,9 +306,7 @@ OpenLayers.WPSProcess = OpenLayers.Class({
|
||||
input.reference = {
|
||||
method: 'POST',
|
||||
href: data.process.server === this.server ?
|
||||
//TODO what about implementations other than GeoServer?
|
||||
'http://geoserver/wps' :
|
||||
this.client.servers[data.process.server].url
|
||||
this.localWPS : this.client.servers[data.process.server].url
|
||||
};
|
||||
data.process.describe({
|
||||
callback: function() {
|
||||
@@ -415,7 +388,7 @@ OpenLayers.WPSProcess = OpenLayers.Class({
|
||||
*
|
||||
* Parameters:
|
||||
* input - {Object} The dataInput that the chained process provides.
|
||||
* chainLink - {<OpenLayers.WPSProcess.ChainLink} The process to chain.
|
||||
* chainLink - {<OpenLayers.WPSProcess.ChainLink>} The process to chain.
|
||||
*/
|
||||
chainProcess: function(input, chainLink) {
|
||||
var output = this.getOutputIndex(
|
||||
|
||||
Reference in New Issue
Block a user