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,668

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();
                 }
             }
         }
         
 }

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi ,

In Above Your Code Snippet CatalogVersion not give the argument for getting the cmscomponent.Use Bellow Code

 import de.hybris.platform.acceleratorcms.model.components.NavigationBarComponentModel
 import de.hybris.platform.catalog.CatalogVersionService
 import de.hybris.platform.catalog.model.CatalogVersionModel
 import de.hybris.platform.cms2.model.contents.components.AbstractCMSComponentModel
 import de.hybris.platform.cms2.model.navigation.CMSNavigationNodeModel
 import de.hybris.platform.cms2.servicelayer.services.CMSComponentService
 import de.hybris.platform.core.Registry
 
 CMSComponentService cmsComponentService = spring.getBean("cmsComponentService");
 CatalogVersionModel version=Registry.getApplicationContext().
         getBean("catalogVersionService",CatalogVersionService.class).getCatalogVersion("apparelProductCatalog", "Online");
 List versionslist=new ArrayList();
 versionslist.add(version);
 AbstractCMSComponentModel component = (AbstractCMSComponentModel) cmsComponentService.getAbstractCMSComponent("A101010",versionslist);
 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();
             }
         }
     }
 }

Answers (1)

Answers (1)

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}"
    }
}