433 lines
13 KiB
Plaintext
Executable File
433 lines
13 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.bean.ManagedBean;
|
|
import javax.faces.bean.ViewScoped;
|
|
|
|
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.TarmRequisito;
|
|
import com.fp.persistence.parmas.param.TarmRequisitoPorTipoTramite;
|
|
import com.fp.persistence.parmas.param.TarmTramite;
|
|
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail;
|
|
|
|
/**
|
|
* Clase controladora del bean requisitos por tramite, tabla TarmRequisitoPorTipoTramite
|
|
*
|
|
* @author Christian Pazmino
|
|
* @version 2.1
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
@ManagedBean(name = "requisitoPorTramiteController")
|
|
@ViewScoped
|
|
public class RequisitoPorTramiteController extends
|
|
AbstractController<TarmRequisitoPorTipoTramite> {
|
|
/**
|
|
* Lista de tipos de tramites
|
|
*/
|
|
List<TgeneCatalogDetail> ltipotramite;
|
|
|
|
/**
|
|
* Lista de tipos de requisitos
|
|
*/
|
|
List<TarmRequisito> lrequisito;
|
|
|
|
/**
|
|
* Booleano que indica si el deposito es por tramite
|
|
*/
|
|
private boolean depositoPorTramite;
|
|
/**
|
|
* Booleano que indica si el deposito es por custodio
|
|
*/
|
|
private boolean depositoPorCustodio;
|
|
/**
|
|
* Codigo de tramite
|
|
*/
|
|
private Long cTramite;
|
|
|
|
public RequisitoPorTramiteController() throws Exception {
|
|
super(TarmRequisitoPorTipoTramite.class);
|
|
}
|
|
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
ltipotramite = CatalogDetailController.find("TIPOTRAMITE");
|
|
lrequisito = RequisitoController.findActivos();
|
|
// Inicializa autoconsulta
|
|
super.startQuery();
|
|
|
|
}
|
|
|
|
/**
|
|
* Incializa el controlador, cuando se esta utilizando una pagina que utliza
|
|
* el controlador.
|
|
*/
|
|
private void init() {
|
|
try {
|
|
recperpage = 10; // Cambiar al # reg a mirar.
|
|
lrecord = new ArrayList<>();
|
|
beanalias = "REQUISITOPORTRAMITE";
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Crea una instancia de TarmRequisitoPorTipoTramite y marca el registro como nuevo.
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
@Override
|
|
public void create() throws Exception {
|
|
if (cTramite==null) {
|
|
MessageHelper.setMessageError("POR FAVOR SELECCIONE UN TR\u00c1MITE");
|
|
return;
|
|
}
|
|
super.create();
|
|
this.record.setActive("Y");
|
|
depositoPorCustodio = false;
|
|
depositoPorTramite = false;
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
if(cTramite!=null){
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
dto.setOrderby("t.pk.crequisito");
|
|
Filter filtro = new Filter();
|
|
filtro.setSql(" t.active = 'Y'");
|
|
dto.addFiltro(filtro);
|
|
// Subquery
|
|
SubQuery subquerypk = new SubQuery("TarmRequisito", "pk", "crequisito", "i.pk = t.pk.crequisito");
|
|
dto.addSubQuery(subquerypk);
|
|
SubQuery subquery = new SubQuery("TarmRequisito", "nombre", "nrequisito", "i.pk = t.pk.crequisito");
|
|
dto.addSubQuery(subquery);
|
|
SubQuery subqueryDescCorta = new SubQuery("TarmRequisito", "descripcioncorta", "ndescripcion", "i.pk = t.pk.crequisito");
|
|
dto.addSubQuery(subqueryDescCorta);
|
|
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
mtables.put(beanalias, dto); // permite adicionar mas de una tabla.
|
|
|
|
Request request = callerhelper.getRequest();
|
|
request.setQueryTables(mtables);
|
|
|
|
Response resp = callerhelper.executeQuery(request);
|
|
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
|
lrecord = new ArrayList<TarmRequisitoPorTipoTramite>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
lrecord = (List<TarmRequisitoPorTipoTramite>) resp
|
|
.get(beanalias);
|
|
super.postQuery(lrecord);
|
|
}
|
|
}
|
|
else{
|
|
MessageHelper.setMessageError("POR FAVOR SELECCIONE UN TR\u00c1MITE");
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
protected void querydatabaseConsultas() {
|
|
try {
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
dto.setOrderby("t.pk.crequisito");
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
mtables.put(beanalias, dto); // permite adicionar mas de una tabla.
|
|
|
|
Request request = callerhelper.getRequest();
|
|
request.setQueryTables(mtables);
|
|
Response resp = callerhelper.executeQuery(request);
|
|
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
|
lrecord = new ArrayList<TarmRequisitoPorTipoTramite>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
lrecord = (List<TarmRequisitoPorTipoTramite>) resp.get(beanalias);
|
|
super.postQuery(lrecord);
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Actualiza datos de registros nuevos o modifiados, si el registro es nuevo
|
|
* se adiciona a lista de nuevos, si es actualizado se adiciona a la lista
|
|
* de actualizados.
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
@Override
|
|
public void update() throws Exception {
|
|
List<TarmRequisitoPorTipoTramite> lista = findInactiveTramiteRequisito(cTramite.toString(), record.getPk().getCrequisito());
|
|
if(lista != null && !lista.isEmpty()){
|
|
System.out.println("existe resultado : " + lista.get(0).getPk().getCrequisito() + "------------- " + lista.get(0).getPk().getCtramite());
|
|
record.setIsnew(false);
|
|
record.put("ORIGINALBEAN", lista.get(0).get("ORIGINALBEAN"));
|
|
this.lrecord.add(record);
|
|
}
|
|
super.update();
|
|
}
|
|
|
|
@Override
|
|
public void save() {
|
|
try {
|
|
DtoSave dtosave = super.getDtoSave();
|
|
if(!dtosave.pendingProcess()){
|
|
return;
|
|
}
|
|
dtosave.setReturnpk(true); // Para que el core devuelva el pk de los
|
|
// registros nuevos.
|
|
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
|
|
|
|
Request request = callerhelper.getRequest();
|
|
msave.put(beanalias, dtosave); // adicionar metadata de
|
|
// mantenimiento para cada tabla.
|
|
|
|
request.setSaveTables(msave);
|
|
Response resp = 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);
|
|
}
|
|
}
|
|
|
|
public void borrarRequisitos(){
|
|
try {
|
|
this.record.setActive("N");
|
|
update();
|
|
this.lrecord.remove(this.record);
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
public void postCommit(Response response) throws Exception {
|
|
super.postCommitGeneric(response, beanalias);
|
|
}
|
|
|
|
/**
|
|
* Fija la descripcion del requisito desde el dialogo de requisitos en el objeto record a persistir
|
|
*/
|
|
public void setNombreReqisito() {
|
|
for (TarmRequisito r : lrequisito) {
|
|
if (r.getPk().compareTo(record.getPk().getCrequisito()) == 0) {
|
|
record.put("nrequisito", r.getNombre());
|
|
}
|
|
}
|
|
record.getPk().setCtramite(cTramite);
|
|
}
|
|
|
|
public List<TgeneCatalogDetail> getLtipotramite() {
|
|
return ltipotramite;
|
|
}
|
|
|
|
public void setLtipotramite(List<TgeneCatalogDetail> ltipotramite) {
|
|
this.ltipotramite = ltipotramite;
|
|
}
|
|
|
|
/**
|
|
* @return the lrequisito
|
|
*/
|
|
public List<TarmRequisito> getLrequisito() {
|
|
return lrequisito;
|
|
}
|
|
|
|
/**
|
|
* @param lrequisito
|
|
* the lrequisito to set
|
|
*/
|
|
public void setLrequisito(List<TarmRequisito> lrequisito) {
|
|
this.lrequisito = lrequisito;
|
|
}
|
|
|
|
/**
|
|
* Consulta una lista de requisitos por tipo de tramite.
|
|
*
|
|
* @param ctipotramite
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public static List<TarmRequisitoPorTipoTramite> find(String ctipotramite)
|
|
throws Exception {
|
|
RequisitoPorTramiteController r = new RequisitoPorTramiteController();
|
|
r.addFilter("pk.ctipotramite", ctipotramite);
|
|
r.querydatabase();
|
|
return r.getLrecord();
|
|
}
|
|
|
|
public static List<TarmRequisitoPorTipoTramite> findxrequisito(String crequisito)
|
|
throws Exception {
|
|
RequisitoPorTramiteController r = new RequisitoPorTramiteController();
|
|
r.addFilter("pk.crequisito", crequisito);
|
|
r.querydatabasesimple();
|
|
return r.getLrecord();
|
|
}
|
|
|
|
/**
|
|
* Metodo que encuentra TarmRequisitoPorTipoTramite por tramite y por requisito en estado inactivo
|
|
* @param codigoSolicitud
|
|
* @return
|
|
*/
|
|
public static List<TarmRequisitoPorTipoTramite> findInactiveTramiteRequisito(String tramite, String requisito) {
|
|
try {
|
|
RequisitoPorTramiteController cc = new RequisitoPorTramiteController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
if(tramite != null){
|
|
cc.addFilter("pk.ctramite", tramite);
|
|
}
|
|
if(requisito != null){
|
|
cc.addFilter("pk.crequisito", requisito);
|
|
}
|
|
cc.addFilter("active", "N");
|
|
cc.querydatabaseConsultas();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public boolean isDepositoPorTramite() {
|
|
return depositoPorTramite;
|
|
}
|
|
|
|
public void setDepositoPorTramite(boolean depositoPorTramite) {
|
|
this.depositoPorTramite = depositoPorTramite;
|
|
}
|
|
|
|
public boolean isDepositoPorCustodio() {
|
|
return depositoPorCustodio;
|
|
}
|
|
|
|
public void setDepositoPorCustodio(boolean depositoPorCustodio) {
|
|
this.depositoPorCustodio = depositoPorCustodio;
|
|
}
|
|
|
|
public Long getcTramite() {
|
|
return cTramite;
|
|
}
|
|
|
|
public void setcTramite(Long cTramite) {
|
|
this.cTramite = cTramite;
|
|
}
|
|
|
|
/**
|
|
* Método para manejar el evento change en el CheckBox DepositoPorTramite
|
|
*/
|
|
public void onChangeDepositoPorTramite() {
|
|
if (depositoPorTramite) {
|
|
record.setDepositoportramite("Y");
|
|
} else {
|
|
record.setDepositoportramite("N");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Método para manejar el evento change en el CheckBox DepositoPorCustodio
|
|
*/
|
|
public void onChangeDepositoPorCustodio() {
|
|
if (depositoPorCustodio) {
|
|
record.setDepositoporcustodio("Y");
|
|
} else {
|
|
record.setDepositoporcustodio("N");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Abre el dialog para seleccionar un tramite
|
|
*/
|
|
public void openRequisitosPorTramiteLov() {
|
|
Map<String, List<String>> params = new HashMap<>();
|
|
BuscarTramiteLovController.openLov(params);
|
|
}
|
|
|
|
/**
|
|
* Completa las acciones pertinentes al momento en que se cierra el dialog para seleccionar un tramite
|
|
*/
|
|
public void onReturnRequisitosPorTramiteLov(SelectEvent event)
|
|
throws Exception {
|
|
TarmTramite t = (TarmTramite) event.getObject();
|
|
super.addFilter("pk.ctramite", t.getPk().toString());
|
|
super.addField("tipoTramiteName",
|
|
t.getModifiedData().get("destipoTramite"));
|
|
super.addField("tipoAutorizacionName",
|
|
t.getModifiedData().get("destipoAutorizacion"));
|
|
super.addField("categoriaName", t.getModifiedData().get("descategoria"));
|
|
super.addField("usoActividadName",
|
|
t.getModifiedData().get("desusoactividad"));
|
|
cTramite = t.getPk();
|
|
this.query();
|
|
}
|
|
|
|
protected void querydatabasesimple() {
|
|
try {
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
dto.setOrderby("t.pk.crequisito");
|
|
Filter filtro = new Filter();
|
|
filtro.setSql(" t.active = 'Y'");
|
|
dto.addFiltro(filtro);
|
|
// Subquery
|
|
SubQuery subquery = new SubQuery("TarmRequisito", "nombre", "nrequisito", "i.pk = t.pk.crequisito");
|
|
dto.addSubQuery(subquery);
|
|
SubQuery subqueryDescCorta = new SubQuery("TarmRequisito", "descripcioncorta", "ndescripcion", "i.pk = t.pk.crequisito");
|
|
dto.addSubQuery(subqueryDescCorta);
|
|
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
mtables.put(beanalias, dto); // permite adicionar mas de una tabla.
|
|
|
|
Request request = callerhelper.getRequest();
|
|
request.setQueryTables(mtables);
|
|
|
|
Response resp = callerhelper.executeQuery(request);
|
|
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
|
lrecord = new ArrayList<TarmRequisitoPorTipoTramite>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
lrecord = (List<TarmRequisitoPorTipoTramite>) resp.get(beanalias);
|
|
super.postQuery(lrecord);
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
}
|