Reputation: 121
We have this use-case whereby we need to perform 2 operations in our transform code during loading content:
xdmp:document-filter()
on original and that's inserted too through a function manually using xdmp:document-insert
Now, the problem is there may be cases where binary document fails conversion and we want 2 things to happen then :
original document is still inserted into DB
send response back to NiFi in this form :
[
{
"result": {
"uri": "/test/abc.pdf",
"message": "Successful ingestion",
"success": true
}
},
{
"result": {
"uri": "/test/abc.pdf.xhtml",
"message": "Failed: due to xyz error",
"success": false
}
}
]
I don't seem to find a way we can achieve this with current function definition which is :
declare function example:transform(
$context as map:map,
$params as map:map,
$content as document-node()
) as document-node()**
If I try to return both original $content and response node - (document{$input}, document{$res})
OR (document{$input}, $res)
it doesn't allow me to do so :
XDMP-AS: (err:XPTY0004) $service($context, $service-params, $input) -- Invalid coercion: (document{binary{"255044462d312e330a25e2e3cfd30a312030206f626a0a3c3c0a2f48542f4465..."}}, document{array-node{text{""}, object-node{"result":object-node{"uri":text{"..."}, ...}}}}) as document-node()
Could anyone please provide any input on this if they they have faced similar problem or can guide as to if this can be even achieved or not as per current model.
Upvotes: 1
Views: 38
Reputation: 66723
You need to return a document-node()
, which can only have one child node. So, create an array-node()
and then put your sequence of objects in the array:
document{
array-node{
$input,
$res
}
}
Upvotes: 1