You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Harold Putman <ha...@lexmark.com> on 2019/04/20 15:14:51 UTC

Copy over an existing node

I want to copy a source node over a destination node that already exists.
If I just do
    workspace.copy(sourcePath, targetPath);
I get an ItemExistsException.
I was hoping to  create a new version by
   VersionManager vm = workspace.getVersionManager();
   vm.checkout(targetPath);
   workspace.copy(sourcePath, targetPath);
   vm.checkin(targetPath);
but still I get a ItemExistsException.

What is the right way to do this?


Harold Putman

Re: Copy over an existing node

Posted by Woonsan Ko <wo...@apache.org>.
On Tue, Apr 23, 2019 at 10:48 AM Harold Putman
<ha...@lexmark.com> wrote:
>
> Ah OK, thanks Woonsan. That's how I will handle it then.
>
> I was enticed by the documentation to believe that it might be easier.

:-)

> https://docs.adobe.com/docs/en/spec/jsr170/javadocs/jcr-2.0/javax/jcr/Workspace.html#copy(java.lang.String,%20java.lang.String)
> "When a node N is copied to a location where a node N' already exists, the repository may either immediately throw an ItemExistsException or attempt to update the node N' by selectively replacing part of its subgraph with a copy of the relevant part of the subgraph of N. If the node types of N and N' are compatible, the implementation supports update-on-copy for these node types and no other errors occur, then the copy will succeed. Otherwise an ItemExistsException is thrown."
>
> In practice it is probably better to have control over what is being copied, which I guess is what the implementers decided.

I think so, too. Thanks for sharing the statement in the spec. Good to
be refreshed with that.

Woonsan

>
>
> Harold Putman
>
>
> ________________________________
> From: Woonsan Ko <wo...@apache.org>
> Sent: Tuesday, April 23, 2019 9:25 AM
> To: users@jackrabbit.apache.org
> Subject: Re: Copy over an existing node
>
> On Tue, Apr 23, 2019 at 4:54 AM Harold Putman <ha...@lexmark.com> wrote:
> >
> > I want to copy a source node over a destination node that already exists.
> > If I just do
> >     workspace.copy(sourcePath, targetPath);
> > I get an ItemExistsException.
> > I was hoping to  create a new version by
> >    VersionManager vm = workspace.getVersionManager();
> >    vm.checkout(targetPath);
> >    workspace.copy(sourcePath, targetPath);
> >    vm.checkin(targetPath);
> > but still I get a ItemExistsException.
> >
> > What is the right way to do this?
>
> Iterating properties and child nodes of the source node and copy each
> of those to the target node?
> Copying properties is quite straightforward.
> 'Copying child nodes' is probably your requirement specific.
> Sometimes, I removed child nodes first and add new ones. Or sometimes
> I resolve the mapping child nodes somehow and copy the properties if
> found, etc.
>
> Regards,
>
> Woonsan
>
> >
> >
> > Harold Putman

Re: Copy over an existing node

Posted by Harold Putman <ha...@lexmark.com>.
Ah OK, thanks Woonsan. That's how I will handle it then.

I was enticed by the documentation to believe that it might be easier.
https://docs.adobe.com/docs/en/spec/jsr170/javadocs/jcr-2.0/javax/jcr/Workspace.html#copy(java.lang.String,%20java.lang.String)
"When a node N is copied to a location where a node N' already exists, the repository may either immediately throw an ItemExistsException or attempt to update the node N' by selectively replacing part of its subgraph with a copy of the relevant part of the subgraph of N. If the node types of N and N' are compatible, the implementation supports update-on-copy for these node types and no other errors occur, then the copy will succeed. Otherwise an ItemExistsException is thrown."

In practice it is probably better to have control over what is being copied, which I guess is what the implementers decided.


Harold Putman


________________________________
From: Woonsan Ko <wo...@apache.org>
Sent: Tuesday, April 23, 2019 9:25 AM
To: users@jackrabbit.apache.org
Subject: Re: Copy over an existing node

On Tue, Apr 23, 2019 at 4:54 AM Harold Putman <ha...@lexmark.com> wrote:
>
> I want to copy a source node over a destination node that already exists.
> If I just do
>     workspace.copy(sourcePath, targetPath);
> I get an ItemExistsException.
> I was hoping to  create a new version by
>    VersionManager vm = workspace.getVersionManager();
>    vm.checkout(targetPath);
>    workspace.copy(sourcePath, targetPath);
>    vm.checkin(targetPath);
> but still I get a ItemExistsException.
>
> What is the right way to do this?

Iterating properties and child nodes of the source node and copy each
of those to the target node?
Copying properties is quite straightforward.
'Copying child nodes' is probably your requirement specific.
Sometimes, I removed child nodes first and add new ones. Or sometimes
I resolve the mapping child nodes somehow and copy the properties if
found, etc.

Regards,

Woonsan

>
>
> Harold Putman

Re: Copy over an existing node

Posted by Woonsan Ko <wo...@apache.org>.
On Tue, Apr 23, 2019 at 4:54 AM Harold Putman <ha...@lexmark.com> wrote:
>
> I want to copy a source node over a destination node that already exists.
> If I just do
>     workspace.copy(sourcePath, targetPath);
> I get an ItemExistsException.
> I was hoping to  create a new version by
>    VersionManager vm = workspace.getVersionManager();
>    vm.checkout(targetPath);
>    workspace.copy(sourcePath, targetPath);
>    vm.checkin(targetPath);
> but still I get a ItemExistsException.
>
> What is the right way to do this?

Iterating properties and child nodes of the source node and copy each
of those to the target node?
Copying properties is quite straightforward.
'Copying child nodes' is probably your requirement specific.
Sometimes, I removed child nodes first and add new ones. Or sometimes
I resolve the mapping child nodes somehow and copy the properties if
found, etc.

Regards,

Woonsan

>
>
> Harold Putman