valida Institu y Formacion antes de InstitutoFormacion
This commit is contained in:
parent
0e9c375ff8
commit
3b06e360c5
@ -187,24 +187,24 @@ public class ClasePrincipal {
|
|||||||
IInstitutoDAO iInstitutoDAO = new InstitutoDaoJPA();
|
IInstitutoDAO iInstitutoDAO = new InstitutoDaoJPA();
|
||||||
|
|
||||||
for (InstitutoFormacion institutoFormacion : listaInstitutoFormacion) {
|
for (InstitutoFormacion institutoFormacion : listaInstitutoFormacion) {
|
||||||
// Se obiene el instituto en la BBDD
|
// Sólo se insertará el InstitutoFormacion si existen tanto el Instituto como la
|
||||||
InstitutoFormacion institutoFormacionBBDD = institutoFormacionDAO
|
// Formación en la Base de datos.
|
||||||
.obtenerInstitutoFormacionPorID(institutoFormacion.getIdInstitutoFormacion());
|
Instituto instituto = iInstitutoDAO
|
||||||
|
.obtenerInstitutoPorID(institutoFormacion.getInstituto().getIdentificador());
|
||||||
|
Formacion formacion = iFormacionDAO
|
||||||
|
.obtenerFormacionPorID(institutoFormacion.getFormacion().getCodigo());
|
||||||
|
// Se insertará el InstitutoFormacion sólo si la formación es STEM
|
||||||
|
if (instituto != null && formacion != null && formacion.getIndicadorSTEM() == EIndicadorSTEM.sí) {
|
||||||
|
// Se obiene el instituto en la BBDD
|
||||||
|
InstitutoFormacion institutoFormacionBBDD = institutoFormacionDAO
|
||||||
|
.obtenerInstitutoFormacionPorID(institutoFormacion.getIdInstitutoFormacion());
|
||||||
|
|
||||||
// Si no existe información en la Base de datos.
|
// Si no existe información en la Base de datos.
|
||||||
if (institutoFormacionBBDD == null) {
|
if (institutoFormacionBBDD == null) {
|
||||||
|
|
||||||
// Sólo se insertará el InstitutoFormacion si existen tanto el Instituto como la
|
|
||||||
// Formación en la Base de datos.
|
|
||||||
Instituto instituto = iInstitutoDAO
|
|
||||||
.obtenerInstitutoPorID(institutoFormacion.getInstituto().getIdentificador());
|
|
||||||
Formacion formacion = iFormacionDAO
|
|
||||||
.obtenerFormacionPorID(institutoFormacion.getFormacion().getCodigo());
|
|
||||||
// Se insertará el InstitutoFormacion sólo si la formación es STEM
|
|
||||||
if (instituto != null && formacion != null && formacion.getIndicadorSTEM() == EIndicadorSTEM.sí) {
|
|
||||||
institutoFormacion.setInstituto(instituto);
|
institutoFormacion.setInstituto(instituto);
|
||||||
institutoFormacion.setFormacion(formacion);
|
institutoFormacion.setFormacion(formacion);
|
||||||
institutoFormacionDAO.insertarInstitutoFormacion(institutoFormacion);
|
institutoFormacionDAO.insertarInstitutoFormacion(institutoFormacion);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,14 +13,13 @@ import org.hibernate.Session;
|
|||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Organización: Virgen de la Paloma
|
* Organización: Virgen de la Paloma Programador: Isidoro Nevares Martín Fecha:
|
||||||
* Programador: Isidoro Nevares Martín
|
* 26 marzo 2026
|
||||||
* Fecha: 26 marzo 2026
|
*/
|
||||||
*/
|
public class InstitutoFormacionDaoHibernate implements IInstitutoFormacionDAO {
|
||||||
public class InstitutoFormacionDaoHibernate implements IInstitutoFormacionDAO{
|
|
||||||
@Override
|
@Override
|
||||||
public void insertarInstitutoFormacion(InstitutoFormacion institutoFormacion) throws FormacionException {
|
public void insertarInstitutoFormacion(InstitutoFormacion institutoFormacion) throws FormacionException {
|
||||||
Transaction transaccion=null;
|
Transaction transaccion = null;
|
||||||
|
|
||||||
Session sesion = null;
|
Session sesion = null;
|
||||||
try {
|
try {
|
||||||
@ -45,7 +44,7 @@ public class InstitutoFormacionDaoHibernate implements IInstitutoFormacionDAO{
|
|||||||
@Override
|
@Override
|
||||||
public InstitutoFormacion obtenerInstitutoFormacionPorID(InstitutoFormacionID identificador)
|
public InstitutoFormacion obtenerInstitutoFormacionPorID(InstitutoFormacionID identificador)
|
||||||
throws FormacionException {
|
throws FormacionException {
|
||||||
InstitutoFormacion institutoFormacion =null;
|
InstitutoFormacion institutoFormacion = null;
|
||||||
|
|
||||||
// try con recursos "cerrables": Session
|
// try con recursos "cerrables": Session
|
||||||
try (Session sesion = GestorSesionHibernate.getSession();) {
|
try (Session sesion = GestorSesionHibernate.getSession();) {
|
||||||
@ -54,7 +53,7 @@ public class InstitutoFormacionDaoHibernate implements IInstitutoFormacionDAO{
|
|||||||
throw new FormacionException(e, FormacionException.ERROR_CONSULTA, getClass());
|
throw new FormacionException(e, FormacionException.ERROR_CONSULTA, getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
return institutoFormacion;
|
return institutoFormacion;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,6 +71,18 @@ public class InstitutoFormacion {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "InstitutoFormacionID [idIntituto=" + idIntituto + ", idFormacion=" + codFormacion + "]";
|
return "InstitutoFormacionID [idIntituto=" + idIntituto + ", idFormacion=" + codFormacion + "]";
|
||||||
|
}
|
||||||
|
public Integer getIdIntituto() {
|
||||||
|
return idIntituto;
|
||||||
|
}
|
||||||
|
public void setIdIntituto(Integer idIntituto) {
|
||||||
|
this.idIntituto = idIntituto;
|
||||||
|
}
|
||||||
|
public String getCodFormacion() {
|
||||||
|
return codFormacion;
|
||||||
|
}
|
||||||
|
public void setCodFormacion(String codFormacion) {
|
||||||
|
this.codFormacion = codFormacion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user