/*
 * 
 */
package com.fp.bpmlib.transaction.flow;

import org.kie.api.runtime.process.ProcessInstance;

import com.fp.bpmlib.BPMException;
import com.fp.bpmlib.Flujo;
import com.fp.dto.rules.TransactionRule;
import com.fp.dto.save.SaveRequest;

/**
 * Class StartFlowMemory encargada de.
 * 
 * @author gfiallos
 */
public class StartFlowMemory extends TransactionRule {

    /** serialVersionUID. */
    private static final long serialVersionUID = 1L;

    /**
     * Normal process.
     * 
     * @param pRequest the request
     * @return save request
     * @throws Exception la exception
     */
    @Override
    public SaveRequest normalProcess(SaveRequest pRequest) throws Exception {
        Flujo flujo = new Flujo();
        try {
            flujo.iniciar(this.flow, pRequest);
            if (flujo.getProcessInstance().getState() != ProcessInstance.STATE_COMPLETED) {
                throw new BPMException("BPM-0005", "EL FLUJO {0} NO ESTA FINALIZADO", flujo.getProcessInstance().getId());
            }
            return pRequest;
        } finally {

        }
    }

    /**
     * Reverse process.
     * 
     * @param pRequest the request
     * @return save request
     * @throws Exception la exception
     */
    @Override
    public SaveRequest reverseProcess(SaveRequest pRequest) throws Exception {
        return pRequest;
    }

}