225 lines
6.1 KiB
Plaintext
Executable File
225 lines
6.1 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.funcionalidad;
|
|
|
|
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.save.DtoSave;
|
|
import com.fp.frontend.controller.AbstractController;
|
|
import com.fp.frontend.enums.EnumLovOption;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.pgeneral.gene.TgeneProvince;
|
|
|
|
/**
|
|
* Clase controladora del bean TarmSitioAlmacenamiento.
|
|
*
|
|
* @author abenalcazar
|
|
*
|
|
*/
|
|
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class ProvinceLovController extends AbstractController<TgeneProvince> {
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
public ProvinceLovController() throws Exception {
|
|
super(TgeneProvince.class);
|
|
}
|
|
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
// Inicializa autoconsulta
|
|
super.startQuery();
|
|
|
|
}
|
|
|
|
/**
|
|
* Incializa el controlador, cuando se esta utilizando una pagina que utliza
|
|
* el controlador.
|
|
*/
|
|
private void init() {
|
|
try {
|
|
this.recperpage = 10; // Cambiar al # reg a mirar.
|
|
this.lrecord = new ArrayList<>();
|
|
this.beanalias = "PROVINCELOV";
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
Request request = this.callerhelper.getRequest();
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
dto.setOrderby("t.description"); // En en string van todos los
|
|
// campos de orden
|
|
// ("t.pk, t.nombre, t.cpais").
|
|
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
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<TgeneProvince>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
this.lrecord = (List<TgeneProvince>) resp.get(this.beanalias);
|
|
super.postQuery(this.lrecord);
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void save() {
|
|
try {
|
|
Request request = this.callerhelper.getRequest();
|
|
DtoSave dtosave = super.getDtoSave();
|
|
if (!dtosave.pendingProcess()) {
|
|
return;
|
|
}
|
|
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
|
|
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
|
|
public void postCommit(Response response) throws Exception {
|
|
super.postCommitGeneric(response, this.beanalias);
|
|
}
|
|
|
|
/**
|
|
* Método que entrega el listado objetos TgeneProvince provincias
|
|
*
|
|
* @param countrycode
|
|
* Código de país
|
|
* @return lrecord Lista de objetos TgeneProvince
|
|
*/
|
|
public static List<TgeneProvince> find(String countrycode) {
|
|
try {
|
|
ProvinceLovController cc = new ProvinceLovController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.addFilter("pk.countrycode", countrycode);
|
|
cc.querydatabase();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Metodo para buscar por codigo de provincia
|
|
*
|
|
* @param provincecode
|
|
* @return
|
|
*/
|
|
public static List<TgeneProvince> findPorCodigo(String countrycode,
|
|
String provincecode) {
|
|
try {
|
|
ProvinceLovController cc = new ProvinceLovController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.addFilter("pk.countrycode", countrycode);
|
|
cc.addFilter("pk.provincecode", provincecode);
|
|
cc.querydatabase();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static List<TgeneProvince> findxDescripcion(String countrycode,
|
|
String codigoProvincia, String descripcion) {
|
|
try {
|
|
ProvinceLovController cc = new ProvinceLovController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.addFilter("pk.countrycode", countrycode);
|
|
if (codigoProvincia != null && codigoProvincia.length() > 0) {
|
|
cc.addFilter("pk.provincecode", codigoProvincia);
|
|
}
|
|
if (descripcion != null && descripcion.length() > 0) {
|
|
cc.addFilter("description", descripcion);
|
|
}
|
|
cc.querydatabase();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
public static void openLov(Map<String, List<String>> params) {
|
|
Map<String, Object> options = new HashMap<String, Object>();
|
|
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/provinciaLov.xhtml", options, params);
|
|
}
|
|
|
|
public void setprovince() {
|
|
// se utiliza en la pagina del lov.
|
|
RequestContext.getCurrentInstance().closeDialog(this.record);
|
|
}
|
|
|
|
public void setprovince(TgeneProvince tgeneProvince) {
|
|
// se utiliza en la pagina del lov.
|
|
RequestContext.getCurrentInstance().closeDialog(tgeneProvince);
|
|
}
|
|
|
|
}
|