Changeset 719 for trunk/zoo-project


Ignore:
Timestamp:
Jul 1, 2015, 12:57:36 AM (9 years ago)
Author:
djay
Message:

Add minmial support for WPS 2.0.0 in ZOO-Client.

Location:
trunk/zoo-project/zoo-client/lib
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-client/lib/js/wps-client/wps-payload.js

    r517 r719  
    8585            } else if (params.request == 'Execute') {
    8686                return this.getPayload_Execute(params);
     87            } else if (params.request == 'Dismiss') {
     88                return this.getPayload_Dismiss(params);
    8789            } else {
    8890                console.log("#### UNKNOWN REQUEST ####");
     
    107109         */
    108110        getPayload_GetCapabilities: function(params) {
    109             return templates["payload_GetCapabilities"].render(params);
     111            var id="payload_GetCapabilities";
     112            if(params.version=="2.0.0")
     113                id+="2";
     114            return templates[id].render(params);
    110115        },
    111116       
     
    128133         */
    129134        getPayload_DescribeProcess: function(params) {
     135            var id="payload_DescribeProcess";
     136            if(params.version=="2.0.0")
     137                id+="2";
    130138            if (params.Identifier) {
    131139                if ($.isArray(params.Identifier)) {
    132                     return templates["payload_DescribeProcess"].render({identifiers: params.Identifier,language: params.language});
     140                    return templates[id].render({identifiers: params.Identifier,language: params.language});
    133141                }
    134142                else {
    135                     return templates["payload_DescribeProcess"].render({identifiers: [params.Identifier],language: params.language});
     143                    return templates[id].render({identifiers: [params.Identifier],language: params.language});
    136144                }
    137145            }
    138146            // TODO: no Identifier
    139147        },
     148
     149        /**
     150         * The getPayload_Dismiss function is used to generate a valid
     151         * WPS XML Dimiss request using the
     152         * [payload_Dismiss.mustache]{@link http://zoo-project.org/trac/browser/trunk/zoo-project/zoo-client/lib/tpl/payload_Dismiss.mustache}
     153         * template.
     154         *
     155         * @static
     156         * @param {Object} params - The object representing the request.
     157         * @returns {string} - The corresponding XML request
     158         * @example
     159         * // log the XML request in console
     160         * var request_params = {
     161         *     jobId: ["XXXX","XXX"]
     162         * };
     163         * console.log(wpsPayload.getPayload_DescribeProcess(request_params));
     164         */
     165        getPayload_Dismiss: function(params) {
     166            var id="payload_Dismiss";
     167            params.version="2.0.0";
     168            if (params.jobid) {
     169                if ($.isArray(params.jobid)) {
     170                    return templates[id].render({jobid: params.jobid});
     171                }
     172                else {
     173                    return templates[id].render({jobid: [params.jobid]});
     174                }
     175            }
     176            // TODO: no Identifier
     177        },
     178
    140179
    141180        /**
     
    159198         */
    160199        getPayload_Execute: function(params) {
     200            var id="payload_Execute";
     201            if(params.version=="2.0.0")
     202                id+="2";
    161203            if (params.DataInputs) {
    162204                for (var i = 0; i < params.DataInputs.length; i++) {
     
    210252                   
    211253                    // Complex data from payload callback.
    212                     console.log("CALLBACK");
    213                     console.log(params.DataInputs[i]);
    214254                    if (params.DataInputs[i].complexPayload_callback) {
    215255                        params.DataInputs[i].value = window[params.DataInputs[i].complexPayload_callback];
    216                         console.log(params.DataInputs[i].value);
    217256                    }
    218257                   
     
    245284            }
    246285           
    247             return templates["payload_Execute"].render(params);
     286            return templates[id].render(params);
    248287        },
    249288       
  • trunk/zoo-project/zoo-client/lib/js/wps-client/zoo.js

    r517 r719  
    7373         * @access public
    7474         * @memberof ZooProcess#
     75         * @var version {String} The WPS version
     76         */
     77        this.version = params.version?params.version:"1.0.0";
     78        /**
     79         * @access public
     80         * @memberof ZooProcess#
    7581         * @var language {String} The language to be used to request the WPS Server
    7682         * @default "en-US"
     
    137143                request: 'GetCapabilities',
    138144                service: 'WPS',
    139                 version: '1.0.0',
     145                version: (params.hasOwnProperty('version')?params.version:closure.version),
    140146            }
    141147
     
    170176                request: 'DescribeProcess',
    171177                service: 'WPS',
    172                 version: '1.0.0',
     178                version: (params.hasOwnProperty('version')?params.version:closure.version),
    173179            }
    174180
     
    198204                request: 'Execute',
    199205                service: 'WPS',
    200                 version: '1.0.0',
     206                version: (params.hasOwnProperty('version')?params.version:closure.version),
    201207                Identifier: params.identifier,
    202208                DataInputs: params.dataInputs ? params.dataInputs : '',
     
    204210            }
    205211
     212            console.log(zoo_request_params);
    206213
    207214            if (params.hasOwnProperty('responseDocument')) {
    208215                zoo_request_params.ResponseDocument = params.responseDocument;
     216            }
     217            if (params.hasOwnProperty('mode')) {
     218                zoo_request_params.mode = params.mode;
    209219            }
    210220            if (params.hasOwnProperty('storeExecuteResponse') &&  params.storeExecuteResponse) {
     
    257267                    console.log("======== POST PAYLOAD ========");
    258268                    console.log(payload);
     269                    console.log(params);
    259270                }
    260271
     
    367378                        }
    368379                        var launched;
    369                        
    370                         if (params.storeExecuteResponse == 'true' && params.status == 'true') {
    371                             launched = closure.parseStatusLocation(data);           
    372                             closure.statusLocation[launched.sid] = launched.statusLocation;
    373                            
    374                             if ( launched.hasOwnProperty('sid') &&
    375                                  !closure.launched.hasOwnProperty(launched.sid)) {
    376                                 closure.launched[launched.sid] = launched.statusLocation;
     380                        var version=(params.version?params.version:closure.version);
     381                        if(version=="1.0.0"){
     382                            if (params.storeExecuteResponse == 'true' && params.status == 'true') {
     383                                launched = closure.parseStatusLocation(data);           
     384                                closure.statusLocation[launched.sid] = launched.statusLocation;
     385                               
     386                                if ( launched.hasOwnProperty('sid') &&
     387                                     !closure.launched.hasOwnProperty(launched.sid)) {
     388                                    closure.launched[launched.sid] = launched.statusLocation;
     389                                }
    377390                            }
     391                        }
     392                        else{
     393                            if (params.mode == 'async') {
     394                                launched = closure.parseJobID(data);
     395                                closure.statusLocation[launched.sid] = closure.url+"?request=GetStatus&service=WPS&version=2.0.0&JobID="+launched.jobid;
     396                                if ( launched.hasOwnProperty('sid') &&
     397                                     !closure.launched.hasOwnProperty(launched.sid)) {
     398                                    closure.launched[launched.sid] = launched.jobid;
     399                                }
     400                            }       
    378401                        }
    379402
     
    446469                }
    447470
     471                if(data.StatusInfo || data.Result){
     472                    if (data.Result) {
     473
     474                        var ret = {
     475                            sid: sid,
     476                            text: "",
     477                            result: data
     478                        };
     479
     480                        if (handlers.onProcessSucceeded instanceof Function) {
     481                            handlers.onProcessSucceeded(ret);
     482                        }
     483
     484                        return;
     485                    }
     486                    if (data.StatusInfo.Status == "Running") {
     487                        if(closure.debug){
     488                            console.log("#### ProcessStarted");
     489                        }
     490                       
     491                        var message="";
     492                        for(index=0;index<data._origin.childNodes[0].childNodes.length;index++){
     493                            if(data._origin.childNodes[0].childNodes[index].nodeType==8){
     494                                message=data._origin.childNodes[0].childNodes[index].textContent;
     495                            }
     496                        }
     497                        var ret = {
     498                            sid: sid,
     499                            percentCompleted: (data.StatusInfo.PercentCompleted?data.StatusInfo.PercentCompleted:0),
     500                            text: message,
     501                            creationTime: "",
     502                        };
     503
     504                        if (handlers.onPercentCompleted instanceof Function) {
     505                            handlers.onPercentCompleted(ret);
     506                        }
     507                    }
     508                    else if (data.StatusInfo.Status == "Succeeded") {
     509                        if(closure.debug){
     510                            console.log("#### ProcessSucceeded");
     511                        }
     512
     513                        var text = "";
     514                        closure.terminated[sid] = true;
     515
     516                        ret = {
     517                            sid: sid,
     518                            text: text,
     519                            result: data
     520                        };
     521                       
     522                        closure.getResult(sid, onSuccess, onError);
     523                    }
     524                    else {
     525                        if(closure.debug){
     526                            console.log("#### UNHANDLED EXCEPTION");
     527                        }
     528                        closure.terminated[sid] = true;
     529                        ret = {
     530                            sid: sid,
     531                            code: 'BAD',
     532                            text: 'UNHANDLED EXCEPTION'
     533                        };
     534                       
     535                        //closure.emit('exception', ret);
     536                        if (handlers.onError instanceof Function) {
     537                            handlers.onError(ret);
     538                        }
     539                    }
     540
     541                    return
     542                }
     543
    448544                if (data.ExecuteResponse.Status.ProcessAccepted) {
    449545                    var ret = {
     
    529625                    console.log("PING: "+sid);
    530626                }
     627
    531628                closure.getStatus(sid, onSuccess, onError);
    532629                if (closure.terminated[sid]) {
     
    613710                    });
    614711        };
     712
     713        /**
     714         * The getResult method is used by {@link ZooProcess#watch} to get the
     715         * final result of services called asynchronously.
     716         *
     717         * @method getResult
     718         * @memberof ZooProcess#
     719         * @param {Integer} sid Service Identifier
     720         * @param {Function} onSuccess callback
     721         * @param {Function} onError callback
     722         */
     723        this.getResult = function(sid, onSuccess, onError) {
     724            var closure = this;
     725            if(closure.debug){
     726                console.log("GET STATUS: "+sid);
     727                console.log(closure.statusLocation[sid].replace(/GetStatus/g,"GetResult"));
     728            }
     729            $.ajax({
     730                url: closure.statusLocation[sid].replace(/GetStatus/g,"GetResult")
     731            })
     732                .fail(
     733                    function(jqXHR, textStatus, errorThrown) {
     734                        if(closure.debug){
     735                            console.log("======== ERROR ========");
     736                        }
     737                        var robj=_x2js.xml2json( jqXHR.responseXML );
     738                        if(closure.debug){
     739                            console.log(robj);
     740                        }
     741                        if(onError)
     742                            onError(robj);
     743                    }
     744                )
     745                .done(
     746                    function(data, textStatus, jqXHR) {
     747                        if(closure.debug){
     748                            console.log("======== SUCCESS ========2");
     749                            console.log(data);
     750                        }
     751                        var ctype=jqXHR.getResponseHeader("Content-Type").split(";")[0];
     752                        if( ctype=="text/xml" ){
     753                            var tmpD=data;
     754                            data = _x2js.xml2json( data );
     755                            data._origin=tmpD;
     756                        }
     757                        if(onSuccess)
     758                            onSuccess(data);
     759                    });
     760        };
    615761       
    616762        /**
     
    791937            }
    792938        };       
     939
     940        /**
     941         * The parseJobID method parse the JobID and return an
     942         * object with sid and the JobID attributes which contains
     943         * respectively: a unique identifier named sid and the JobID
     944         * value returned by the WPS server.
     945         *
     946         * @method parseJobID
     947         * @memberof ZooProcess#
     948         * @param {Object} data The XML response parsed by x2js.xml2json
     949         * @returns {Object} The result is an object with sid and jobID
     950         */
     951        this.parseJobID = function(data) {
     952            var closure = this;
     953
     954            if (jobID = data.StatusInfo.JobID) {
     955
     956                var lsid=0;
     957                for(i in closure.statusLocation)
     958                    lsid++;
     959               
     960                return {sid: lsid, jobid: jobID};
     961            }
     962        };
     963
     964        /**
     965         * The dismiss method run the Dismiss request by calling {@link ZooProcess#request}.
     966         *
     967         * @method dismiss
     968         * @memberof ZooProcess#
     969         * @param {Object} params
     970         * @example
     971         * // Log x2js representation of all available services in console
     972         * myZooObject.dismiss({
     973         *     type: 'POST',
     974         *     jobid: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
     975         *     success: function(data){
     976         *         console.log(data);
     977         *     }
     978         * });
     979         */
     980        this.dismiss = function(params) {
     981            var closure = this;
     982
     983            if (!params.hasOwnProperty('type')) {
     984                params.type = 'GET';
     985            }
     986
     987            var zoo_request_params = {
     988                Identifier: params.identifier,
     989                request: 'Dismiss',
     990                service: 'WPS',
     991                jobid: params.jobid,
     992                version: "2.0.0",
     993            }
     994
     995            this.request(zoo_request_params, params.success, params.error, params.type);
     996        };
     997
    793998    };
    794999   
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png