Step to reproduce:
- create two workspace (with title "Workspace 1" and "Workspace 2").
- in each workspace create a document with identical titles "My Document"
- try to move document from workspace 2 to workspace 1
JCRSession.move does not test whether a document already exist with the same path and we get the following stacktrace:
Caused by: org.nuxeo.ecm.core.api.WrappedException: Exception: org.nuxeo.ecm.core.api.DocumentException. message: Could not move the document to /domain/workspaces/workspace-1
at org.nuxeo.ecm.core.repository.jcr.JCRSession.move(JCRSession.java:345)
at org.nuxeo.ecm.core.api.AbstractSession.move(AbstractSession.java:503)
... 209 more
Caused by: org.nuxeo.ecm.core.api.WrappedException: Exception: javax.jcr.ItemExistsException. message: /ecm:root/ecm:children/domain/ecm:children/workspaces/ecm:children/workspace-1/ecm:children/my-document
at org.apache.jackrabbit.core.SessionImpl.move(SessionImpl.java:971)
at org.nuxeo.ecm.core.repository.jcr.JCRSession.move(JCRSession.java:342)
... 210 more
Proposed solution is to add test and generate a new local id if necessary as done in JCRSession.copy:
// test whether source document and naive target document have
// conflicting JCR paths
String dstPath = ((JCRDocument) dstContainer).getNode().getPath()
+ '/' + ModelAdapter.getChildPath(dstName);
if (dstContainer.hasChild(dstName))
{ // we have a conflict, generate a new locally unique name based // on the title of the document dstName = generateDocumentName(src.getString("title")); dstPath = ((JCRDocument) dstContainer).getNode().getPath() + '/' + ModelAdapter.getChildPath(dstName); }