144 lines
3.9 KiB
Plaintext
Executable File
144 lines
3.9 KiB
Plaintext
Executable File
package com.fp.armas.rules.save.calificacion;
|
||
|
||
|
||
|
||
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
|
||
import org.apache.commons.validator.Msg;
|
||
|
||
import com.fp.dto.rules.TransactionRule;
|
||
import com.fp.dto.save.SaveRequest;
|
||
import com.fp.persistence.commondb.PersistenceHelper;
|
||
import com.fp.persistence.parmas.eval.TarmDetallePreguntas;
|
||
import com.fp.persistence.parmas.eval.TarmEvaluacion;
|
||
import com.fp.sessionbeans.helper.Sequence;
|
||
|
||
|
||
/**
|
||
* @author Andres Cevallos
|
||
* Clase que califica una evaluacion
|
||
*/
|
||
public class Calificacion extends TransactionRule {
|
||
|
||
/**
|
||
*
|
||
*/
|
||
private static final long serialVersionUID = 1L;
|
||
|
||
@Override
|
||
public SaveRequest normalProcess(SaveRequest pSaveRequest) throws Exception {
|
||
TarmEvaluacion registroArma = (TarmEvaluacion) pSaveRequest.getSaveBeanModifiedObject("EVALUACION");
|
||
List<Object> levaluacionDetalle = (List<Object>)pSaveRequest.getSaveBeanModifiedRecords("DETALLEPREGUNTAS");
|
||
float respuestas=0;
|
||
float preguntas=0;
|
||
float porcentaje=0;
|
||
if(levaluacionDetalle==null || levaluacionDetalle.isEmpty()){
|
||
TarmDetallePreguntas detalle=(TarmDetallePreguntas)pSaveRequest.getSaveBeanModifiedObject("DETALLEPREGUNTAS");
|
||
levaluacionDetalle.add(detalle);
|
||
}
|
||
|
||
|
||
if (registroArma == null) {
|
||
|
||
return pSaveRequest;
|
||
}
|
||
|
||
if(registroArma.getPk()==null)
|
||
{
|
||
registroArma.setPk(getCodigoEvaluacion().toString());
|
||
porcentaje = (float) registroArma.getModifiedData().get("aprobacion");
|
||
|
||
}
|
||
|
||
for(Object deta : levaluacionDetalle){
|
||
TarmDetallePreguntas detalle = (TarmDetallePreguntas) deta;
|
||
String valor= detalle.getModifiedData().get("valor").toString();
|
||
if(valor.equals("Y"))
|
||
{
|
||
respuestas++;
|
||
}
|
||
preguntas++;
|
||
|
||
}
|
||
|
||
if(preguntas!=0){
|
||
if((100*respuestas/preguntas)>=porcentaje){
|
||
registroArma.setResultado("APROBADO");
|
||
registroArma.setResultadocodigo("RESULTADO");
|
||
Date fechaexpiracion=new Date();
|
||
fechaexpiracion.setYear(fechaexpiracion.getYear()+2);
|
||
registroArma.setFechaexpiracion(new java.sql.Date(fechaexpiracion.getTime()));
|
||
pSaveRequest.getResponse().put("result", "APR");
|
||
|
||
}
|
||
else{
|
||
registroArma.setResultado("REPROBADO");
|
||
registroArma.setResultadocodigo("RESULTADO");
|
||
registroArma.setFechapreox(null);
|
||
registroArma.setFechaexpiracion(null);
|
||
pSaveRequest.getResponse().put("result", "REP");
|
||
}
|
||
PersistenceHelper.getEntityManager().persist(registroArma);
|
||
}
|
||
System.out.println("Respuestas Correctas "+respuestas+"de "+preguntas+" preguntas");
|
||
|
||
for(Object deta : levaluacionDetalle){
|
||
TarmDetallePreguntas detalle = (TarmDetallePreguntas) deta;
|
||
|
||
detalle.setPk(getCodigoDetallePreguntas());
|
||
detalle.setCevaluacion(registroArma.getPk());
|
||
|
||
PersistenceHelper.getEntityManager().persist(detalle);
|
||
}
|
||
|
||
|
||
PersistenceHelper.getEntityManager().flush();
|
||
|
||
return pSaveRequest;
|
||
|
||
|
||
}
|
||
|
||
@Override
|
||
public SaveRequest reverseProcess(SaveRequest pSaveRequest) throws Exception {
|
||
|
||
|
||
|
||
return pSaveRequest;
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* Metodo que devuelve la secuencia de una evaluacion.
|
||
*
|
||
* @return Codigo del nuevo cliente.
|
||
* @throws Exception
|
||
*/
|
||
private Long getCodigoEvaluacion() throws Exception {
|
||
Sequence sequence = new Sequence();
|
||
Long codigo = sequence.getNextValue("CEVALUACION").longValue();
|
||
|
||
return codigo;
|
||
|
||
}
|
||
|
||
/**
|
||
* M<>todo que devuelve el detalle de las preguntas
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
private String getCodigoDetallePreguntas() throws Exception {
|
||
Sequence sequence = new Sequence();
|
||
String codigo = sequence.getNextValue("CDETALLEPREGUNTAS").toString();
|
||
|
||
return codigo;
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
} |