Skip to content

Getting started with Process Manager

This guide explains the minimal steps to integrate Process Manager in a new application.

Prepare the Application

A new application created on start.vaadin.com can be used as a starting point for this tutorial. Open the site, select an empty project, choose Spring Boot as the framework, and download the generated archive. Extract it, import it into your IDE of choice, and verify the application starts correctly by running the main class.

Add the AppJars Repository

AppJars artifacts are published to the public AppJars Maven repository. Add it to your pom.xml so that Maven can resolve the AppJars dependencies:

<repositories>
    <repository>
        <id>appjars</id>
        <name>AppJars Public Repository</name>
        <url>https://maven.appjars.com</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

Add the Dependencies

Given that it is a monolithic application, the following dependencies representing the three layers of the appjar must be added:

<dependency>
    <groupId>com.appjars</groupId>
    <artifactId>appjars-process-manager-flow</artifactId>
</dependency>
<dependency>
    <groupId>com.appjars</groupId>
    <artifactId>appjars-process-manager-data-impl</artifactId>
</dependency>
<dependency>
    <groupId>com.appjars</groupId>
    <artifactId>appjars-process-manager-business-impl</artifactId>
</dependency>

After adding them, build the application to confirm that the dependencies are resolved correctly.

Modifying the Main Application Class

The following annotation must be added to the main application class to include the Process Manager auto-configuration and its Spring components:

@ComponentScan(basePackageClasses = {ProcessManagerAutoConfiguration.class, AppJarsAutoConfiguration.class, Application.class})
  • @ComponentScan: Instructs Spring to load the beans provided by the appjar as well as the beans of the application itself.

The import for ProcessManagerAutoConfiguration is com.appjars.processmanager.ProcessManagerAutoConfiguration.

Then inject the RouteConfigurer provided by Process Manager and configure the router layout in a @PostConstruct method so that the appjar views share the same layout as the rest of the application:

@Autowired
@Qualifier("ProcessManagerRouteConfigurer")
RouteConfigurer routeConfigurer;

@PostConstruct
public void configure() {
    routeConfigurer.setViewsRouterLayout(MainLayout.class);
}

The import for RouteConfigurer is com.appjars.processmanager.flow.util.RouteConfigurer.

Finally, annotate the AppShellConfigurator class with @Push:

@Push
public class Application extends SpringBootServletInitializer implements AppShellConfigurator {

The import is com.vaadin.flow.component.page.Push. Process Manager updates the status badges and the row actions of the Processes view over server push as processes start, finish, or are paused and resumed. Without @Push the view still works, but it only shows the state as it was when the page was loaded.

Add the View to the Navigation

Add the Process Manager view to the application's navigation menu. Insert the following snippet at the end of the method createNavigation() in MainLayout, before returning nav:

if (accessChecker.hasAccess(ProcessListView.class)) {
    nav.addItem(new SideNavItem("Processes", ProcessListView.class, LineAwesomeIcon.COG_SOLID.create()));
}

The import for the view class is:

  • com.appjars.processmanager.flow.view.ProcessListView

Define a Task

Process Manager discovers background tasks by scanning for Spring-managed Runnable beans. To register a task, create a component that implements Runnable:

@Component
public class MyTask implements Runnable {

    @Override
    public void run() {
        // Task logic goes here
    }
}

Any Runnable bean present in the application context becomes available for scheduling through the Processes view.

Configure Application Properties

Add the following properties to application.properties:

spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true
spring.aop.proxy-target-class=false
vaadin.i18n.provider=com.appjars.utils.i18n.AppjarsI18nProvider

The spring.aop.proxy-target-class=false property is required for the appjar to function correctly.

Finally, add com.flowingcode and com.appjars to the list of whitelisted packages in application.properties:

vaadin.allowed-packages = com.vaadin,org.vaadin,dev.hilla,com.example.application,com.flowingcode,com.appjars

Testing the Application

Start the application by running the main Spring Boot class. After it starts, log in with an administrator account and navigate to Processes in the menu.

Create a new process by clicking the New Process button, assigning the task defined earlier, and configuring a cron schedule. Once saved, the process will run automatically according to its schedule and its execution history will be available in the view.