Skip to content

Commit

Permalink
Support specifying a path in getCallbackParameters* to support load_c…
Browse files Browse the repository at this point in the history
…ollection filters. Open-EO/openeo-js-processgraphs#5
  • Loading branch information
m-mohr committed Sep 3, 2020
1 parent e0f03e5 commit ec115d1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/processUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
schemas = schemas.map(schema => ProcessUtils.normalizeJsonSchema(ProcessUtils.getElementJsonSchema(schema, key)));
schemas = schemas.concat(...schemas);
}


let cbParams = [];
for(let schema of schemas) {
Expand All @@ -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);
}

/**
Expand Down
32 changes: 32 additions & 0 deletions tests/processUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});


Expand Down

0 comments on commit ec115d1

Please sign in to comment.