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

Can I import storefront classes in groovy?

former_member1049674
Participant
0 Kudos
1,430

Hi,

I am creating a groovy script that requires some classes from our Storefront extension.

I do not know why Groovy is complaining about it. These is the error I am getting:

 Script compilation has failed [reason: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
 Script3.groovy: 27: unable to resolve class com.xxxxxxxxx.storefront.breadcrumb.Breadcrumb
  @ line 27, column 1.
 
    import com.xxxxxxxxx.storefront.breadcrumb.Breadcrumb;
 
    ^
 
 Script3.groovy: 23: unable to resolve class com.xxxxxxxxx.storefront.breadcrumb.impl.ProductBreadcrumbBuilder
  @ line 23, column 1.
 
    import com.xxxxxxxxx.storefront.breadcrumb.impl.ProductBreadcrumbBuilder;
 
    ^
 
 2 errors
 ]


And this is the Groovy Script I have:

 import de.hybris.platform.catalog.CatalogVersionService;
 
 import de.hybris.platform.category.CategoryService;
 
 import de.hybris.platform.category.model.CategoryModel;
 
 import de.hybris.platform.core.model.product.ProductModel;
 
 import de.hybris.platform.europe1.model.PriceRowModel;
 
 import de.hybris.platform.core.model.product.UnitModel;
 
 import de.hybris.platform.core.model.c2l.CurrencyModel;
 
 import de.hybris.platform.product.ProductService;
 
 import de.hybris.platform.servicelayer.model.ModelService;
 
 import de.hybris.platform.variants.model.VariantProductModel;
 
 import com.xxxxxxxxx.storefront.breadcrumb.impl.ProductBreadcrumbBuilder;
 
 import java.util.ArrayList;
 
 import com.xxxxxxxxx.storefront.breadcrumb.Breadcrumb;
 
 import java.util.Collection;
 
 import java.util.Iterator;
 
 import java.util.List;
 
 import java.lang.Integer;
 
 import com.xxxxxxxxx.facades.product.data.ProductTypeMainCategoryProduct;
 
 import org.apache.commons.collections.CollectionUtils;
 
 import com.aswatson.igc.core.model.IgcVariantProductModel;
 
 CategoryService categoryService = spring.getBean("categoryService");
 
 ProductService productService = spring.getBean("xxxxxxxxxProductService");
 
 ProductTypeMainCategoryProduct productTypeMainCategoryProduct = spring.getBean("productTypeMainCategoryProduct");
 
 ProductBreadcrumbBuilder productBreadcrumbBuilder = spring.getBean("productBreadcrumbBuilder");
 
 CatalogVersionService catalogVersionService = spring.getBean("catalogVersionService");
 
 ModelService modelService = spring.getBean("modelService");
 
 final Collection<CategoryModel> categories = categoryService.getRootCategoriesForCatalogVersion(catalogVersionService.getCatalogVersion("xxxxxxxxxProductCatalog", "Online"));
 
 final Iterator<CategoryModel> iterator = categories.iterator();
 
 int prodProcessed=0;
 
 while (iterator.hasNext())
 
 {
 
   final CategoryModel rootCategory = iterator.next();
 
   final List<CategoryModel> subCategories = rootCategory.getCategories();
 
   if (subCategories != null)
 
     {
 
         for (final CategoryModel subCategory : subCategories)
 
         {
 
             final List<ProductModel> products = productService.getProductsForCategory(subCategory);
 
             if (products != null)
 
             {
 
                 for (final ProductModel product : products)
 
                 {
 
                     final Collection<VariantProductModel> variants = product.getVariants();
 
                     if (!CollectionUtils.isEmpty(variants))
 
                     {
                         for (final VariantProductModel variant : variants)
 
                         {
                             if (variant instanceof IgcVariantProductModel)
                             {
                                         
                                 final List<Breadcrumb> breadcrumbs = productBreadcrumbBuilder.getBreadcrumbs(productModel);                                
                                 if (breadcrumbs!=null && breadcrumbs.size()>0 && breadcrumbs.get(0)!=null){    
                                     List<String> listMainCategories= Arrays.asList(((String)"makeup,skincare,fragrance,baby,hair,men,toiletries,electricals,health").split(","));
                                     if (listMainCategories.contains(listPThierarchy.get(0).getName())){
                                         //do nothing
                                     }
                                 }
                                 println "variant code " + variant.getCode() + "do not have main category ";    
 
                             }
                         }
 
                     }
 
                 }
 
             }
 
         }
 
     }
 
 }
 

Can anyone let me know why I am getting this error?

Thank you

View Entire Topic
andyfletcher
Active Contributor
0 Kudos

It depends where the class is located. If it's in your web/src folder of your storefront context then it is loaded by a different classloader from the one used by the hac context where your script is being run. https://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html

former_member1049674
Participant
0 Kudos

Hi Andrew,

thank you for coming back to me. Do you know which the file I need to update so that Tomcat grabs the Storefront extension?

Thank you

former_member1049674
Participant
0 Kudos

I have added the following new packages in catalina.properties and no luck:

package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,\ org.apache.naming.resources.,org.apache.tomcat.,com.xxxxxxx.storefront.breadcrumb,com.xxxxxxxxxx.storefront.breadcrumb.impl

andyfletcher
Active Contributor
0 Kudos

As I understand it that's not something that you should be doing (if it's even possible).

The contexts are intended to be separate.

You could try running your script from a scriptlet in a jsp (since it's not really Groovy, it's just Java) Then it would allow you to call a page that ran your script.

You'd have to change web.xml to allow scripting. The default accelerator has this set.

 <scripting-invalid>true</scripting-invalid>