Skip to content

Commit

Permalink
fix(osgi) force load OSGIActionletService - less is more
Browse files Browse the repository at this point in the history
ref: #30291
  • Loading branch information
wezell committed Oct 9, 2024
1 parent 0075d70 commit 87f5447
Showing 1 changed file with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String, String> 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<String, String> props = new Hashtable<>();
context.registerService(WorkflowAPIOsgiService.class.getName(), this, props);
}

}

/**
Expand Down Expand Up @@ -1690,7 +1698,7 @@ public List<WorkflowAction> 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
Expand All @@ -1703,7 +1711,7 @@ public List<WorkflowAction> 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
Expand Down Expand Up @@ -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<WorkflowActionClass> actionClasses = findActionClasses(baseAction);
if((actionClasses.size() > 1) && (actionClasses.size() != orderOfActionClassToDelete)) {
Expand Down Expand Up @@ -2273,12 +2281,12 @@ public void reorderActionClass(final WorkflowActionClass actionClass,

List<WorkflowActionClass> 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());
Expand Down

0 comments on commit 87f5447

Please sign in to comment.