115 lines
4.1 KiB
Plaintext
Executable File
115 lines
4.1 KiB
Plaintext
Executable File
package com.fp.armas.rules.save.calificacion;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import javax.persistence.EntityManager;
|
|
import javax.persistence.Query;
|
|
|
|
import com.fp.armas.rules.save.funcionalidad.Movimiento;
|
|
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.persistence.parmas.param.TarmComercianteCupo;
|
|
import com.fp.persistence.parmas.soli.TarmGuardias;
|
|
import com.fp.sessionbeans.helper.Sequence;
|
|
|
|
|
|
/**
|
|
* @author Andres Cevallos
|
|
* Clase que daclara apto o no apto a un guardia dependiendo de su evaluacion
|
|
*/
|
|
public class EvaluarGuardia extends TransactionRule {
|
|
|
|
|
|
private static final String JPQL_GUARDIAS = "from TarmGuardias tag" + " where tag.pk = :personcode";
|
|
private static final String JPQL_EVALUACION= "from TarmEvaluacion tev where tev.personcode = :personcode and tev.resultado='APROBADO' and tev.tipoevaluacion = :tipoevaluacion";
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
@Override
|
|
public SaveRequest normalProcess(SaveRequest pSaveRequest) throws Exception {
|
|
// TarmEvaluacion registroArma = (TarmEvaluacion) pSaveRequest.getSaveBeanModifiedObject("EVALUACION");
|
|
List<Object> levaluacion = (List<Object>)pSaveRequest.getSaveBeanModifiedRecords("EVALUACION");
|
|
|
|
if(levaluacion==null || levaluacion.isEmpty()){
|
|
TarmEvaluacion evaluacion = (TarmEvaluacion) pSaveRequest.getSaveBeanModifiedObject("EVALUACION");
|
|
if (evaluacion == null) {
|
|
|
|
return pSaveRequest;
|
|
}
|
|
levaluacion.add(evaluacion);
|
|
}
|
|
|
|
for(Object deta : levaluacion){
|
|
TarmEvaluacion detalle = (TarmEvaluacion) deta;
|
|
List<TarmEvaluacion> lpsicologicas = findEvaluacion(PersistenceHelper.getEntityManager(), detalle.getPersoncode(), "PSICOLOGICA");
|
|
if(lpsicologicas == null || lpsicologicas.isEmpty()){
|
|
throw new Exception("DEBE REGISTRAR EL TEST PSICOL\u00d3GICO PRIMERO");
|
|
}
|
|
//validacion en caso de ser guardia
|
|
List<TarmGuardias> guardiasList=findGuardia(PersistenceHelper.getEntityManager(), detalle.getPersoncode());
|
|
TarmGuardias guardia=null;
|
|
if(guardiasList!=null && guardiasList.size()>0){
|
|
guardia=guardiasList.get(0);
|
|
guardia.setIsnew(false);
|
|
List<TarmEvaluacion> lconocimientos = findEvaluacion(PersistenceHelper.getEntityManager(), detalle.getPersoncode(), "CONOCIMIENTO");
|
|
if(lpsicologicas!=null && !lpsicologicas.isEmpty() && ((lconocimientos!=null && !lconocimientos.isEmpty()) || detalle.getResultado().equalsIgnoreCase("APROBADO"))){
|
|
guardia.setEstado("APT");
|
|
}
|
|
else{
|
|
guardia.setEstado("NAPT");
|
|
}
|
|
if(!guardia.isnew){
|
|
PersistenceHelper.getEntityManager().merge(guardia);
|
|
}else{
|
|
PersistenceHelper.getEntityManager().persist(guardia);
|
|
}
|
|
}
|
|
}
|
|
PersistenceHelper.getEntityManager().flush();
|
|
return pSaveRequest;
|
|
}
|
|
|
|
public static List<TarmGuardias> findGuardia(EntityManager pEntityManager, Integer personcodigo) throws Exception {
|
|
|
|
Query qry = pEntityManager.createQuery(EvaluarGuardia.JPQL_GUARDIAS);
|
|
qry.setParameter("personcode", personcodigo);
|
|
return qry.getResultList();
|
|
}
|
|
|
|
public static List<TarmEvaluacion> findEvaluacion(EntityManager pEntityManager, Integer personcodigo, String tipoevaluacion) throws Exception {
|
|
|
|
Query qry = pEntityManager.createQuery(EvaluarGuardia.JPQL_EVALUACION);
|
|
qry.setParameter("personcode", personcodigo);
|
|
qry.setParameter("tipoevaluacion", tipoevaluacion);
|
|
|
|
return qry.getResultList();
|
|
}
|
|
|
|
@Override
|
|
public SaveRequest reverseProcess(SaveRequest pSaveRequest) throws Exception {
|
|
return pSaveRequest;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getCodigoPreguntas() throws Exception {
|
|
Sequence sequence = new Sequence();
|
|
String codigo = sequence.getNextValue("CEVALUACION").toString();
|
|
return codigo;
|
|
}
|
|
|
|
|
|
|
|
|
|
} |