Skip to content

Commit 9e1bddf

Browse files
committed
Implement processing parameters extension
1 parent 4a180b6 commit 9e1bddf

File tree

5 files changed

+89
-2
lines changed

5 files changed

+89
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
"@openeo/js-commons": "^1.5.0",
5656
"@radiantearth/stac-migrate": "^1.0.0",
5757
"axios": "^1.0.0",
58-
"oidc-client": "^1.11.5"
58+
"oidc-client": "^1.11.5",
59+
"regexp.escape": "^2.0.1"
5960
},
6061
"scripts": {
6162
"docs": "jsdoc -r -d docs/ -P package.json -R README.md -c .jsdoc",

src/capabilities.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
const Utils = require('@openeo/js-commons/src/utils');
2+
if (typeof RegExp.escape !== 'function') {
3+
require('regexp.escape').shim();
4+
}
25

36
const FEATURE_MAP = {
47
// Discovery
58
capabilities: true,
69
listFileTypes: 'get /file_formats',
710
listServiceTypes: 'get /service_types',
811
listUdfRuntimes: 'get /udf_runtimes',
12+
listProcessingParameters: 'get /processing_parameters',
913
// Collections
1014
listCollections: 'get /collections',
1115
describeCollection: 'get /collections/{}',
@@ -58,6 +62,22 @@ const FEATURE_MAP = {
5862
debugService: 'get /services/{}/logs',
5963
};
6064

65+
const CONFORMANCE_CLASSES = {
66+
openeo: "https://api.openeo.org/extensions/openeo/v1.*",
67+
// STAC API
68+
stacCollections: [
69+
'https://api.stacspec.org/v1.*/collections',
70+
'https://api.stacspec.org/v1.*/ogcapi-features'
71+
],
72+
stacItems: 'https://api.stacspec.org/v1.*/ogcapi-features',
73+
// openEO API Extensions
74+
commercialData: 'https://api.openeo.org/extensions/commercial-data/0.1.*',
75+
federation: 'https://api.openeo.org/extensions/federation/0.1.*',
76+
processingParameters: "https://api.openeo.org/extensions/processing-parameters/0.1.*",
77+
remoteProcessDefinition: 'https://api.openeo.org/extensions/remote-process-definition/0.1.*',
78+
workspaces: 'https://api.openeo.org/extensions/workspaces/0.1.*'
79+
};
80+
6181
/**
6282
* Capabilities of a back-end.
6383
*/
@@ -261,6 +281,29 @@ class Capabilities {
261281
return feature === true || this.features.some(e => e === feature);
262282
}
263283

284+
/**
285+
* Check whether a conformance class is supported by the back-end.
286+
*
287+
* Use `*` as a wildcard character for e.g. version numbers.
288+
*
289+
* @param {string|Array.<string>} uris - Conformance class URI(s) - any of them must match.
290+
* @returns {boolean} `true` if any of the conformance classes is supported, otherwise `false`.
291+
*/
292+
hasConformance(uris) {
293+
if (typeof uris === 'string') {
294+
uris = [uris];
295+
}
296+
if(!Array.isArray(this.data.conformsTo) || !Array.isArray(uris)) {
297+
return false;
298+
}
299+
300+
const classRegexp = uris
301+
.map(uri => RegExp.escape(uri).replaceAll('\\*', '[^/]+'))
302+
.join('|');
303+
const regexp = new RegExp('^(' + classRegexp + ')$');
304+
return Boolean(this.data.conformsTo.find(uri => uri.match(regexp)));
305+
}
306+
264307
/**
265308
* Get the billing currency.
266309
*
@@ -302,4 +345,6 @@ class Capabilities {
302345
}
303346
}
304347

348+
Capabilities.Conformance = CONFORMANCE_CLASSES;
349+
305350
module.exports = Capabilities;

src/connection.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ class Connection {
194194
return new FileTypes(response.data);
195195
}
196196

197+
/**
198+
* List the supported output file formats.
199+
*
200+
* @async
201+
* @returns {Promise<ProcessingParameters>} A response compatible to the API specification.
202+
* @throws {Error}
203+
*/
204+
async listProcessingParameters() {
205+
const response = await this._get('/processing_parameters');
206+
return response.data;
207+
}
208+
197209
/**
198210
* List the supported secondary service types.
199211
*

src/typedefs.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,23 @@
195195
* @type {object.<string, *>}
196196
*/
197197

198+
/**
199+
* A specific processing parameter.
200+
*
201+
* @typedef ProcessingParameter
202+
* @type {object.<string, *>}
203+
*/
204+
205+
/**
206+
* All types of processing parameters.
207+
*
208+
* @typedef ProcessingParameters
209+
* @type {object}
210+
* @property {Array.<ProcessingParameter>} create_job_parameters Processing parameters for batch jobs.
211+
* @property {Array.<ProcessingParameter>} create_service_parameters Processing parameters for secondary web services.
212+
* @property {Array.<ProcessingParameter>} create_synchronous_parameters Processing parameters for synchronous processing.
213+
*/
214+
198215
/**
199216
* A back-end in the federation.
200217
*

tests/vito.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { Utils } = require('@openeo/js-commons');
55
jest.setTimeout(30*1000);
66

77
describe('VITO back-end', () => {
8-
const TESTBACKEND = 'https://openeo.vito.be';
8+
const TESTBACKEND = 'https://openeo-dev.vito.be';
99

1010
let con;
1111
test('Connect', async () => {
@@ -37,6 +37,18 @@ describe('VITO back-end', () => {
3737
});
3838
});
3939

40+
describe('Processing Parameters', () => {
41+
test('conformance class', async () => {
42+
let cap = await con.capabilities();
43+
expect(cap.hasConformance(Capabilities.Conformance.processingParameters)).toBeTruthy();
44+
});
45+
test('listProcessingParameters', async () => {
46+
let params = await con.listProcessingParameters();
47+
expect(Array.isArray(params.create_job_parameters)).toBeTruthy();
48+
expect(Array.isArray(params.create_synchronous_parameters)).toBeTruthy();
49+
});
50+
});
51+
4052
describe('Request processes from namespace', () => {
4153

4254
// Not implemented yet by VITO

0 commit comments

Comments
 (0)