Skip to content

Commit e93ace8

Browse files
committed
fixed #345
1 parent 5f5e6dc commit e93ace8

File tree

7 files changed

+22
-16
lines changed

7 files changed

+22
-16
lines changed

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/error-lib.xqy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ declare function err:error-to-json($error as element(error:error))
2323
let $_ :=
2424
for $e in $error/*[fn:not(self::error:stack or self::error:data)]
2525
return
26-
map:put($o, err:to-camel(fn:local-name($e)), fn:data($e))
26+
map:put($o, err:to-camel(fn:local-name($e)), fn:string($e))
2727
let $_ :=
2828
let $data := json:array()
2929
let $_ :=
@@ -40,7 +40,7 @@ declare function err:error-to-json($error as element(error:error))
4040
let $_ :=
4141
for $e in $frame/*[fn:not(self::error:variables)]
4242
return
43-
map:put($f, err:to-camel(fn:local-name($e)), fn:data($e))
43+
map:put($f, err:to-camel(fn:local-name($e)), fn:string($e))
4444
let $_ :=
4545
let $variables := json:object()
4646
let $_ :=

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -562,15 +562,15 @@ declare function flow:make-envelope(
562562
map:put($o, "headers", $headers),
563563
map:put($o, "triples", $triples),
564564
map:put($o, "instance",
565-
if ($content castable as map:map) then
565+
if ($content instance of map:map and map:keys($content) = "$type") then
566566
flow:instance-to-canonical-json($content)
567567
else
568568
$content
569569
),
570570
map:put($o, "attachments",
571571
let $content := map:get($map, "content")
572572
return
573-
if ($content castable as map:map) then
573+
if ($content instance of map:map and map:keys($content) = "$attachments") then
574574
map:get($content, "$attachments")
575575
else
576576
()
@@ -591,7 +591,7 @@ declare function flow:make-envelope(
591591
{
592592
let $content := map:get($map, "content")
593593
return
594-
if ($content castable as map:map) then
594+
if ($content instance of map:map and map:keys($content) = "$type") then
595595
flow:instance-to-canonical-xml($content)
596596
else
597597
$content
@@ -601,7 +601,7 @@ declare function flow:make-envelope(
601601
{
602602
let $content := map:get($map, "content")
603603
return
604-
if ($content castable as map:map) then
604+
if ($content instance of map:map and map:keys($content) = "$attachments") then
605605
map:get($content, "$attachments")
606606
else
607607
()
@@ -844,12 +844,11 @@ declare function flow:run-plugin(
844844
let $resp :=
845845
typeswitch($resp)
846846
case object-node() | json:object return
847-
(: map:map lands here too :)
848-
(: map:map is ES response type :)
849-
if ($resp castable as map:map) then
847+
(: object with $type key is ES response type :)
848+
if ($resp instance of map:map and map:keys($resp) = "$type") then
850849
$resp
851850
else if ($data-format = $XML) then
852-
json:transform-from-json($resp, json:config("custom"))
851+
json:transform-from-json($resp)
853852
else
854853
$resp
855854
case json:array return

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/trace-lib.xqy

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,12 @@ declare function trace:error-trace(
231231
let $plugin-map := map:new((
232232
map:entry("pluginModuleUri", $module-uri),
233233
map:entry("input", $input),
234-
map:entry("error", $error),
234+
map:entry("error",
235+
if (map:get($current-trace-settings, "data-format") eq $FORMAT-JSON) then
236+
$error/err:error-to-json(.)
237+
else
238+
$error
239+
),
235240
map:entry("duration", $duration)
236241
))
237242
let $_ := map:put($current-trace, $plugin-type || "Plugin", $plugin-map)
@@ -295,6 +300,8 @@ declare function trace:_walk_json($nodes as node()* ,$o)
295300
$n
296301
return
297302
map:put($o, $name, $unquoted)
303+
else if ($name = "error") then
304+
map:put($o, $name, $n)
298305
else
299306
let $_ := trace:_walk_json($n/node(), $oo)
300307
return

marklogic-data-hub/src/main/resources/ml-modules/services/scaffold-content.xqy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ function createContent(id, options) {{
458458
source = root.xpath('/*:envelope/*:instance/node()');
459459
}}
460460
// for json we need to return the instance
461-
else if (root && root.instance) {{
462-
source = root.instance;
461+
else if (root && root.envelope && root.envelope.instance) {{
462+
source = root.envelope.instance;
463463
}}
464464
// for everything else
465465
else {{

marklogic-data-hub/src/main/resources/scaffolding/harmonize/sjs/content.sjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function createContent(id, options) {
1515
return root.xpath('/*:envelope/*:instance/node()');
1616
}
1717
// for json we need to return the instance
18-
else if (root && root.envelope.instance) {
18+
else if (root && root.envelope && root.envelope.instance) {
1919
return root.envelope.instance;
2020
}
2121
// for everything else

marklogic-data-hub/src/main/resources/scaffolding/harmonize/xqy/headers.xqy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ declare option xdmp:mapping "false";
1717
:)
1818
declare function plugin:create-headers(
1919
$id as xs:string,
20-
$content as node()?,
20+
$content as item()?,
2121
$options as map:map) as node()*
2222
{
2323
()

marklogic-data-hub/src/main/resources/scaffolding/harmonize/xqy/triples.xqy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ declare option xdmp:mapping "false";
1919
declare function plugin:create-triples(
2020
$id as xs:string,
2121
$content as node()?,
22-
$headers as node()*,
22+
$headers as item()*,
2323
$options as map:map) as sem:triple*
2424
{
2525
()

0 commit comments

Comments
 (0)