Changeset 719
- Timestamp:
- Jul 1, 2015, 12:57:36 AM (9 years ago)
- 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 85 85 } else if (params.request == 'Execute') { 86 86 return this.getPayload_Execute(params); 87 } else if (params.request == 'Dismiss') { 88 return this.getPayload_Dismiss(params); 87 89 } else { 88 90 console.log("#### UNKNOWN REQUEST ####"); … … 107 109 */ 108 110 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); 110 115 }, 111 116 … … 128 133 */ 129 134 getPayload_DescribeProcess: function(params) { 135 var id="payload_DescribeProcess"; 136 if(params.version=="2.0.0") 137 id+="2"; 130 138 if (params.Identifier) { 131 139 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}); 133 141 } 134 142 else { 135 return templates[ "payload_DescribeProcess"].render({identifiers: [params.Identifier],language: params.language});143 return templates[id].render({identifiers: [params.Identifier],language: params.language}); 136 144 } 137 145 } 138 146 // TODO: no Identifier 139 147 }, 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 140 179 141 180 /** … … 159 198 */ 160 199 getPayload_Execute: function(params) { 200 var id="payload_Execute"; 201 if(params.version=="2.0.0") 202 id+="2"; 161 203 if (params.DataInputs) { 162 204 for (var i = 0; i < params.DataInputs.length; i++) { … … 210 252 211 253 // Complex data from payload callback. 212 console.log("CALLBACK");213 console.log(params.DataInputs[i]);214 254 if (params.DataInputs[i].complexPayload_callback) { 215 255 params.DataInputs[i].value = window[params.DataInputs[i].complexPayload_callback]; 216 console.log(params.DataInputs[i].value);217 256 } 218 257 … … 245 284 } 246 285 247 return templates[ "payload_Execute"].render(params);286 return templates[id].render(params); 248 287 }, 249 288 -
trunk/zoo-project/zoo-client/lib/js/wps-client/zoo.js
r517 r719 73 73 * @access public 74 74 * @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# 75 81 * @var language {String} The language to be used to request the WPS Server 76 82 * @default "en-US" … … 137 143 request: 'GetCapabilities', 138 144 service: 'WPS', 139 version: '1.0.0',145 version: (params.hasOwnProperty('version')?params.version:closure.version), 140 146 } 141 147 … … 170 176 request: 'DescribeProcess', 171 177 service: 'WPS', 172 version: '1.0.0',178 version: (params.hasOwnProperty('version')?params.version:closure.version), 173 179 } 174 180 … … 198 204 request: 'Execute', 199 205 service: 'WPS', 200 version: '1.0.0',206 version: (params.hasOwnProperty('version')?params.version:closure.version), 201 207 Identifier: params.identifier, 202 208 DataInputs: params.dataInputs ? params.dataInputs : '', … … 204 210 } 205 211 212 console.log(zoo_request_params); 206 213 207 214 if (params.hasOwnProperty('responseDocument')) { 208 215 zoo_request_params.ResponseDocument = params.responseDocument; 216 } 217 if (params.hasOwnProperty('mode')) { 218 zoo_request_params.mode = params.mode; 209 219 } 210 220 if (params.hasOwnProperty('storeExecuteResponse') && params.storeExecuteResponse) { … … 257 267 console.log("======== POST PAYLOAD ========"); 258 268 console.log(payload); 269 console.log(params); 259 270 } 260 271 … … 367 378 } 368 379 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 } 377 390 } 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 } 378 401 } 379 402 … … 446 469 } 447 470 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 448 544 if (data.ExecuteResponse.Status.ProcessAccepted) { 449 545 var ret = { … … 529 625 console.log("PING: "+sid); 530 626 } 627 531 628 closure.getStatus(sid, onSuccess, onError); 532 629 if (closure.terminated[sid]) { … … 613 710 }); 614 711 }; 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 }; 615 761 616 762 /** … … 791 937 } 792 938 }; 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 793 998 }; 794 999
Note: See TracChangeset
for help on using the changeset viewer.