1.4. Creating 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. Create ApprovalHelper
class in the com.company.bpmdemo.core
package.
package com.company.bpmdemo.core;
import org.springframework.stereotype.Component;
import com.company.bpmdemo.entity.Contract;
import com.haulmont.cuba.core.Persistence;
import com.haulmont.cuba.core.Transaction;
import javax.inject.Inject;
import java.util.UUID;
@Component("demo_ApprovalHelper")
public class ApprovalHelper {
@Inject
private Persistence persistence;
public void updateState(UUID entityId, String state) {
try (Transaction tx = persistence.getTransaction()) {
Contract contract = persistence.getEntityManager().find(Contract.class, entityId);
if (contract != null) {
contract.setState(state);
}
tx.commit();
}
}
}