- Timestamp:
- Oct 27, 2014, 6:06:35 PM (10 years ago)
- 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.js2 1 /** 3 2 * Author : Samuel Souk aloun … … 23 22 * THE SOFTWARE. 24 23 */ 25 24 26 25 define([ 27 'jquery', 'utils', 28 'hgn!tpl/payload_GetCapabilities', 29 'hgn!tpl/payload_DescribeProcess', 30 'hgn!tpl/payload_Execute', 26 'jquery', 'utils' 27 ], function($, utils) { 31 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 */ 32 42 33 ], function($, utils, tplGetCapabilities, tplDescribeProcess, tplExecute) {34 35 //36 43 return { 44 45 /** @exports wpsPayload */ 37 46 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 */ 39 80 getPayload: function(params) { 40 81 if (params.request == 'DescribeProcess') { … … 48 89 } 49 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 }, 50 111 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 */ 52 129 getPayload_DescribeProcess: function(params) { 53 130 if (params.Identifier) { 54 131 if ($.isArray(params.Identifier)) { 55 return t plDescribeProcess({identifiers: params.Identifier});132 return templates["payload_DescribeProcess"].render({identifiers: params.Identifier,language: params.language}); 56 133 } 57 134 else { 58 return t plDescribeProcess({identifiers: [params.Identifier]});135 return templates["payload_DescribeProcess"].render({identifiers: [params.Identifier],language: params.language}); 59 136 } 60 137 } … … 62 139 }, 63 140 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 */ 70 160 getPayload_Execute: function(params) { 71 //console.log(params);72 //console.log("==== INPUTS ====");73 161 if (params.DataInputs) { 74 //console.log(params.DataInputs);75 76 162 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 } 78 199 /* 79 80 81 82 83 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"; 84 205 } 85 86 206 if (!params.DataInputs[i].dimension) { 87 207 params.DataInputs[i].dimension = 2; 88 208 } 89 209 } 90 91 if (params.DataInputs[i].type) {92 params.DataInputs[i]['is_'+params.DataInputs[i].type] = true;93 }94 210 95 211 // Complex data from payload callback. 212 console.log("CALLBACK"); 213 console.log(params.DataInputs[i]); 96 214 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); 98 217 } 99 218 … … 116 235 //console.log("==== OUTPUTS ===="); 117 236 if (params.DataOutputs || params.storeExecuteResponse || params.status || params.lineage) { 118 console.log(params.DataOutputs);119 237 120 238 for (var i = 0; i < params.DataOutputs.length; i++) { … … 127 245 } 128 246 129 return t plExecute(params);247 return templates["payload_Execute"].render(params); 130 248 }, 131 249 … … 134 252 135 253 }); 136 137 138
Note: See TracChangeset
for help on using the changeset viewer.