Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Can't able to import certain classes in groovy script
In my groovy script I tried to import the following classes and some of them failed. This script is from the Liferay Kaleo Designer Documentation.
This is the exception I got.
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.kernel.workflow.WorkflowHandler;
import com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil;
// Failed to import
import com.liferay.portlet.asset.model.AssetCategory;
import com.liferay.portlet.asset.model.AssetEntry;
import com.liferay.portlet.asset.model.AssetRenderer;
import com.liferay.portlet.asset.model.AssetRendererFactory;
import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
This is the exception I got.
2019-05-10 16:44:59.205 ERROR [liferay/kaleo_graph_walker-2][ParallelDestination:55] Unable to process message {destinationName=liferay/kaleo_graph_walker, response=null, responseDestinationName=null, responseId=null, payload=com.liferay.portal.workflow.kaleo.runtime.graph.PathElement@48e2a9df, values={defaultLocale=en_US, companyId=20115, groupId=0, principalName=20155, permissionChecker=com.liferay.portal.kernel.util.TransientValue@66fa0c32, siteDefaultLocale=en_US, themeDisplayLocale=en_US}}
com.liferay.portal.kernel.messaging.MessageListenerException: com.liferay.portal.kernel.scripting.ScriptingException: startup failed:__Script1.groovy: 8: unable to resolve class com.liferay.portlet.asset.model.AssetEntry_ @ line 8, column 13.__ import com.liferay.portlet.asset.model.AssetEntry;__ ^____Script1.groovy: 11: unable to resolve class com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil_ @ line 11, column 13.__ import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;__ ^____Script1.groovy: 9: unable to resolve class com.liferay.portlet.asset.model.AssetRenderer_ @ line 9, column 13.__ import com.liferay.portlet.asset.model.AssetRenderer;__ ^____Script1.groovy: 7: unable to resolve class com.liferay.portlet.asset.model.AssetCategory_ @ line 7, column 13.__ import com.liferay.portlet.asset.model.AssetCategory;__ ^____Script1.groovy: 10: unable to resolve class com.liferay.portlet.asset.model.AssetRendererFactory_ @ line 10, column 13.__ import com.liferay.portlet.asset.model.AssetRendererFactory;__ ^____Script1.groovy: 44: unable to resolve class AssetVocabulary _ @ line 44, column 28.__ AssetVocabulary vocabulary= AssetVocabularyLocalServiceUtil.getAssetVocabulary(assetCategory.getVocabularyId());__ ^____6 errors___Line 1: _Line 2: import com.liferay.portal.kernel.util.GetterUtil;_Line 3: import com.liferay.portal.kernel.workflow.WorkflowConstants;_Line 4: import com.liferay.portal.kernel.workflow.WorkflowHandler;_Line 5: import com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil;_Line 6: _Line 7: import com.liferay.portlet.asset.model.AssetCategory;_Line 8: import com.liferay.portlet.asset.model.AssetEntry;_Line 9: import com.liferay.portlet.asset.model.AssetRenderer;_Line 10: import com.liferay.portlet.asset.model.AssetRendererFactory;_Line 11: import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;_Line 12: _Line 13: import com.liferay.asset.kernel.service.AssetVocabularyLocalServiceUtil;_Line 14: _Line 15: import java.util.List;_Line 16: _Line 17: ThModuleKaleoworkflowService.hasLegalWorkflow(serviceContext.getAttribute("classPK")); _Line 18: String className = (String)workflowContext.get(_Line 19: WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME);_Line 20: _Line 21: WorkflowHandler workflowHandler =_Line 22: WorkflowHandlerRegistryUtil.getWorkflowHandler(className);_Line 23: _Line 24: AssetRendererFactory assetRendererFactory =_Line 25: workflowHandler.getAssetRendererFactory();_Line 26: _Line 27: long classPK =_Line 28: serviceContext.getAttribute("classPK");_Line 29: _Line 30: AssetRenderer assetRenderer =_Line 31: workflowHandler.getAssetRenderer(classPK);_Line 32: _Line 33: AssetEntry assetEntry = assetRendererFactory.getAssetEntry(_Line 34: assetRendererFactory.getClassName(), assetRenderer.getClassPK());_Line 35: _Line 36: List<assetcategory> assetCategories = assetEntry.getCategories();_Line 37: _Line 38: returnValue = "unknown";_Line 39: _Line 40: _Line 41: for (AssetCategory assetCategory : assetCategories) {_Line 42: String categoryName = assetCategory.getName();_Line 43: _Line 44: AssetVocabulary vocabulary= AssetVocabularyLocalServiceUtil.getAssetVocabulary(assetCategory.getVocabularyId());_Line 45: _Line 46: if (categoryName.contentEquals("legal") && vocabulary.getName().contentEquals("workflow")) {_Line 47: returnValue = "legal-review";_Line 48: return;_Line 49: }_Line 50: }_Line 51: _Line 52: _ [Sanitized]
at com.liferay.portal.kernel.messaging.BaseMessageListener.receive(BaseMessageListener.java:32)
at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:74)
at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:52)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:756)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:667)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.liferay.portal.kernel.scripting.ScriptingException: startup failed:__Script1.groovy: 8: unable to resolve class com.liferay.portlet.asset.model.AssetEntry_ @ line 8, column 13.__ import com.liferay.portlet.asset.model.AssetEntry;__ ^____Script1.groovy: 11: unable to resolve class com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil_ @ line 11, column 13.__ import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;__ ^____Script1.groovy: 9: unable to resolve class com.liferay.portlet.asset.model.AssetRenderer_ @ line 9, column 13.__ import com.liferay.portlet.asset.model.AssetRenderer;__ ^____Script1.groovy: 7: unable to resolve class com.liferay.portlet.asset.model.AssetCategory_ @ line 7, column 13.__ import com.liferay.portlet.asset.model.AssetCategory;__ ^____Script1.groovy: 10: unable to resolve class com.liferay.portlet.asset.model.AssetRendererFactory_ @ line 10, column 13.__ import com.liferay.portlet.asset.model.AssetRendererFactory;__ ^____Script1.groovy: 44: unable to resolve class AssetVocabulary _ @ line 44, column 28.__ AssetVocabulary vocabulary= AssetVocabularyLocalServiceUtil.getAssetVocabulary(assetCategory.getVocabularyId());__ ^____6 errors___Line 1: _Line 2: import com.liferay.portal.kernel.util.GetterUtil;_Line 3: import com.liferay.portal.kernel.workflow.WorkflowConstants;_Line 4: import com.liferay.portal.kernel.workflow.WorkflowHandler;_Line 5: import com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil;_Line 6: _Line 7: import com.liferay.portlet.asset.model.AssetCategory;_Line 8: import com.liferay.portlet.asset.model.AssetEntry;_Line 9: import com.liferay.portlet.asset.model.AssetRenderer;_Line 10: import com.liferay.portlet.asset.model.AssetRendererFactory;_Line 11: import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;_Line 12: _Line 13: import com.liferay.asset.kernel.service.AssetVocabularyLocalServiceUtil;_Line 14: _Line 15: import java.util.List;_Line 16: _Line 17: ThModuleKaleoworkflowService.hasLegalWorkflow(serviceContext.getAttribute("classPK")); _Line 18: String className = (String)workflowContext.get(_Line 19: WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME);_Line 20: _Line 21: WorkflowHandler workflowHandler =_Line 22: WorkflowHandlerRegistryUtil.getWorkflowHandler(className);_Line 23: _Line 24: AssetRendererFactory assetRendererFactory =_Line 25: workflowHandler.getAssetRendererFactory();_Line 26: _Line 27: long classPK =_Line 28: serviceContext.getAttribute("classPK");_Line 29: _Line 30: AssetRenderer assetRenderer =_Line 31: workflowHandler.getAssetRenderer(classPK);_Line 32: _Line 33: AssetEntry assetEntry = assetRendererFactory.getAssetEntry(_Line 34: assetRendererFactory.getClassName(), assetRenderer.getClassPK());_Line 35: _Line 36: List<assetcategory> assetCategories = assetEntry.getCategories();_Line 37: _Line 38: returnValue = "unknown";_Line 39: _Line 40: _Line 41: for (AssetCategory assetCategory : assetCategories) {_Line 42: String categoryName = assetCategory.getName();_Line 43: _Line 44: AssetVocabulary vocabulary= AssetVocabularyLocalServiceUtil.getAssetVocabulary(assetCategory.getVocabularyId());_Line 45: _Line 46: if (categoryName.contentEquals("legal") && vocabulary.getName().contentEquals("workflow")) {_Line 47: returnValue = "legal-review";_Line 48: return;_Line 49: }_Line 50: }_Line 51: _Line 52: _ [Sanitized]
at com.liferay.portal.scripting.internal.ScriptingImpl.eval(ScriptingImpl.java:91)
at com.liferay.portal.workflow.kaleo.runtime.scripting.internal.util.KaleoScriptingEvaluator.execute(KaleoScriptingEvaluator.java:58)
at com.liferay.portal.workflow.kaleo.runtime.scripting.internal.condition.ScriptingConditionEvaluator.evaluate(ScriptingConditionEvaluator.java:50)
at com.liferay.portal.workflow.kaleo.runtime.internal.condition.MultiLanguageConditionEvaluator.evaluate(MultiLanguageConditionEvaluator.java:59)
at com.liferay.portal.workflow.kaleo.runtime.internal.node.ConditionNodeExecutor.doExecute(ConditionNodeExecutor.java:65)
at com.liferay.portal.workflow.kaleo.runtime.node.BaseNodeExecutor.execute(BaseNodeExecutor.java:83)</assetcategory></assetcategory>
What version of Liferay are you using? in 7.0 the packages changed for those Asset classes.
Amos FongWhat version of Liferay are you using? in 7.0 the packages changed for those Asset classes.
Thanks Amon! That was the reason. I already fixed it.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™