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.menu.TgeneMenuLevelTran;

/**
 * Clase que completa el nombre de la transaccion en niveles
 * 
 * @author scastillo
 */
public class CompleteTransactionLevel 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("TGENEMENULEVELTRAN");
        for (Object obj : lobjects) {
            TgeneMenuLevelTran tgeneMenuLevelTran = (TgeneMenuLevelTran) obj;
            if ((tgeneMenuLevelTran.getPk().getTransactionmodule() != null) && (tgeneMenuLevelTran.getPk().getTransactioncode() != null)
                    && (tgeneMenuLevelTran.getPk().getTransactionversion() != null)) {
                tgeneMenuLevelTran.addAddtionalInfo("name", GeneralDescriptions.getTransactiondesc(tgeneMenuLevelTran.getPk().getTransactionmodule(),
                        tgeneMenuLevelTran.getPk().getTransactioncode(), tgeneMenuLevelTran.getPk().getTransactionversion()));
            } else {
                tgeneMenuLevelTran.addAddtionalInfo("name", null);
            }
        }
        return pQueryRequest;
    }
}
