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.gene.TgeneTransactionMixPages;

/**
 * Clase que se encarga de completar el nombre de la transaccion par la definicion de las paginas en caja multiple
 * 
 * @author scastillo
 */
public class CompleteTransactionMixPages extends QueryRule {

    /**
     * Metodo que completa 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("TGENETRANSACTIONMIXPAGES");
        for (Object obj : lobjects) {
            TgeneTransactionMixPages tgeneTransactionMixPages = (TgeneTransactionMixPages) obj;
            if ((tgeneTransactionMixPages.getPk().getTransactionmodule() != null) && (tgeneTransactionMixPages.getPk().getTransactioncode() != null)
                    && (tgeneTransactionMixPages.getPk().getTransactionversion() != null)) {
                tgeneTransactionMixPages.addAddtionalInfo("name", GeneralDescriptions.getTransactiondesc(tgeneTransactionMixPages.getPk()
                        .getTransactionmodule(), tgeneTransactionMixPages.getPk().getTransactioncode(), tgeneTransactionMixPages.getPk()
                        .getTransactionversion()));
            } else {
                tgeneTransactionMixPages.addAddtionalInfo("name", null);
            }
        }
        return pQueryRequest;
    }
}
