[480] | 1 | // Filename: wps-payload.js |
---|
| 2 | /** |
---|
| 3 | * Author : Samuel Souk aloun |
---|
| 4 | * |
---|
| 5 | * Copyright (c) 2014 GeoLabs SARL |
---|
| 6 | * |
---|
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 8 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 9 | * in the Software without restriction, including without limitation the rights |
---|
| 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 11 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 12 | * furnished to do so, subject to the following conditions: |
---|
| 13 | * |
---|
| 14 | * The above copyright notice and this permission notice shall be included in |
---|
| 15 | * all copies or substantial portions of the Software. |
---|
| 16 | * |
---|
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 23 | * THE SOFTWARE. |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | define([ |
---|
| 27 | 'jquery', 'utils', |
---|
| 28 | 'hgn!tpl/payload_GetCapabilities', |
---|
| 29 | 'hgn!tpl/payload_DescribeProcess', |
---|
| 30 | 'hgn!tpl/payload_Execute', |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | ], function($, utils, tplGetCapabilities, tplDescribeProcess, tplExecute) { |
---|
| 34 | |
---|
| 35 | // |
---|
| 36 | return { |
---|
| 37 | |
---|
| 38 | // |
---|
| 39 | getPayload: function(params) { |
---|
| 40 | if (params.request == 'DescribeProcess') { |
---|
| 41 | return this.getPayload_DescribeProcess(params); |
---|
| 42 | } else if (params.request == 'GetCapabilities') { |
---|
| 43 | return this.getPayload_GetCapabilities(params); |
---|
| 44 | } else if (params.request == 'Execute') { |
---|
| 45 | return this.getPayload_Execute(params); |
---|
| 46 | } else { |
---|
| 47 | console.log("#### UNKNOWN REQUEST ####"); |
---|
| 48 | } |
---|
| 49 | }, |
---|
| 50 | |
---|
| 51 | // |
---|
| 52 | getPayload_DescribeProcess: function(params) { |
---|
| 53 | if (params.Identifier) { |
---|
| 54 | if ($.isArray(params.Identifier)) { |
---|
| 55 | return tplDescribeProcess({identifiers: params.Identifier}); |
---|
| 56 | } |
---|
| 57 | else { |
---|
| 58 | return tplDescribeProcess({identifiers: [params.Identifier]}); |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | // TODO: no Identifier |
---|
| 62 | }, |
---|
| 63 | |
---|
| 64 | // |
---|
| 65 | getPayload_GetCapabilities: function(params) { |
---|
| 66 | return tplGetCapabilities(); |
---|
| 67 | }, |
---|
| 68 | |
---|
| 69 | // |
---|
| 70 | getPayload_Execute: function(params) { |
---|
| 71 | //console.log(params); |
---|
| 72 | //console.log("==== INPUTS ===="); |
---|
| 73 | if (params.DataInputs) { |
---|
| 74 | //console.log(params.DataInputs); |
---|
| 75 | |
---|
| 76 | for (var i = 0; i < params.DataInputs.length; i++) { |
---|
| 77 | |
---|
| 78 | /* |
---|
| 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"; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | if (!params.DataInputs[i].dimension) { |
---|
| 87 | params.DataInputs[i].dimension = 2; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | if (params.DataInputs[i].type) { |
---|
| 92 | params.DataInputs[i]['is_'+params.DataInputs[i].type] = true; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | // Complex data from payload callback. |
---|
| 96 | if (params.DataInputs[i].complexPayload_callback) { |
---|
| 97 | params.DataInputs[i].complexPayload = window[params.DataInputs[i].complexPayload_callback]; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | // Complex data from reference. |
---|
| 101 | if (params.DataInputs[i].href) { |
---|
| 102 | params.DataInputs[i].is_reference = true; |
---|
| 103 | //params.DataInputs[i].href = utils.encodeXML(params.DataInputs[i].href); |
---|
| 104 | if (params.DataInputs[i].method == 'POST') { |
---|
| 105 | params.DataInputs[i].is_post = true; |
---|
| 106 | } else { |
---|
| 107 | params.DataInputs[i].is_get = true; |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | else { |
---|
| 111 | // Complex data, embeded |
---|
| 112 | } |
---|
| 113 | } // for i loop |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | //console.log("==== OUTPUTS ===="); |
---|
| 117 | if (params.DataOutputs || params.storeExecuteResponse || params.status || params.lineage) { |
---|
| 118 | console.log(params.DataOutputs); |
---|
| 119 | |
---|
| 120 | for (var i = 0; i < params.DataOutputs.length; i++) { |
---|
| 121 | //console.log(params.DataOutputs[i]); |
---|
| 122 | |
---|
| 123 | if (params.DataOutputs[i].type) { |
---|
| 124 | params.DataOutputs[i]['is_'+params.DataOutputs[i].type] = true; |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | return tplExecute(params); |
---|
| 130 | }, |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | }; |
---|
| 134 | |
---|
| 135 | }); |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | |
---|