on 2017 May 26 12:22 PM
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
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.