jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From SCHEDENIG Marian <Marian.Schede...@infinica.com>
Subject Workspace.copy() not updating existing target node?
Date Thu, 27 Mar 2014 11:17:38 GMT
Hi,

I'm struggling with Workspace's copy method.

http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Workspace.html#copy%28java.lang.String,%20java.lang.String%29

The way I understand the specification, it should copy the entire sub tree of the source node,
even if the target node already exists (in this case updating any already existing nodes).
Or, failing that, it should throw an exception.

But the behaviour I get differs: If the target node does not exist, the source sub tree is
copied correctly. If the target node exists, it seems to be not changed at all. In particular,
if the source node has child nodes and the target node exists and is empty before the copy
call, it is still empty after the call finishes (without exceptions).

Is this a bug? It doesn't seem to be, because I've been getting this behaviour with Jackrabbit
2.4.2, 2.6.5 and 2.7.5. But if it isn't, what about the specification am I not interpreting
correctly?

Here's the relevant code from my test method. I'm not providing the full file, as it references
a couple of project internal convenience classes for setting up stuff, but the issue should
be clear from this snippet. If required, I can create a standalone test class.

@Test
public void testCopy() throws LoginException, RepositoryException, IOException
{
                Node root = session.getRootNode();

                Node dir1 = createFolder(root, "dir1");
                Node file1 = createFile(dir1, "file.txt");
                storeContent(file1, "test1".getBytes());

                Node dir2 = createFolder(root, "dir2");
                Node file2 = createFile(dir2, "file.txt");
                storeContent(file2, "test2".getBytes());

                Node dir3 = createFolder(root, "dir3");

                Assert.assertEquals("test1", new String(readContent(file1)));
                Assert.assertEquals("test2", new String(readContent(file2)));
                session.save();

                session.getWorkspace().copy(dir1.getPath(), dir3.getPath());
//            session.getWorkspace().copy(dir1.getPath(), root.getPath() + "dir3/");
                session.save();

//            Node dir3 = root.getNode("dir3");
                Assert.assertEquals(1, getChildren(dir3).size());
                Node file3 = dir3.getNode("file.txt");
                Assert.assertEquals("test1", new String(readContent(file3)));

                session.getWorkspace().copy(dir1.getPath(), dir2.getPath());
                session.save();

                Assert.assertEquals("test1", new String(readContent(file1)));
                Assert.assertEquals("test1", new String(readContent(file2)));
}

This code fails at Assert.assertEquals(1, getChildren(dir3).size());, because the existing
dir3 node is still empty after the copy().

If I remove the current dir3 assignment and the matching copy() call and instead activate
the currently commented out lines, the dir3 segment runs through and the final assert fails,
because file2 was not changed by the second copy() call.

Thx,
Marian.

--
DI Marian Schedenig
Senior Developer

[Description: Description: Description: Description: Description: Description: cid:image001.png@01CCBE64.F3314040]

INFINICA - Member of Qualysoft Group
Leonard-Bernstein-Straße 10
A-1220 Wien
Österreich

Tel +43 1 263 12 96
Fax +43 1 4095987-11

www.infinica.at<http://www.infinica.at/>
www.qualysoft.at<http://www.qualysoft.at/>
marian.schedenig@infinica.at<mailto:marian.schedenig@infinica.at>

P Please consider the environment before printing this email


Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message