[MarkLogic Dev General] Preserving collection membership in managed documents

Karl Erisman erismank at avalonconsult.com
Tue Mar 27 07:59:55 PDT 2012


I'm having trouble understanding why the Library Services API behaves
as it does in a very specific case.

The example below does this:
 Transaction 1: insert a document as a member of a collection '/collection/A'
 Transaction 2: use dls:document-insert-and-manage to place a new
document under management, ***using the collections of the original
document***
 Transaction 3: use dls:document-checkout-update-checkin to create a
new version of the managed document ***using the collections of the
original document***
 Transaction 4: print out the documents in the database along with
their collection membership

(See the results I included below the code.)

In the results, version #1 does not belong to the collection, even
though dls:document-insert-and-manage was called with the collection
URI from the original doc.  Interestingly, using
dls:document-checkout-update-checkin to create version #2 results in
versions that belong to the collection, as I would expect.

Is it supposed to work this way?  If so, how can I preserve collection
membership?

BTW: If more transactions are added like the last one in the script
that calls dls:document-checkout-update-checkin, the same pattern
continues: version #1 has no collections while the rest of the
versions belong to the test collection.  I'm running on version 5.0.

Thanks,
Karl

(:::::::::::::::::::::::::::::::::::::::::::::::::::)

(: First, a retention rule is needed to keep all versions: :)

import module namespace dls = "http://marklogic.com/xdmp/dls" at
"/MarkLogic/dls.xqy";
dls:retention-rule-insert(
    dls:retention-rule( "All Versions Retention Rule for archive",
        "Retain all versions of all documents", (), (),
        "Locate all of the documents",
        cts:and-query(()))
)

(:::::::::::::::::::::::::::::::::::::::::::::::::::)

(: This 4-transaction script can then be run :)

xdmp:document-insert("/current/manageme", <y/>, (), ('/collection/A'))

; (:--- NEW TRANSACTION ---:)

import module namespace dls = 'http://marklogic.com/xdmp/dls' at
'/MarkLogic/dls.xqy';

let $muri := "/archive/manageme"
let $uri := "/current/manageme"
let $p := xdmp:document-get-permissions($uri), $c :=
xdmp:document-get-collections($uri), $q :=
xdmp:document-get-quality($uri)
let $_:=xdmp:log('using these collections for new managed doc: '),
$_:=xdmp:log($c)
return
 dls:document-insert-and-manage($muri, fn:true(), fn:doc($uri),
'create managed doc',$p, $c, $q)

; (:--- NEW TRANSACTION ---:)

import module namespace dls = 'http://marklogic.com/xdmp/dls' at
'/MarkLogic/dls.xqy';

let $muri := "/archive/manageme"
let $uri := "/current/manageme"
let $p := xdmp:document-get-permissions($uri), $c :=
xdmp:document-get-collections($uri), $q :=
xdmp:document-get-quality($uri)
let $_:=xdmp:log('using these collections for new managed doc: '),
$_:=xdmp:log($c)
return
 dls:document-checkout-update-checkin($muri, fn:doc($uri), 'New
version', fn:true(), $p,$c,$q)

; (:--- NEW TRANSACTION ---:)

(:show results:)
for $d in fn:doc()
let $u := fn:document-uri($d)
let $c := xdmp:document-get-collections($u)
where fn:ends-with($u, 'manageme')
return fn:concat('doc uri: ', $u, '; collections: ', if($c) then $c
else 'NONE!')
(:::::::::::::::::::::::::::::::::::::::::::::::::::)

Result:
doc uri: /current/manageme; collections: /collection/A
doc uri: /archive/manageme_manageme_versions/1-manageme; collections: NONE!
doc uri: /archive/manageme_manageme_versions/2-manageme; collections:
/collection/A
doc uri: /archive/manageme; collections: /collection/A


More information about the General mailing list