cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Groovy: Script execution has failed [reason: java.lang.IllegalArgumentException: Value is instanceof Collection but cannot be empty collection for key: catalogVersions

former_member1049674
Participant
0 Kudos
3,665

Hi,

I am getting the following error when I run the following groovy script. Can anyone advice why I am getting the error message?

Thank you

Script execution has failed [reason: java.lang.IllegalArgumentException: Value is instanceof Collection but cannot be empty collection for key: catalogVersions]

The script is:

 import de.hybris.platform.cms2.model.contents.components.AbstractCMSComponentModel;
 import de.hybris.platform.cms2.model.navigation.CMSNavigationNodeModel;
 import de.hybris.platform.acceleratorcms.model.components.NavigationBarComponentModel;
 import de.hybris.platform.cms2.servicelayer.services.CMSComponentService;
 import java.util.ArrayList;
 import java.util.List;
 
 CMSComponentService cmsComponentService = spring.getBean("cmsComponentService");
 
 AbstractCMSComponentModel component = (AbstractCMSComponentModel) cmsComponentService.getSimpleCMSComponent("categoryId");
 
 if (component != null){
 
         CMSNavigationNodeModel levels=((NavigationBarComponentModel)component).getNavigationNode();
         if (levels!=null){
             List<CMSNavigationNodeModel> listLevels=levels.getChildren();
             for (CMSNavigationNodeModel level:listLevels){
                 println " level: " + level.getUid();
                 for (CMSNavigationNodeModel subLevel1:level.getChildren()){
                     println " subLevel1: " + subLevel1.getUid();
                 }
             }
         }
         
 }

View Entire Topic
andyfletcher
Active Contributor

You need to set the session catalog version.

e.g.

catalogVersionService.setSessionCatalogVersion 'Default', 'Staged'

Also, although that will run as Groovy, it's not very groovy. What are all those types and semi colons doing there? And you definitely don't need to access the application context directly to retrieve beans.

Perhaps something more like this?

catalogVersionService.setSessionCatalogVersion 'myContentCatalog','Staged'
component = cmsComponentService.getSimpleCMSComponent('MyAccountComponent')
component?.navigationNode?.children.each { level ->
    println " level: ${level.uid}"
    level.children.each { subLevel ->
        println " subLevel1: ${subLevel1.uid}"
    }
}