maia/.svn/pristine/5f/5fc7b80e1a58ed14b7c1a2c1e45...

148 lines
4.9 KiB
Plaintext
Executable File

package com.fp.frontend.controller.armas.solicitud;
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.query.SubQuery;
import com.fp.dto.save.DtoSave;
import com.fp.frontend.controller.AbstractController;
import com.fp.frontend.helper.MessageHelper;
import com.fp.persistence.parmas.soli.TarmTransaccionArmaBodega;
/**
* Clase controladora del bean TarmTransaccionArmaBodega.
*
* @author C.P.
* @version 2.1
*/
@SuppressWarnings("serial")
@ManagedBean
@ViewScoped
public class TransaccionArmaBodegaController extends AbstractController<TarmTransaccionArmaBodega> {
public TransaccionArmaBodegaController() throws Exception {
super(TarmTransaccionArmaBodega.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 = 15; // Cambiar al # reg a mirar.
this.lrecord = new ArrayList<>();
this.beanalias = "TRANSACCIONARMABODEGA";
} catch (Exception e) {
MessageHelper.setMessageError(e);
}
}
@SuppressWarnings("unchecked")
@Override
protected void querydatabase() {
try {
DtoQuery dto = super.getDtoQuery(true);
dto.setOrderby("t.pk");
SubQuery subqueryCentroControlOrig= new SubQuery("TgeneCatalogDetail","description","nombreinstitucionorig",
"i.pk.catalog= (select o.nombreinstitucion from TarmCentroControl o where o.pk=t.ccentrocontrolorigen)"
+ " and i.pk.catalogcode=(select o.nombreinstitucioncodigo from TarmCentroControl o where o.pk=t.ccentrocontrolorigen)");
dto.addSubQuery(subqueryCentroControlOrig);
SubQuery subqueryCentroControlDest= new SubQuery("TgeneCatalogDetail","description","nombreinstituciondest",
"i.pk.catalog= (select o.nombreinstitucion from TarmCentroControl o where o.pk=t.ccentrocontroldestino)"
+ " and i.pk.catalogcode=(select o.nombreinstitucioncodigo from TarmCentroControl o where o.pk=t.ccentrocontroldestino)");
dto.addSubQuery(subqueryCentroControlDest);
SubQuery subqueryPaisDes= new SubQuery("TarmCentroControl","provincecode","provincecodeorig", "i.pk=t.ccentrocontrolorigen");
dto.addSubQuery(subqueryPaisDes);
SubQuery subqueryNombreinstitucion= new SubQuery("TarmCentroControl","nombreinstitucion","nombreinstitucion", "i.pk=t.ccentrocontrolorigen");
dto.addSubQuery(subqueryNombreinstitucion);
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<TarmTransaccionArmaBodega>();
MessageHelper.setMessageError(resp);
} else {
this.lrecord = (List<TarmTransaccionArmaBodega>) resp.get(this.beanalias);
super.postQuery(this.lrecord);
}
} catch (Throwable 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);
}
}
/**
*
* @param codigo
* @return
*/
public static TarmTransaccionArmaBodega find(String codigo) {
try {
TransaccionArmaBodegaController cc = new TransaccionArmaBodegaController();
cc.init();
cc.recperpage = 300;
cc.addFilter("cdecomisoarmatransaccion", codigo);
cc.querydatabase();
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
return cc.lrecord.get(0);
}
return null;
} catch (Throwable e) {
MessageHelper.setMessageError(e);
return null;
}
}
}