Hi Alex,

If you can, then definitely use JCR API (Node, Session,etc). Btw, what's
missing in your snippet is essentially that you aren't committing the
changes. You can use NodeStore.merge to do that. But, that is very low
level access - e.g that won't make callbacks to the various editors that
you might be plugging in. It'd definitely be better to utilise JCR API...
Session.save() would persist the changes.

--Vikas
(sent from mobile)

On Mar 4, 2017 03:36, "Alex Benenson" <alex.benen...@gmail.com> wrote:

> Hi all
>
> Following an earlier discussion about storing a large number of nodes at
> root, I am trying to move content nodes from root into a hierarchy
> /documents/xx/yy/{id}
>
> Hitting some issues:
>
> 1 - loop over all nodes in root,  move each content node
>
> root.getChildNodeEntries().forEach(entry -> {
>   NodeState nodeState = entry.getNodeState();
>
>   if (isMyContentNode(nodeState)) {
>      String name = entry.getName();
>
>      // get or create parent folder
>     NodeBuilder parent = getParent(name);
>
>     NodeBuilder builder = rootBuilder.child(name);
>     boolean result = builder.moveTo(parent, name);
>
>     if (result)
>       counter++;
>     else
>       logger.warn('not moved");
>   }
> });
>
>
> after executing this with no warnings, all nodes are stil in the root
> folder (inspected using oak-mongo.js)
>
>
> 2 - run garbage collection
> nodeStore.getVersionGarbageCollector().gc(1, TimeUnit.SECONDS);
>
> all nodes are still in the root
>
>
>
>
> Questions:
>
> 1 - Is this the right approach to move nodes in the repository? Or should I
> create a repository and use either Session.move or Workspace.move?
>
>
> 2 - how do I force old revisions out of root?
>
> Thanks in advance
>
> -- Alex
>
>
>
>
>
>
> --
> Alex Benenson
>

Reply via email to