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.general.exception.GeneralException;
import com.fp.persistence.pgeneral.gene.TgeneOfficer;
import com.fp.persistence.pgeneral.safe.TsafeUser;

/**
 * Metodo que completa el nombre del usuario oficial de cuenta.
 * 
 * @author Jorge Vaca
 * @version 2.1
 */
public class LovOfficer extends QueryRule {

    /*
     * (non-Javadoc)
     * 
     * @see com.fp.dto.rules.QueryRule#process(com.fp.dto.query.QueryRequest)
     */
    @Override
    @SuppressWarnings("unchecked")
    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("TGENEOFFICER");
        for (Object obj : lobjects) {
            TgeneOfficer officer = (TgeneOfficer) obj;
            if (officer.getPk().getModulecode() == null) {
                throw new GeneralException("GENE-0033", "OFICIAL DE CUENTA NO DEFINIDO PARA EL PRODUCTO EN TGENEOFFICER");
            }
            TsafeUser user = com.fp.base.persistence.util.db.DataHelper.getInstance().getTsafeUser(officer.getPk().getUsercode());
            officer.addAddtionalInfo("name", GeneralDescriptions.getPersonname(user.getPersoncode()));
        }
        return pQueryRequest;
    }
}
