Creating a shortcut (live proxy)?
I'd like to create a proxy that always points to the live representation of a document, so that the proxy always reflects the changes to its target (and so edits to the proxy apply to the target).
I see that the javadoc for CoreSession says this for the createProxy() method:
Creates a generic proxy to the given document inside the given folder. The document may be a version, or a working copy (live document) in which case the proxy will be a “shortcut”.
My code to create a shortcut does the following:
DocumentModel childWorkingCopyDoc = coreSession.getWorkingCopy(sourceDoc.getRef()); childDoc = coreSession.createProxy(childWorkingCopyDoc.getRef(), destinationDir.getRef()); childDoc = coreSession.createDocument(childDoc);
I use this code in the following way:
- Call coreSession.createDocumentModel(), set the dc:title property, and then call coreSession.createDocument(doc) to set up the original document.
- Create a shortcut to the document using the above code.
- Set additional property values on the original document.
- Save the original document.
What I see when viewing the doc and its shortcut in Nuxeo DM after all of this is that the original document has the properties set in step 3, but the shortcut does not.
Am I interpreting “shortcut” in the javadoc incorrectly (does a shortcut always point to the live document or not?) If a shortcut does indeed do what I'd like it to, can you provide a code snippet that illustrates how to create it correctly?
I had copied/pasted my code for creating a new document (step 1 above) to use as the base for my proxy creation code. I changed the above code to:
DocumentModel childWorkingCopyDoc = coreSession.getWorkingCopy(sourceDoc.getRef()); childDoc = coreSession.createProxy(childWorkingCopyDoc.getRef(), destinationDir.getRef()); coreSession.saveDocument(childDoc);
And now my live proxies work as expected. I can edit the proxy target and see the change reflected in the proxy, and can also edit the proxy and see the change in the target.