Ignore:
Timestamp:
Oct 27, 2014, 6:06:35 PM (10 years ago)
Author:
djay
Message:

Update ZOO-Client API and add its jsdoc documentation.

File:
1 edited

Legend:

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

    r480 r517  
    1 // Filename: wps-payload.js
    21/**
    32 * Author : Samuel Souk aloun
     
    2322 * THE SOFTWARE.
    2423 */
    25  
     24
    2625define([
    27     'jquery', 'utils',
    28     'hgn!tpl/payload_GetCapabilities',
    29     'hgn!tpl/payload_DescribeProcess',
    30     'hgn!tpl/payload_Execute',
     26    'jquery', 'utils'
     27], function($, utils) {
    3128   
     29    /**
     30     * The wpsPayload module is using the
     31     * [Hogan.js]{@link http://twitter.github.io/hogan.js/} templating engine to
     32     * generate XML requests to be sent to a WPS Server.
     33     * In the ZOO-Client API, the Hogan.js templates have to be compiled before
     34     * you can use them from you application. Please refer to the ZOO-Client
     35     * installation documentation for more informations.
     36     *
     37     * @module wpsPayload
     38     * @requires payloads
     39     * @requires jquery
     40     * @requires utils
     41     */
    3242   
    33 ], function($, utils, tplGetCapabilities, tplDescribeProcess, tplExecute) {
    34    
    35     //
    3643    return {
     44
     45        /** @exports wpsPayload */
    3746       
    38         //
     47        /**
     48         * The getPayload function uses the mustache
     49         * templates and the parameters provided to generate a valid WPS XML
     50         * request.
     51         *
     52         * @static
     53         * @param {Object} params - The object representing the request.
     54         * @returns {string} - The corresponding XML request
     55         * @example
     56         * // GetCapabilities
     57         * var request_params = {
     58         *     request: 'GetCapabilities',
     59         *     language: 'en-US'
     60         * };
     61         * console.wpsPayload.getPayload(request_params));
     62         * @example
     63         * // DescribeProcess with Identifier value set to "all".
     64         * var request_params = {
     65         *     request: 'DescribeProcess',
     66         *     identifier: ["all"]
     67         * };
     68         * console.log(wpsPayload.getPayload(request_params));
     69         * @example
     70         * //
     71         * var request_params = {
     72         *     request: 'Execute',
     73         *     Identifier: "Buffer",
     74         *     DataInputs: [{"identifier":"InputPolygon","href":"http://features.org/toto.xml","mimeType":"text/xml"}],
     75         *     DataOutputs: [{"identifier":"Result","mimeType":"application/json"}],
     76         *     language: 'en-US'
     77         * };
     78         * console.log(wpsPayload.getPayload(request_params));
     79         */
    3980        getPayload: function(params) {
    4081            if (params.request == 'DescribeProcess') {
     
    4889            }
    4990        },
     91
     92        /**
     93         * The getPayload_GetCapabilities function is used to generate a valid
     94         * WPS XML GetCapabilities request using the
     95         * [payload_GetCapabilities.mustache]{@link http://zoo-project.org/trac/browser/trunk/zoo-project/zoo-client/lib/tpl/payload_GetCapabilities.mustache}
     96         * template.
     97         *
     98         * @static
     99         * @param {Object} params - The object representing the request.
     100         * @returns {string} - The corresponding XML request
     101         * @example
     102         * // log the XML request in console
     103         * var request_params = {
     104         *     language: 'en-US'
     105         * };
     106         * console.log(wpsPayload.getPayload_GetCapabilities(request_params));
     107         */
     108        getPayload_GetCapabilities: function(params) {
     109            return templates["payload_GetCapabilities"].render(params);
     110        },
    50111       
    51         //
     112        /**
     113         * The getPayload_DescribeProcess function is used to generate a valid
     114         * WPS XML DescribeProcess  request using the
     115         * [payload_DescribeProcess.mustache]{@link http://zoo-project.org/trac/browser/trunk/zoo-project/zoo-client/lib/tpl/payload_DescribeProcess.mustache}
     116         * template.
     117         *
     118         * @static
     119         * @param {Object} params - The object representing the request.
     120         * @returns {string} - The corresponding XML request
     121         * @example
     122         * // log the XML request in console
     123         * var request_params = {
     124         *     Identifier: ["Buffer","Centroid"],
     125         *     language: 'en-US'
     126         * };
     127         * console.log(wpsPayload.getPayload_DescribeProcess(request_params));
     128         */
    52129        getPayload_DescribeProcess: function(params) {
    53130            if (params.Identifier) {
    54131                if ($.isArray(params.Identifier)) {
    55                     return tplDescribeProcess({identifiers: params.Identifier});
     132                    return templates["payload_DescribeProcess"].render({identifiers: params.Identifier,language: params.language});
    56133                }
    57134                else {
    58                     return tplDescribeProcess({identifiers: [params.Identifier]});
     135                    return templates["payload_DescribeProcess"].render({identifiers: [params.Identifier],language: params.language});
    59136                }
    60137            }
     
    62139        },
    63140
    64         //
    65         getPayload_GetCapabilities: function(params) {
    66             return tplGetCapabilities();
    67         },
    68 
    69         //
     141        /**
     142         * The getPayload_Execute function is used to generate a valid WPS XML
     143         * Excute request using the
     144         * [payload_Execute.mustache]{@link http://zoo-project.org/trac/browser/trunk/zoo-project/zoo-client/lib/tpl/payload_Execute.mustache}
     145         * template.
     146         *
     147         * @static
     148         * @param {Object} params - The object representing the request.
     149         * @returns {string} - The corresponding XML request
     150         * @example
     151         * // log the XML request in console
     152         * var request_params = {
     153         *     Identifier: "Buffer",
     154         *     DataInputs: [{"identifier":"InputPolygon","href":"http://features.org/toto.xml","mimeType":"text/xml"}],
     155         *     DataOutputs: [{"identifier":"Result","mimeType":"application/json"}],
     156         *     language: 'en-US'
     157         * };
     158         * console.log(wpsPayload.getPayload_Execute(request_params));
     159         */
    70160        getPayload_Execute: function(params) {
    71             //console.log(params);
    72             //console.log("==== INPUTS ====");
    73161            if (params.DataInputs) {
    74                 //console.log(params.DataInputs);
    75 
    76162                for (var i = 0; i < params.DataInputs.length; i++) {
    77                    
     163                    /**
     164                     * Define inputs type depending on presence of mimeType,
     165                     * dataType and crs or dimension for ComplexData,
     166                     * LiteralData and BoundingBox data respectively
     167                     */
     168                    var hasType=false;
     169                    var lp={"data":"literal","mime":"complex"};
     170                    for(j in lp){
     171                        if (params.DataInputs[i][j+"Type"]) {
     172                            params.DataInputs[i]['is_'+lp[j]] = true;
     173                            params.DataInputs[i].type=lp[j];
     174                            if(j=="mime"){
     175                                params.DataInputs[i].is_XML=(params.DataInputs[i][j+"Type"]=="text/xml");
     176                                if(!params.DataInputs[i].is_XML){
     177                                    var tmp=params.DataInputs[i][j+"Type"].split(";");
     178                                    params.DataInputs[i].is_XML=(tmp[0]=="text/xml");
     179                                }
     180                            }
     181                            hasType=true;
     182                        }
     183                    }
     184                    if(!hasType){
     185                        if (params.DataInputs[i]["type"]=="bbox" ||
     186                            params.DataInputs[i]["dimension"] ||
     187                            params.DataInputs[i]["crs"]){
     188
     189                            params.DataInputs[i]['is_bbox'] = true;
     190                            params.DataInputs[i].type='bbox';
     191                            hasType=true;
     192                           
     193                        }
     194                        if(!hasType){
     195                            params.DataInputs[i]['is_literal'] = true;
     196                            params.DataInputs[i].type = "literal";
     197                        }
     198                    }
    78199                    /*
    79                         * Set some default values and flags.
    80                         */
    81                         if (params.DataInputs[i].type == 'bbox') {
    82                             if (!params.DataInputs[i].crs) {
    83                                 params.DataInputs[i].crs = "EPSG:4326";
     200                    * Set some default values and flags.
     201                    */
     202                    if (params.DataInputs[i].type == 'bbox') {
     203                        if (!params.DataInputs[i].crs) {
     204                            params.DataInputs[i].crs = "EPSG:4326";
    84205                        }
    85 
    86206                        if (!params.DataInputs[i].dimension) {
    87                                 params.DataInputs[i].dimension = 2;
     207                            params.DataInputs[i].dimension = 2;
    88208                        }
    89209                    }
    90 
    91                     if (params.DataInputs[i].type) {
    92                         params.DataInputs[i]['is_'+params.DataInputs[i].type] = true;
    93                     }
    94210                   
    95211                    // Complex data from payload callback.
     212                    console.log("CALLBACK");
     213                    console.log(params.DataInputs[i]);
    96214                    if (params.DataInputs[i].complexPayload_callback) {
    97                         params.DataInputs[i].complexPayload = window[params.DataInputs[i].complexPayload_callback];
     215                        params.DataInputs[i].value = window[params.DataInputs[i].complexPayload_callback];
     216                        console.log(params.DataInputs[i].value);
    98217                    }
    99218                   
     
    116235            //console.log("==== OUTPUTS ====");
    117236            if (params.DataOutputs || params.storeExecuteResponse || params.status || params.lineage) {
    118                 console.log(params.DataOutputs);
    119237               
    120238                for (var i = 0; i < params.DataOutputs.length; i++) {
     
    127245            }
    128246           
    129             return tplExecute(params);
     247            return templates["payload_Execute"].render(params);
    130248        },
    131249       
     
    134252
    135253});
    136 
    137 
    138 
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