Changeset 517 for trunk/zoo-project/zoo-client
- Timestamp:
- Oct 27, 2014, 6:06:35 PM (10 years ago)
- Location:
- trunk/zoo-project/zoo-client/lib
- Files:
-
- 5 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 -
trunk/zoo-project/zoo-client/lib/js/wps-client/zoo.js
r480 r517 1 // Filename: zoo-process.js2 1 /** 3 2 * Author : Samuel Souk aloun … … 28 27 ], function(X2JS, qs, wpsPayload, utils) { 29 28 29 /** 30 * The ZooProcess Class 31 * @constructs ZooProcess 32 * @param {Object} params Parameters 33 * @example 34 * var myZooObject = new ZooProcess({ 35 * url: "http://localhost/cgi-bin/zoo_loader.cgi", 36 * delay: 2500 37 * }); 38 */ 30 39 var ZooProcess = function(params) { 31 40 32 41 /** 33 * Private 34 */ 35 42 * Object configuring the xml2json use. 43 * 44 * @access private 45 * @memberof ZooProcess# 46 * @var _x2js {x2js} 47 */ 36 48 var _x2js = new X2JS({ 37 49 arrayAccessFormPaths: [ … … 44 56 }); 45 57 46 47 /** 48 * Public 49 */ 50 58 59 /** 60 * @access public 61 * @memberof ZooProcess# 62 * @var debug {Boolean} true if verbose messages should be displayed on the console 63 * @default false 64 */ 65 this.debug = false; 66 /** 67 * @access public 68 * @memberof ZooProcess# 69 * @var url {String} The WPS Server URL 70 */ 51 71 this.url = params.url; 52 72 /** 73 * @access public 74 * @memberof ZooProcess# 75 * @var language {String} The language to be used to request the WPS Server 76 * @default "en-US" 77 */ 78 this.language = params.language?params.language:"en-US"; 79 /** 80 * @access public 81 * @memberof ZooProcess# 82 * @var statusLocation {Object} An object to store the statusLocation 83 * URLs when running request including both the storeExecuteResponse and 84 * the status parameters set to true. 85 */ 53 86 this.statusLocation = {}; 87 /** 88 * @access public 89 * @memberof ZooProcess# 90 * @var launched {Object} An object to store the running asynchrone services. 91 */ 54 92 this.launched = {}; 93 /** 94 * @access public 95 * @memberof ZooProcess# 96 * @var terminated {Object} An object to store the finished services. 97 */ 55 98 this.terminated = {}; 99 /** 100 * @access public 101 * @memberof ZooProcess# 102 * @var percent {Object} An object to store the percentage of completude of services. 103 */ 56 104 this.percent = {}; 57 this.delay = params.delay || 2000, 58 59 // 105 /** 106 * @access public 107 * @memberof ZooProcess# 108 * @var delay {Integer} The time (in milliseconds) between each polling requests. 109 * @default 2000 110 */ 111 this.delay = params.delay || 2000; 112 113 /** 114 * The getCapabilities method run the GetCapabilities request by calling {@link ZooProcess#request}. 115 * 116 * @method getCapabilities 117 * @memberof ZooProcess# 118 * @param {Object} params The parameter for the request and callback functions to call on success or 119 * on failure. 120 * @example 121 * // Log the array of available processes in console 122 * myZooObject.getCapabilities({ 123 * type: 'POST', 124 * success: function(data){ 125 * console.log(data["Capabilities"]["ProcessOfferings"]["Process"]); 126 * } 127 * }); 128 */ 129 this.getCapabilities = function(params) { 130 var closure = this; 131 132 if (!params.hasOwnProperty('type')) { 133 params.type = 'GET'; 134 } 135 136 var zoo_request_params = { 137 request: 'GetCapabilities', 138 service: 'WPS', 139 version: '1.0.0', 140 } 141 142 this.request(zoo_request_params, params.success, params.error, params.type); 143 }; 144 145 /** 146 * The describeProcess method run the DescribeProcess request by calling {@link ZooProcess#request}. 147 * 148 * @method describeProcess 149 * @memberof ZooProcess# 150 * @param {Object} params 151 * @example 152 * // Log x2js representation of all available services in console 153 * myZooObject.describeProcess({ 154 * type: 'POST', 155 * identifier: "all" 156 * success: function(data){ 157 * console.log(data); 158 * } 159 * }); 160 */ 60 161 this.describeProcess = function(params) { 61 162 var closure = this; … … 67 168 var zoo_request_params = { 68 169 Identifier: params.identifier, 69 metapath: params.metapath ? params.metapath : '',70 170 request: 'DescribeProcess', 71 171 service: 'WPS', … … 76 176 }; 77 177 78 // 79 this.getCapabilities = function(params) { 80 var closure = this; 81 82 if (!params.hasOwnProperty('type')) { 83 params.type = 'GET'; 84 } 85 86 // http://zoo-server/cgi-bin/zoo_loader.cgi?ServiceProvider=&metapath=&Service=WPS&Request=GetCapabilities&Version=1.0.0 87 var zoo_request_params = { 88 ServiceProvider: '', 89 metapath: params.metapath ? params.metapath : '', 90 request: 'GetCapabilities', 91 service: 'WPS', 92 version: '1.0.0', 93 } 94 95 this.request(zoo_request_params, params.success, params.error, params.type); 96 }; 97 98 // 99 this.execute = function(params) { 100 var closure = this; 101 console.log("======== Execute "+params.identifier); 102 console.log(params); 178 /** 179 * The convertParams method convert parameters for Execute requests 180 * 181 * @method convertParams 182 * @memberof ZooProcess# 183 * @param {Object} params The original object 184 * @returns {Object} The converted object 185 */ 186 this.convertParams = function(params){ 187 var closure = this; 188 if(closure.debug){ 189 console.log("======== Execute "+params.identifier); 190 console.log(params); 191 } 103 192 104 193 if (!params.hasOwnProperty('type')) { … … 113 202 DataInputs: params.dataInputs ? params.dataInputs : '', 114 203 DataOutputs: params.dataOutputs ? params.dataOutputs : '', 115 116 //storeExecuteResponse: params.storeExecuteResponse ? 'true' : 'false',117 //status: params.status ? 'true' : 'false',118 204 } 119 205 … … 131 217 zoo_request_params.lineage = 'true'; 132 218 } 133 134 135 this.request(zoo_request_params, params.success, params.error, params.type); 136 }; 137 138 139 // 140 this.request = function(params, onSuccess, onError, type) { 219 return zoo_request_params; 220 }; 221 222 /** 223 * The buildRequest method is building the object expected by 224 * [jQuery.ajax]{@link http://api.jquery.com/jquery.ajax/}. 225 * In case of GET request, it will use {@link ZooProcess#getQueryString}. 226 * In case of POST request, it will use {@link module:wpsPayload} getPayload. 227 * 228 * @method buildRequest 229 * @memberof ZooProcess# 230 * @param {Object} params the request parameters 231 * @param {String} type the request method ("GET" or "POST") 232 * @returns {Object} The expected object to give as input for the 233 * [jQuery.ajax]{@link http://api.jquery.com/jquery.ajax/} function. 234 */ 235 this.buildRequest = function(params,type){ 141 236 var closure = this; 142 console.log('======== REQUEST type='+type); 143 console.log(params); 144 237 if(closure.debug){ 238 console.log('======== REQUEST method='+type); 239 console.log(params); 240 } 145 241 var url = this.url; 146 242 var payload; 147 243 var headers; 148 244 if(params.hasOwnProperty('DataOutputs')) 245 for(var i=0;i<params.DataOutputs.length;i++) 246 if(params.DataOutputs[i].type==="raw"){ 247 params["RawDataOutput"]=params.DataOutputs[i]; 248 break; 249 } 250 251 params["language"]=this.language; 149 252 if (type == 'GET') { 150 253 url += '?' + this.getQueryString(params); 151 254 } else if (type == 'POST') { 152 255 payload = wpsPayload.getPayload(params); 153 console.log("======== POST PAYLOAD ========"); 154 console.log(payload); 256 if(closure.debug){ 257 console.log("======== POST PAYLOAD ========"); 258 console.log(payload); 259 } 155 260 156 261 headers = { … … 158 263 }; 159 264 } 160 161 console.log("ajax url: "+url); 162 163 $.ajax({ 164 type: type, 165 url: url, 166 dataType: "xml", 167 data: payload, 168 headers: headers 169 }) 170 .always( 171 function() { 172 //console.log("ALWAYS"); 173 } 174 ) 175 .fail( 176 function(jqXHR, textStatus, errorThrown) { 177 console.log("======== ERROR ========"); 178 onError(jqXHR); 179 } 180 ) 181 .done( 182 function(data, textStatus, jqXHR) { 183 console.log("======== SUCCESS ========"); 184 //console.log(data); 185 console.log(utils.xmlToString(data)); 186 187 // TODO: move this transformation 188 data = _x2js.xml2json( data ); 189 190 console.log(data); 191 //------ 192 193 var launched; 194 195 if (params.storeExecuteResponse == 'true' && params.status == 'true') { 196 launched = closure.parseStatusLocation(data); 197 console.log(launched); 198 closure.statusLocation[launched.sid] = launched.statusLocation; 199 200 if (launched.hasOwnProperty('sid') && !closure.launched.hasOwnProperty(launched.sid)) { 201 closure.launched[launched.sid] = launched.params; 202 //closure.emit('launched', launched); 203 } 265 266 if(closure.debug){ 267 console.log("ajax url: "+url); 268 } 269 return {"url":url,"headers": headers,"data": payload,"type":type}; 270 }; 271 272 /** 273 * The getRequest method call the {@link ZooProcess#buildRequest} method 274 * by giving the {@link ZooProcess#convertParams} result as first 275 * argument and the detected type (default is 'GET') defined in params. 276 * 277 * @method getRequest 278 * @memberof ZooProcess# 279 * @params {Object} params The request parameters 280 */ 281 this.getRequest = function(params){ 282 var closure = this; 283 var type = 'GET'; 284 if(params.hasOwnProperty("type")) 285 type=params["type"]; 286 return closure.buildRequest(closure.convertParams(params),type); 287 }; 288 289 /** 290 * The execute method run the Execute request by calling {@link ZooProcess#request} 291 * with the params converted by {@link ZooProcess#convertParams}. 292 * 293 * @method execute 294 * @memberof ZooProcess# 295 * @param {Object} param Parameters 296 * @example 297 * myZooObject.execute({ 298 * identifier: "Buffer", 299 * dataInputs: [{"identifier":"InputPolygon","href":"http://features.org/toto.xml","mimeType":"text/xml"}], 300 * dataOutputs: [{"identifier":"Result","mimeType":"application/json","type":"raw"}], 301 * type: 'POST', 302 * success: function(data) { 303 * console.log(data); 304 * } 305 * }); 306 */ 307 this.execute = function(params) { 308 var closure = this; 309 this.request(closure.convertParams(params), params.success, params.error, params.type); 310 }; 311 312 313 /** 314 * The request method call {@link ZooProcess#buildRequest} method to 315 * to build parameters to give to 316 * [jQuery.ajax]{@link http://api.jquery.com/jquery.ajax/}. 317 * If the request succeed and if the content-type of the response is 318 * "text/xml" then xml2json is called on the resulting data and passed 319 * to the onSuccess callback function given in parameter. In case the 320 * request failed, the WPS Exception Repport will be parsed with 321 * xml2json and given as parameter to the onError callback function. 322 * 323 * @method request 324 * @memberof ZooProcess# 325 * @param {Object} params The object used as parameter for 326 * [jQuery.ajax]{@link http://api.jquery.com/jquery.ajax/} 327 * @param {Function} onSuccess The callback function called if the request succeed 328 * @param {Function} onError The callback function called if the request failed 329 * @param {String} type The request method ('GET' or 'POST') 330 */ 331 this.request = function(params, onSuccess, onError, type) { 332 var closure = this; 333 334 var obj; 335 obj=closure.buildRequest(params,type); 336 $.ajax(obj) 337 .always( 338 function() { 339 //console.log("ALWAYS"); 204 340 } 205 onSuccess(data, launched); 206 }); 341 ) 342 .fail( 343 function(jqXHR, textStatus, errorThrown) { 344 if(closure.debug){ 345 console.log("======== ERROR ========"); 346 } 347 var robj=_x2js.xml2json( jqXHR.responseXML ); 348 if(closure.debug){ 349 console.log(robj); 350 } 351 if(onError) 352 onError(robj); 353 } 354 ) 355 .done( 356 function(data, textStatus, jqXHR) { 357 if(closure.debug){ 358 console.log("======== SUCCESS ========2"); 359 console.log(data); 360 } 361 var ctype=jqXHR.getResponseHeader("Content-Type").split(";")[0]; 362 if( ctype=="text/xml" ) 363 { 364 var tmpD=data; 365 data = _x2js.xml2json( data ); 366 data._origin=tmpD; 367 } 368 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; 377 } 378 } 379 380 if(onSuccess) 381 onSuccess(data, launched); 382 }); 207 383 }; 208 384 209 // 385 /** 386 * The watch method should be used from the success callback function 387 * passed to {@link ZooProcess#execute} when both status and 388 * storeExecuteResponse parameters are set to 'true', so when the 389 * service should be called asynchronously. This function is 390 * responsible for polling the WPS server until the service end (success 391 * or failure). It call the {@link ZooProcess#getStatus} method every 392 * {@link ZooProcess#delay} milliseconds. 393 * 394 * @method watch 395 * @memberof ZooProcess# 396 * @param {Integer} sid The identifier of the running service 397 * @param {Object} handlers The callback function definitions 398 * (onPercentCompleted, onProcessSucceeded, onError) 399 * @example 400 * zoo.execute({ 401 * identifier: 'MyIdentifier', 402 * type: 'POST', 403 * dataInputs: myInputs, 404 * dataOutputs: myOupts, 405 * storeExecuteResponse: true, 406 * status: true, 407 * success: function(data, launched) { 408 * zoo.watch(launched.sid, { 409 * onPercentCompleted: function(data) { 410 * console.log("**** PercentCompleted ****"); 411 * console.log(data); 412 * progress.text(data.text+' : '+(data.percentCompleted)+'%'); 413 * }, 414 * onProcessSucceeded: function(data) { 415 * progress.css('width', (100)+'%'); 416 * progress.text(data.text+' : '+(100)+'%'); 417 * if (data.result.ExecuteResponse.ProcessOutputs) { 418 * console.log("**** onSuccess ****"); 419 * console.log(data.result); 420 * } 421 * }, 422 * onError: function(data) { 423 * console.log("**** onError ****"); 424 * console.log(data); 425 * }, 426 * }); 427 * }, 428 * error: function(data) { 429 * console.log("**** ERROR ****"); 430 * console.log(data); 431 * notify("Execute asynchrone failed", 'danger'); 432 * } 433 * }); 434 */ 210 435 this.watch = function(sid, handlers) { 211 436 //onPercentCompleted, onProcessSucceeded, onError 212 437 var closure = this; 213 214 console.log("WATCH: "+sid); 438 if(closure.debug){ 439 console.log("WATCH: "+sid); 440 } 215 441 216 442 function onSuccess(data) { 217 console.log("++++ getStatus SUCCESS "+sid); 218 console.log(data); 219 220 if (data.ExecuteResponse.Status.ProcessStarted) { 221 console.log("#### ProcessStarted"); 443 if(closure.debug){ 444 console.log("++++ getStatus SUCCESS "+sid); 445 console.log(data); 446 } 447 448 if (data.ExecuteResponse.Status.ProcessAccepted) { 449 var ret = { 450 sid: sid, 451 percentCompleted: 0, 452 text: data.ExecuteResponse.Status.ProcessAccepted.__text, 453 creationTime: data.ExecuteResponse.Status._creationTime, 454 }; 455 456 closure.percent[sid] = ret.percentCompleted; 457 //closure.emit('percent', ret); 458 459 if (handlers.onPercentCompleted instanceof Function) { 460 handlers.onPercentCompleted(ret); 461 } 462 463 } 464 else if (data.ExecuteResponse.Status.ProcessStarted) { 465 if(closure.debug){ 466 console.log("#### ProcessStarted"); 467 } 222 468 223 469 var ret = { … … 225 471 percentCompleted: data.ExecuteResponse.Status.ProcessStarted._percentCompleted, 226 472 text: data.ExecuteResponse.Status.ProcessStarted.__text, 227 creationTime: data.ExecuteResponse.Status. ProcessStarted._creationTime,473 creationTime: data.ExecuteResponse.Status._creationTime, 228 474 }; 229 475 … … 236 482 } 237 483 else if (data.ExecuteResponse.Status.ProcessSucceeded) { 238 console.log("#### ProcessSucceeded"); 484 if(closure.debug){ 485 console.log("#### ProcessSucceeded"); 486 } 239 487 240 488 var text = data.ExecuteResponse.Status.ProcessSucceeded.__text; … … 253 501 } 254 502 else { 255 console.log("#### UNHANDLED EXCEPTION"); 503 if(closure.debug){ 504 console.log("#### UNHANDLED EXCEPTION"); 505 } 256 506 closure.terminated[sid] = true; 257 507 ret = { … … 269 519 270 520 function onError(data) { 271 console.log("++++ getStatus ERROR "+sid); 272 console.log(data); 521 if(closure.debug){ 522 console.log("++++ getStatus ERROR "+sid); 523 console.log(data); 524 } 273 525 } 274 526 275 527 function ping(sid) { 276 console.log("PING: "+sid); 528 if(closure.debug){ 529 console.log("PING: "+sid); 530 } 277 531 closure.getStatus(sid, onSuccess, onError); 278 532 if (closure.terminated[sid]) { 279 console.log("++++ getStatus TERMINATED "+sid); 533 if(closure.debug){ 534 console.log("++++ getStatus TERMINATED "+sid); 535 } 280 536 } 281 537 else if (!closure.percent.hasOwnProperty(sid) || closure.percent[sid]<100) { 282 538 setTimeout( function() { 283 539 ping(sid); 284 }, closure.delay);540 }, closure.delay); 285 541 } else { 286 console.log(closure.percent); 542 if(closure.debug){ 543 console.log(closure.percent); 544 } 287 545 } 288 546 } … … 291 549 }; 292 550 293 // 551 /** 552 * The getStatus method call 553 * [jQuery.ajax]{@link http://api.jquery.com/jquery.ajax/} to fecth the 554 * ExecuteResponse document which contains a Status node and 555 * potentially the result (when the asynch service end). This method is 556 * used by {@link ZooProcess#watch} to get the ongoing status of 557 * services called asynchronously. 558 * 559 * @method getStatus 560 * @memberof ZooProcess# 561 * @param {Integer} sid Service Identifier 562 * @param {Function} onSuccess callback 563 * @param {Function} onError callback 564 */ 294 565 this.getStatus = function(sid, onSuccess, onError) { 295 566 var closure = this; 296 297 298 567 if(closure.debug){ 568 console.log("GET STATUS: "+sid); 569 } 299 570 if (closure.terminated[sid]) { 300 console.log("DEBUG TERMINATED"); 571 if(closure.debug){ 572 console.log("DEBUG TERMINATED"); 573 } 301 574 return; 302 575 } 303 576 if (!closure.launched[sid]) { 304 console.log("DEBUG LAUNCHED"); 577 if(closure.debug){ 578 console.log("DEBUG LAUNCHED"); 579 } 305 580 return; 306 581 } 307 console.log("PARSE URI: "+closure.statusLocation[sid]); 308 var parsed_url = utils.parseUri(closure.statusLocation[sid]); 309 console.log(parsed_url); 310 zoo_request_params = parsed_url.queryKey; 311 312 this.request(zoo_request_params, onSuccess, onError, 'GET'); 582 583 $.ajax({ 584 url: closure.statusLocation[sid] 585 }) 586 .fail( 587 function(jqXHR, textStatus, errorThrown) { 588 if(closure.debug){ 589 console.log("======== ERROR ========"); 590 } 591 var robj=_x2js.xml2json( jqXHR.responseXML ); 592 if(closure.debug){ 593 console.log(robj); 594 } 595 if(onError) 596 onError(robj); 597 } 598 ) 599 .done( 600 function(data, textStatus, jqXHR) { 601 if(closure.debug){ 602 console.log("======== SUCCESS ========2"); 603 console.log(data); 604 } 605 var ctype=jqXHR.getResponseHeader("Content-Type").split(";")[0]; 606 if( ctype=="text/xml" ){ 607 var tmpD=data; 608 data = _x2js.xml2json( data ); 609 data._origin=tmpD; 610 } 611 if(onSuccess) 612 onSuccess(data); 613 }); 313 614 }; 314 615 315 // 616 /** 617 * The getQueryString method generate a KVP GET request which can be 618 * used to request a WPS server. 619 * 620 * @method getQueryString 621 * @memberof ZooProcess# 622 * @param {Object} params The WPS requests parameters 623 * @returns {String} The GET WPS request 624 * @example 625 * // Log GetCapabilities GET request in console 626 * var request_params = { 627 * request: 'GetCapabilities', 628 * service: 'WPS', 629 * version: '1.0.0', 630 * language; 'en-US' 631 * } 632 * console.log(myZooObject.getQueryString(request_params)); 633 */ 316 634 this.getQueryString = function(params) { 317 635 var closure = this; 318 636 var ret = ''; 319 637 320 // TODO: serialize attributes321 638 serializeInputs = function(obj) { 322 console.log("SERIALIZE dataInputs"); 323 console.log(obj); 324 if($.type(obj) === "string") { 325 return obj; 326 } 327 var str = []; 328 for(var p in obj){ 329 if (obj.hasOwnProperty(p)) { 330 //str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); 331 str.push(p + "=" + obj[p]); 332 } 333 } 334 return str.join(";"); 335 } 336 639 if(closure.debug){ 640 console.log("SERIALIZE dataInputs"); 641 console.log(obj); 642 } 643 var lt=$.type(obj); 644 if(lt === "string") { 645 return obj; 646 } 647 var str = []; 648 for(var p in obj){ 649 if(lt === "array"){ 650 if(obj[p].hasOwnProperty("href")) 651 str.push(obj[p]["identifier"] + "=Reference"); 652 else 653 str.push(obj[p]["identifier"] + "=" + obj[p]["value"]); 654 for(var q in obj[p]){ 655 if(q!="identifier" && q!="value" && q!="href") 656 str.push("@" + q + "=" + obj[p][q]); 657 else 658 if(q=="href") 659 str.push("@xlink:" + q + "=" + encodeURIComponent(obj[p][q])); 660 } 661 str.push(";"); 662 } 663 else 664 if (obj.hasOwnProperty(p)) { 665 if(p=="href") 666 str.push(p + "=" + encodeURIComponent(obj[p])); 667 else 668 str.push(p + "=" + obj[p]); 669 } 670 } 671 return str.join(""); 672 } 673 674 serializeOutputs = function(obj) { 675 if(closure.debug){ 676 console.log("SERIALIZE dataOutputs"); 677 console.log(obj); 678 } 679 var lt=$.type(obj); 680 if(lt === "string") { 681 return obj; 682 } 683 var str = []; 684 for(var p in obj){ 685 str.push(obj[p]["identifier"]); 686 for(var q in obj[p]){ 687 if(q!="identifier" && q!="type") 688 str.push("@" + q + "=" + obj[p][q]); 689 } 690 str.push(";"); 691 } 692 return str.join(""); 693 } 694 337 695 var responseDocument = params.ResponseDocument; 338 696 var tmp_params = {}; … … 346 704 var skip = { 347 705 'DataInputs': true, 348 'DataOu ptputs': true,706 'DataOutputs': true, 349 707 'ResponseDocument': true, 708 'RawDataOutput': true, 350 709 } 351 710 var keys = objectKeys(params); … … 359 718 } 360 719 } 361 362 720 ret = qs.stringify(tmp_params); 363 721 … … 365 723 if (params.hasOwnProperty('DataInputs')) { 366 724 //var dataInputs = params.DataInputs; 367 var dataInputs = serializeInputs(params.DataInputs); 368 console.log("dataInputs: "+dataInputs); 369 ret += '&DataInputs=' + dataInputs; 370 } 371 /* 725 var dataInputs = serializeInputs(params.DataInputs); 726 if(closure.debug){ 727 console.log("dataInputs: "+dataInputs); 728 } 729 ret += '&DataInputs=' + dataInputs; 730 } 731 372 732 if (params.hasOwnProperty('DataOutputs')) { 373 var dataOutputs = serializeOutputs(params.DataOutputs); 374 console.log("dataOutputs: "+dataOutputs); 375 ret += '&DataOutputs=' + dataOutputs; 376 } 377 */ 378 //ResponseDocument=Result ou RawDataOutput=Result 379 380 if (params.ResponseDocument) { 381 ret += '&ResponseDocument=' + params.ResponseDocument; 382 } 383 733 var dataOutputs = serializeOutputs(params.DataOutputs); 734 if(closure.debug){ 735 console.log("dataOutputs: "+dataOutputs); 736 } 737 if(dataOutputs!=""){ 738 var displayInputs=true; 739 for(var i=0;i<params.DataOutputs.length;i++) 740 if(params.DataOutputs[i].type==="raw"){ 741 ret += '&RawDataOutput=' + dataOutputs; 742 displayInputs=false; 743 break; 744 } 745 if(displayInputs) 746 ret += '&ResponseDocument=' + dataOutputs; 747 } 748 }else{ 749 if (params.hasOwnProperty('RawDataOutput')) { 750 ret+="&RawDataOutput="+params['RawDataOutput']+";"; 751 }else{ 752 if (params.hasOwnProperty('ResponseDocument')) { 753 var lt=$.type(params['ResponseDocument']); 754 if(lt === "string") { 755 ret+="&ResponseDocument="+params['ResponseDocument']+";"; 756 }else{ 757 var tmp_ret=serializeOutputs(params['ResponseDocument']); 758 ret+="&ResponseDocument="+tmp; 759 } 760 } 761 } 762 } 763 384 764 return ret; 385 765 }; 386 766 767 /** 768 * The parseStatusLocation method parse the statusLocation and return an 769 * object with sid and statusLocation attributes which contains 770 * respectively: a unique identifier named sid and the statusLocation 771 * value returned by the WPS server. 772 * 773 * @method parseStatusLocation 774 * @memberof ZooProcess# 775 * @param {Object} data The XML response parsed by x2js.xml2json 776 * @returns {Object} The result is an object with sid and statusLocation 777 */ 387 778 this.parseStatusLocation = function(data) { 388 779 var closure = this; 389 780 390 781 if (statusLocation = data.ExecuteResponse._statusLocation) { 391 console.log("statusLocation: "+statusLocation); 392 393 var parsed_url = utils.parseUri(statusLocation); 394 console.log(parsed_url); 395 var parsed_params = parsed_url.queryKey; 396 397 return {sid: parsed_url.queryKey.DataInputs, params: parsed_params, statusLocation: statusLocation}; 782 if(closure.debug){ 783 console.log("statusLocation: "+statusLocation); 784 } 785 786 var lsid=0; 787 for(i in closure.statusLocation) 788 lsid++; 789 790 return {sid: lsid, statusLocation: statusLocation}; 398 791 } 399 792 }; -
trunk/zoo-project/zoo-client/lib/tpl/payload_DescribeProcess.mustache
r480 r517 1 <DescribeProcess xmlns="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 ../wpsDescribeProcess_request.xsd" service="WPS" version="1.0.0" language=" en-CA">1 <DescribeProcess xmlns="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 ../wpsDescribeProcess_request.xsd" service="WPS" version="1.0.0" language="{{language}}"> 2 2 {{#identifiers}} 3 3 <ows:Identifier>{{.}}</ows:Identifier> -
trunk/zoo-project/zoo-client/lib/tpl/payload_Execute.mustache
r480 r517 1 1 <wps:Execute service="WPS" version="1.0.0" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 2 ../wpsExecute_request.xsd" >2 ../wpsExecute_request.xsd" language="{{language}}"> 3 3 <!-- template-version: 0.21 --> 4 4 <ows:Identifier>{{Identifier}}</ows:Identifier> … … 29 29 <wps:Input> 30 30 <ows:Identifier>{{identifier}}</ows:Identifier> 31 <wps:Reference xlink:href="{{href}}" />31 <wps:Reference xlink:href="{{href}}"{{#schema}} schema="{{shema}}"{{/schema}}{{#mimeType}} mimeType="{{mimeType}}"{{/mimeType}}{{#encoding}} encoding="{{encoding}}"{{/encoding}}/> 32 32 </wps:Input> 33 33 {{/is_get}} … … 36 36 <ows:Identifier>{{identifier}}</ows:Identifier> 37 37 <wps:Reference xlink:href="{{href}}" method="{{method}}"> 38 {{# mimeType}}39 <wps:Header key=" Content-type" value="{{mimeType}}" />40 {{/ mimeType}}41 <wps:Body>{{{ complexPayload}}}</wps:Body>38 {{#headers}} 39 <wps:Header key="{{key}}" value="{{value}}" /> 40 {{/headers}} 41 <wps:Body>{{{value}}}</wps:Body> 42 42 </wps:Reference> 43 43 </wps:Input> … … 48 48 <ows:Identifier>{{identifier}}</ows:Identifier> 49 49 <wps:Data> 50 <wps:ComplexData{{#schema}} schema="{{shema}}"{{/schema}}{{#mimeType}} mimeType="{{mimeType}}"{{/mimeType}}{{#encoding}} encoding="{{encoding}}"{{/encoding}}> 51 {{{complexPayload}}}50 <wps:ComplexData{{#schema}} schema="{{shema}}"{{/schema}}{{#mimeType}} mimeType="{{mimeType}}"{{/mimeType}}{{#encoding}} encoding="{{encoding}}"{{/encoding}}>{{#is_XML}} 51 {{{value}}}{{/is_XML}}{{^is_XML}}<![CDATA[{{{value}}}]]>{{/is_XML}} 52 52 </wps:ComplexData> 53 53 </wps:Data> … … 59 59 <wps:ResponseForm> 60 60 {{#RawDataOutput}} 61 {{#DataOutputs}} 61 62 <wps:RawDataOutput mimeType="{{mimeType}}"> 62 63 <ows:Identifier>{{identifier}}</ows:Identifier> 63 64 </wps:RawDataOutput> 65 {{/DataOutputs}} 64 66 {{/RawDataOutput}} 65 67 {{^RawDataOutput}} … … 67 69 {{#DataOutputs}} 68 70 {{#is_literal}} 69 <wps:Output >71 <wps:Output{{#dataType}} dataType="{{dataType}}"{{/dataType}}{{#uom}} uom="{{uom}}"{{/uom}}> 70 72 <ows:Identifier>{{identifier}}</ows:Identifier> 71 73 </wps:Output> -
trunk/zoo-project/zoo-client/lib/tpl/payload_GetCapabilities.mustache
r480 r517 1 <wps:GetCapabilities xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 ../wpsGetCapabilities_request.xsd" language=" en-CA" service="WPS">1 <wps:GetCapabilities xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 ../wpsGetCapabilities_request.xsd" language="{{language}}" service="WPS"> 2 2 <wps:AcceptVersions> 3 3 <ows:Version>1.0.0</ows:Version>
Note: See TracChangeset
for help on using the changeset viewer.