package com.fp.general.application;

import com.fp.dto.Response;
import com.fp.dto.query.QueryRequest;
import com.fp.dto.rules.QueryRule;
import com.fp.persistence.commondb.PersistenceHelper;
import com.fp.persistence.pgeneral.gene.TgeneSolicitude;

/**
 * Clase que se encarga de obtener la descripción del oficial de la solicitud.
 * 
 * @author Andres E. Carpio
 * @version 1.0
 */
public class OfficerDescription extends QueryRule {
    /** Constante SQL. */
    private final static String SQL = "select name from TcustPersonDetail where personcode=(select personcode from TsafeUser where usercode=:userCode)";

    @Override
    public QueryRequest process(QueryRequest pQueryRequest) throws Exception {
        Response response = pQueryRequest.getResponse();
        TgeneSolicitude tgeneSolicitude = (TgeneSolicitude) response.get("TGENESOLICITUDE");

        javax.persistence.Query qry = PersistenceHelper.createNativeQuery(OfficerDescription.SQL);
        qry.setParameter("userCode", tgeneSolicitude.getOfficer());

        tgeneSolicitude.addAddtionalInfo("officerdescription", qry.getResultList());

        return pQueryRequest;

    }
}
