BPM: Dynamic Approval helper class

I am trying to develop user definable workflow at run time!
Is there any way we can make the ApprovalHelper class not Entity dependent i.e. avoid repeated coding of each entities as follows?

Contract contract = persistence.getEntityManager().find(Contract.class, entityId);

public class ApprovalHelper {

    private Persistence persistence;

    public void updateState(UUID entityId, String state) {
        try (Transaction tx = persistence.getTransaction()) {
            <b>Contract contract = persistence.getEntityManager().find(Contract.class, entityId);</b>
            if (contract != null) {

You can pass an entity name as a method argument and use it. Something like this:

package com.company.demo.core;

import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.cuba.core.EntityManager;
import com.haulmont.cuba.core.Persistence;
import com.haulmont.cuba.core.Transaction;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.Metadata;
import org.springframework.stereotype.Component;

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

public class UniversalApprovalHelper {

    private Persistence persistence;

    private Metadata metadata;

    public void updateState(UUID entityId, String entityName, String state) {
        Transaction tx = persistence.getTransaction();
        try {
            EntityManager em = persistence.getEntityManager();
            MetaClass metaClass = metadata.getClassNN(entityName);
            Entity entity = em.find((Class<Entity>) metaClass.getJavaClass(), entityId);
            if (entity != null) {
                entity.setValue("state", state);
        } finally {

Thank you Max. I have another question but asking in a separate post.