1.4.1. ApprovalHelper Bean

The updateState() method of the ApprovalHelper bean will be invoked from the contract approval process for setting a contract state.

Method parameters:
  • entityId - contract entity identifier

  • state - contract state

Open the project in an IDE. A simple way to do it is to use an IDE button from any section of the Studio navigator, e.g. Project properties.

Create a package com.company.demo.core in the core module. Create ApprovalHelper class in this package.

package com.company.demo.core;

import com.company.demo.entity.Contract;
import com.haulmont.cuba.core.EntityManager;
import com.haulmont.cuba.core.Persistence;
import com.haulmont.cuba.core.Transaction;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.UUID;

public class ApprovalHelper {

    private Persistence persistence;

    public void updateState(UUID entityId, String state) {
        Transaction tx = persistence.getTransaction();
        try {
            EntityManager em = persistence.getEntityManager();
            Contract contract = em.find(Contract.class, entityId);
            if (contract != null) {
        } finally {