From f51ec09ba865fd2f103baa63b65dc36631d44b51 Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Thu, 3 Sep 2020 18:27:25 +0200 Subject: [PATCH] Support specifying a path in getCallbackParameters* to support load_collection filters. https://github.com/Open-EO/openeo-js-processgraphs/issues/5 --- src/processUtils.js | 12 +++++++++--- tests/processUtils.test.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/processUtils.js b/src/processUtils.js index 63c3017..c7b00e6 100644 --- a/src/processUtils.js +++ b/src/processUtils.js @@ -74,12 +74,18 @@ class ProcessUtils { * @returns {array} * @throws {Error} */ - static getCallbackParameters(processParameter) { + static getCallbackParameters(processParameter, keyPath = []) { if (!Utils.isObject(processParameter) || !processParameter.schema) { return []; } let schemas = ProcessUtils.normalizeJsonSchema(processParameter.schema); + let key; + while(key = keyPath.shift()) { // jshint ignore:line + schemas = schemas.map(schema => ProcessUtils.normalizeJsonSchema(ProcessUtils.getElementJsonSchema(schema, key))); // jshint ignore:line + schemas = schemas.concat(...schemas); + } + let cbParams = []; for(let schema of schemas) { @@ -102,13 +108,13 @@ class ProcessUtils { * @returns {array} * @throws {Error} */ - static getCallbackParametersForProcess(process, parameterName) { + static getCallbackParametersForProcess(process, parameterName, path = []) { if (!Utils.isObject(process) || !Array.isArray(process.parameters)) { return []; } let param = process.parameters.find(p => p.name === parameterName); - return ProcessUtils.getCallbackParameters(param); + return ProcessUtils.getCallbackParameters(param, path); } /** diff --git a/tests/processUtils.test.js b/tests/processUtils.test.js index 7812392..b19d055 100644 --- a/tests/processUtils.test.js +++ b/tests/processUtils.test.js @@ -276,6 +276,38 @@ describe('ProcessProcessUtils Tests', () => { } ] })).toThrow(); + + let lcParams = [ + { + "name": "value", + "description": "The property value to be checked against.", + "schema": { + "description": "Any data type." + } + } + ]; + let lc = { + "name": "properties", + "description": "", + "schema": [ + { + "type": "object", + "subtype": "metadata-filter", + "description": "", + "additionalProperties": { + "type": "object", + "subtype": "process-graph", + "parameters": lcParams + } + }, + { + "title": "No filter", + "description": "Don't filter by metadata properties.", + "type": "null" + } + ] + }; + expect(ProcessUtils.getCallbackParameters(lc, ['eo:cloud_cover'])).toEqual(lcParams); });