[MarkLogic Dev General] Preserving collection membership in managed documents

John Zhong john at yuxipacific.com
Tue Mar 27 09:46:22 PDT 2012


Hi,

I had the same problems as you and I sent the questions before, the below
were what I had sent:

1, I want to use dls:document-insert-and-manage to insert a xml and add it
into a collection, here is my code,

dls:document-insert-and-manage("/test.xml", fn:true(), <test/>, 'test
load', (), 'collection1')

/test.xml - element test (properties)  *collections:collection1*
/test_xml_version/1-test.xml - element test (properties)  *(no collections)*

Why the /test_xml_version/1-test.xml is not added into collection1?

2, I want to use dls:document-checkout-update-checkin to update a xml and
move it into a new collection, here is my code,

dls:document-checkout-update-checkin("/test.xml", <test>test2</test>, 'test
update', fn:true(), (), "collection2")

/test.xml - element test (properties)  *collections:collection1*
/test_xml_version/1-test.xml - element test (properties)  (no collections)
/test_xml_version/2-test.xml - element test (properties)  *
collections:collection2*

Why the /test.xml is not added into the new collection - collection2, while
the /test_xml_version/2-test.xml is?

After reading the source code - dls.xqy in MarkLogic install
folder/Modules/MarkLogic, *in my opinion*:

1, because the main document is not committed, so
xdmp:document-get-collections($uri)
returns empty, so the version1 document has no collection.

document-insert-version(
    $uri,$element,$annotation,$permissions,
    xdmp:document-get-collections($uri),xdmp:document-get-quality($uri),
    xdmp:document-forest($uri),fn:true())

2, xdmp:document-get-collections($uri) gets the old collections, that is
why the updated main document keeps the old collections.

return (
    dls-document-insert($uri,$doc,$previous-perms,
      xdmp:document-get-collections($uri),$quality,$forest-ids)

Again, just my thoughts...

John




On Tue, Mar 27, 2012 at 10:59 PM, Karl Erisman
<erismank at avalonconsult.com>wrote:

> 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
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20120328/0db2406a/attachment-0001.html 


More information about the General mailing list