Useful Groovy Scripts. Part 7.

Previous parts:

Clear Specific Cache Region

This approach is useful for troubleshooting database interaction. After cleaning cache before the operation, next commands or requests will be performed with no data in the caches, and you can be ensured that all SQL statements generated after this point of time will be properly logged in the JDBC log (at least once).

Turn Off Caching Subsystem

Warning! Your system will work tremendously slow after applying this setting. You can turn cache off, perform some operations and turn it on again for debugging purposes or to collect performance metrics.
In order to turn it on, change false to true.

Turn Off the Cronjobs

It is convinient for debugging the components called from not only the code you troubleshoot, but from cronjobs too. To ease the process, turn all cronjobs off by setting <<active>> to false.
q="select {pk} from {CronJob} where {active} = true"; {

Type system: Get information about a type

Just change Product with your type in the code below and you will see all attributes, their types, and type classes.

Create a groovy-powered REST API Server

Thanks for a great article about the REST API server powered by Groovy in hybris. This approach is great for adding temporary functionality accessible via http protocol.

CMS: Print all page/slot/component structure

import de.hybris.platform.cms2.enums.CmsPageStatus;
import de.hybris.platform.cms2.model.pages.AbstractPageModel;

void showComponentDetails(component) {
println " \\-- "+component.getUid();
void showSlotDetails(slot) {
println "* "+slot.getUid();
void showPageDetails(page) {
println "["+page.getUid()+"]";

void showComponents(slot) {
components = slot.getCMSComponents();
components.each {
component -> showComponentDetails(component);
void showSlotsAndComponents(page) {

slots = defaultCMSAdminContentSlotService.getContentSlotsForPage(page);
slots.each {
slot -> showComponents(slot);
void showPageConfiguration(AbstractPageModel page) {
template = page.getMasterTemplate();
println template;


SUCCESS_STATUS = Arrays.asList(CmsPageStatus.ACTIVE);
catalogVersionStaged = catalogVersionService.getCatalogVersion("lynxContentCatalog","Staged");
pages=defaultCMSAdminPageService.getAllPagesForCatalogVersionAndPageStatuses(catalogVersionStaged, SUCCESS_STATUS);
sessionService.setAttribute("activeCatalogVersion", catalogVersionStaged.getPk());
sessionService.setAttribute("activeSite", site.getPk());
pages.each {
page ->

Leave a Reply