[MarkLogic Dev General] REST API call results in XDMP-UPDATEFUNCTIONFROMQUERY

Joe Bryan Joe.Bryan at marklogic.com
Wed Mar 11 17:57:05 PDT 2015


Hi Danny,

You don't have to make the entire transaction a query to spawn an update; you can explicitly set the transaction-mode in the xdmp:spawn-function expression. (note: you will have to explicitly commit the update transaction)

Ex:

xdmp:spawn-function(function() {
    xdmp:document-insert("/2014/11/20/danny.jpg", $temp_image, xdmp:default-permissions()),
    xdmp:commit()
  },
  <options xmlns="xdmp:eval">
    <transaction-mode>update</transaction-mode>
  </options>)

Thanks.

-jb

From: Danny Sinang <d.sinang at gmail.com<mailto:d.sinang at gmail.com>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Wednesday, March 11, 2015 at 2:34 PM
To: general <General at developer.marklogic.com<mailto:General at developer.marklogic.com>>
Subject: Re: [MarkLogic Dev General] REST API call results in XDMP-UPDATEFUNCTIONFROMQUERY

I think it's working now.

Just added this line :

declare namespace rapi= "http://marklogic.com/rest-api";

On Wed, Mar 11, 2015 at 3:27 PM, Danny Sinang <d.sinang at gmail.com<mailto:d.sinang at gmail.com>> wrote:
I tried prefixing my function declaration like this :


declare %rapi:transaction-mode("update")

as suggested in http://docs.marklogic.com/guide/rest-dev/extensions#id_17130 .

But I'm now getting this error :

XDMP-UNBPRFX: (err:XPST0081) Prefix rapi has no namespace binding.

Regards,
Danny


On Wed, Mar 11, 2015 at 3:00 PM, Danny Sinang <d.sinang at gmail.com<mailto:d.sinang at gmail.com>> wrote:
Hello,

Whenever I make call to

http://marklogic.mycompany.com:9042/v1/resources/resize?rs:width=300&rs:height=300&rs:uri=/2014/11/20/IC20141120.jpg

I get this error message :

<rapi:error xmlns:rapi="http://marklogic.com/rest-api"><rapi:status-code>500</rapi:status-code><rapi:status>INTERNAL ERROR</rapi:status><rapi:message-code>XDMP-UPDATEFUNCTIONFROMQUERY</rapi:message-code><rapi:message>XDMP-UPDATEFUNCTIONFROMQUERY: Q{http://marklogic.com/rest-api/resource/resize}get#2($context, $service-params) -- Cannot apply an update function from a query. See the MarkLogic server error log for further detail.</rapi:message></rapi:error>

I know this happens because of the xdmp:document-insert() call inside the code for that API call.

My question is, is there a workaround for this ?

I already tried wrapping the document-insert call with xdmp:spawn-function, but that didn't work either.

Below is the code.

Regards,
Danny

=======================================================================================

xquery version "1.0-ml";

module namespace local = "http://marklogic.com/rest-api/resource/resize";

declare option xdmp:update "true";

declare function local:get($contextas map:map, $params  as map:map) as document-node()* {
let $image_server_root  := "http://solrdev1.mycompany.com:7000/resize_image"
let $uri                := map:get($params,"uri")
let $width              := map:get($params,"width")
let $height             := map:get($params,"height")
let $resized_uri        := fn:concat(fn:substring-before($uri,".jpg"),"_",$width,"_",$height,".jpg")
let $resized_image      :=
if (xdmp:uri-is-file($resized_uri)) then
fn:doc($resized_uri)
else
let $image      := fn:doc($uri)/node()
let$image_name := fn:tokenize($uri,"/")[last()]
let$temp_image := xdmp:http-put(fn:concat($image_server_root,"/",$width,"/",$height,"/",$image_name,"?resized_uri=",$resized_uri), (), $image)[2]
let$_ := xdmp:spawn-function(function() { xdmp:document-insert("/2014/11/20/danny.jpg", $temp_image, xdmp:default-permissions()) })
return
$temp_image
let $mime_type := map:put($context,"output-types","image/jpeg")
return document{$resized_image}
};


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150312/9ccd299b/attachment-0001.html 


More information about the General mailing list