package com.fitbank.bpm.common;

import com.fitbank.common.logger.FitbankLogger;
import com.fitbank.dto.management.Detail;
import com.fitbank.dto.management.Field;

public class RuleTriggerTrn extends AbstractFitSend {

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

    public Detail execute(Detail pDetail, String pRule) throws Exception {
        Detail det = this.prepareDetail(pDetail, "CON", "01", "8004", "01");
        String lastUser = null;
        for (Field f : pDetail.getFields()) {
            if (f.getName().indexOf("_USER_NOTIFY") == 0) {
                if (f.getName().compareTo("_USER_NOTIFY") == 0) {
                    lastUser = f.getStringValue();
                }
                f.setValue(null);
            }
        }
        pDetail.findFieldByNameCreate("_LASTUSER_NOTIFY").setValue(lastUser);
        det.findFieldByNameCreate("_TRN").setValue(pDetail);
        det.findFieldByNameCreate("CREGLABPM").setValue(pRule);
        det = this.send(det);
        pDetail = (Detail) det.findFieldByNameCreate("_TRN").getValue();
        Field f = pDetail.findFieldByNameCreate("_USER_NOTIFY");
        if ((f.getValue() == null) || (f.getStringValue().compareTo("") == 0)) {
            f.setValue(pDetail.findFieldByNameCreate("_LASTUSER_NOTIFY").getValue());
        }
        return pDetail;
    }

}
