@@ -33,7 +33,6 @@ import module namespace doc = "http://fusiondb.com/ns/studio/api/document" at "m
3333import module namespace exp = "http://fusiondb.com/ns/studio/api/explorer" at "modules/explorer.xqm" ;
3434import module namespace hsc = "https://tools.ietf.org/html/rfc2616#section-10" at "modules/http-status-codes.xqm" ;
3535import module namespace idx = "http://fusiondb.com/ns/studio/api/index" at "modules/index.xqm" ;
36- import module namespace jx = "http://joewiz.org/ns/xquery/json-xml" at "modules/json-xml.xqm" ;
3736import module namespace mul = "http://fusiondb.com/ns/studio/api/multipart" at "modules/multipart.xqm" ;
3837import module namespace perr = "http://fusiondb.com/ns/studio/api/error" at "modules/error.xqm" ;
3938import module namespace prxq = "http://fusiondb.com/ns/studio/api/restxq" at "modules/restxq.xqm" ;
@@ -232,6 +231,52 @@ function api:put-document($uri, $copy-source, $move-source, $media-type, $body)
232231 })
233232};
234233
234+ declare
235+ %rest:POST("{$body}" )
236+ %rest:path("/fusiondb/document" )
237+ %rest:query-param("uri" , "{$uri}" )
238+ %rest:consumes("application/json" )
239+ %rest:produces("application/json" )
240+ %output:method("json" )
241+ function api:update-document-properties ($uri, $body) {
242+ api:with-valid-uri-ex ($uri, function ($uri) {
243+ if (empty ($body))
244+ then
245+ [
246+ map {
247+ "code" : $hsc:bad-request,
248+ "reason" : "Missing request body"
249+ },
250+ ()
251+ ]
252+ else
253+ (: TODO explicit xs:string cast below is required due to
254+ a Type error in eXist-db that needs investigating...
255+ UntypedValueCheck.java for $body has atomize=false,
256+ but should be atomize=true.
257+ :)
258+ let $json-txt := util:base64-decode ($body cast as xs:string)
259+ let $document-properties := fn:parse-json ($json-txt)
260+ return
261+ try {
262+ [
263+ map {
264+ "code" : if (doc:update-properties ($uri, $document-properties)) then $hsc:no-content else $hsc:not-found
265+ },
266+ ()
267+ ]
268+ } catch perr:PD001 {
269+ [
270+ map {
271+ "code" : $hsc:forbidden,
272+ "reason" : $err:description
273+ },
274+ ()
275+ ]
276+ }
277+ })
278+ };
279+
235280declare
236281 %rest:DELETE
237282 %rest:path("/fusiondb/document" )
@@ -322,6 +367,52 @@ function api:put-collection($uri, $copy-source, $move-source) {
322367 })
323368};
324369
370+ declare
371+ %rest:POST("{$body}" )
372+ %rest:path("/fusiondb/collection" )
373+ %rest:query-param("uri" , "{$uri}" )
374+ %rest:consumes("application/json" )
375+ %rest:produces("application/json" )
376+ %output:method("json" )
377+ function api:update-collection-properties ($uri, $body) {
378+ api:with-valid-uri-ex ($uri, function ($uri) {
379+ if (empty ($body))
380+ then
381+ [
382+ map {
383+ "code" : $hsc:bad-request,
384+ "reason" : "Missing request body"
385+ },
386+ ()
387+ ]
388+ else
389+ (: TODO explicit xs:string cast below is required due to
390+ a Type error in eXist-db that needs investigating...
391+ UntypedValueCheck.java for $body has atomize=false,
392+ but should be atomize=true.
393+ :)
394+ let $json-txt := util:base64-decode ($body cast as xs:string)
395+ let $collection-properties := fn:parse-json ($json-txt)
396+ return
397+ try {
398+ [
399+ map {
400+ "code" : if (col:update-properties ($uri, $collection-properties)) then $hsc:no-content else $hsc:not-found
401+ },
402+ ()
403+ ]
404+ } catch perr:PD001 {
405+ [
406+ map {
407+ "code" : $hsc:forbidden,
408+ "reason" : $err:description
409+ },
410+ ()
411+ ]
412+ }
413+ })
414+ };
415+
325416declare
326417 %rest:DELETE
327418 %rest:path("/fusiondb/collection" )
0 commit comments