package com.fitbank.bpm.common; import java.io.Serializable; import org.apache.log4j.Logger; import com.fitbank.common.exception.FitbankException; import com.fitbank.common.logger.FitbankLogger; import com.fitbank.dto.GeneralResponse; import com.fitbank.dto.management.Detail; import com.fitbank.dto.management.Field; import com.fitbank.processor.RequestProcessorEmbedded; import org.hibernate.StaleStateException; public abstract class AbstractFitSend implements Serializable { private static final Logger LOGGER = Logger.getLogger(AbstractFitSend.class); private static final long serialVersionUID = 1L; protected Detail send(Detail pDetail) throws Exception { try { LOGGER.debug("Ejecutando comandos del FLUJO BPM..."); pDetail.findFieldByNameCreate("__BPM__").setValue("1"); RequestProcessorEmbedded rpe = new RequestProcessorEmbedded(pDetail); pDetail = rpe.process(); pDetail.findFieldByNameCreate("__BPM__").setValue("0"); pDetail.findFieldByNameCreate("_BPM_FIT_RES").setValue(pDetail.getResponse()); pDetail.findFieldByNameCreate("_BPM_FIT_STACK").setValue(pDetail.getResponse().getStackTrace()); LOGGER.debug("Fin de ejecucion de comandos del FLUJO BPM"); if (!GeneralResponse.OK.equals(pDetail.getResponse().getCode())) { Exception e = new Exception(pDetail.getResponse().getStackTrace()); throw new FitbankException(pDetail.getResponse().getCode(), pDetail.getResponse().getUserMessage(), e); } return pDetail; } catch (StaleStateException e) { FitbankLogger.getLogger().error(e, e); throw new FitbankException("FIT070", "INGRESO INCONSISTENTE DE DATOS", e); } } protected Detail prepareDetail(Detail pDetailReference, String pType, String pSubsistem, String pTransaction, String pVersion) throws Exception { Detail det = new Detail(); pDetailReference.copy(det); det.setMessageId(""); det.setType(pType); det.setSubsystem(pSubsistem); det.setTransaction(pTransaction); det.setVersion(pVersion); det.setResponse(null); for (Field f : pDetailReference.getFields()) { if (det.findFieldByName(f.getName()) == null) { det.findFieldByNameCreate(f.getName()).setValue(f.getValue()); } } return det; } }