0
votes

I'm facing issue in Jackrabbit node contents moving from one path to another.

Trying to move list of documents(from temporary node in jcr) under a node to new path(new node, which does not contain any documents).

Nodes are of mixin types.

Following is the partial snippet for creating document node:

Node documentNode = session.getNode("/1/doc/1").addNode("Test_Sample", "et:document");
documentNode.setProperty(PROPERTY_ID, 123);
documentNode.setProperty(Property.JCR_TITLE, "Test Sample");
documentNode.setProperty(Property.JCR_DESCRIPTION, "Sample Description");
documentNode.setProperty(ETNodeTypes.ET_TAGS.getName(), "web");

Node resourceNode = documentNode.addNode (Property.JCR_CONTENT, "nt:resource");
resourceNode.setProperty (Property.JCR_MIMETYPE, "application/xstream");
resourceNode.setProperty (Property.JCR_ENCODING, "UTF-8");
Binary value = session.getValueFactory().createBinary(new ByteArrayInputStream(document.getData()));
resourceNode.setProperty (Property.JCR_DATA, value);

Calendar lastModified = Calendar.getInstance ();
resourceNode.setProperty (Property.JCR_LAST_MODIFIED, lastModified);
session.save();

VersionManager versionManager = session.getWorkspace().getVersionManager();
documentNode.addMixin(JcrConstants.MIX_VERSIONABLE);
versionManager.checkin(documentNode.getPath());
doc.setVersionNumber(versionManager.getBaseVersion(documentNode.getPath()).getName());
return documentNode.getIdentifier();

Node type description:

/**
* Document node
*/
[et:document] > nt:file, mix:title, mix:versionable, mix:shareable
+ * (nt:file) VERSION
- et:tags multiple
- et:role multiple
- et:id (LONG)

Wanted to move the contents using jcr api itself, instead of getting all sub-nodes iterate and move to destination folder.

Using Jackrabbit core 2.6.0 with JCR 2.0.

1
Try this code before session save. session.move(srcAbsPath, destAbsPath);Rajashekhar Arroju

1 Answers

0
votes

Not sure what's your exact problem, you can use either Session.move or Workspace.move to move nodes, the API docs that I'm linking to explain the differences.

Make sure the target node definition accepts the node types that you are moving under it, or use an nt:unstructured target node to start with, as that accepts any node type under it.