package com.fp.frontend.controller.armas.lov; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import org.primefaces.context.RequestContext; import com.fp.dto.Request; import com.fp.dto.Response; import com.fp.dto.query.DtoQuery; import com.fp.dto.query.Filter; import com.fp.dto.query.SubQuery; import com.fp.frontend.controller.AbstractController; import com.fp.frontend.enums.EnumLovOption; import com.fp.frontend.helper.CallerHelper; import com.fp.frontend.helper.MessageHelper; import com.fp.persistence.parmas.param.TarmTipoArmaExplosivo; import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail; /** * Clase controladora del lov asociado al bean TgeneCatalog. * * @author C.P. * @version 2.1 */ @ManagedBean @ViewScoped public class ArmaExplosivoLovController extends AbstractController { private static final long serialVersionUID = 1L; private String tituloLOV; private String categoriaParam; private String descripcionClase; private String descripcionTipo; public ArmaExplosivoLovController() throws Exception { super(TarmTipoArmaExplosivo.class); } @PostConstruct private void postconstruct() throws Exception { this.init(); tituloLOV = CallerHelper.getLovParameter("tituloLOV"); categoriaParam = CallerHelper.getLovParameter("categoria"); if(categoriaParam!=null){ categoriaParam = " and t.clase in ('"+categoriaParam+"')"; categoriaParam=categoriaParam.replace(",", "','"); } // Inicializa autoconsulta super.startQuery(); } /** * Incializa el controlador, cuando se esta utilizando una pagina que utliza el controlador. */ private void init() { try { this.recperpage = 15; // Cambiar al # reg a mirar. this.lrecord = new ArrayList<>(); this.beanalias = "TIPOARMAEXPLOSIVOLOV"; } catch (Exception e) { MessageHelper.setMessageError(e); } } @SuppressWarnings("unchecked") @Override protected void querydatabase() { try { Request request = this.callerhelper.getRequest(); DtoQuery dto = super.getDtoQuery(true); SubQuery subqueryClase = new SubQuery("TgeneCatalogDetail", "description", "nclase", "i.pk.catalog = t.clase and i.pk.catalogcode = t.clasecodigo"); dto.addSubQuery(subqueryClase); SubQuery subqueryTipoArmaExplosivo = new SubQuery("TgeneCatalogDetail", "description", "ntipo", "i.pk.catalog = t.tipoarmaexplosivo and i.pk.catalogcode = t.tipoarmaexplosivocodigo"); dto.addSubQuery(subqueryTipoArmaExplosivo); SubQuery subqueryLongitud = new SubQuery("TgeneCatalogDetail", "description", "nlongitud", "i.pk.catalog = t.longitud and i.pk.catalogcode = t.longitudcodigo"); dto.addSubQuery(subqueryLongitud); SubQuery subqueryCalibre = new SubQuery("TgeneCatalogDetail", "description", "ncalibre", "i.pk.catalog = t.calibre and i.pk.catalogcode = t.calibrecodigo"); dto.addSubQuery(subqueryCalibre); SubQuery subunidad= new SubQuery("TgeneCatalogDetail", "description", "desunidad", "i.pk.catalog = t.pk.unidadmedidapeso and i.pk.catalogcode=t.pk.unidadmedidapesocodigo"); dto.addSubQuery(subunidad); SubQuery subunidadlegalcode= new SubQuery("TgeneCatalogDetail", "legalcode", "deslegalcode", "i.pk.catalog = t.pk.unidadmedidapeso and i.pk.catalogcode=t.pk.unidadmedidapesocodigo"); dto.addSubQuery(subunidadlegalcode); String sql=" 1=1 "; if(descripcionClase!= null && descripcionClase.trim().length()>0){ sql=sql+" and clase in (select o.pk.catalog from TgeneCatalogDetail o where o.description like '%"+descripcionClase+"%' and o.pk.catalogcode='CLASE')"; }//TarmTipoArmaExplosivo if(descripcionTipo!= null && descripcionTipo.trim().length()>0){ sql=sql+" and tipoarmaexplosivo in (select o.pk.catalog from TgeneCatalogDetail o where o.description like '%"+descripcionTipo+"%' and o.pk.catalogcode='TIPOARMAEXPLOSIVO')"; //TarmTipoArmaExplosivo//catalogcode } Filter filtro= new Filter(); sql += categoriaParam!=null?categoriaParam:""; filtro.setSql(sql); //TarmTipoArmaExplosivo//catalogcode dto.addFiltro(filtro); HashMap mtables = new HashMap(); mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla. request.setQueryTables(mtables); Response resp = this.callerhelper.executeQuery(request); if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) { this.lrecord = new ArrayList(); MessageHelper.setMessageError(resp); } else { this.lrecord = (List) resp.get(this.beanalias); super.postQuery(this.lrecord); } } catch (Throwable e) { MessageHelper.setMessageError(e); } } public void setcatalog() { // se utiliza en la pagina del lov. RequestContext.getCurrentInstance().closeDialog(this.record); } public void setcatalog(TarmTipoArmaExplosivo armaExplosivo) { // se utiliza en la pagina del lov. RequestContext.getCurrentInstance().closeDialog(armaExplosivo); } public String getTituloLOV() { return tituloLOV; } public void setTituloLOV(String tituloLOV) { this.tituloLOV = tituloLOV; } public static void openLov(Map> params) { Map options = new HashMap(); options.put(EnumLovOption.MODAL.getLabel(), true); options.put(EnumLovOption.HEIGHT.getLabel(), 450); options.put(EnumLovOption.WIDTH.getLabel(), 700); options.put(EnumLovOption.RESIZABLE.getLabel(), false); RequestContext.getCurrentInstance().openDialog("/pages/armas/lov/armaExplosivoLov.xhtml", options, params); } public String getDescripcionClase() { return descripcionClase; } public void setDescripcionClase(String descripcionClase) { this.descripcionClase = descripcionClase; } public String getDescripcionTipo() { return descripcionTipo; } public void setDescripcionTipo(String descripcionTipo) { this.descripcionTipo = descripcionTipo; } public String getCategoriaParam() { return categoriaParam; } public void setCategoriaParam(String categoriaParam) { this.categoriaParam = categoriaParam; } }