Last active
November 5, 2020 13:55
-
-
Save DavidForster/c209e8ad23aea4d2b019fb22131ee0a0 to your computer and use it in GitHub Desktop.
Bloomreach Experience Manager Groovy updater script to change the namespace of documents
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.admin.updater | |
import org.onehippo.repository.update.BaseNodeUpdateVisitor | |
import javax.jcr.Node | |
import javax.jcr.RepositoryException | |
import javax.jcr.Session | |
class UpdaterNamespace extends BaseNodeUpdateVisitor { | |
String findNamespace; | |
String replaceNamespace; | |
@Override | |
public void setParametersMap(Map<String, Object> parametersMap) { | |
super.setParametersMap(parametersMap) | |
findNamespace = parametersMap["findNamespace"]; | |
replaceNamespace = parametersMap["replaceNamespace"]; | |
log.info("Changing nodes of namespace '${findNamespace}' to '${replaceNamespace}'"); | |
} | |
boolean doUpdate(Node node) { | |
log.trace("Found node at '${node.path}'"); | |
if (findNamespace == node.getPrimaryNodeType().getName()) { | |
node.setPrimaryType(replaceNamespace); | |
log.debug "Reaplaced namespace on node ${node.path}"; | |
return true; | |
} | |
log.trace("Skipped node at '${node.path}'") | |
return false; | |
} | |
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