@boundlessgeo/cloud-core
Advanced tools
Comparing version 0.4.5 to 0.4.6
{ | ||
"name": "@boundlessgeo/cloud-core", | ||
"author": "Boundless Spatial Inc.", | ||
"version": "0.4.5", | ||
"version": "0.4.6", | ||
"description": "A library for facilitating communication with the Boundless mBSE.", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -10,2 +10,3 @@ 'use strict'; | ||
exports.formatPreamble = formatPreamble; | ||
exports.formatInlinePreamble = formatInlinePreamble; | ||
exports.formatPostamble = formatPostamble; | ||
@@ -19,4 +20,16 @@ exports.formatWpsRequest = formatWpsRequest; | ||
var REFERENCE_TYPES = exports.REFERENCE_TYPES = { | ||
raster: 'image/tiff', | ||
vector: 'text/xml; subtype=gml/3.1.1', | ||
geom: 'text/xml; subtype=gml/3.1.1' | ||
}; | ||
var SUBPROCESS = exports.SUBPROCESS = 'SUBPROCESS'; | ||
function formatInput(inputDef) { | ||
var layer = void 0; | ||
if (inputDef.value !== undefined && inputDef.value.type === SUBPROCESS) { | ||
var body = formatWpsRequest(inputDef.value.value, undefined, true); | ||
return '\n <wps:Input>\n <ows:Identifier>' + inputDef.id + '</ows:Identifier>\n <wps:Reference xlink:href="http://geoserver/wps" method="POST" mimeType="' + REFERENCE_TYPES[inputDef.type] + '">\n <wps:Body>\n ' + body + '\n </wps:Body>\n </wps:Reference>\n </wps:Input>\n '; | ||
} | ||
if (inputDef.type === 'text' && (inputDef.value !== undefined || inputDef.default !== undefined)) { | ||
@@ -45,3 +58,9 @@ return '\n <wps:Input>\n <ows:Identifier>' + inputDef.id + '</ows:Identifier>\n <wps:Data>\n <wps:LiteralData>' + (inputDef.value !== undefined ? inputDef.value : inputDef.default) + '</wps:LiteralData>\n </wps:Data>\n </wps:Input>\n '; | ||
function formatOutput(mimeType) { | ||
return '\n <wps:ResponseForm>\n <wps:RawDataOutput mimeType="' + mimeType + '">\n <ows:Identifier>result</ows:Identifier>\n </wps:RawDataOutput>\n </wps:ResponseForm>\n '; | ||
var rawDataOutput = void 0; | ||
if (mimeType) { | ||
rawDataOutput = '<wps:RawDataOutput mimeType="' + mimeType + '">'; | ||
} else { | ||
rawDataOutput = '<wps:RawDataOutput>'; | ||
} | ||
return '\n <wps:ResponseForm>\n ' + rawDataOutput + '\n <ows:Identifier>result</ows:Identifier>\n </wps:RawDataOutput>\n </wps:ResponseForm>\n '; | ||
} | ||
@@ -53,2 +72,6 @@ | ||
function formatInlinePreamble(processId) { | ||
return '<wps:Execute\n version="1.0.0"\n service="WPS"\n>\n <ows:Identifier>' + processId + '</ows:Identifier>\n '; | ||
} | ||
function formatPostamble() { | ||
@@ -58,4 +81,10 @@ return '</wps:Execute>'; | ||
function formatWpsRequest(wpsDesc, outputFormat) { | ||
return formatPreamble(wpsDesc.id) + '\n ' + formatInputs(wpsDesc.inputs) + '\n ' + formatOutput(outputFormat) + '\n' + formatPostamble(); | ||
function formatWpsRequest(wpsDesc, outputFormat, inline) { | ||
var preamble = void 0; | ||
if (inline) { | ||
preamble = formatInlinePreamble(wpsDesc.id); | ||
} else { | ||
preamble = formatPreamble(wpsDesc.id); | ||
} | ||
return preamble + '\n ' + formatInputs(wpsDesc.inputs) + '\n ' + formatOutput(outputFormat) + '\n' + formatPostamble(); | ||
} |
58
wps.js
@@ -11,3 +11,6 @@ 'use strict'; | ||
exports.getProcessDescription = getProcessDescription; | ||
exports.executeRawProcess = executeRawProcess; | ||
exports.executeProcess = executeProcess; | ||
exports.checkAsyncStatus = checkAsyncStatus; | ||
exports.getAsyncResults = getAsyncResults; | ||
@@ -232,3 +235,3 @@ var _util = require('./util'); | ||
function executeProcess(geoServerUrl, wpsDescription) { | ||
function executeRawProcess(geoServerUrl, body) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
@@ -240,3 +243,3 @@ | ||
fetch_opts.method = 'POST'; | ||
fetch_opts.body = (0, _wpsUtil.formatWpsRequest)(wpsDescription, options.mimeType); | ||
fetch_opts.body = body; | ||
fetch_opts.headers.set('Content-Type', 'text/xml'); | ||
@@ -256,2 +259,53 @@ | ||
}); | ||
} | ||
function executeProcess(geoServerUrl, wpsDescription) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var request_body = (0, _wpsUtil.formatWpsRequest)(wpsDescription, options.mimeType); | ||
return executeRawProcess(geoServerUrl, request_body, options); | ||
} | ||
function checkAsyncStatus(geoServerUrl, executionId) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var fetch_opts = (0, _util.getFetchOptions)(options.headers); | ||
var query_string = (0, _util.encodeQueryParams)({}, options.accessToken); | ||
var url = geoServerUrl + '/rest/wps/' + executionId + '?' + query_string; | ||
return fetch(url, fetch_opts).then(function (response) { | ||
if (response.ok) { | ||
return response.json(); | ||
} else { | ||
return response.text().then(function (text) { | ||
throw new Error(response.statusText + ': ' + text); | ||
}); | ||
} | ||
}); | ||
} | ||
function getAsyncResults(geoServerUrl, executionId) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var fetch_opts = (0, _util.getFetchOptions)(options.headers); | ||
var params = { | ||
service: 'WPS', | ||
version: '1.0.0', | ||
request: 'GetExecutionStatus', | ||
executionId: executionId | ||
}; | ||
var query_string = (0, _util.encodeQueryParams)(params, options.accessToken); | ||
var url = geoServerUrl + '/ows?' + query_string; | ||
return fetch(url, fetch_opts).then(function (response) { | ||
if (response.ok) { | ||
return response.text(); | ||
} else { | ||
return response.text().then(function (text) { | ||
throw new Error(response.statusText + ': ' + text); | ||
}); | ||
} | ||
}); | ||
} |
51044
1286
24