Search code examples
marklogic

Needing additional data in managed Version of documents


I need to manage versions of documents. For this I am using MarkLogic's DataManagement (dls:document-insert-and-manage and dls:document-checkout-update-checkin).

I am trying to include additional data for each version of this documents (e.g. majorversion, minorversion, ...). As far as I see, I cannot change the dls: Version properties. Using dls:document-set-property($uri,<dls:majorversion>1</dls:majorversion>) results in

DLS-SPECIALPROP: (err:FOER0000) Cannot update properties in dls namespace

How can I add information for every version of a documents, so that I can query for them (e.g. give me latest version of a document where majorversion is equal 1)?

Edit: I tried setting properties using dls:document-set-property($uri, $prop) while updating.

dls:document-checkout('/textdoc/4.xml', fn:true(),"checking out 2",3)
;
dls:document-set-property('/textdoc/4.xml', <mainversion>3</mainversion>),
dls:document-update('/textdoc/4.xml', $doc,   "update",   fn:true() )
;
dls:document-checkin('/textdoc/4.xml',   fn:true())

Unfortunally I could not get the history of my property. Using

 let $uri := fn:concat('/textdoc/4.xml')   
 let $results := for $versionuri in dls:document-version-uris($uri)
 return xdmp:document-properties($versionuri)

got me none of my properties.

using xdmp:document-properties($uri) (on the base uri of the documents) results just in the latest content (<mainversion>3</mainversion>)of my properties. All former contents for property mainversion are lost.

I did not found any method retrieving properties in dls. Is there a history of properties?

Am I missing something?


Solution

  • The DLS library is not designed to work with major and minor versions, and it won't be easy to retrofit that. Best I can think of right now is to manage major versions as part of the document uri, and have DLS take care of minor versions. You can then use directory queries to limit to a major version of a document.

    You could still give document properties a go too, but avoid using the dls: prefix. Use a prefix/namespace of your own, or just no prefix/namespace at all.

    Something like this might get you close:

    xquery version "1.0-ml";
    
    import module namespace dls = "http://marklogic.com/xdmp/dls" 
      at "/MarkLogic/dls.xqy";
    
    dls:retention-rule-insert(
      dls:retention-rule(
        "retain-everything",
        "Retain all versions of all documents",
        (),
        (),
        "Locate all of the documents",
        cts:true-query()
      )
    )
    
    ;
    
    import module namespace dls = "http://marklogic.com/xdmp/dls" 
      at "/MarkLogic/dls.xqy";
    
    let $contents :=   
    <BOOK>
      <TITLE>Baz Goes to the Disco</TITLE>
      <CHAPTER1>
         <TITLE>Baz Wakes Up to James Brown and Feels Funky</TITLE>
      </CHAPTER1>
    </BOOK> 
    
    return (
      dls:document-insert-and-manage(
        "/foo/bar/baz.xml",
        fn:true(),
        $contents
      )
    )
    
    ;
    
    import module namespace dls = "http://marklogic.com/xdmp/dls" 
      at "/MarkLogic/dls.xqy";
    
    dls:document-set-property(
      dls:document-version-uri('/foo/bar/baz.xml', 1), 
      <mainversion>3</mainversion>
    )
    
    ;
    
    import module namespace dls = "http://marklogic.com/xdmp/dls" 
      at "/MarkLogic/dls.xqy";
    
    let $bazbook :=  
    <BOOK>
      <TITLE>Baz Goes to the Disco</TITLE>
      <CHAPTER1>
        <TITLE>Baz Wakes Up</TITLE>
        <PARA>
          Baz woke up this afternoon to the sound of James Brown.  Soon
          Baz was feeling a little funky, so he put on his cleanest
          propeller hat and headed out in search of a Disco.
        </PARA>
      </CHAPTER1>
    </BOOK> 
    
    return
      dls:document-checkout-update-checkin(
        "/foo/bar/baz.xml",
        $bazbook,
        "Changed the title from Baz Feelin' Funky",
        fn:true()
      )
    
    ;
    
    import module namespace dls = "http://marklogic.com/xdmp/dls" 
      at "/MarkLogic/dls.xqy";
    
    dls:document-set-property(
      dls:document-version-uri('/foo/bar/baz.xml', 2), 
      <mainversion>4</mainversion>
    )
    

    HTH!