Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing more than one options in input flows using mlcp #1722

Merged
merged 2 commits into from
Dec 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,20 @@ const tracelib = require("/data-hub/4/impl/trace-lib.sjs");
function transform(content, context) {
let uri = content.uri;
let params = {};
let splits = context.transform_param.split(',');
let optionsString = null;
let parsedTransformParam = null;
let transformString = context.transform_param;
let pattern = '^.*(options=\{.*\}).*$';
let match = new RegExp(pattern).exec(transformString);
if (match === null){
parsedTransformParam = transformString;
}
else{
optionsString = match[1];
parsedTransformParam = transformString.replace(optionsString, '');
}

let splits = parsedTransformParam.split(',');
for (let i in splits) {
let pair = splits[i];
let parts = pair.split('=');
Expand All @@ -38,11 +51,10 @@ function transform(content, context) {
if (!flow) {
fn.error(null, "RESTAPI-SRVEXERR", "The specified flow " + params.flow + " is missing.");
}

// configure the options
let options = {};
if (params.options) {
options = JSON.parse(params.options);
if (optionsString) {
let splits = optionsString.split("=");
options = JSON.parse(splits[1]);
}
flowlib.setDefaultOptions(options, flow);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,23 @@ declare function mlcpFlow:transform(
let $uri := map:get($content, "uri")
return
perf:log('mlcp-flow-transform(' || $uri || ')', function() {
let $params := map:new((
for $pair in map:get($context, 'transform_param') ! fn:tokenize(., ",")
let $parts := fn:tokenize($pair, "=")
return
map:entry($parts[1], $parts[2])
))

let $transform-string := map:get($context, 'transform_param')
let $options-string := replace($transform-string, '^.*(options=\{.*\}).*$', '$1')
let $parsed-transform-string :=
if ($transform-string = $options-string) then
$transform-string
else
fn:replace($transform-string, 'options=\{.*\}', '')
let $params := map:new(
for $pair in $parsed-transform-string ! fn:tokenize(., ",")
let $parts := fn:tokenize($pair, "=")
return
if(fn:not(fn:empty($parts[1]))) then
map:entry($parts[1], $parts[2])
else
()
)

let $job-id := (map:get($params, "job-id"), sem:uuid-string())[1]
let $entity-name := map:get($params, 'entity-name') ! xdmp:url-decode(.)
let $flow-name := map:get($params, 'flow-name') ! xdmp:url-decode(.)
Expand All @@ -74,8 +84,14 @@ declare function mlcpFlow:transform(
fn:error((), "RESTAPI-SRVEXERR", "The specified flow " || map:get($params, "flow") || " is missing.")

(: configure the options :)
let $opts := map:new(
let $opt-parts := fn:tokenize($options-string, "=")

return
map:entry($opt-parts[1], $opt-parts[2])
)
let $options as map:map := (
map:get($params, "options") ! xdmp:unquote(.)/object-node(),
map:get($opts, "options") ! xdmp:unquote(.)/object-node(),
map:map()
)[1]
let $_ := flow:set-default-options($options, $flow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ public List<DynamicTest> generateExtraPluginTests() {
tests.add(DynamicTest.dynamicTest(flowName + " MLCP", () -> {
Map<String, Object> options = new HashMap<>();
options.put("extraPlugin", true);
options.put("secondOption", "secondValue");
FinalCounts finalCounts = new FinalCounts(1, 0, 1, 1, 0, 0, 1, 0, 0, 0, "FINISHED");
testInputFlowViaMlcp(prefix, useEs ? "-es" : "", flowRunnerClient, codeFormat, dataFormat, useEs, options, finalCounts);
}));
Expand Down