diff --git a/src/connection.js b/src/connection.js index dee45c6..1ccea8c 100644 --- a/src/connection.js +++ b/src/connection.js @@ -804,6 +804,62 @@ class Connection { return await pg.describeUserProcess(); } + isOgcProcess(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 executeOgcProcess(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 (isOgcProcess(requestBody.process)) { + return this.executeOgcProcess(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..640b461 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(); } @@ -66,6 +67,14 @@ class GdcCapabilities extends Capabilities { "path": "/processes", "methods": ["GET"] }); + this.data.endpoints.push({ + "path": "/processes/{processId}", + "methods": ["GET"] + }); + this.data.endpoints.push({ + "path": "/processes/{processId}/execution", + "methods": ["POST"] + }); this.data.endpoints.push({ "path": "/jobs", "methods": ["GET"] @@ -189,6 +198,7 @@ const Migrate = { // Make sure the required properties are present collection = StacMigrate.collection(collection); + collection.ogcapi = true; // Make links absolute if (Array.isArray(collection.links)) { collection.links = this.connection.makeLinksAbsolute(collection.links, response); @@ -202,6 +212,7 @@ const Migrate = { return process; } + process.ogcapi = true; process.summary = process.title; process.parameters = []; @@ -247,6 +258,7 @@ const Migrate = { return job; } + job.ogcapi = true; job.id = job.jobID; job.process = { process_graph: {