source: trunk/zoo-project/zoo-client/lib/js/wps-client/wps-payload.js @ 517

Last change on this file since 517 was 517, checked in by djay, 9 years ago

Update ZOO-Client API and add its jsdoc documentation.

File size: 9.5 KB
Line 
1/**
2 * Author : Samuel Souk aloun
3 *
4 * Copyright (c) 2014 GeoLabs SARL
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25define([
26    'jquery', 'utils'
27], function($, utils) {
28   
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     */
42   
43    return {
44
45        /** @exports wpsPayload */
46       
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         */
80        getPayload: function(params) {
81            if (params.request == 'DescribeProcess') {
82                return this.getPayload_DescribeProcess(params);
83            } else if (params.request == 'GetCapabilities') {
84                return this.getPayload_GetCapabilities(params);
85            } else if (params.request == 'Execute') {
86                return this.getPayload_Execute(params);
87            } else {
88                console.log("#### UNKNOWN REQUEST ####");
89            }
90        },
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        },
111       
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         */
129        getPayload_DescribeProcess: function(params) {
130            if (params.Identifier) {
131                if ($.isArray(params.Identifier)) {
132                    return templates["payload_DescribeProcess"].render({identifiers: params.Identifier,language: params.language});
133                }
134                else {
135                    return templates["payload_DescribeProcess"].render({identifiers: [params.Identifier],language: params.language});
136                }
137            }
138            // TODO: no Identifier
139        },
140
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         */
160        getPayload_Execute: function(params) {
161            if (params.DataInputs) {
162                for (var i = 0; i < params.DataInputs.length; i++) {
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                    }
199                    /*
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";
205                        }
206                        if (!params.DataInputs[i].dimension) {
207                            params.DataInputs[i].dimension = 2;
208                        }
209                    }
210                   
211                    // Complex data from payload callback.
212                    console.log("CALLBACK");
213                    console.log(params.DataInputs[i]);
214                    if (params.DataInputs[i].complexPayload_callback) {
215                        params.DataInputs[i].value = window[params.DataInputs[i].complexPayload_callback];
216                        console.log(params.DataInputs[i].value);
217                    }
218                   
219                    // Complex data from reference.
220                    if (params.DataInputs[i].href) {
221                        params.DataInputs[i].is_reference = true;
222                        //params.DataInputs[i].href = utils.encodeXML(params.DataInputs[i].href);
223                        if (params.DataInputs[i].method == 'POST') {
224                            params.DataInputs[i].is_post = true;
225                        } else {
226                            params.DataInputs[i].is_get = true;
227                        }
228                    }
229                    else {                       
230                        // Complex data, embeded
231                    }
232                } // for i loop
233            }
234
235            //console.log("==== OUTPUTS ====");
236            if (params.DataOutputs || params.storeExecuteResponse || params.status || params.lineage) {
237               
238                for (var i = 0; i < params.DataOutputs.length; i++) {
239                    //console.log(params.DataOutputs[i]);
240                   
241                    if (params.DataOutputs[i].type) {
242                        params.DataOutputs[i]['is_'+params.DataOutputs[i].type] = true;
243                    }
244                }
245            }
246           
247            return templates["payload_Execute"].render(params);
248        },
249       
250
251    };
252
253});
Note: See TracBrowser for help on using the repository browser.

Search

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