Introduction
Plugins have the ability to use system services (components) or other plugins. They can also share their services with other installed plugins.
Importing services
Every plugin must have access to PlusWorkflow services/components. All actions on users, processes require corresponding services. The PlusWorkflow system provides the plug-in mechanism with all services present in the application context.
Import of these should be done through the component-import module.
<!-- Import of UserServicee --> <component-import key="userService" source="system" interface="com.suncode.pwfl.administration.user.UserService" />
Such an instruction will add the wrapper of this service to the plug-in context. To use this wrapper, simply retrieve this service from the plugin context using, for example, dependency injection (@Autowired)
import com.suncode.pwfl.administration.user.UserService; @Component public class ServiceConsumer { @Autowired private UserService userService; public void printUserInfo(){ User user = userService.get('admin'); System.out.println("User 'admin' full name is: " + user.getFullName()); } }
Importing services from other plugins looks similar:
<!-- MessageService import --> <component-import key="messageService" source="plugin" interface="com.suncode.plugin.test.MessageService" />
Sharing services
Plugins that allow integrations or provide some specific functionality should make their services available to other plugins.
A plugin can make any of its components available from the plugin context. To do so, the component must be marked with the Provides annotation.
import com.suncode.plugin.test.TestService; @Service @Provides(TestService.class) public class TestServiceImpl implements TestService { /** ... */ }
When the plugin is launched, the specified service (as a result, its instance) will be registered in the ServiceRegistry under the key com.suncode.plugin.test.TestService.
Due to the fact that multiple services can be registered under the given class name, we can specify the properties of the service so that the consumer can retrieve the correct one using filters.
@Provides(value = DashboardService.class, properties = { @ServiceProperty(name = "language", value = "pl") })
Each shared service (via the @Provides annotation) is registered with a plugin property containing the key of the plugin that registered this service. This allows you to create an appropriate filter to, for example, retrieve a service from a specific plugin:
<component-import key="someService" source="plugin" interface="com.suncode.smth.Service" filter="(plugin=com.suncode.plugin-test)" />