465 lines
12 KiB
Plaintext
Executable File
465 lines
12 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.eval;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
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.ManagedProperty;
|
|
import javax.faces.bean.ViewScoped;
|
|
|
|
|
|
|
|
import org.primefaces.context.RequestContext;
|
|
|
|
import com.fp.dto.AbstractDataTransport;
|
|
import com.fp.dto.Request;
|
|
import com.fp.dto.Response;
|
|
import com.fp.dto.save.DtoSave;
|
|
import com.fp.frontend.controller.AbstractController;
|
|
import com.fp.frontend.controller.armas.parametros.PreguntasParaEvaluacionesController;
|
|
import com.fp.frontend.controller.pgeneral.gene.CatalogDetailController;
|
|
import com.fp.frontend.controller.pgeneral.gene.ParametersController;
|
|
import com.fp.frontend.enums.EnumLovOption;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.frontend.utility.MsgControlArmas;
|
|
import com.fp.persistence.parmas.eval.TarmPreguntas;
|
|
import com.fp.persistence.parmas.eval.TarmRespuestas;
|
|
import com.fp.persistence.pcustomer.gene.TcustPersonDetail;
|
|
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail;
|
|
import com.fp.persistence.pgeneral.gene.TgeneParameters;
|
|
|
|
/**
|
|
* Clase controladora del lov asociado con la evaluacion.
|
|
*
|
|
* @author Andres Cevallos.
|
|
* @version 2.1
|
|
*/
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class ConocimientoLovController extends AbstractController<AbstractDataTransport> {
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
/**
|
|
* Instancia de la clase TarmPreguntas
|
|
*/
|
|
private TarmPreguntas pregunta;
|
|
/**
|
|
* Boleano que comprueba si la pregunta fue respondida correctamente
|
|
*/
|
|
private Boolean isCorrecta;
|
|
/**
|
|
* Lista de Preguntas
|
|
*/
|
|
private List<TarmPreguntas> lpreguntas;
|
|
/**
|
|
* Lista de Respuestas
|
|
*/
|
|
private List<TarmRespuestas> lrespuestas;
|
|
/**
|
|
* Instancia de TcustpersonDetail, corresponde a la persona a ser
|
|
* evaluada
|
|
*/
|
|
private static TcustPersonDetail personevaluada;
|
|
/**
|
|
* Instancia de una Evaluacion, maneja una pregunta y sus respectivasrespuestas
|
|
* que son mostradas en pantalla
|
|
*/
|
|
private Evaluacion currentEvaluacion;
|
|
|
|
/**
|
|
* Lista del objetos Evaluacion
|
|
*/
|
|
private List<Evaluacion> leva;
|
|
/**
|
|
* Tipo de Evaluacion
|
|
*/
|
|
private static String tipoeval;
|
|
/**
|
|
* Contador que Lleva el numero de pregunta en el que se encuentra
|
|
*/
|
|
private int numeropregunta;
|
|
/**
|
|
* Maneja la ultima pregunta
|
|
*/
|
|
private boolean finalizar;
|
|
/**
|
|
* Fecha Actual del Sistema
|
|
*/
|
|
private Date fecha;
|
|
/**
|
|
* Objeto que sera retornado conteniendo todas las preguntas.
|
|
*/
|
|
EvaluacionCompleta evaluacionCompleta;
|
|
/**
|
|
* Tipo de persona referenciada en el catalogo
|
|
*/
|
|
private TgeneCatalogDetail tipopersona;
|
|
|
|
/**
|
|
* Tipo de evaluacion referenciado en el catalogo
|
|
*/
|
|
private TgeneCatalogDetail tipoevaluacion;
|
|
/**
|
|
* Numero de preguntas que tendra la evaluacion
|
|
*/
|
|
int npreguntas=4;
|
|
private Boolean errorrend=false;
|
|
|
|
private String error;
|
|
public ConocimientoLovController() throws Exception {
|
|
super(AbstractDataTransport.class);
|
|
}
|
|
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
|
|
}
|
|
|
|
/**
|
|
* 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<>();
|
|
lpreguntas = new ArrayList<TarmPreguntas>();
|
|
this.beanalias = "EVALUACIONLOV";
|
|
tipoevaluacion = new TgeneCatalogDetail();
|
|
TgeneParameters parametro= ParametersController.find("NUMEROPREGUNTAS", "1");
|
|
|
|
try{
|
|
npreguntas=parametro.getNumbervalue().intValue();
|
|
tipoevaluacion=CatalogDetailController.findxCodigoCodcatalogo(tipoeval, "TIPOEVALUACION");
|
|
setTipopersona(CatalogDetailController.findxCodigoCodcatalogo(personevaluada.getPersontypecatalog(), personevaluada.getPersontypecatalogcode()));
|
|
lpreguntas.addAll( PreguntasParaEvaluacionesController.findxPregunta(tipopersona.getPk().getCatalog(),"CONOCIMIENTO"));
|
|
}
|
|
catch(Exception e){
|
|
MessageHelper.setMessageError("PROBLEMAS DE PARAMETRIZACION. CONSULTE AL EVALUADOR");
|
|
error="PROBLEMAS DE PARAMETRIZACION. CONSULTE AL EVALUADOR";
|
|
errorrend=true;
|
|
System.out.println("Error");
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
numeropregunta=0;
|
|
finalizar=false;
|
|
|
|
fecha=Calendar.getInstance().getTime();
|
|
evaluacionCompleta=new EvaluacionCompleta();
|
|
evaluacionCompleta.inicializa();
|
|
construirEvaluacion();
|
|
currentEvaluacion=leva.get(numeropregunta);
|
|
comprobarpreguntafinal();
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Construye la evaluacion en base a las preguntas que se tengan catalogadas
|
|
*/
|
|
public void construirEvaluacion(){
|
|
|
|
leva = new ArrayList<Evaluacion>();
|
|
|
|
|
|
int i=0;
|
|
while(i<npreguntas){
|
|
int numAleatorio = (int) (Math.random()*(lpreguntas.size()-1));
|
|
//RespuestasController.
|
|
Evaluacion eva = new Evaluacion();
|
|
eva.setPregunta(lpreguntas.get((numAleatorio)));
|
|
eva.setRespuesta(RespuestasController.findxPregunta(eva.getPregunta().getPk().toString()));
|
|
lpreguntas.remove(numAleatorio);
|
|
if(eva.getRespuesta()!=null){
|
|
leva.add(eva);
|
|
i++;
|
|
}
|
|
if(lpreguntas.isEmpty())
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Verifica si se ha respondido una pregunta y llama a la vista la
|
|
* siguiente pregunta
|
|
*/
|
|
public void siguiente(){
|
|
|
|
|
|
if(currentEvaluacion.getCodigorespuesta()==null || currentEvaluacion.getCodigorespuesta()==0)
|
|
{
|
|
MessageHelper.setMessageWarn(MsgControlArmas.getProperty("msg_ingreseresp"));
|
|
return;
|
|
}
|
|
evaluacionCompleta.getLevaluacion().add(currentEvaluacion);
|
|
currentEvaluacion=leva.get(numeropregunta);
|
|
|
|
comprobarpreguntafinal();
|
|
}
|
|
|
|
/**
|
|
* Verifica que se encuentre en la ultima pregunta
|
|
*/
|
|
public void comprobarpreguntafinal(){
|
|
numeropregunta++;
|
|
if(numeropregunta==leva.size()){
|
|
finalizar=true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
* @see com.fp.frontend.controller.AbstractController#querydatabase()
|
|
*/
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
|
|
|
|
}
|
|
|
|
catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
finally{
|
|
return;
|
|
}
|
|
}
|
|
|
|
public static String getTipoeval() {
|
|
return tipoeval;
|
|
}
|
|
|
|
/**
|
|
*Regresa el Objeto de Evaluacion a la pantalla principal
|
|
*/
|
|
public void setEvaluacion() {
|
|
if(currentEvaluacion.getCodigorespuesta()==null || currentEvaluacion.getCodigorespuesta()==0)
|
|
{
|
|
MessageHelper.setMessageWarn(MsgControlArmas.getProperty("msg_ingreseresp"));
|
|
return;
|
|
}
|
|
|
|
evaluacionCompleta.getLevaluacion().add(currentEvaluacion);
|
|
// se utiliza en la pagina del lov.
|
|
|
|
RequestContext.getCurrentInstance().closeDialog(evaluacionCompleta);
|
|
}
|
|
|
|
public static void setTipoeval(String tipoeval) {
|
|
ConocimientoLovController.tipoeval = tipoeval;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Abre el Lov donde se realiza la evaluacion
|
|
* @param params
|
|
* @param persona
|
|
* @param catalogo
|
|
*/
|
|
public static void openLov(Map<String, List<String>> params, TcustPersonDetail persona,String catalogo) {
|
|
personevaluada=persona;
|
|
tipoeval=catalogo;
|
|
Map<String, Object> options = new HashMap<String, Object>();
|
|
options.put(EnumLovOption.MODAL.getLabel(), true);
|
|
options.put(EnumLovOption.HEIGHT.getLabel(), 350);
|
|
options.put(EnumLovOption.WIDTH.getLabel(), 900);
|
|
options.put(EnumLovOption.RESIZABLE.getLabel(), false);
|
|
options.put("closable", false);
|
|
|
|
RequestContext.getCurrentInstance().openDialog("/pages/armas/lov/conocimientoLov.xhtml", options, params);
|
|
}
|
|
|
|
/**
|
|
* Crea una instancia y marca el registro como nuevo.
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
@Override
|
|
public void create() throws Exception {
|
|
super.create();
|
|
isCorrecta = false;
|
|
// record.setCpregunta(pregunta.getPk());
|
|
}
|
|
|
|
/**
|
|
* Actualiza la lista de registros a grabar
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public void update() throws Exception {
|
|
//if(record.getEscorrecta()==null){
|
|
// record.setEscorrecta("N");
|
|
// }
|
|
//super.update();
|
|
}
|
|
|
|
/* (non-Javadoc)
|
|
* @see com.fp.frontend.controller.AbstractController#save()
|
|
*/
|
|
@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 = callerhelper.getRequest();
|
|
msave.put(beanalias, dtosave); // adicionar metadata de
|
|
// mantenimiento para cada tabla.
|
|
|
|
request.setSaveTables(msave);
|
|
Response resp = 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 TarmPreguntas getPregunta() {
|
|
return pregunta;
|
|
}
|
|
|
|
public void setPregunta(TarmPreguntas pregunta) {
|
|
this.pregunta = pregunta;
|
|
}
|
|
|
|
public Boolean getIsCorrecta() {
|
|
return isCorrecta;
|
|
}
|
|
|
|
public void setIsCorrecta(Boolean isCorrecta) {
|
|
this.isCorrecta = isCorrecta;
|
|
}
|
|
|
|
public void onChangeEsCorrecta() {
|
|
/* if (isCorrecta) {
|
|
record.setEscorrecta("Y");
|
|
} else {
|
|
record.setEscorrecta("N");
|
|
}*/
|
|
}
|
|
|
|
public List<TarmPreguntas> getLpreguntas() {
|
|
return lpreguntas;
|
|
}
|
|
|
|
public void setLpreguntas(List<TarmPreguntas> lpreguntas) {
|
|
this.lpreguntas = lpreguntas;
|
|
}
|
|
|
|
public List<TarmRespuestas> getLrespuestas() {
|
|
return lrespuestas;
|
|
}
|
|
|
|
public void setLrespuestas(List<TarmRespuestas> lrespuestas) {
|
|
this.lrespuestas = lrespuestas;
|
|
}
|
|
|
|
public List<Evaluacion> getLeva() {
|
|
return leva;
|
|
}
|
|
|
|
public void setLeva(List<Evaluacion> leva) {
|
|
this.leva = leva;
|
|
}
|
|
|
|
public TcustPersonDetail getPersonevaluada() {
|
|
return personevaluada;
|
|
}
|
|
|
|
public void setPersonevaluada(TcustPersonDetail personevaluada) {
|
|
this.personevaluada = personevaluada;
|
|
}
|
|
|
|
public TgeneCatalogDetail getTipopersona() {
|
|
return tipopersona;
|
|
}
|
|
|
|
public void setTipopersona(TgeneCatalogDetail tipopersona) {
|
|
this.tipopersona = tipopersona;
|
|
}
|
|
|
|
|
|
|
|
public TgeneCatalogDetail getTipoevaluacion() {
|
|
return tipoevaluacion;
|
|
}
|
|
|
|
public void setTipoevaluacion(TgeneCatalogDetail tipoevaluacion) {
|
|
this.tipoevaluacion = tipoevaluacion;
|
|
}
|
|
|
|
public Evaluacion getCurrentEvaluacion() {
|
|
return currentEvaluacion;
|
|
}
|
|
|
|
public void setCurrentEvaluacion(Evaluacion currentEvaluacion) {
|
|
this.currentEvaluacion = currentEvaluacion;
|
|
}
|
|
|
|
public boolean isFinalizar() {
|
|
return finalizar;
|
|
}
|
|
|
|
public void setFinalizar(boolean finalizar) {
|
|
this.finalizar = finalizar;
|
|
}
|
|
|
|
|
|
public int getNumeropregunta() {
|
|
return numeropregunta;
|
|
}
|
|
|
|
public void setNumeropregunta(int numeropregunta) {
|
|
this.numeropregunta = numeropregunta;
|
|
}
|
|
|
|
public Date getFecha() {
|
|
return fecha;
|
|
}
|
|
|
|
public void setFecha(Date fecha) {
|
|
this.fecha = fecha;
|
|
}
|
|
|
|
public String getError() {
|
|
return error;
|
|
}
|
|
|
|
public void setError(String error) {
|
|
this.error = error;
|
|
}
|
|
|
|
public Boolean getErrorrend() {
|
|
return errorrend;
|
|
}
|
|
|
|
public void setErrorrend(Boolean errorrend) {
|
|
this.errorrend = errorrend;
|
|
}
|
|
|
|
|
|
}
|