Created
October 14, 2020 15:34
-
-
Save DavidForster/ba653b6ba87c2dec19e97ffcdeda46f7 to your computer and use it in GitHub Desktop.
Bloomreach Experience Manager Groovy updater script to replace specific values on nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.hippoecm.frontend.plugins.cms.dev.updater; | |
import org.onehippo.repository.update.BaseNodeUpdateVisitor; | |
import javax.jcr.Node; | |
class PropertyUpdater extends BaseNodeUpdateVisitor { | |
String propertyToFind; | |
String valueToFind; | |
String valueToReplace; | |
@Override | |
public void setParametersMap(Map<String, Object> parametersMap) { | |
super.setParametersMap(parametersMap) | |
propertyToFind = parametersMap["propertyToFind"]; | |
valueToFind = parametersMap["valueToFind"]; | |
valueToReplace = parametersMap["valueToReplace"]; | |
log.info("Searching for nodes with property '${propertyToFind}', replacing '${valueToFind}' with '${valueToReplace}'") | |
} | |
public boolean doUpdate(Node node) { | |
log.trace("Found node at '${node.path}'"); | |
if (node.hasProperty(propertyToFind)) { | |
log.trace("node has property '${propertyToFind}'"); | |
if (node.getProperty(propertyToFind).getValue().getString() == valueToFind) { | |
log.trace("property has value '${valueToFind}'"); | |
node.getProperty(propertyToFind).setValue(valueToReplace); | |
log.trace("Replaced value with '${valueToReplace}'"); | |
log.debug("Replaced property on node '${node.path}'") | |
return true; | |
} | |
} | |
log.trace("Skipped node at '${node.path}'") | |
return false; | |
} | |
public boolean undoUpdate(Node node) { | |
throw new UnsupportedOperationException('Updater does not implement undoUpdate method'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment