181 lines
5.0 KiB
Plaintext
Executable File
181 lines
5.0 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.funcionalidad;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.faces.bean.ManagedBean;
|
|
import javax.faces.bean.ViewScoped;
|
|
|
|
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.helper.MessageHelper;
|
|
import com.fp.persistence.parmas.fun.TarmRegistroArmas;
|
|
|
|
/**
|
|
* Clase controladora del bean TarmSolicitudImportacion.
|
|
*
|
|
* @author Andres Cevallos.
|
|
* @version 2.1
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class RegistroArmController extends AbstractController<TarmRegistroArmas> {
|
|
|
|
|
|
|
|
|
|
public RegistroArmController() throws Exception {
|
|
super(TarmRegistroArmas.class);
|
|
}
|
|
|
|
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
// Inicializa autoconsulta
|
|
super.startQuery();
|
|
//Ingreso de Datos Quemados
|
|
|
|
}
|
|
|
|
/**
|
|
* Incializa el controlador, cuando se esta utilizando una pagina que utliza
|
|
* el controlador.
|
|
*/
|
|
public void init() {
|
|
try {
|
|
this.recperpage = 15; // Cambiar al # reg a mirar.
|
|
this.lrecord = new ArrayList<>();
|
|
// record = new TarmSolicitudImportacion();
|
|
this.beanalias = "TREGISTROARMAS";
|
|
// this.create();
|
|
} 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);
|
|
}
|
|
}
|
|
|
|
|
|
public static List<TarmRegistroArmas> find() {
|
|
try {
|
|
RegistroArmController cc = new RegistroArmController();
|
|
cc.init();
|
|
cc.recperpage = 5000;
|
|
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<TarmRegistroArmas> findxPersoncode(String personcode) {
|
|
try {
|
|
RegistroArmController cc = new RegistroArmController();
|
|
cc.init();
|
|
cc.addFilter("personcode", personcode);
|
|
cc.recperpage = 5000;
|
|
cc.querydatabase();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
public static TarmRegistroArmas findByCodigo(String cRegistro) {
|
|
try {
|
|
RegistroArmController cc = new RegistroArmController();
|
|
cc.init();
|
|
cc.recperpage = 3000000;
|
|
cc.addFilter("pk", cRegistro);
|
|
cc.querydatabase();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord.get(0);
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void postCommit(Response response) throws Exception {
|
|
super.postCommitGeneric(response, this.beanalias);
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
Request request = this.callerhelper.getRequest();
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
dto.setOrderby("t.pk"); // 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<TarmRegistroArmas>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
this.lrecord = (List<TarmRegistroArmas>) resp.get(this.beanalias);
|
|
super.postQuery(this.lrecord);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
|
|
}
|
|
|
|
public void update(TarmRegistroArmas bean) throws Exception {
|
|
record=bean;
|
|
update();
|
|
}
|
|
} |