167 lines
4.8 KiB
Plaintext
Executable File
167 lines
4.8 KiB
Plaintext
Executable File
package com.fp.frontend.controller.pgeneral.gene;
|
|
|
|
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.SubQuery;
|
|
import com.fp.dto.save.DtoSave;
|
|
import com.fp.frontend.controller.AbstractController;
|
|
import com.fp.frontend.controller.pgeneral.lov.ProcessLovControler;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.pgeneral.gene.TgeneQueryProcess;
|
|
import com.fp.persistence.pgeneral.proc.TgeneProcess;
|
|
|
|
/**
|
|
* Clase controladora del bean TgeneQueryProcess.
|
|
*
|
|
* @author Andres E. Carpio
|
|
* @version 2.1
|
|
*/
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class QueryProcessController extends AbstractController<TgeneQueryProcess> {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
public QueryProcessController() throws Exception {
|
|
super(TgeneQueryProcess.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 = "QUERYPROCESS";
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Crea una instancia de TgeneQueryProcess y marca el registro como
|
|
* nuevo.
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
@Override
|
|
public void create() throws Exception {
|
|
super.create();
|
|
}
|
|
|
|
/**
|
|
* 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 {
|
|
if(this.record.getProcesscode() == null){
|
|
MessageHelper.setMessageError("msg_processrequired");
|
|
return;
|
|
}
|
|
super.update();
|
|
}
|
|
|
|
public DtoQuery getDtoQuery() throws Exception {
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
dto.setOrderby("t.pk"); // En en string van todos los campos de orden
|
|
// ("t.pk, t.nombre, t.cpais").
|
|
|
|
// subqueries
|
|
SubQuery subquery = new SubQuery(
|
|
"TgeneProcess",
|
|
"shortdesc",
|
|
"shortdesc",
|
|
"i.pk.processcode = t.processcode and i.pk.catalogtypeprocess = t.catalogtypeprocess and i.pk.catalogcodetypeprocess = t.catalogcodetypeprocess");
|
|
dto.addSubQuery(subquery);
|
|
return dto;
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
Request request = this.callerhelper.getRequest();
|
|
DtoQuery dto = this.getDtoQuery();
|
|
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<TgeneQueryProcess>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
this.lrecord = (List<TgeneQueryProcess>) 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);
|
|
}
|
|
}
|
|
|
|
public void openProcessLov() {
|
|
Map<String, List<String>> params = new HashMap<>();
|
|
List<String> l = new ArrayList<>();
|
|
l.add("QUERY"); // valor del parametro
|
|
params.put("processtype", l);
|
|
ProcessLovControler.openLov(params);
|
|
}
|
|
|
|
public void onReturnProcessLov(SelectEvent event) throws Exception {
|
|
TgeneProcess t = (TgeneProcess) event.getObject();
|
|
this.record.setProcesscode(t.getPk().getProcesscode());
|
|
this.record.put("messagedesc", t.getDescription());
|
|
}
|
|
|
|
}
|