Class: ZooProcess

ZooProcess


new ZooProcess(params)

The ZooProcess Class
Parameters:
Name Type Description
params Object Parameters
Example
var myZooObject = new ZooProcess({
    url: "http://localhost/cgi-bin/zoo_loader.cgi",
    delay: 2500
});

Members


debug :Boolean

true if verbose messages should be displayed on the console
Type:
  • Boolean
Default Value:
  • false

delay :Integer

The time (in milliseconds) between each polling requests.
Type:
  • Integer
Default Value:
  • 2000

language :String

The language to be used to request the WPS Server
Type:
  • String
Default Value:
  • "en-US"

launched :Object

An object to store the running asynchrone services.
Type:
  • Object

percent :Object

An object to store the percentage of completude of services.
Type:
  • Object

statusLocation :Object

An object to store the statusLocation URLs when running request including both the storeExecuteResponse and the status parameters set to true.
Type:
  • Object

terminated :Object

An object to store the finished services.
Type:
  • Object

url :String

The WPS Server URL
Type:
  • String

version :String

The WPS version
Type:
  • String

Methods


buildRequest(params, type)

The buildRequest method is building the object expected by jQuery.ajax. In case of GET request, it will use ZooProcess#getQueryString. In case of POST request, it will use module:wpsPayload getPayload.
Parameters:
Name Type Description
params Object the request parameters
type String the request method ("GET" or "POST")
Returns:
The expected object to give as input for the jQuery.ajax function.
Type
Object

convertParams(params)

The convertParams method convert parameters for Execute requests
Parameters:
Name Type Description
params Object The original object
Returns:
The converted object
Type
Object

describeProcess(params)

The describeProcess method run the DescribeProcess request by calling ZooProcess#request.
Parameters:
Name Type Description
params Object
Example
// Log x2js representation of all available services in console
myZooObject.describeProcess({
    type: 'POST',
    identifier: "all"
    success: function(data){
        console.log(data);
    }
});

dismiss(params)

The dismiss method run the Dismiss request by calling ZooProcess#request.
Parameters:
Name Type Description
params Object
Example
// Log x2js representation of all available services in console
myZooObject.dismiss({
    type: 'POST',
    jobid: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
    success: function(data){
        console.log(data);
    }
});

execute(param)

The execute method run the Execute request by calling ZooProcess#request with the params converted by ZooProcess#convertParams.
Parameters:
Name Type Description
param Object Parameters
Example
myZooObject.execute({
    identifier: "Buffer",
    dataInputs: [{"identifier":"InputPolygon","href":"http://features.org/toto.xml","mimeType":"text/xml"}],
    dataOutputs: [{"identifier":"Result","mimeType":"application/json","type":"raw"}],
    type: 'POST',
    success: function(data) {
        console.log(data);
    }
});

getCapabilities(params)

The getCapabilities method run the GetCapabilities request by calling ZooProcess#request.
Parameters:
Name Type Description
params Object The parameter for the request and callback functions to call on success or on failure.
Example
// Log the array of available processes in console
myZooObject.getCapabilities({
    type: 'POST',
    success: function(data){
        console.log(data["Capabilities"]["ProcessOfferings"]["Process"]);
    }
});

getQueryString(params)

The getQueryString method generate a KVP GET request which can be used to request a WPS server.
Parameters:
Name Type Description
params Object The WPS requests parameters
Returns:
The GET WPS request
Type
String
Example
// Log GetCapabilities GET request in console
var request_params = {
    request: 'GetCapabilities',
    service: 'WPS',
    version: '1.0.0',
    language; 'en-US'
}
console.log(myZooObject.getQueryString(request_params));

getRequest()

The getRequest method call the ZooProcess#buildRequest method by giving the ZooProcess#convertParams result as first argument and the detected type (default is 'GET') defined in params.

getResult(sid, onSuccess, onError)

The getResult method is used by ZooProcess#watch to get the final result of services called asynchronously.
Parameters:
Name Type Description
sid Integer Service Identifier
onSuccess function callback
onError function callback

getStatus(sid, onSuccess, onError)

The getStatus method call jQuery.ajax to fecth the ExecuteResponse document which contains a Status node and potentially the result (when the asynch service end). This method is used by ZooProcess#watch to get the ongoing status of services called asynchronously.
Parameters:
Name Type Description
sid Integer Service Identifier
onSuccess function callback
onError function callback

parseJobID(data)

The parseJobID method parse the JobID and return an object with sid and the JobID attributes which contains respectively: a unique identifier named sid and the JobID value returned by the WPS server.
Parameters:
Name Type Description
data Object The XML response parsed by x2js.xml2json
Returns:
The result is an object with sid and jobID
Type
Object

parseStatusLocation(data)

The parseStatusLocation method parse the statusLocation and return an object with sid and statusLocation attributes which contains respectively: a unique identifier named sid and the statusLocation value returned by the WPS server.
Parameters:
Name Type Description
data Object The XML response parsed by x2js.xml2json
Returns:
The result is an object with sid and statusLocation
Type
Object

request(params, onSuccess, onError, type)

The request method call ZooProcess#buildRequest method to to build parameters to give to jQuery.ajax. If the request succeed and if the content-type of the response is "text/xml" then xml2json is called on the resulting data and passed to the onSuccess callback function given in parameter. In case the request failed, the WPS Exception Repport will be parsed with xml2json and given as parameter to the onError callback function.
Parameters:
Name Type Description
params Object The object used as parameter for jQuery.ajax
onSuccess function The callback function called if the request succeed
onError function The callback function called if the request failed
type String The request method ('GET' or 'POST')

watch(sid, handlers)

The watch method should be used from the success callback function passed to ZooProcess#execute when both status and storeExecuteResponse parameters are set to 'true', so when the service should be called asynchronously. This function is responsible for polling the WPS server until the service end (success or failure). It call the ZooProcess#getStatus method every ZooProcess#delay milliseconds.
Parameters:
Name Type Description
sid Integer The identifier of the running service
handlers Object The callback function definitions (onPercentCompleted, onProcessSucceeded, onError)
Example
zoo.execute({
    identifier: 'MyIdentifier',
    type: 'POST',
    dataInputs: myInputs,
    dataOutputs: myOupts,
    storeExecuteResponse: true,
    status: true,
    success: function(data, launched) {
        zoo.watch(launched.sid, {
            onPercentCompleted: function(data) {
                console.log("**** PercentCompleted ****");
                console.log(data);
                progress.text(data.text+' : '+(data.percentCompleted)+'%');
            },
            onProcessSucceeded: function(data) {
                progress.css('width', (100)+'%');
                progress.text(data.text+' : '+(100)+'%');
                    if (data.result.ExecuteResponse.ProcessOutputs) {
                        console.log("**** onSuccess ****");
                        console.log(data.result);
                    }
            },
            onError: function(data) {
                console.log("**** onError ****");
                console.log(data);
            },
        });
    },
    error: function(data) {
        console.log("**** ERROR ****");
        console.log(data);
        notify("Execute asynchrone failed", 'danger');
    }
});