Hello dear community colleagues. I am writing a script for deleting channels. As I see in the old Implementations, there was a way to bind a JavaClass to the Script update method and make a method call like this.
This was written a long time ago. I tried the same in the new implementation for deleting channels, because I would like to write the Implementation in java and not .groovy. What am I doing wrong?
Hello machak, I want to write the logic in the ChannelRemover.java in which I want to clean channel settings in hst:hst, hippo:namespaces, hippo:configuration and the content/documents of the channel which I want to delete. Due to this fact of deleting different nodes at different places I would prefer writing it in Java and not Groovy. I would like to process the node as parameter in the remove(node, parametersMap) method of the ChannelRemover.java. Is it possible?
You can write all your logic in Java and call it from Groovy. Groovy runs on the JVM and has access to the same classloader…sort of, it’s a actually a special classloader to prevent some obvious avenues for mistakes and abuse.
ChannelRemover does have to be in the cms project for this to work and you need to have an include statement in the class. Groovy is almost identical to Java in many ways, such that if you just write Java odds are it will work as a Groovy script.
Ok, I saw, I forgot the import statement of the class in the groovy script. I added it. Now I would like to have the option of logging or debugging. Either of both is fine for me. When I have the log.info in the update methode and logging target repository, I should see this in the BRX output console or not?
I just get this output:
INFO 2024-04-17 14:28:22 Executing updater ChannelRemoveUpdator
INFO 2024-04-17 14:28:22 Finished executing updater ChannelRemoveUpdator
My question is which magic behiond gives me a node. Before in other tasks I was always using the xpath for the groovy scripts. Now I use the option updator in BRX
Debugging in Groovy is challenging. The log should output to the console or the log files. If you are using Java classes in your Groovy you can of course set a breakpoint in those. Also, Java classes can be unit tested. See this