174 lines
4.7 KiB
Plaintext
Executable File
174 lines
4.7 KiB
Plaintext
Executable File
package com.fp.frontend.controller.pgeneral.product;
|
|
|
|
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.pgeneral.product.TgeneModule;
|
|
import com.fp.persistence.pgeneral.product.TgeneProduct;
|
|
|
|
/**
|
|
* Clase controladora del bean TgeneProduct.
|
|
*
|
|
* @author Jorge Vaca.
|
|
* @version 2.1
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class ProductController extends AbstractController<TgeneProduct> {
|
|
|
|
|
|
List<TgeneModule> lmodules;
|
|
|
|
public ProductController() throws Exception {
|
|
super(TgeneProduct.class);
|
|
}
|
|
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
// Inicializa autoconsulta
|
|
super.startQuery();
|
|
this.lmodules = ModuleController.find();
|
|
}
|
|
|
|
/**
|
|
* Incializa el controlador, cuando se esta utilizando una pagina que utliza el controlador.
|
|
*/
|
|
private void init() {
|
|
try {
|
|
this.recperpage = 500; // Cambiar al # reg a mirar.
|
|
this.lrecord = new ArrayList<>();
|
|
this.beanalias = "PRODUCT";
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Crea una instancia de TgeneTransactionProcess y marca el registro como nuevo.
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
@Override
|
|
public void create() throws Exception {
|
|
super.create();
|
|
this.record.getPk().setModulecode(super.getMfilters().get("pk.modulecode"));
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
String module = super.getMfilters().get("pk.modulecode");
|
|
if ((module==null) || module.isEmpty()) {
|
|
MessageHelper.setMessageError("msg_modulerequird");
|
|
return;
|
|
}
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
dto.setOrderby("t.pk.productcode");
|
|
|
|
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<TgeneProduct>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
this.lrecord = (List<TgeneProduct>) 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);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void postCommit(Response response) throws Exception {
|
|
super.postCommitGeneric(response, this.beanalias);
|
|
}
|
|
|
|
|
|
public void changemodule() throws Exception {
|
|
//Metodo dummy es necesario para actualizar datos del filtro para ejecutar la consulta.
|
|
this.querydatabase();
|
|
}
|
|
|
|
public static List<TgeneProduct> find(String modulecode) {
|
|
try {
|
|
ProductController pc = new ProductController();
|
|
pc.addFilter("pk.modulecode", modulecode);
|
|
pc.init();
|
|
pc.recperpage = 300;
|
|
pc.querydatabase();
|
|
if ((pc.lrecord != null) && !pc.lrecord.isEmpty()) {
|
|
return pc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Entrega el valor de: lmodules
|
|
* @return List<TgeneModule>
|
|
*/
|
|
public List<TgeneModule> getLmodules() {
|
|
return this.lmodules;
|
|
}
|
|
|
|
/**
|
|
* Fija el valor de: lmodules
|
|
* @param lmodules Valor a fijar en el atributo.
|
|
*/
|
|
|
|
public void setLmodules(List<TgeneModule> lmodules) {
|
|
this.lmodules = lmodules;
|
|
}
|
|
|
|
|
|
}
|