Hi,

you need to to first acquire a node builder from the root node state. This is the builder all your changes will be connected to. See documentation for details:

https://jackrabbit.apache.org/oak/docs/architecture/nodestate.html

Finally you will have to merge the root builder:

https://jackrabbit.apache.org/oak/docs/apidocs/org/apache/jackrabbit/oak/spi/state/NodeStore.html#merge-org.apache.jackrabbit.oak.spi.state.NodeBuilder-org.apache.jackrabbit.oak.spi.commit.CommitHook-org.apache.jackrabbit.oak.spi.commit.CommitInfo-

Please keep in mind that using this low level API will not guarantee integrity as required by the JCR specification or even some Oak internals. You are responsible for passing in the required CommitHook with editors and validators to ensure integrity depending on the changes you make. E.g. if you change an indexed property, you will have to ensure that index update editors are present in the commit hook.

Regards
 Marcel

On 09/01/18 09:07, Marco Piovesana wrote:
Hi Marcel,
here a piece of code that shows more less what I'm trying to do. I have the
NodeState of the verison I want to modify (versionNodeState) and I create
from it the updated version (updatedNodeState), but then I don't understand
how can I use it to update the actual value in the FrozenNode:

     public void changeFirstVersionProperty(NodeStore nodeStore, Node
myFolder) throws IOException, InvalidFileStoreVersionException,
RepositoryException {
         NodeState versionNodeState = getNodeState(nodeStore, myFolder);
         NodeState updatedNodeState =
versionNodeState.builder().setProperty("custom:trashed",
true).getNodeState();

     }

     private NodeState getNodeState(NodeStore nodeStore, Node node) throws
RepositoryException {
         NodeState rootState = nodeStore.getRoot();
         NodeState versionStorageState =
rootState.getChildNode(JcrConstants.JCR_SYSTEM).getChildNode(JcrConstants.JCR_VERSIONSTORAGE);
         NodeState versionHistoryState =
getVersionHistoryState(versionStorageState, node.getIdentifier());
         return
versionHistoryState.getChildNode("1.0").getChildNode(JcrConstants.JCR_FROZENNODE);
     }

     private NodeState getVersionHistoryState(NodeState nodeState, String
remainingIdentifier) {
         String clusterFolderName = remainingIdentifier.substring(0, 2);
         NodeState childNode = nodeState.getChildNode(clusterFolderName);
         if (childNode.exists()) {
             return getVersionHistoryState(childNode,
remainingIdentifier.substring(2));
         } else {
             String versionHistoryNodeName = getFirstChild(nodeState);
             return nodeState.getChildNode(versionHistoryNodeName);
         }
     }

     private String getFirstChild(NodeState nodeState) {
         return nodeState.getChildNodeNames().iterator().next();
     }

Marco.

On Tue, Jan 9, 2018 at 8:46 AM Marcel Reutegger <[email protected]>
wrote:

Hi,

can you please provide a link to the upgrade script you have?

Regards
   Marcel

On 08/01/18 18:24, Marco Piovesana wrote:
Hi all,
I'm trying to modify a frozen node property in a custom upgrade script. I
was following this
<
http://oak.markmail.org/message/htxdaeffnr73m3q6?q=frozen+node#query:frozen%20node+page:1+mid:ib57du3viyaz7x4b+state:results

post and I tried to use the NodeStore API to do so. I am able to get the
NodeState of the required node (from the version storage), create a new
node state from its NodeBuilder, but then I don't understand how to
replace
the previous node state with the new one so that the corresponding frozen
node will have the updated properties values. Am I doing it wrong? How
can
I use the NodeStore API to modify a frozen node?

Marco.



Reply via email to