463 lines
16 KiB
Plaintext
Executable File
463 lines
16 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.parametros;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
import javax.annotation.PostConstruct;
|
||
import javax.faces.application.FacesMessage;
|
||
import javax.faces.bean.ManagedBean;
|
||
import javax.faces.bean.ViewScoped;
|
||
import javax.faces.context.FacesContext;
|
||
|
||
import org.primefaces.context.RequestContext;
|
||
import org.primefaces.event.SelectEvent;
|
||
|
||
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.dto.save.DtoSave;
|
||
import com.fp.frontend.controller.AbstractController;
|
||
import com.fp.frontend.controller.pgeneral.gene.CatalogDetailController;
|
||
import com.fp.frontend.helper.MessageHelper;
|
||
import com.fp.persistence.parmas.param.TarmOrigenTramite;
|
||
import com.fp.persistence.parmas.param.TarmOrigenTramiteKey;
|
||
import com.fp.persistence.parmas.param.TarmTipoTramite;
|
||
import com.fp.persistence.parmas.param.TarmTramite;
|
||
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail;
|
||
|
||
/**
|
||
* Clase controladora de ingreso de tramites de control de armas.
|
||
*
|
||
* @author Jorge Vaca.
|
||
* @author dcruz
|
||
* @version 2.1
|
||
*/
|
||
@SuppressWarnings("serial")
|
||
@ManagedBean
|
||
@ViewScoped
|
||
public class OrigenTramiteController extends AbstractController<TarmOrigenTramite> {
|
||
|
||
private TarmTipoTramite tipoTramite;
|
||
private String origenAdquisicion;
|
||
private String tipoPersona;
|
||
private String tipoDeTramite;
|
||
private String tipoAutorizacion;
|
||
private String categoria;
|
||
private String actividad;
|
||
private String tipoDeTramiteD;
|
||
private String tipoAutorizacionD;
|
||
private String categoriaD;
|
||
private String actividadD;
|
||
private String origenAdquisicionD;
|
||
/**
|
||
* Trámite seleccionado
|
||
*/
|
||
private TarmTramite tarmTramite;
|
||
|
||
/**
|
||
* Lista de origen de adquisición
|
||
*/
|
||
private List<TgeneCatalogDetail> lorigenadquisicion;
|
||
|
||
|
||
public OrigenTramiteController() throws Exception {
|
||
super(TarmOrigenTramite.class);
|
||
}
|
||
|
||
@PostConstruct
|
||
private void postconstruct() {
|
||
try {
|
||
init();
|
||
} catch (Exception e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Incializa el controlador, cuando se esta utilizando una pagina que utliza el controlador.
|
||
* @throws Exception
|
||
*/
|
||
private void init() throws Exception {
|
||
try{
|
||
this.beanalias="ORIGENTRAMITE";
|
||
this.recperpage = 15; // Cambiar al # reg a mirar.
|
||
this.lrecord = new ArrayList<TarmOrigenTramite>();
|
||
this.record = new TarmOrigenTramite();
|
||
this.record.setPk(new TarmOrigenTramiteKey());
|
||
lorigenadquisicion = CatalogDetailController.find("ORIGENADQUISICION");
|
||
} catch (Exception e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void save() {
|
||
try {
|
||
DtoSave dtosave = super.getDtoSave();
|
||
dtosave.setReturnpk(true); // Para que el core devuelva el pk de los registros nuevos.
|
||
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
|
||
|
||
Request request = this.callerhelper.getRequest();
|
||
msave.put(this.beanalias, dtosave); // adicionar metadata de mantenimiento para cada tabla.
|
||
|
||
request.setSaveTables(msave);
|
||
Response resp = this.callerhelper.executeSave(request);
|
||
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
|
||
this.postCommit(resp);
|
||
MessageHelper.setMessageInfo(resp);
|
||
} else {
|
||
MessageHelper.setMessageError(resp);
|
||
}
|
||
} catch (Throwable e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
|
||
@Override
|
||
protected void querydatabase() {
|
||
try {
|
||
if((this.origenAdquisicion == null || this.origenAdquisicion.equals("")) && this.tarmTramite == null){
|
||
MessageHelper.setMessageError("DEBE SELECCIONAR UN TRAMITE O UN ORIGEN DE ADQUISICI<43>N PARA REALIZAR LA BUSQUEDA");
|
||
return;
|
||
}
|
||
|
||
Boolean existeFiltro = Boolean.FALSE;
|
||
DtoQuery dto = super.getDtoQuery(true);
|
||
|
||
SubQuery tramiteSQ = new SubQuery("TgeneCatalogDetail", "description", "tipoAutorizacion",
|
||
"i.pk.catalog = (select a.tipoautorizacion from TarmTramite a where a.pk = t.pk.ctramite) "
|
||
+ " and "
|
||
+ "i.pk.catalogcode = (select a.tipoautorizacioncodigo from TarmTramite a where a.pk = t.pk.ctramite)");
|
||
dto.addSubQuery(tramiteSQ);
|
||
|
||
SubQuery tipoTramiteSQ = new SubQuery("TgeneCatalogDetail", "description", "tipoDeTramite",
|
||
"i.pk.catalog = (select a.tipotramite from TarmTramite a where a.pk = t.pk.ctramite) "
|
||
+ " and "
|
||
+ "i.pk.catalogcode = (select a.tipotramitecodigo from TarmTramite a where a.pk = t.pk.ctramite)");
|
||
dto.addSubQuery(tipoTramiteSQ);
|
||
|
||
SubQuery categoriaSQ = new SubQuery("TgeneCatalogDetail", "description", "categoria",
|
||
"i.pk.catalog = (select a.categoria from TarmTramite a where a.pk = t.pk.ctramite) "
|
||
+ " and "
|
||
+ "i.pk.catalogcode = (select a.categoriacodigo from TarmTramite a where a.pk = t.pk.ctramite)");
|
||
dto.addSubQuery(categoriaSQ);
|
||
|
||
SubQuery usoActividadSQ = new SubQuery("TgeneCatalogDetail", "description", "actividad",
|
||
"i.pk.catalog = (select a.usoactividad from TarmTramite a where a.pk = t.pk.ctramite) "
|
||
+ " and "
|
||
+ "i.pk.catalogcode = (select a.usoactividadcodigo from TarmTramite a where a.pk = t.pk.ctramite)");
|
||
dto.addSubQuery(usoActividadSQ);
|
||
|
||
SubQuery adquisicionSQ = new SubQuery("TgeneCatalogDetail", "description", "adquisicion",
|
||
"i.pk.catalog = t.pk.origencatalog and i.pk.catalogcode = t.pk.origencatalogcode");
|
||
dto.addSubQuery(adquisicionSQ);
|
||
|
||
|
||
Filter filtro=new Filter();
|
||
StringBuilder sql = new StringBuilder();
|
||
if(this.origenAdquisicion != null && !this.origenAdquisicion.equals("")){
|
||
sql.append("t.pk.origencatalog='"+this.origenAdquisicion+"'");
|
||
existeFiltro = Boolean.TRUE;
|
||
}
|
||
if(this.tarmTramite!=null){
|
||
if(this.origenAdquisicion != null && !this.origenAdquisicion.equals("")){
|
||
sql.append(" and ");
|
||
}
|
||
sql.append("t.pk.ctramite='"+this.tarmTramite.getPk()+"'");
|
||
existeFiltro = Boolean.TRUE;
|
||
}
|
||
if(existeFiltro){
|
||
filtro.setSql(sql.toString());
|
||
dto.addFiltro(filtro);
|
||
}
|
||
|
||
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
||
mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla.
|
||
|
||
Request request = this.callerhelper.getRequest();
|
||
request.setQueryTables(mtables);
|
||
|
||
Response resp = this.callerhelper.executeQuery(request);
|
||
|
||
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
||
this.lrecord = new ArrayList<TarmOrigenTramite>();
|
||
MessageHelper.setMessageError(resp);
|
||
} else {
|
||
this.lrecord = (List<TarmOrigenTramite>) resp.get(this.beanalias);
|
||
super.postQuery(this.lrecord);
|
||
}
|
||
|
||
} catch (Throwable e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
protected void querydatabasesimple() {
|
||
try {
|
||
|
||
Boolean existeFiltro = Boolean.FALSE;
|
||
DtoQuery dto = super.getDtoQuery(true);
|
||
Filter filtro=new Filter();
|
||
StringBuilder sql = new StringBuilder();
|
||
|
||
if(this.tarmTramite!=null){
|
||
sql.append("t.pk.ctramite='"+this.tarmTramite.getPk()+"'");
|
||
existeFiltro = Boolean.TRUE;
|
||
}
|
||
if(existeFiltro){
|
||
filtro.setSql(sql.toString());
|
||
dto.addFiltro(filtro);
|
||
}
|
||
|
||
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
||
mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla.
|
||
|
||
Request request = this.callerhelper.getRequest();
|
||
request.setQueryTables(mtables);
|
||
|
||
Response resp = this.callerhelper.executeQuery(request);
|
||
|
||
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
||
this.lrecord = new ArrayList<TarmOrigenTramite>();
|
||
MessageHelper.setMessageError(resp);
|
||
} else {
|
||
this.lrecord = (List<TarmOrigenTramite>) resp.get(this.beanalias);
|
||
super.postQuery(this.lrecord);
|
||
}
|
||
|
||
} catch (Throwable e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* Abre el LOV de trámite
|
||
*/
|
||
public void openLovTramite() {
|
||
Map<String, List<String>> params = new HashMap<String, List<String>>();
|
||
List<String> ltipopersona = new ArrayList<>();
|
||
|
||
|
||
// ltipopersona.add(ParametersController.find("CODIGO.PERSONTYPE.NATURAL", "1").getTextvalue());//1
|
||
//
|
||
// ltipopersona.add(ParametersController.find("CODIGO.PERSONTYPE.JURIDICA", "1").getTextvalue());//2
|
||
//
|
||
//
|
||
// params.put("tipopersonasol", ltipopersona);
|
||
BuscarTramiteLovController.openLov(params);
|
||
}
|
||
|
||
/**
|
||
* Regresa del LOV para cargar valores
|
||
* @param event {@link SelectEvent}
|
||
*/
|
||
public void onReturnTramite(SelectEvent event) {
|
||
try{
|
||
TarmTramite tramite = (TarmTramite) event.getObject();
|
||
this.tarmTramite = tramite;
|
||
TgeneCatalogDetail tipoTramiteCD = CatalogDetailController.findxCodigoCodcatalogo(tramite.getTipotramite(), tramite.getTipotramitecodigo());
|
||
TgeneCatalogDetail tipoAutorizacionCD = CatalogDetailController.findxCodigoCodcatalogo(tramite.getTipoautorizacion(), tramite.getTipoautorizacioncodigo());
|
||
TgeneCatalogDetail categoriaCD = CatalogDetailController.findxCodigoCodcatalogo(tramite.getCategoria(), tramite.getCategoriacodigo());
|
||
TgeneCatalogDetail actividadCD = CatalogDetailController.findxCodigoCodcatalogo(tramite.getUsoactividad(), tramite.getUsoactividadcodigo());
|
||
tipoDeTramite = tipoTramiteCD!=null?tipoTramiteCD.getDescription():"";
|
||
tipoAutorizacion = tipoAutorizacionCD!=null?tipoAutorizacionCD.getDescription():"";
|
||
categoria=categoriaCD!=null?categoriaCD.getDescription():"";
|
||
actividad=actividadCD!=null?actividadCD.getDescription():"";
|
||
} catch(Throwable e){
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Regresa del LOV para cargar valores
|
||
* @param event {@link SelectEvent}
|
||
*/
|
||
public void onReturnTramiteDialog(SelectEvent event) {
|
||
try{
|
||
TarmTramite tramite = (TarmTramite) event.getObject();
|
||
this.tarmTramite = tramite;
|
||
TgeneCatalogDetail tipoTramiteCD = CatalogDetailController.findxCodigoCodcatalogo(tramite.getTipotramite(), tramite.getTipotramitecodigo());
|
||
TgeneCatalogDetail tipoAutorizacionCD = CatalogDetailController.findxCodigoCodcatalogo(tramite.getTipoautorizacion(), tramite.getTipoautorizacioncodigo());
|
||
TgeneCatalogDetail categoriaCD = CatalogDetailController.findxCodigoCodcatalogo(tramite.getCategoria(), tramite.getCategoriacodigo());
|
||
TgeneCatalogDetail actividadCD = CatalogDetailController.findxCodigoCodcatalogo(tramite.getUsoactividad(), tramite.getUsoactividadcodigo());
|
||
TgeneCatalogDetail adquisicionCD = CatalogDetailController.findxCodigoCodcatalogo(tramite.getUsoactividad(), tramite.getUsoactividadcodigo());
|
||
record.getModifiedData().put("tipoDeTramite", tipoTramiteCD!=null?tipoTramiteCD.getDescription():"");
|
||
record.getModifiedData().put("tipoAutorizacion", tipoAutorizacionCD!=null?tipoAutorizacionCD.getDescription():"");
|
||
record.getModifiedData().put("categoria", categoriaCD!=null?categoriaCD.getDescription():"");
|
||
record.getModifiedData().put("actividad", actividadCD!=null?actividadCD.getDescription():"");
|
||
record.getModifiedData().put("adquisicion", adquisicionCD!=null?adquisicionCD.getDescription():"");
|
||
this.record.getPk().setCtramite(tramite.getPk());
|
||
} catch(Throwable e){
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Regresa del LOV para cargar valores
|
||
*
|
||
* @param tarmTramite Tarm Tramite
|
||
* @param event
|
||
* {@link SelectEvent}
|
||
*/
|
||
public static List<TarmOrigenTramite> findOrigenTramite(TarmTramite tarmTramite) {
|
||
try {
|
||
OrigenTramiteController cc = new OrigenTramiteController();
|
||
cc.init();
|
||
cc.recperpage = 1000;
|
||
cc.setTarmTramite(tarmTramite);
|
||
cc.querydatabasesimple();
|
||
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
||
return cc.lrecord;
|
||
}
|
||
return null;
|
||
|
||
} catch (Throwable e) {
|
||
MessageHelper.setMessageError(e);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Actualiza la lista de registros a grabar
|
||
*
|
||
* @throws Exception
|
||
*/
|
||
public void update() throws Exception {
|
||
|
||
if(this.record.getPk().getCtramite()==null){
|
||
MessageHelper.setMessageError("DEBE SELECCIONAR UN TRAMITE","formOrigenTramiteDialog");
|
||
return;
|
||
}
|
||
|
||
this.record.getPk().setOrigencatalogcode("ORIGENADQUISICION");
|
||
TgeneCatalogDetail adquisicionCD = CatalogDetailController.findxCodigoCodcatalogo(this.record.getPk().getOrigencatalog(), this.record.getPk().getOrigencatalogcode());
|
||
record.getModifiedData().put("adquisicion", adquisicionCD!=null?adquisicionCD.getDescription():"");
|
||
super.update();
|
||
tarmTramite = null;
|
||
origenAdquisicion = null;
|
||
}
|
||
|
||
|
||
public TarmTipoTramite getTipoTramite() {
|
||
return tipoTramite;
|
||
}
|
||
|
||
public void setTipoTramite(TarmTipoTramite tipoTramite) {
|
||
this.tipoTramite = tipoTramite;
|
||
}
|
||
|
||
public String getOrigenAdquisicion() {
|
||
return origenAdquisicion;
|
||
}
|
||
|
||
public void setOrigenAdquisicion(String origenAdquisicion) {
|
||
this.origenAdquisicion = origenAdquisicion;
|
||
}
|
||
|
||
public List<TgeneCatalogDetail> getLorigenadquisicion() {
|
||
return lorigenadquisicion;
|
||
}
|
||
|
||
public void setLorigenadquisicion(List<TgeneCatalogDetail> lorigenadquisicion) {
|
||
this.lorigenadquisicion = lorigenadquisicion;
|
||
}
|
||
|
||
public String getTipoPersona() {
|
||
return tipoPersona;
|
||
}
|
||
|
||
public void setTipoPersona(String tipoPersona) {
|
||
this.tipoPersona = tipoPersona;
|
||
}
|
||
|
||
public TarmTramite getTarmTramite() {
|
||
return tarmTramite;
|
||
}
|
||
|
||
public void setTarmTramite(TarmTramite tarmTramite) {
|
||
this.tarmTramite = tarmTramite;
|
||
}
|
||
|
||
public String getTipoAutorizacion() {
|
||
return tipoAutorizacion;
|
||
}
|
||
|
||
public void setTipoAutorizacion(String tipoAutorizacion) {
|
||
this.tipoAutorizacion = tipoAutorizacion;
|
||
}
|
||
|
||
public String getCategoria() {
|
||
return categoria;
|
||
}
|
||
|
||
public void setCategoria(String categoria) {
|
||
this.categoria = categoria;
|
||
}
|
||
|
||
public String getActividad() {
|
||
return actividad;
|
||
}
|
||
|
||
public void setActividad(String actividad) {
|
||
this.actividad = actividad;
|
||
}
|
||
|
||
public String getTipoDeTramite() {
|
||
return tipoDeTramite;
|
||
}
|
||
|
||
public void setTipoDeTramite(String tipoDeTramite) {
|
||
this.tipoDeTramite = tipoDeTramite;
|
||
}
|
||
|
||
public String getTipoDeTramiteD() {
|
||
return tipoDeTramiteD;
|
||
}
|
||
|
||
public void setTipoDeTramiteD(String tipoDeTramiteD) {
|
||
this.tipoDeTramiteD = tipoDeTramiteD;
|
||
}
|
||
|
||
public String getTipoAutorizacionD() {
|
||
return tipoAutorizacionD;
|
||
}
|
||
|
||
public void setTipoAutorizacionD(String tipoAutorizacionD) {
|
||
this.tipoAutorizacionD = tipoAutorizacionD;
|
||
}
|
||
|
||
public String getCategoriaD() {
|
||
return categoriaD;
|
||
}
|
||
|
||
public void setCategoriaD(String categoriaD) {
|
||
this.categoriaD = categoriaD;
|
||
}
|
||
|
||
public String getActividadD() {
|
||
return actividadD;
|
||
}
|
||
|
||
public void setActividadD(String actividadD) {
|
||
this.actividadD = actividadD;
|
||
}
|
||
|
||
public String getOrigenAdquisicionD() {
|
||
return origenAdquisicionD;
|
||
}
|
||
|
||
public void setOrigenAdquisicionD(String origenAdquisicionD) {
|
||
this.origenAdquisicionD = origenAdquisicionD;
|
||
}
|
||
|
||
|
||
|
||
}
|