From 87f5447f687b57939b7f58e34708219d5a084c81 Mon Sep 17 00:00:00 2001 From: Will Ezell Date: Wed, 9 Oct 2024 08:32:52 -0400 Subject: [PATCH] fix(osgi) force load OSGIActionletService - less is more ref: #30291 --- .../workflows/business/WorkflowAPIImpl.java | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/business/WorkflowAPIImpl.java b/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/business/WorkflowAPIImpl.java index 6e1d50fdbd9c..f7ae608762db 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/business/WorkflowAPIImpl.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/business/WorkflowAPIImpl.java @@ -140,6 +140,7 @@ import io.vavr.control.Try; import org.apache.commons.lang.time.StopWatch; import org.apache.commons.lang3.concurrent.ConcurrentUtils; +import org.apache.felix.framework.OSGIUtil; import org.elasticsearch.search.query.QueryPhaseExecutionException; import org.osgi.framework.BundleContext; @@ -367,16 +368,23 @@ private FriendClass getFriendClass () { } public void registerBundleService () { - if(System.getProperty(WebKeys.OSGI_ENABLED)!=null){ - // Register main service - BundleContext context = HostActivator.instance().getBundleContext(); - if (null != context) { - Hashtable props = new Hashtable<>(); - context.registerService(WorkflowAPIOsgiService.class.getName(), this, props); - } else { - Logger.error(this, "Bundle Context is null, WorkflowAPIOsgiService has been not registered"); - } + + // force init if not already done + OSGIUtil.getInstance().initializeFramework(); + if (System.getProperty(WebKeys.OSGI_ENABLED) == null) { + // OSGI is not inited + throw new DotRuntimeException("Unable to register WorkflowAPIOsgiService as OSGI is not inited"); + } + + BundleContext context = HostActivator.instance().getBundleContext(); + if (context == null) { + throw new DotRuntimeException("Bundle Context is null, WorkflowAPIOsgiService has been not registered"); + } + if (context.getServiceReference(WorkflowAPIOsgiService.class.getName()) == null) { + Hashtable props = new Hashtable<>(); + context.registerService(WorkflowAPIOsgiService.class.getName(), this, props); } + } /** @@ -1690,7 +1698,7 @@ public List findAvailableActionsEditing(final Contentlet content return this.findAvailableActions(contentlet, user, RenderMode.EDITING); } - + /** * This method will return the list of workflows actions available to a user on any give * piece of content, based on how and who has the content locked and what workflow step the content @@ -1703,7 +1711,7 @@ public List findAvailableActionsListing(final Contentlet content return this.findAvailableActions(contentlet, user, RenderMode.LISTING); } - + /** * This method will return the list of workflows actions available to a user on any give * piece of content, based on how and who has the content locked and what workflow step the content @@ -2224,13 +2232,13 @@ public void deleteActionClass(final WorkflowActionClass actionClass, final User // Delete action class final int orderOfActionClassToDelete = actionClass.getOrder(); workFlowFactory.deleteActionClass(actionClass); - - // We don't need to get "complete" base action object from the database + + // We don't need to get "complete" base action object from the database // to retrieve all action classes from him. So, we can create the base action object // with the "action id" contain in actionClass parameter. WorkflowAction baseAction = new WorkflowAction(); baseAction.setId(actionClass.getActionId()); - + // Reorder the action classes in the database final List actionClasses = findActionClasses(baseAction); if((actionClasses.size() > 1) && (actionClasses.size() != orderOfActionClassToDelete)) { @@ -2273,12 +2281,12 @@ public void reorderActionClass(final WorkflowActionClass actionClass, List actionClasses = null; try { - // We don't need to get "complete" base action object from the database + // We don't need to get "complete" base action object from the database // to retrieve all action classes from him. So, we can create the base action object // with the "action id" contain in actionClass parameter. final WorkflowAction baseAction = new WorkflowAction(); baseAction.setId(actionClass.getActionId()); - + actionClasses = findActionClasses(baseAction); } catch (Exception e) { throw new DotDataException(e.getLocalizedMessage());