Activiti Process Diagram

Activiti supports in section 6.5 of their documentation the ability to generate a process diagram. Does Cuba support this? Is this something I can setup? If not, is it on the roadmap?

We’ve setup our solution where users can create their own workflows and then run them against entities without the need of changing any code. In other words, codeless workflow creation and execution. We are wiring up the workflows dynamically. It would be nice to be able to also dynamically give a process diagram as well.



Basically, everything that is supported by Activiti is automatically supported by the platform.
You can use Activiti API to generate a diagram image. The service implementation will be something like this:


import com.haulmont.bpm.entity.ProcDefinition;
import com.haulmont.cuba.core.EntityManager;
import com.haulmont.cuba.core.Persistence;
import com.haulmont.cuba.core.Transaction;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.ArrayList;

public class ProcessDiagramServiceBean implements ProcessDiagramService {

    private ProcessEngineConfiguration processEngineConfiguration;

    private Persistence persistence;

    private RepositoryService repositoryService;

    private Logger log;

    public byte[] createDiagram(String procCode) {
        byte[] result = null;
        ProcDefinition procDefinition;
        try (Transaction tx = persistence.createTransaction()) {
            EntityManager em = persistence.getEntityManager();
            procDefinition = em.createQuery("select pd from bpm$ProcDefinition pd where pd.code = :code", ProcDefinition.class)
                    .setParameter("code", procCode)

            ProcessDefinitionEntity pde = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(procDefinition.getActId());
            if (pde != null && pde.isGraphicalNotationDefined()) {
                BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
                InputStream resource = processEngineConfiguration.getProcessDiagramGenerator()
                        .generateDiagram(bpmnModel, "png", new ArrayList<>());
                result = IOUtils.toByteArray(resource);
            } else {
                throw new ActivitiIllegalArgumentException("Process instance with id '" + procDefinition.getActId() + "' has no graphical notation defined.");
        } catch (IOException e) {
            log.error("Error on creating the process diagram image", e);
        return result;

In future we’ll probably add some API that will allow you to generate a diagram in an easier way.

Thanks for the response. We’ve got it working.

:ticket: See the following issue in our bug tracker: