2.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.

ApprovalHelper.java. 

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 javax.annotation.ManagedBean;
import javax.inject.Inject;
import java.util.UUID;

@ManagedBean("demo_ApprovalHelper")
public class ApprovalHelper {

    @Inject
    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) {
                contract.setState(state);
            }
            tx.commit();
        } finally {
            tx.end();
        }
    }
}