Correct way to set a list of properties to a node

Hello dear community. I have a node with a list properties. I have a task to get all the properties, filter them by name and set the filtered list of properties back to this node.
What is the correct way of setting multiple properties to the node? There is no method like "node.setProperties(List properties) and also no for removing the properties.

Do I have to create a new node, set every single property to it, delete the old node and add the new node to the jcr tree?

Appreciate your help,
Petra

Hello, there is no need to create a new node. node.setProperty() takes a null which will remove existing properties. Also I’m not sure if you’re referring to multi-value properties when you say List, in which case these are set as a Value[] array. For example here’s some Groovyscript for renaming a property:

if(p.isMultiple()) {
  node.setProperty(newName, p.getValues());
  node.setProperty(oldName, (Value[])null);
} else {
  node.setProperty(newName, p.getValue());
  node.setProperty(oldName, (Value)null);
}
1 Like

Hello @david.bailey thank you for your answer. Ok, I will do it this way. The property is not multiple. Concretely I am dealing with the node /hippo:configuration/hippo:translations/hippo:cms/validators
The node is of type “hipposys:resourcebundle” and has different properties. I want to look for properties having a certain prefix-, delete these properties and set the remaining.
Thank you very much.