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.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.TarmSitioAlmacenamiento; import com.fp.persistence.pgeneral.gene.TgeneCityKey; /** * Clase controladora del lov asociado al bean TgeneCatalog. * * @author Jorge Vaca. * @version 2.1 */ @ManagedBean @ViewScoped public class SitioAlmacenamientoLovController extends AbstractController { private static final long serialVersionUID = 1L; public SitioAlmacenamientoLovController() throws Exception { super(TarmSitioAlmacenamiento.class); } @PostConstruct private void postconstruct() { this.init(); try { String codeperson = CallerHelper.getLovParameter("personcode"); if (codeperson != null) { super.addFilter("personcode", codeperson); this.querydatabase(); } super.startQuery(); } catch (Exception e) { MessageHelper.setMessageError(e); } } /** * Incializa el controlador, cuando se esta utilizando una pagina que utliza el controlador. */ private void init() { try { this.recperpage = 200; // Cambiar al # reg a mirar. this.lrecord = new ArrayList<>(); this.beanalias = "CATALOGLOV"; } catch (Exception e) { MessageHelper.setMessageError(e); } } @SuppressWarnings("unchecked") @Override protected void querydatabase() { try { this.addFilter("estado", "ACT"); Request request = this.callerhelper.getRequest(); DtoQuery dto = super.getDtoQuery(true); dto.setOrderby("t.pk"); SubQuery subqueryProvincia = new SubQuery("TgeneProvince", "description", "provincia", "i.pk.provincecode = t.provincecode and i.pk.countrycode = t.countrycode"); dto.addSubQuery(subqueryProvincia); SubQuery subqueryCanton = new SubQuery("TgeneCanton", "description", "canton", "i.pk.provincecode = t.provincecode and i.pk.countrycode = t.countrycode and i.pk.cantoncode=t.cantoncode"); dto.addSubQuery(subqueryCanton); SubQuery subqueryCiudad = new SubQuery("TgeneCity", "description", "ciudad", "i.pk.provincecode = t.provincecode and i.pk.countrycode = t.countrycode and i.pk.cantoncode=t.cantoncode "); dto.addSubQuery(subqueryCiudad); SubQuery subqueryParroquia = new SubQuery("TgeneParroquia", "description", "parroquia", "i.pk.provincecode = t.provincecode and i.pk.countrycode = t.countrycode and i.pk.cantoncode=t.cantoncode and i.pk.parroquiacode=t.parroquiacode"); dto.addSubQuery(subqueryParroquia); 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(TarmSitioAlmacenamiento tarmSitioAlmacenamiento) { // se utiliza en la pagina del lov. RequestContext.getCurrentInstance().closeDialog(tarmSitioAlmacenamiento); } 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/sitioAlmacenamientoLov.xhtml", options, params); } }