package com.fp.general.rules.query;

import java.util.List;

import com.fp.base.persistence.util.helper.GeneralDescriptions;
import com.fp.bpm.query.Query;
import com.fp.dto.Response;
import com.fp.dto.query.QueryRequest;
import com.fp.dto.rules.QueryRule;
import com.fp.persistence.pgeneral.trans.TgeneTransactionEvent;

/**
 * Clase para completar el nombre de la transaccion por eventos
 * 
 * @author scastillo
 */
public class LovTransactionEvent extends QueryRule {

    /**
     * Proceso que se encarga de completar el nombre de la transaccion
     * 
     * @param pQueryRequest
     * @return
     * @throws Exception
     */
    @Override
    public QueryRequest process(QueryRequest pQueryRequest) throws Exception {
        Response response = pQueryRequest.getResponse();
        Query qry = new Query();
        qry.process(pQueryRequest);
        List<Object> lobjects = (List<Object>) response.get("TGENETRANSACTIONEVENT");
        for (Object obj : lobjects) {
            TgeneTransactionEvent tgeneTransactionEvent = (TgeneTransactionEvent) obj;
            if (tgeneTransactionEvent.getTransactionmodule() != null) {
                tgeneTransactionEvent.addAddtionalInfo(
                        "name",
                        GeneralDescriptions.getTransactiondesc(tgeneTransactionEvent.getTransactionmodule(),
                                tgeneTransactionEvent.getTransactioncode(), tgeneTransactionEvent.getTransactionversion()));
                tgeneTransactionEvent.addAddtionalInfo("moduledesc", GeneralDescriptions.getModuledesc(tgeneTransactionEvent.getTransactionmodule()));
            } else {
                tgeneTransactionEvent.addAddtionalInfo("name", null);
                tgeneTransactionEvent.addAddtionalInfo("moduledesc", null);
            }
        }
        return pQueryRequest;
    }
}
