diff --git a/src/connection.js b/src/connection.js index dee45c6..ab8b991 100644 --- a/src/connection.js +++ b/src/connection.js @@ -804,6 +804,62 @@ class Connection { return await pg.describeUserProcess(); } + isOgcApiProcess(process) { + let nodes = Object.values(process.process_graph); + return Boolean(nodes.find(node => { + let process = this.processes.get(node.process_id); + return Utils.isObject(process) && Boolean(process.ogcapi); + })); + } + + async executeOgcApiProcess(process, abortController = null) { + if (Utils.size(process.process_graph) !== 1) { + throw new Error('Synchronous execution with OGC API - Processes only supports one process at at time.'); + } + let requestBody = this._normalizeUserProcess( + process, + { + plan: plan, + budget: budget + } + ); + let response = await this._post('/result', requestBody, Environment.getResponseType(), abortController); + let syncResult = { + data: response.data, + costs: null, + type: null, + logs: [] + }; + + if (typeof response.headers['openeo-costs'] === 'number') { + syncResult.costs = response.headers['openeo-costs']; + } + + if (typeof response.headers['content-type'] === 'string') { + syncResult.type = response.headers['content-type']; + } + + let links = Array.isArray(response.headers.link) ? response.headers.link : [response.headers.link]; + for(let link of links) { + if (typeof link !== 'string') { + continue; + } + let logs = link.match(/^<([^>]+)>;\s?rel="monitor"/i); + if (Array.isArray(logs) && logs.length > 1) { + try { + let logsResponse = await this._get(logs[1]); + if (Utils.isObject(logsResponse.data) && Array.isArray(logsResponse.data.logs)) { + syncResult.logs = logsResponse.data.logs; + } + } catch(error) { + console.warn(error); + } + } + } + + return syncResult; + } + /** * Executes a process synchronously and returns the result as the response. * @@ -824,6 +880,9 @@ class Connection { budget: budget } ); + if (isOgcApiProcess(requestBody.process)) { + return this.executeOgcApiProcess(process, abortController); + } let response = await this._post('/result', requestBody, Environment.getResponseType(), abortController); let syncResult = { data: response.data, diff --git a/src/gdc.js b/src/gdc.js index 58338df..cb36625 100644 --- a/src/gdc.js +++ b/src/gdc.js @@ -12,6 +12,7 @@ class GdcCapabilities extends Capabilities { describeCoverageRangetype: 'get /collections/{collection_id}/coverage/rangetype', describeCoverageRangeset: 'get /collections/{collection_id}/coverage/rangeset', describeCoverageMetadata: 'get /collections/{collection_id}/coverage/metadata', + executeOgcProcess: 'post /processes/{processId}/execution', }); this.checkConformance(); } @@ -202,6 +203,7 @@ const Migrate = { return process; } + process.ogcapi = true; process.summary = process.title; process.parameters = [];