Skip to content

Commit

Permalink
GDC draft II
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Aug 7, 2023
1 parent ec854e8 commit 54de33f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,62 @@ class Connection {
return await pg.describeUserProcess();
}

isOgcApiProcess(process) {

Check failure on line 807 in src/connection.js

View workflow job for this annotation

GitHub Actions / deploy

Missing JSDoc comment
let nodes = Object.values(process.process_graph);
return Boolean(nodes.find(node => {
let process = this.processes.get(node.process_id);

Check failure on line 810 in src/connection.js

View workflow job for this annotation

GitHub Actions / deploy

'process' is already declared in the upper scope on line 807 column 18
return Utils.isObject(process) && Boolean(process.ogcapi);
}));
}

async executeOgcApiProcess(process, abortController = null) {

Check failure on line 815 in src/connection.js

View workflow job for this annotation

GitHub Actions / deploy

Missing JSDoc comment
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,

Check failure on line 822 in src/connection.js

View workflow job for this annotation

GitHub Actions / deploy

'plan' is not defined
budget: budget

Check failure on line 823 in src/connection.js

View workflow job for this annotation

GitHub Actions / deploy

'budget' is not defined
}
);
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.
*
Expand All @@ -824,6 +880,9 @@ class Connection {
budget: budget
}
);
if (isOgcApiProcess(requestBody.process)) {

Check failure on line 883 in src/connection.js

View workflow job for this annotation

GitHub Actions / deploy

'isOgcApiProcess' is not defined
return this.executeOgcApiProcess(process, abortController);
}
let response = await this._post('/result', requestBody, Environment.getResponseType(), abortController);
let syncResult = {
data: response.data,
Expand Down
2 changes: 2 additions & 0 deletions src/gdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -202,6 +203,7 @@ const Migrate = {
return process;
}

process.ogcapi = true;
process.summary = process.title;

process.parameters = [];
Expand Down

0 comments on commit 54de33f

Please sign in to comment.