Next training February 27. Next free webinar March 6.
« Back to all tutorials

Setting up a business process

This video provides an overview of the BPM subsystem of the CUBA platform using the example of a simple contract approval process . Integrated visual designer, integrated data model, process forms, running instances and assignments and process management at runtime are demonstrated.

NB: this sample project requires CUBA Studio premium add-ons.

1. Groovy scripts for Script task nodes


import com.company.bpmdemo.entity.Contract
def em = persistence.getEntityManager()
def contract = em.find(Contract.class, entityId)

contract.setState('Approved')

import com.company.bpmdemo.entity.Contract
def em = persistence.getEntityManager()
def contract = em.find(Contract.class, entityId)

contract.setState('Rejected')

2. XML components descriptor for the contract-edit.xml


<groupBox id="procActionsBox"
          caption="msg://process"
          orientation="vertical"
          spacing="true"
          width="AUTO">
          <frame id="procActionsFrame"
                 screen="procActionsFrame"/>
</groupBox>

3. ContractEdit.java class


import com.haulmont.cuba.gui.components.AbstractEditor;
import com.haulmont.bpm.entity.ProcAttachment;
import com.haulmont.bpm.gui.procactions.ProcActionsFrame;
import com.haulmont.cuba.gui.app.core.file.FileDownloadHelper;
import com.haulmont.cuba.gui.components.Table;

import javax.inject.Inject;

public class ContractEdit extends AbstractEditor {

    @Inject
    private ProcActionsFrame procActionsFrame;

    @Override
    protected void postInit() {
        initProcActionsFrame();
    }

    private void initProcActionsFrame() {
        procActionsFrame.initializer()
                .setBeforeStartProcessPredicate(this::commit)
                .setAfterStartProcessListener(() -> {
                    showNotification(getMessage("Process started"), NotificationType.HUMANIZED);
                    close(COMMIT_ACTION_ID);
                })
                .setBeforeCompleteTaskPredicate(this::commit)
                .setAfterCompleteTaskListener(() -> {
                    showNotification(getMessage("Task completed"), NotificationType.HUMANIZED);
                    close(COMMIT_ACTION_ID);
                })
                .init("Contract approval", getItem());
    }

}

Download .txt with code