Procesado de ficheros
This commit is contained in:
parent
e447864322
commit
1a0f8809a4
8
pom.xml
8
pom.xml
@ -50,6 +50,14 @@
|
|||||||
<version>42.7.9</version>
|
<version>42.7.9</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Source: https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.42</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@ -1,6 +1,10 @@
|
|||||||
package es.palomafp.aadd.inm;
|
package es.palomafp.aadd.inm;
|
||||||
|
|
||||||
import es.palomafp.aadd.inm.procesador.ProcesadorFicheros;
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorSesionesHibernate;
|
||||||
|
import es.palomafp.aadd.inm.procesador.ProcesadorFicheroCSV;
|
||||||
|
import es.palomafp.aadd.inm.procesador.ProcesadorFicheroJSON;
|
||||||
|
import es.palomafp.aadd.inm.procesador.ProcesadorFicheroXML;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -16,18 +20,49 @@ public class AppProyectosIES {
|
|||||||
AppProyectosIES app = new AppProyectosIES();
|
AppProyectosIES app = new AppProyectosIES();
|
||||||
|
|
||||||
// Generar la estructura de la base de datos en PostgreSQL
|
// Generar la estructura de la base de datos en PostgreSQL
|
||||||
//GestorSesionesHibernate.getSession();
|
// GestorSesionesHibernate.getSession();
|
||||||
|
|
||||||
app.procesarFicheros();
|
try {
|
||||||
|
app.procesarFicheros();
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
String mensajeError = "Error en la clase %s al realizar una operación de %s";
|
||||||
|
String operacion = "Operación desconocida";
|
||||||
|
int codigoError = e.getCodigoError();
|
||||||
|
switch (codigoError) {
|
||||||
|
case ProyectosIESException.ERROR_GESTION_CONEXION:
|
||||||
|
operacion = "Gestión de Conexión";
|
||||||
|
break;
|
||||||
|
case ProyectosIESException.ERROR_CONSULTA:
|
||||||
|
operacion = "Consulta";
|
||||||
|
break;
|
||||||
|
case ProyectosIESException.ERROR_INSERCION:
|
||||||
|
operacion = "Inserción";
|
||||||
|
break;
|
||||||
|
case ProyectosIESException.ERROR_BORRADO:
|
||||||
|
operacion = "Borrado";
|
||||||
|
break;
|
||||||
|
case ProyectosIESException.ERROR_ACTUALIZACION:
|
||||||
|
operacion = "Actualización";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mensajeError = String.format(mensajeError, e.getClaseOrigen().getName(), operacion);
|
||||||
|
System.out.println(mensajeError);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void procesarFicheros() {
|
private void procesarFicheros() throws ProyectosIESException {
|
||||||
ProcesadorFicheros procesador = new ProcesadorFicheros();
|
// Procesar datos de catálogos
|
||||||
|
ProcesadorFicheroXML procesadorFicheroXML = new ProcesadorFicheroXML();
|
||||||
procesador.procesarFicheroXMLCatalogos();
|
procesadorFicheroXML.procesarFicheroXMLCatalogos();
|
||||||
|
|
||||||
procesador.procesarFicheroJSONGastos();
|
// Procesar datos de Gastos
|
||||||
|
ProcesadorFicheroJSON procesadorFicheroJSON = new ProcesadorFicheroJSON();
|
||||||
procesador.procesarFicheroCSVIngresos();
|
procesadorFicheroJSON.procesarFicheroJSONGastos();
|
||||||
|
|
||||||
|
// Procesar datos de Ingresos
|
||||||
|
ProcesadorFicheroCSV procesadorFicheroCSV = new ProcesadorFicheroCSV();
|
||||||
|
procesadorFicheroCSV.procesarFicheroCSVIngresos();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
18
src/main/java/es/palomafp/aadd/inm/dao/IConceptoDAO.java
Normal file
18
src/main/java/es/palomafp/aadd/inm/dao/IConceptoDAO.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.vo.Concepto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* IProyectoDAO: Clase que realiza ....
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 ene 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface IConceptoDAO extends IOperacionesDAOEntidad<Concepto, Integer> {
|
||||||
|
Concepto obtenerConceptoPorNombre(String nombreConcepto) throws ProyectosIESException;
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
package es.palomafp.aadd.inm.dao;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import es.palomafp.aadd.inm.vo.Patrocinador;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* IContinenteDAO: Interfaz que define las operaciones de acceso a datos para
|
|
||||||
* Continente.
|
|
||||||
*
|
|
||||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
|
||||||
* @date 31 oct 2025
|
|
||||||
*/
|
|
||||||
public interface IContinenteDAO {
|
|
||||||
Patrocinador obtenerContinentePorID(String codigo);
|
|
||||||
|
|
||||||
List<Patrocinador> obtenerListaContientes();
|
|
||||||
|
|
||||||
void crearContinente(Patrocinador continente);
|
|
||||||
|
|
||||||
void actualizarContinente(Patrocinador continente);
|
|
||||||
}
|
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.vo.CursoProyecto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* IProyectoDAO: Clase que realiza ....
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 ene 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface ICursoProyectoDAO extends IOperacionesDAOEntidad<CursoProyecto, Integer> {
|
||||||
|
CursoProyecto obtenerCursoProyectoPorCursoYProyecto(String codigoCursoAcademico, Integer idProyecto) throws ProyectosIESException;
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* IOperacionesBasicas: Clase que realiza ....
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 14 dic 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface IOperacionesDAOEntidad<T, ID> {
|
||||||
|
T obtenerEntidadPorID(ID clave) throws ProyectosIESException;
|
||||||
|
void crearEntidad(T entidad) throws ProyectosIESException;
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
package es.palomafp.aadd.inm.dao;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import es.palomafp.aadd.inm.vo.Gasto;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* IPaisDAO: Interfaz que define las operaciones de acceso a datos para País.
|
|
||||||
*
|
|
||||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
|
||||||
* @date 31 oct 2025
|
|
||||||
*/
|
|
||||||
public interface IPaisDAO {
|
|
||||||
Gasto obtenerPaisPorID(int identificador);
|
|
||||||
|
|
||||||
List<Gasto> obtenerListaPaises();
|
|
||||||
|
|
||||||
void crearPais(Gasto pais);
|
|
||||||
|
|
||||||
void actualizarPais(Gasto pais);
|
|
||||||
|
|
||||||
Gasto obtenerPaisPorNombre(String nombre);
|
|
||||||
|
|
||||||
}
|
|
||||||
18
src/main/java/es/palomafp/aadd/inm/dao/IProyectoDAO.java
Normal file
18
src/main/java/es/palomafp/aadd/inm/dao/IProyectoDAO.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.vo.Proyecto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* IProyectoDAO: Clase que realiza ....
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 ene 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface IProyectoDAO extends IOperacionesDAOEntidad<Proyecto, Integer> {
|
||||||
|
Proyecto obtenerProyectoPorNombre(String nombreProyecto) throws ProyectosIESException;
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao.hbm;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.SelectionQuery;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IConceptoDAO;
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorSesionesHibernate;
|
||||||
|
import es.palomafp.aadd.inm.vo.Concepto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ConceptoDaoHibernate: Clase que implementa el interfaz IOperacionesDAOEntidad
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public class ConceptoDaoHibernate implements IConceptoDAO{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Concepto entidad) throws ProyectosIESException {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_INSERCION);
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Concepto obtenerEntidadPorID(Integer clave) throws ProyectosIESException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Concepto obtenerConceptoPorNombre(String nombreConcepto) throws ProyectosIESException {
|
||||||
|
Concepto concepto = null;
|
||||||
|
String sentenciaHQL = "SELECT c FROM Concepto c WHERE c.nombre = :nombre";
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
SelectionQuery<Concepto> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Concepto.class);
|
||||||
|
sentenciaConsulta.setParameter("nombre", nombreConcepto);
|
||||||
|
|
||||||
|
concepto = sentenciaConsulta.getSingleResultOrNull();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_CONSULTA);
|
||||||
|
}
|
||||||
|
return concepto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,52 +0,0 @@
|
|||||||
package es.palomafp.aadd.inm.dao.hbm;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.query.SelectionQuery;
|
|
||||||
|
|
||||||
import es.palomafp.aadd.inm.dao.IContinenteDAO;
|
|
||||||
import es.palomafp.aadd.inm.gestor.GestorSesionesHibernate;
|
|
||||||
import es.palomafp.aadd.inm.vo.Patrocinador;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* ContinenteDaoJDBC: Clase que implementa el interfaz IContinenteDAO
|
|
||||||
*
|
|
||||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
|
||||||
* @date 31 oct 2025
|
|
||||||
*/
|
|
||||||
public class ContinenteDaoHibernate implements IContinenteDAO {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Patrocinador> obtenerListaContientes() {
|
|
||||||
List<Patrocinador> listaContinentes = null;
|
|
||||||
String sentenciaHQL = """
|
|
||||||
SELECT c
|
|
||||||
FROM Continente c
|
|
||||||
""";
|
|
||||||
// try con recursos "cerrables": Session
|
|
||||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
|
||||||
SelectionQuery<Patrocinador> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Patrocinador.class);
|
|
||||||
listaContinentes = sentenciaConsulta.getResultList();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return listaContinentes;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void crearContinente(Patrocinador continente) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Patrocinador obtenerContinentePorID(String codigo) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actualizarContinente(Patrocinador continente) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao.hbm;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IOperacionesDAOEntidad;
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorSesionesHibernate;
|
||||||
|
import es.palomafp.aadd.inm.vo.CursoAcademico;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* CursoAcademicoDaoHibernate: Clase que implementa el interfaz
|
||||||
|
* IOperacionesDAOEntidad
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public class CursoAcademicoDaoHibernate implements IOperacionesDAOEntidad<CursoAcademico, String>{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(CursoAcademico entidad) throws ProyectosIESException {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_INSERCION);
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CursoAcademico obtenerEntidadPorID(String clave) throws ProyectosIESException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,71 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao.hbm;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.SelectionQuery;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.ICursoProyectoDAO;
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorSesionesHibernate;
|
||||||
|
import es.palomafp.aadd.inm.vo.CursoProyecto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* CursoProyectoDaoHibernate: Clase que implementa el interfaz
|
||||||
|
* IOperacionesDAOEntidad
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public class CursoProyectoDaoHibernate implements ICursoProyectoDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(CursoProyecto entidad) throws ProyectosIESException {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_INSERCION);
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CursoProyecto obtenerEntidadPorID(Integer clave) throws ProyectosIESException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CursoProyecto obtenerCursoProyectoPorCursoYProyecto(String codigoCursoAcademico, Integer idProyecto) throws ProyectosIESException {
|
||||||
|
CursoProyecto cursoProyecto = null;
|
||||||
|
String sentenciaHQL = "SELECT cp FROM CursoProyecto cp WHERE cp.cursoAcademico.codigo= :codigo and cp.proyecto.identificador= :idProyecto";
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
SelectionQuery<CursoProyecto> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, CursoProyecto.class);
|
||||||
|
sentenciaConsulta.setParameter("codigo", codigoCursoAcademico);
|
||||||
|
sentenciaConsulta.setParameter("idProyecto", idProyecto);
|
||||||
|
|
||||||
|
cursoProyecto = sentenciaConsulta.getSingleResultOrNull();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_CONSULTA);
|
||||||
|
}
|
||||||
|
return cursoProyecto;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,102 +0,0 @@
|
|||||||
package es.palomafp.aadd.inm.dao.hbm;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.query.SelectionQuery;
|
|
||||||
|
|
||||||
import es.palomafp.aadd.inm.dao.IPaisDAO;
|
|
||||||
import es.palomafp.aadd.inm.gestor.GestorSesionesHibernate;
|
|
||||||
import es.palomafp.aadd.inm.vo.Gasto;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* PaisDaoJDBC: Clase que implementa el interfaz IPaisDAO
|
|
||||||
*
|
|
||||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
|
||||||
* @date 31 oct 2025
|
|
||||||
*/
|
|
||||||
public class PaisDaoHibernate implements IPaisDAO {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Gasto> obtenerListaPaises() {
|
|
||||||
List<Gasto> listaPaises = null;
|
|
||||||
String sentenciaHQL = """
|
|
||||||
SELECT p
|
|
||||||
FROM Pais p
|
|
||||||
""";
|
|
||||||
|
|
||||||
// try con recursos "cerrables": Session
|
|
||||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
|
||||||
|
|
||||||
SelectionQuery<Gasto> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Gasto.class);
|
|
||||||
listaPaises = sentenciaConsulta.getResultList();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return listaPaises;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actualizarPais(Gasto pais) {
|
|
||||||
Transaction transaccion = null;
|
|
||||||
Session sesion = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
sesion = GestorSesionesHibernate.getSession();
|
|
||||||
transaccion = sesion.beginTransaction();
|
|
||||||
|
|
||||||
if (!sesion.contains(pais))
|
|
||||||
sesion.merge(pais);
|
|
||||||
|
|
||||||
transaccion.commit();
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (transaccion != null && transaccion.isActive()) {
|
|
||||||
transaccion.rollback();
|
|
||||||
}
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (sesion != null) {
|
|
||||||
sesion.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Gasto obtenerPaisPorID(int identificador) {
|
|
||||||
Gasto pais = null;
|
|
||||||
|
|
||||||
return pais;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void crearPais(Gasto pais) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Gasto obtenerPaisPorNombre(String nombre) {
|
|
||||||
Gasto pais = null;
|
|
||||||
String sentenciaHQL = """
|
|
||||||
SELECT p
|
|
||||||
FROM Pais p
|
|
||||||
where p.nombrePais = :nombre
|
|
||||||
""";
|
|
||||||
|
|
||||||
// try con recursos "cerrables": Session
|
|
||||||
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
|
||||||
|
|
||||||
SelectionQuery<Gasto> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Gasto.class);
|
|
||||||
sentenciaConsulta.setParameter("nombre", nombre);
|
|
||||||
pais = sentenciaConsulta.getSingleResult();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return pais;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao.hbm;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IOperacionesDAOEntidad;
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorSesionesHibernate;
|
||||||
|
import es.palomafp.aadd.inm.vo.Patrocinador;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ConceptoDaoHibernate: Clase que implementa el interfaz IOperacionesDAOEntidad
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public class PatrocinadorDaoHibernate implements IOperacionesDAOEntidad<Patrocinador, Integer>{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Patrocinador entidad) throws ProyectosIESException {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_INSERCION);
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Patrocinador obtenerEntidadPorID(Integer clave) throws ProyectosIESException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao.hbm;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.SelectionQuery;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IProyectoDAO;
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorSesionesHibernate;
|
||||||
|
import es.palomafp.aadd.inm.vo.Proyecto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ConceptoDaoHibernate: Clase que implementa el interfaz IOperacionesDAOEntidad
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public class ProyectoDaoHibernate implements IProyectoDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Proyecto entidad) throws ProyectosIESException {
|
||||||
|
Transaction transaccion = null;
|
||||||
|
Session sesion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
sesion = GestorSesionesHibernate.getSession();
|
||||||
|
transaccion = sesion.beginTransaction();
|
||||||
|
|
||||||
|
sesion.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_INSERCION);
|
||||||
|
} finally {
|
||||||
|
if (sesion != null) {
|
||||||
|
sesion.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Proyecto obtenerProyectoPorNombre(String nombreProyecto) throws ProyectosIESException {
|
||||||
|
Proyecto proyecto = null;
|
||||||
|
String sentenciaHQL = "SELECT p FROM Proyecto p WHERE p.nombre = :nombre";
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (Session sesion = GestorSesionesHibernate.getSession();) {
|
||||||
|
SelectionQuery<Proyecto> sentenciaConsulta = sesion.createSelectionQuery(sentenciaHQL, Proyecto.class);
|
||||||
|
sentenciaConsulta.setParameter("nombre", nombreProyecto);
|
||||||
|
|
||||||
|
proyecto = sentenciaConsulta.getSingleResultOrNull();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_CONSULTA);
|
||||||
|
}
|
||||||
|
return proyecto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Proyecto obtenerEntidadPorID(Integer clave) throws ProyectosIESException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,71 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao.jpa;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IConceptoDAO;
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorEntityManagerJPA;
|
||||||
|
import es.palomafp.aadd.inm.vo.Concepto;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityTransaction;
|
||||||
|
import jakarta.persistence.TypedQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ConceptoDaoJPA: Clase que implementa el interfaz IOperacionesDAOEntidad
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public class ConceptoDaoJPA implements IConceptoDAO {
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Concepto entidad) throws ProyectosIESException{
|
||||||
|
EntityManager gestorEntidades= null;
|
||||||
|
EntityTransaction transaccion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||||
|
transaccion = gestorEntidades.getTransaction();
|
||||||
|
transaccion .begin();
|
||||||
|
|
||||||
|
gestorEntidades.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_INSERCION);
|
||||||
|
} finally {
|
||||||
|
if (gestorEntidades != null) {
|
||||||
|
gestorEntidades.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Concepto obtenerEntidadPorID(Integer clave) throws ProyectosIESException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Concepto obtenerConceptoPorNombre(String nombreConcepto) throws ProyectosIESException {
|
||||||
|
Concepto concepto = null;
|
||||||
|
|
||||||
|
String sentenciaJPQL = """
|
||||||
|
SELECT p FROM Concepto c
|
||||||
|
WHERE c.nombre= :nombre
|
||||||
|
""";
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (EntityManager entityManager = GestorEntityManagerJPA.getEntityManager();) {
|
||||||
|
TypedQuery<Concepto> query = entityManager.createQuery(sentenciaJPQL, Concepto.class);
|
||||||
|
query.setParameter("nombre", nombreConcepto);
|
||||||
|
|
||||||
|
concepto = query.getSingleResult();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_CONSULTA);
|
||||||
|
}
|
||||||
|
|
||||||
|
return concepto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,90 +0,0 @@
|
|||||||
package es.palomafp.aadd.inm.dao.jpa;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import es.palomafp.aadd.inm.dao.IContinenteDAO;
|
|
||||||
import es.palomafp.aadd.inm.gestor.GestorEntityManagerJPA;
|
|
||||||
import es.palomafp.aadd.inm.vo.Patrocinador;
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import jakarta.persistence.EntityTransaction;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* ContinenteDaoJDBC: Clase que implementa el interfaz IContinenteDAO
|
|
||||||
*
|
|
||||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
|
||||||
* @date 31 oct 2025
|
|
||||||
*/
|
|
||||||
public class ContinenteDaoJPA implements IContinenteDAO {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Patrocinador obtenerContinentePorID(String codigo) {
|
|
||||||
Patrocinador continente = null;
|
|
||||||
|
|
||||||
// try con recursos "cerrables": Session
|
|
||||||
try (EntityManager gestorEntidades = GestorEntityManagerJPA.getEntityManager()) {
|
|
||||||
continente = gestorEntidades.find(Patrocinador.class, codigo);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return continente;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void crearContinente(Patrocinador continente) {
|
|
||||||
EntityManager gestorEntidades= null;
|
|
||||||
EntityTransaction transaccion = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
|
||||||
transaccion = gestorEntidades.getTransaction();
|
|
||||||
transaccion .begin();
|
|
||||||
|
|
||||||
gestorEntidades.persist(continente);
|
|
||||||
|
|
||||||
transaccion.commit();
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (transaccion != null && transaccion.isActive()) {
|
|
||||||
transaccion.rollback();
|
|
||||||
}
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (gestorEntidades != null) {
|
|
||||||
gestorEntidades.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actualizarContinente(Patrocinador continente) {
|
|
||||||
EntityManager gestorEntidades= null;
|
|
||||||
EntityTransaction transaccion = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
|
||||||
transaccion = gestorEntidades.getTransaction();
|
|
||||||
transaccion .begin();
|
|
||||||
|
|
||||||
if (!gestorEntidades.contains(continente))
|
|
||||||
gestorEntidades.merge(continente);
|
|
||||||
|
|
||||||
transaccion.commit();
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (transaccion != null && transaccion.isActive()) {
|
|
||||||
transaccion.rollback();
|
|
||||||
}
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (gestorEntidades != null) {
|
|
||||||
gestorEntidades.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Patrocinador> obtenerListaContientes() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao.jpa;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IOperacionesDAOEntidad;
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorEntityManagerJPA;
|
||||||
|
import es.palomafp.aadd.inm.vo.CursoAcademico;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityTransaction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* CursoAcademicoDaoJPA: Clase que implementa el interfaz IOperacionesDAOEntidad
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public class CursoAcademicoDaoJPA implements IOperacionesDAOEntidad<CursoAcademico, String>{
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(CursoAcademico entidad) throws ProyectosIESException {
|
||||||
|
EntityManager gestorEntidades = null;
|
||||||
|
EntityTransaction transaccion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||||
|
transaccion = gestorEntidades.getTransaction();
|
||||||
|
transaccion.begin();
|
||||||
|
|
||||||
|
gestorEntidades.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_INSERCION);
|
||||||
|
} finally {
|
||||||
|
if (gestorEntidades != null) {
|
||||||
|
gestorEntidades.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CursoAcademico obtenerEntidadPorID(String clave) throws ProyectosIESException {
|
||||||
|
CursoAcademico cursoAcademico = null;
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (EntityManager entityManager = GestorEntityManagerJPA.getEntityManager();) {
|
||||||
|
cursoAcademico = entityManager.find(CursoAcademico.class, clave);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_CONSULTA);
|
||||||
|
}
|
||||||
|
return cursoAcademico;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,73 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao.jpa;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.ICursoProyectoDAO;
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorEntityManagerJPA;
|
||||||
|
import es.palomafp.aadd.inm.vo.CursoProyecto;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityTransaction;
|
||||||
|
import jakarta.persistence.TypedQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* CursoProyectoDaoJPA: Clase que implementa el interfaz IOperacionesDAOEntidad
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public class CursoProyectoDaoJPA implements ICursoProyectoDAO {
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(CursoProyecto entidad) throws ProyectosIESException {
|
||||||
|
EntityManager gestorEntidades = null;
|
||||||
|
EntityTransaction transaccion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||||
|
transaccion = gestorEntidades.getTransaction();
|
||||||
|
transaccion.begin();
|
||||||
|
|
||||||
|
gestorEntidades.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_INSERCION);
|
||||||
|
} finally {
|
||||||
|
if (gestorEntidades != null) {
|
||||||
|
gestorEntidades.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CursoProyecto obtenerEntidadPorID(Integer clave) throws ProyectosIESException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CursoProyecto obtenerCursoProyectoPorCursoYProyecto(String codigoCursoAcademico, Integer idProyecto)
|
||||||
|
throws ProyectosIESException {
|
||||||
|
CursoProyecto cursoProyecto = null;
|
||||||
|
|
||||||
|
String sentenciaJPQL = """
|
||||||
|
SELECT cp FROM CursoProyecto cp
|
||||||
|
WHERE cp.proyecto.identificador = :idProyecto
|
||||||
|
AND cp.cursoAcademico.codigo = :codigoCurso
|
||||||
|
""";
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (EntityManager entityManager = GestorEntityManagerJPA.getEntityManager();) {
|
||||||
|
TypedQuery<CursoProyecto> query = entityManager.createQuery(sentenciaJPQL, CursoProyecto.class);
|
||||||
|
|
||||||
|
query.setParameter("idProyecto", idProyecto);
|
||||||
|
query.setParameter("codigoCurso", codigoCursoAcademico);
|
||||||
|
|
||||||
|
cursoProyecto = query.getSingleResult();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_CONSULTA);
|
||||||
|
}
|
||||||
|
return cursoProyecto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,100 +0,0 @@
|
|||||||
package es.palomafp.aadd.inm.dao.jpa;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import es.palomafp.aadd.inm.dao.IPaisDAO;
|
|
||||||
import es.palomafp.aadd.inm.gestor.GestorEntityManagerJPA;
|
|
||||||
import es.palomafp.aadd.inm.vo.Gasto;
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import jakarta.persistence.EntityTransaction;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* PaisDaoJPA: Clase que implementa el interfaz IPaisDAO
|
|
||||||
*
|
|
||||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
|
||||||
* @date 31 oct 2025
|
|
||||||
*/
|
|
||||||
public class PaisDaoJPA implements IPaisDAO {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Gasto obtenerPaisPorID(int identificador) {
|
|
||||||
Gasto pais = null;
|
|
||||||
|
|
||||||
// try con recursos "cerrables": Session
|
|
||||||
try (EntityManager gestorEntidades = GestorEntityManagerJPA.getEntityManager()) {
|
|
||||||
pais = gestorEntidades.find(Gasto.class, identificador);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return pais;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void crearPais(Gasto pais) {
|
|
||||||
EntityManager gestorEntidades = null;
|
|
||||||
EntityTransaction transaccion = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
|
||||||
transaccion = gestorEntidades.getTransaction();
|
|
||||||
transaccion.begin();
|
|
||||||
|
|
||||||
gestorEntidades.persist(pais);
|
|
||||||
|
|
||||||
transaccion.commit();
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (transaccion != null && transaccion.isActive()) {
|
|
||||||
transaccion.rollback();
|
|
||||||
}
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (gestorEntidades != null) {
|
|
||||||
gestorEntidades.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actualizarPais(Gasto pais) {
|
|
||||||
EntityManager gestorEntidades = null;
|
|
||||||
EntityTransaction transaccion = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
|
||||||
transaccion = gestorEntidades.getTransaction();
|
|
||||||
transaccion.begin();
|
|
||||||
|
|
||||||
if (!gestorEntidades.contains(pais))
|
|
||||||
gestorEntidades.merge(pais);
|
|
||||||
|
|
||||||
transaccion.commit();
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (transaccion != null && transaccion.isActive()) {
|
|
||||||
transaccion.rollback();
|
|
||||||
}
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (gestorEntidades != null) {
|
|
||||||
gestorEntidades.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Gasto> obtenerListaPaises() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Gasto obtenerPaisPorNombre(String nombre) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao.jpa;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IOperacionesDAOEntidad;
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorEntityManagerJPA;
|
||||||
|
import es.palomafp.aadd.inm.vo.Patrocinador;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityTransaction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PatrocinadorDaoJPA: Clase que implementa el interfaz IOperacionesDAOEntidad
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public class PatrocinadorDaoJPA implements IOperacionesDAOEntidad<Patrocinador, Integer> {
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Patrocinador entidad) throws ProyectosIESException{
|
||||||
|
EntityManager gestorEntidades= null;
|
||||||
|
EntityTransaction transaccion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||||
|
transaccion = gestorEntidades.getTransaction();
|
||||||
|
transaccion .begin();
|
||||||
|
|
||||||
|
gestorEntidades.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_INSERCION);
|
||||||
|
} finally {
|
||||||
|
if (gestorEntidades != null) {
|
||||||
|
gestorEntidades.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Patrocinador obtenerEntidadPorID(Integer clave) throws ProyectosIESException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,71 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao.jpa;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IProyectoDAO;
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorEntityManagerJPA;
|
||||||
|
import es.palomafp.aadd.inm.vo.Proyecto;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityTransaction;
|
||||||
|
import jakarta.persistence.TypedQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ConceptoDaoJPA: Clase que implementa el interfaz IOperacionesDAOEntidad
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public class ProyectoDaoJPA implements IProyectoDAO {
|
||||||
|
@Override
|
||||||
|
public void crearEntidad(Proyecto entidad) throws ProyectosIESException{
|
||||||
|
EntityManager gestorEntidades= null;
|
||||||
|
EntityTransaction transaccion = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||||
|
transaccion = gestorEntidades.getTransaction();
|
||||||
|
transaccion .begin();
|
||||||
|
|
||||||
|
gestorEntidades.persist(entidad);
|
||||||
|
|
||||||
|
transaccion.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaccion != null && transaccion.isActive()) {
|
||||||
|
transaccion.rollback();
|
||||||
|
}
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_INSERCION);
|
||||||
|
} finally {
|
||||||
|
if (gestorEntidades != null) {
|
||||||
|
gestorEntidades.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Proyecto obtenerProyectoPorNombre(String nombreProyecto) throws ProyectosIESException {
|
||||||
|
Proyecto proyecto = null;
|
||||||
|
|
||||||
|
String sentenciaJPQL = """
|
||||||
|
SELECT p FROM Proyecto p
|
||||||
|
WHERE p.nombre= :nombre
|
||||||
|
""";
|
||||||
|
|
||||||
|
// try con recursos "cerrables": Session
|
||||||
|
try (EntityManager entityManager = GestorEntityManagerJPA.getEntityManager();) {
|
||||||
|
TypedQuery<Proyecto> query = entityManager.createQuery(sentenciaJPQL, Proyecto.class);
|
||||||
|
query.setParameter("nombre", nombreProyecto);
|
||||||
|
|
||||||
|
proyecto = query.getSingleResult();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ProyectosIESException(e, this.getClass(), ProyectosIESException.ERROR_CONSULTA);
|
||||||
|
}
|
||||||
|
|
||||||
|
return proyecto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Proyecto obtenerEntidadPorID(Integer clave) throws ProyectosIESException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package es.palomafp.aadd.inm.excepcion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ProyectosIESException: Clase que realiza ....
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 20 ene 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ProyectosIESException extends Exception {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -7090518753638026268L;
|
||||||
|
|
||||||
|
private int codigoError;
|
||||||
|
private Class<?> claseOrigen;
|
||||||
|
|
||||||
|
public static final int ERROR_GENERAL=0;
|
||||||
|
public static final int ERROR_GESTION_CONEXION=1;
|
||||||
|
public static final int ERROR_CONSULTA=2;
|
||||||
|
public static final int ERROR_INSERCION=3;
|
||||||
|
public static final int ERROR_ACTUALIZACION=4;
|
||||||
|
public static final int ERROR_BORRADO=5;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public ProyectosIESException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public ProyectosIESException(Exception e, Class<?> clase, int codError) {
|
||||||
|
super(e);
|
||||||
|
claseOrigen=clase;
|
||||||
|
codigoError=codError;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Class<?> getClaseOrigen() {
|
||||||
|
return claseOrigen;
|
||||||
|
}
|
||||||
|
public void setClaseOrigen(Class<?> claseOrigen) {
|
||||||
|
this.claseOrigen = claseOrigen;
|
||||||
|
}
|
||||||
|
public int getCodigoError() {
|
||||||
|
return codigoError;
|
||||||
|
}
|
||||||
|
public void setCodigoError(int codigoError) {
|
||||||
|
this.codigoError = codigoError;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
package es.palomafp.aadd.inm.procesador;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorFicheroConfiguracion;
|
||||||
|
|
||||||
|
public class ProcesadorFicheroCSV {
|
||||||
|
|
||||||
|
public void procesarFicheroCSVIngresos() {
|
||||||
|
|
||||||
|
String rutaFichero = GestorFicheroConfiguracion.getValorfromClave("ingresos.fichero.csv.ruta");
|
||||||
|
File fichero = new File(rutaFichero);
|
||||||
|
|
||||||
|
try (BufferedReader lector = new BufferedReader(new FileReader(fichero));) {
|
||||||
|
String linea;
|
||||||
|
|
||||||
|
lector.readLine(); // Saltar la cabecera
|
||||||
|
|
||||||
|
while ((linea = lector.readLine()) != null) {
|
||||||
|
System.out.println("linea:" + linea);
|
||||||
|
// Procesar la línea leída
|
||||||
|
String[] campos = linea.split(",");
|
||||||
|
// Suponiendo que el CSV tiene dos columnas: id, ingreso
|
||||||
|
String id = campos[0];
|
||||||
|
String ingreso = campos[1];
|
||||||
|
// Aquí iría la lógica para procesar cada línea
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,105 @@
|
|||||||
|
package es.palomafp.aadd.inm.procesador;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IConceptoDAO;
|
||||||
|
import es.palomafp.aadd.inm.dao.ICursoProyectoDAO;
|
||||||
|
import es.palomafp.aadd.inm.dao.IOperacionesDAOEntidad;
|
||||||
|
import es.palomafp.aadd.inm.dao.IProyectoDAO;
|
||||||
|
import es.palomafp.aadd.inm.dao.hbm.ConceptoDaoHibernate;
|
||||||
|
import es.palomafp.aadd.inm.dao.hbm.CursoProyectoDaoHibernate;
|
||||||
|
import es.palomafp.aadd.inm.dao.hbm.ProyectoDaoHibernate;
|
||||||
|
import es.palomafp.aadd.inm.dao.jpa.CursoProyectoDaoJPA;
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorFicheroConfiguracion;
|
||||||
|
import es.palomafp.aadd.inm.vo.Concepto;
|
||||||
|
import es.palomafp.aadd.inm.vo.CursoAcademico;
|
||||||
|
import es.palomafp.aadd.inm.vo.CursoProyecto;
|
||||||
|
import es.palomafp.aadd.inm.vo.Gasto;
|
||||||
|
import es.palomafp.aadd.inm.vo.Proyecto;
|
||||||
|
import tools.jackson.databind.JsonNode;
|
||||||
|
import tools.jackson.databind.ObjectMapper;
|
||||||
|
import tools.jackson.databind.node.ArrayNode;
|
||||||
|
|
||||||
|
public class ProcesadorFicheroJSON {
|
||||||
|
|
||||||
|
|
||||||
|
public void procesarFicheroJSONGastos() throws ProyectosIESException {
|
||||||
|
String rutaFichero = GestorFicheroConfiguracion.getValorfromClave("gastos.fichero.json.ruta");
|
||||||
|
File fichero = new File(rutaFichero);
|
||||||
|
|
||||||
|
// Se asume que la información de Paises es correcta y ya existe en la BD
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
JsonNode root = mapper.readTree(fichero);
|
||||||
|
|
||||||
|
String codigoCurso= root.get("curso").asString();
|
||||||
|
String nombreProyecto = root.get("proyecto").asString();
|
||||||
|
|
||||||
|
CursoAcademico cursoAcademico = new CursoAcademico();
|
||||||
|
cursoAcademico.setCodigo(codigoCurso);
|
||||||
|
IProyectoDAO proyectoDAO = new ProyectoDaoHibernate();
|
||||||
|
Proyecto proyecto = proyectoDAO.obtenerProyectoPorNombre(nombreProyecto);
|
||||||
|
|
||||||
|
CursoProyecto cursoProyecto = new CursoProyecto();
|
||||||
|
cursoProyecto.setCursoAcademico(cursoAcademico);
|
||||||
|
cursoProyecto.setProyecto(proyecto);
|
||||||
|
|
||||||
|
// Inserción en PostgreSQL con Hibernate
|
||||||
|
ICursoProyectoDAO operacionesDAOCursoProyecto = new CursoProyectoDaoHibernate();
|
||||||
|
operacionesDAOCursoProyecto.crearEntidad(cursoProyecto);
|
||||||
|
// Inserción en ObjectDB con JPA
|
||||||
|
operacionesDAOCursoProyecto = new CursoProyectoDaoJPA();
|
||||||
|
operacionesDAOCursoProyecto.crearEntidad(cursoProyecto);
|
||||||
|
|
||||||
|
// Se obtiene el CursoProyecto ya persistido
|
||||||
|
cursoProyecto = operacionesDAOCursoProyecto.obtenerCursoProyectoPorCursoYProyecto(codigoCurso, proyecto.getIdentificador());
|
||||||
|
|
||||||
|
JsonNode nodoGastos= root.get("gastos");
|
||||||
|
// Se obtienen los nodos Gasto
|
||||||
|
ArrayNode nodosGasto= convertirJsonNodeEnArrayNode(nodoGastos.get("gasto"));
|
||||||
|
|
||||||
|
for (JsonNode gastoNode : nodosGasto) {
|
||||||
|
String nombreConcepto=gastoNode.get("concepto").asString();
|
||||||
|
double precioUnitario = gastoNode.get("precio_unitario").asDouble();
|
||||||
|
int unidades = gastoNode.get("unidades").asInt();
|
||||||
|
String sFecha = gastoNode.get("fecha").asString();
|
||||||
|
LocalDate fecha = LocalDate.parse(sFecha);
|
||||||
|
|
||||||
|
Gasto gasto = new Gasto();
|
||||||
|
gasto.setFecha(fecha);
|
||||||
|
gasto.setNumeroUnidades(unidades);
|
||||||
|
gasto.setPrecioUnidad(precioUnitario);
|
||||||
|
|
||||||
|
IConceptoDAO conceptoDAO = new ConceptoDaoHibernate();
|
||||||
|
Concepto concepto=conceptoDAO.obtenerConceptoPorNombre(nombreConcepto)
|
||||||
|
gasto.setConcepto(concepto);
|
||||||
|
|
||||||
|
|
||||||
|
// Inserción en PostgreSQL con Hibernate
|
||||||
|
IOperacionesDAOEntidad<Gasto, Integer> operacionesDAOGasto = new GastoDaoHibernate();
|
||||||
|
operacionesDAOGasto.crearEntidad(gasto);
|
||||||
|
// Inserción en ObjectDB con JPA
|
||||||
|
operacionesDAOGasto = new GastoDaoJPA();
|
||||||
|
operacionesDAOGasto.crearEntidad(gasto);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("nodoGastos:" + nodoGastos);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayNode convertirJsonNodeEnArrayNode(JsonNode node) {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
if (node.isArray()) {
|
||||||
|
return (ArrayNode) node;
|
||||||
|
} else {
|
||||||
|
ArrayNode arrayNode = mapper.createArrayNode();
|
||||||
|
if (!node.isMissingNode()) {
|
||||||
|
arrayNode.add(node);
|
||||||
|
}
|
||||||
|
return arrayNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,153 @@
|
|||||||
|
package es.palomafp.aadd.inm.procesador;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IOperacionesDAOEntidad;
|
||||||
|
import es.palomafp.aadd.inm.dao.hbm.ConceptoDaoHibernate;
|
||||||
|
import es.palomafp.aadd.inm.dao.hbm.CursoAcademicoDaoHibernate;
|
||||||
|
import es.palomafp.aadd.inm.dao.hbm.PatrocinadorDaoHibernate;
|
||||||
|
import es.palomafp.aadd.inm.dao.hbm.ProyectoDaoHibernate;
|
||||||
|
import es.palomafp.aadd.inm.dao.jpa.ConceptoDaoJPA;
|
||||||
|
import es.palomafp.aadd.inm.dao.jpa.CursoAcademicoDaoJPA;
|
||||||
|
import es.palomafp.aadd.inm.dao.jpa.PatrocinadorDaoJPA;
|
||||||
|
import es.palomafp.aadd.inm.dao.jpa.ProyectoDaoJPA;
|
||||||
|
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorFicheroConfiguracion;
|
||||||
|
import es.palomafp.aadd.inm.vo.Concepto;
|
||||||
|
import es.palomafp.aadd.inm.vo.CursoAcademico;
|
||||||
|
import es.palomafp.aadd.inm.vo.Patrocinador;
|
||||||
|
import es.palomafp.aadd.inm.vo.Proyecto;
|
||||||
|
import tools.jackson.databind.JsonNode;
|
||||||
|
import tools.jackson.databind.ObjectMapper;
|
||||||
|
import tools.jackson.databind.node.ArrayNode;
|
||||||
|
import tools.jackson.dataformat.xml.XmlMapper;
|
||||||
|
|
||||||
|
public class ProcesadorFicheroXML {
|
||||||
|
|
||||||
|
public void procesarFicheroXMLCatalogos() throws ProyectosIESException {
|
||||||
|
String rutaFichero = GestorFicheroConfiguracion.getValorfromClave("catalogos.fichero.xml.ruta");
|
||||||
|
File fichero = new File(rutaFichero);
|
||||||
|
|
||||||
|
// Procesar con Jackson XML
|
||||||
|
ObjectMapper mapper = new XmlMapper();
|
||||||
|
JsonNode root = mapper.readTree(fichero);
|
||||||
|
|
||||||
|
// procesar nodos Curso
|
||||||
|
JsonNode nodoCursos = root.get("Cursos");
|
||||||
|
procesarCursos(nodoCursos);
|
||||||
|
|
||||||
|
// procesar nodos Proyectos
|
||||||
|
JsonNode nodoProyectos = root.get("Proyectos");
|
||||||
|
procesarProyectos(nodoProyectos);
|
||||||
|
|
||||||
|
// procesar nodos Conceptos
|
||||||
|
JsonNode nodoConceptos = root.get("Conceptos");
|
||||||
|
procesarConceptos(nodoConceptos);
|
||||||
|
|
||||||
|
// procesar nodos Patrocinadores
|
||||||
|
JsonNode nodoPatrocinadores = root.get("Patrocinadores");
|
||||||
|
procesarPatrocinadores(nodoPatrocinadores);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void procesarCursos(JsonNode nodoCursos) throws ProyectosIESException {
|
||||||
|
// Se obtienen los nodos Curso
|
||||||
|
ArrayNode nodosCurso = convertirJsonNodeEnArrayNode(nodoCursos.get("Curso"));
|
||||||
|
for (JsonNode nodoCurso : nodosCurso) {
|
||||||
|
String codigo = nodoCurso.get("Codigo").asString();
|
||||||
|
String nombre = nodoCurso.get("Nombre").asString();
|
||||||
|
String sFechaInicio = nodoCurso.get("Fechas").get("FechaInicio").asString();
|
||||||
|
LocalDate fechaInicio = LocalDate.parse(sFechaInicio);
|
||||||
|
String sFechaFin = nodoCurso.get("Fechas").get("FechaFin").asString();
|
||||||
|
LocalDate fechaFin = LocalDate.parse(sFechaFin);
|
||||||
|
|
||||||
|
CursoAcademico curso = new CursoAcademico();
|
||||||
|
curso.setCodigo(codigo);
|
||||||
|
curso.setNombre(nombre);
|
||||||
|
curso.setFechaInicio(fechaInicio);
|
||||||
|
curso.setFechaFin(fechaFin);
|
||||||
|
|
||||||
|
// Inserción en PostgreSQL con Hibernate
|
||||||
|
IOperacionesDAOEntidad<CursoAcademico, String> operacionesDAOCursoAcademico = new CursoAcademicoDaoHibernate();
|
||||||
|
operacionesDAOCursoAcademico.crearEntidad(curso);
|
||||||
|
// Inserción en ObjectDB con JPA
|
||||||
|
operacionesDAOCursoAcademico = new CursoAcademicoDaoJPA();
|
||||||
|
operacionesDAOCursoAcademico.crearEntidad(curso);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void procesarProyectos(JsonNode nodoProyectos) throws ProyectosIESException {
|
||||||
|
// Se obtienen los nodos Proyecto
|
||||||
|
ArrayNode nodosProyecto = convertirJsonNodeEnArrayNode(nodoProyectos.get("Proyecto"));
|
||||||
|
for (JsonNode proyectoNode : nodosProyecto) {
|
||||||
|
JsonNode nodoInfoProyecto = proyectoNode.get("Informacion_descriptiva");
|
||||||
|
String nombre = nodoInfoProyecto.get("Nombre").asString();
|
||||||
|
String descripcion = nodoInfoProyecto.get("Descripcion").asString();
|
||||||
|
String urlImagenLogo = nodoInfoProyecto.get("url_imagen_logo").asString();
|
||||||
|
|
||||||
|
Proyecto proyecto = new Proyecto();
|
||||||
|
proyecto.setNombre(nombre);
|
||||||
|
proyecto.setDescripcion(descripcion);
|
||||||
|
proyecto.setUrlLogo(urlImagenLogo);
|
||||||
|
|
||||||
|
// Inserción en PostgreSQL con Hibernate
|
||||||
|
IOperacionesDAOEntidad<Proyecto, Integer> operacionesDAOProyecto = new ProyectoDaoHibernate();
|
||||||
|
operacionesDAOProyecto.crearEntidad(proyecto);
|
||||||
|
// Inserción en ObjectDB con JPA
|
||||||
|
operacionesDAOProyecto = new ProyectoDaoJPA();
|
||||||
|
operacionesDAOProyecto.crearEntidad(proyecto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void procesarConceptos(JsonNode nodoConceptos) throws ProyectosIESException {
|
||||||
|
// Se obtienen los nodos Concepto
|
||||||
|
ArrayNode nodosConcepto = convertirJsonNodeEnArrayNode(nodoConceptos.get("Concepto"));
|
||||||
|
for (JsonNode conceptoNode : nodosConcepto) {
|
||||||
|
String nombre = conceptoNode.get("Nombre").asString();
|
||||||
|
String descripcion = conceptoNode.get("Descripcion").asString();
|
||||||
|
|
||||||
|
Concepto concepto = new Concepto();
|
||||||
|
concepto.setNombre(nombre);
|
||||||
|
concepto.setDescripcion(descripcion);
|
||||||
|
|
||||||
|
// Inserción en PostgreSQL con Hibernate
|
||||||
|
IOperacionesDAOEntidad<Concepto, Integer> operacionesDAOConcepto = new ConceptoDaoHibernate();
|
||||||
|
operacionesDAOConcepto.crearEntidad(concepto);
|
||||||
|
// Inserción en ObjectDB con JPA
|
||||||
|
operacionesDAOConcepto = new ConceptoDaoJPA();
|
||||||
|
operacionesDAOConcepto.crearEntidad(concepto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void procesarPatrocinadores(JsonNode nodoPatrocinadores) throws ProyectosIESException {
|
||||||
|
// Se obtienen los nodos Patrocinador
|
||||||
|
ArrayNode nodosPatrocinador = convertirJsonNodeEnArrayNode(nodoPatrocinadores.get("Patrocinador"));
|
||||||
|
for (JsonNode patrocinadorNode : nodosPatrocinador) {
|
||||||
|
String nombre = patrocinadorNode.get("Nombre").asString();
|
||||||
|
|
||||||
|
Patrocinador patrocinador = new Patrocinador();
|
||||||
|
patrocinador.setNombre(nombre);
|
||||||
|
|
||||||
|
// Inserción en PostgreSQL con Hibernate
|
||||||
|
IOperacionesDAOEntidad<Patrocinador, Integer> operacionesDAOPatrocinador = new PatrocinadorDaoHibernate();
|
||||||
|
operacionesDAOPatrocinador.crearEntidad(patrocinador);
|
||||||
|
// Inserción en ObjectDB con JPA
|
||||||
|
operacionesDAOPatrocinador = new PatrocinadorDaoJPA();
|
||||||
|
operacionesDAOPatrocinador.crearEntidad(patrocinador);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayNode convertirJsonNodeEnArrayNode(JsonNode node) {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
if (node.isArray()) {
|
||||||
|
return (ArrayNode) node;
|
||||||
|
} else {
|
||||||
|
ArrayNode arrayNode = mapper.createArrayNode();
|
||||||
|
if (!node.isMissingNode()) {
|
||||||
|
arrayNode.add(node);
|
||||||
|
}
|
||||||
|
return arrayNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,59 +0,0 @@
|
|||||||
package es.palomafp.aadd.inm.procesador;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import es.palomafp.aadd.inm.gestor.GestorFicheroConfiguracion;
|
|
||||||
import tools.jackson.databind.JsonNode;
|
|
||||||
import tools.jackson.databind.ObjectMapper;
|
|
||||||
|
|
||||||
public class ProcesadorFicheros {
|
|
||||||
|
|
||||||
public void procesarFicheroXMLCatalogos() {
|
|
||||||
String rutaFichero = GestorFicheroConfiguracion.getValorfromClave("catalogos.fichero.xml.ruta");
|
|
||||||
File fichero = new File(rutaFichero);
|
|
||||||
|
|
||||||
// Se asume que la información de Paises es correcta y ya existe en la BD
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
JsonNode root = mapper.readTree(fichero);
|
|
||||||
JsonNode nodoPeliculas = root.get("peliculas");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void procesarFicheroJSONGastos() {
|
|
||||||
String rutaFichero = GestorFicheroConfiguracion.getValorfromClave("gastos.fichero.json.ruta");
|
|
||||||
File fichero = new File(rutaFichero);
|
|
||||||
|
|
||||||
// Se asume que la información de Paises es correcta y ya existe en la BD
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
JsonNode root = mapper.readTree(fichero);
|
|
||||||
JsonNode nodoPeliculas = root.get("peliculas");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void procesarFicheroCSVIngresos() {
|
|
||||||
|
|
||||||
String rutaFichero = GestorFicheroConfiguracion.getValorfromClave("ingresos.fichero.csv.ruta");
|
|
||||||
File fichero = new File(rutaFichero);
|
|
||||||
|
|
||||||
try (BufferedReader lector = new BufferedReader(new FileReader(fichero));) {
|
|
||||||
String linea;
|
|
||||||
while ((linea = lector.readLine()) != null) {
|
|
||||||
// Procesar la línea leída
|
|
||||||
String[] campos = linea.split(",");
|
|
||||||
// Suponiendo que el CSV tiene dos columnas: id, ingreso
|
|
||||||
String id = campos[0];
|
|
||||||
String ingreso = campos[1];
|
|
||||||
// Aquí iría la lógica para procesar cada línea
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -6,6 +6,7 @@ import jakarta.persistence.GeneratedValue;
|
|||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -17,6 +18,7 @@ import jakarta.persistence.Table;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "T_CONCEPTO")
|
@Table(name = "T_CONCEPTO")
|
||||||
public class Concepto {
|
public class Concepto {
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import jakarta.persistence.Column;
|
|||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -16,6 +17,7 @@ import jakarta.persistence.Table;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="T_CURSO_ACADEMICO")
|
@Table(name="T_CURSO_ACADEMICO")
|
||||||
public class CursoAcademico {
|
public class CursoAcademico {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import jakarta.persistence.Id;
|
|||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -18,6 +19,7 @@ import jakarta.persistence.Table;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "T_CURSO_PROYECTO")
|
@Table(name = "T_CURSO_PROYECTO")
|
||||||
public class CursoProyecto {
|
public class CursoProyecto {
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import jakarta.persistence.Id;
|
|||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -21,6 +22,7 @@ import jakarta.persistence.Table;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="T_GASTO")
|
@Table(name="T_GASTO")
|
||||||
public class Gasto {
|
public class Gasto {
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import jakarta.persistence.Id;
|
|||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -21,6 +22,7 @@ import jakarta.persistence.Table;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="T_INGRESO")
|
@Table(name="T_INGRESO")
|
||||||
public class Ingreso {
|
public class Ingreso {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import jakarta.persistence.GenerationType;
|
|||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Lob;
|
import jakarta.persistence.Lob;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -17,6 +18,7 @@ import jakarta.persistence.Table;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="T_PATROCINADOR")
|
@Table(name="T_PATROCINADOR")
|
||||||
public class Patrocinador {
|
public class Patrocinador {
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import jakarta.persistence.GeneratedValue;
|
|||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -16,6 +17,7 @@ import jakarta.persistence.Table;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="T_PROYECTO")
|
@Table(name="T_PROYECTO")
|
||||||
public class Proyecto {
|
public class Proyecto {
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
<property name="connection.password">postgresql_123</property>
|
<property name="connection.password">postgresql_123</property>
|
||||||
|
|
||||||
<!-- DB schema will be updated if needed -->
|
<!-- DB schema will be updated if needed -->
|
||||||
<property name="hbm2ddl.auto">create-drop</property>
|
<property name="hbm2ddl.auto">none</property>
|
||||||
<property name="show_sql">true</property>
|
<property name="show_sql">true</property>
|
||||||
<property name="format_sql">true</property>
|
<property name="format_sql">true</property>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user