Commit inicial
This commit is contained in:
commit
2725ebf0ea
41
.classpath
Normal file
41
.classpath
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/bin/
|
||||
*.class
|
||||
/target/
|
||||
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>examen_aadd_2trim_FP</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
13
.settings/org.eclipse.jdt.core.prefs
Normal file
13
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,13 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=24
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=24
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=24
|
||||
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
9
ficheros/formacion-Instituto.csv
Normal file
9
ficheros/formacion-Instituto.csv
Normal file
@ -0,0 +1,9 @@
|
||||
a_tratar,cod_formacion, cod_instituto, anyo
|
||||
S, 1, 1, 2021
|
||||
S, 1, 2, 2022
|
||||
S, 2, 1, 2022
|
||||
S, 2, 2, 2021
|
||||
N, 2, 3, 2023
|
||||
S, 3, 1, 2024
|
||||
S, 3, 3, 2024
|
||||
S, 4, 3, 2020
|
||||
|
53
pom.xml
Normal file
53
pom.xml
Normal file
@ -0,0 +1,53 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>FormacionProfesionalDAM2</groupId>
|
||||
<artifactId>FormacionProfesionalDAM2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
|
||||
<!-- Source: https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync -->
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongodb-driver-sync</artifactId>
|
||||
<version>5.6.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Source: https://mvnrepository.com/artifact/org.postgresql/postgresql -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.7.8</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>9.5.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-core -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate.orm</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>7.1.11.Final</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/tools.jackson.dataformat/jackson-dataformat-xml -->
|
||||
<dependency>
|
||||
<groupId>tools.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.opencsv/opencsv -->
|
||||
<dependency>
|
||||
<groupId>com.opencsv</groupId>
|
||||
<artifactId>opencsv</artifactId>
|
||||
<version>5.10</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
190
src/main/java/org/comunidadmadrid/fp/dam2/ClasePrincipal.java
Normal file
190
src/main/java/org/comunidadmadrid/fp/dam2/ClasePrincipal.java
Normal file
@ -0,0 +1,190 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.comunidadmadrid.fp.dam2.dao.ICicloFormativoDAO;
|
||||
import org.comunidadmadrid.fp.dam2.dao.IFormacionDAO;
|
||||
import org.comunidadmadrid.fp.dam2.dao.IInstitutoDAO;
|
||||
import org.comunidadmadrid.fp.dam2.dao.IInstitutoFormacionDAO;
|
||||
import org.comunidadmadrid.fp.dam2.dao.hibernate.CicloFormativoDaoHibernate;
|
||||
import org.comunidadmadrid.fp.dam2.dao.hibernate.FormacionDaoHibernate;
|
||||
import org.comunidadmadrid.fp.dam2.dao.hibernate.InstitutoFormacionDaoHibernate;
|
||||
import org.comunidadmadrid.fp.dam2.dao.jdbc.CicloFormativoDaoJDBC;
|
||||
import org.comunidadmadrid.fp.dam2.dao.jpa.InstitutoDaoJPA;
|
||||
import org.comunidadmadrid.fp.dam2.dao.mongodb.InstitutoDaoMongoDB;
|
||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||
import org.comunidadmadrid.fp.dam2.gestores.GestorFicheroConfiguracion;
|
||||
import org.comunidadmadrid.fp.dam2.procesamiento.ProcesadorDatos;
|
||||
import org.comunidadmadrid.fp.dam2.utilidades.GestorURLs;
|
||||
import org.comunidadmadrid.fp.dam2.vo.CicloFormativo;
|
||||
import org.comunidadmadrid.fp.dam2.vo.Formacion;
|
||||
import org.comunidadmadrid.fp.dam2.vo.Instituto;
|
||||
import org.comunidadmadrid.fp.dam2.vo.InstitutoFormacion;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 1 mar 2025
|
||||
*/
|
||||
public class ClasePrincipal {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
ClasePrincipal appPrincipal = new ClasePrincipal();
|
||||
// GestorSesionHibernate.getSession();
|
||||
|
||||
try {
|
||||
appPrincipal.tratarCiclosFormativos();
|
||||
|
||||
appPrincipal.tratarInstitutos();
|
||||
|
||||
appPrincipal.tratarFormaciones();
|
||||
|
||||
appPrincipal.tratarInstitutoFormacion();
|
||||
} catch (FormacionException 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 FormacionException.ERROR_GESTION_CONEXION:
|
||||
operacion = "Gestión de Conexión";
|
||||
break;
|
||||
case FormacionException.ERROR_CONSULTA:
|
||||
operacion = "Consulta";
|
||||
break;
|
||||
case FormacionException.ERROR_INSERCION:
|
||||
operacion = "Inserción";
|
||||
break;
|
||||
case FormacionException.ERROR_BORRADO:
|
||||
operacion = "Borrado";
|
||||
break;
|
||||
case FormacionException.ERROR_ACTUALIZACION:
|
||||
operacion = "Actualización";
|
||||
break;
|
||||
}
|
||||
|
||||
mensajeError = String.format(mensajeError, e.getClaseOrigen().getName(), operacion);
|
||||
System.err.println(mensajeError);
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tratamiento de información de Ciclos Formativos
|
||||
*
|
||||
* @throws FormacionException
|
||||
*/
|
||||
private void tratarCiclosFormativos() throws FormacionException {
|
||||
|
||||
// Se obtiene la lista de Ciclos formativos de PostgreSQL
|
||||
ICicloFormativoDAO iCicloFormativoDAO = new CicloFormativoDaoJDBC();
|
||||
List<CicloFormativo> listaCiclos = iCicloFormativoDAO.obtenerListCiclosFormativosActivos();
|
||||
|
||||
if (listaCiclos != null && listaCiclos.size() > 0) {
|
||||
|
||||
// Se prepara el AADD de Ciclo formativo para que se realice mediante Hibernate
|
||||
iCicloFormativoDAO = new CicloFormativoDaoHibernate();
|
||||
|
||||
for (CicloFormativo cicloFormativo : listaCiclos) {
|
||||
|
||||
System.out.println(cicloFormativo);
|
||||
|
||||
if (cicloFormativo.getUrlLogo() != null) {
|
||||
// Se carga la imagen a partir de la URL.
|
||||
byte[] bytesImagen = GestorURLs.obtenerBytesImagenDeURL(cicloFormativo.getUrlLogo());
|
||||
cicloFormativo.setImagenCiclo(bytesImagen);
|
||||
}
|
||||
// Se inserta el ciclo formativo mediante Hibernate
|
||||
iCicloFormativoDAO.insertarCicloFormativo(cicloFormativo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tratamiento de información de Formaciones
|
||||
*
|
||||
* @throws FormacionException
|
||||
*/
|
||||
private void tratarFormaciones() throws FormacionException {
|
||||
|
||||
// Se obtiene la lista de Formaciones a partir de una URL
|
||||
String urlFormaciones = GestorFicheroConfiguracion.obtenerValor("url.formaciones");
|
||||
ProcesadorDatos procesador = new ProcesadorDatos();
|
||||
List<Formacion> listaFormaciones = procesador.obtenerFormacionesDeURL(urlFormaciones);
|
||||
|
||||
if (listaFormaciones != null && listaFormaciones.size() > 0) {
|
||||
// Se prepara el AADD de Formación para que se realice mediante Hibernate
|
||||
IFormacionDAO iFormacionDAO = new FormacionDaoHibernate();
|
||||
|
||||
for (Formacion formacion : listaFormaciones) {
|
||||
|
||||
System.out.println(formacion);
|
||||
iFormacionDAO.insertarFormacion(formacion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tratamiento de información de Institutos
|
||||
*
|
||||
* @throws FormacionException
|
||||
*/
|
||||
private void tratarInstitutos() throws FormacionException {
|
||||
|
||||
// Se obtiene la lista de Institutos a partir de MongoDB
|
||||
IInstitutoDAO institutoDAO = new InstitutoDaoMongoDB();
|
||||
List<Instituto> listaInstitutos = institutoDAO.obtenerListaInstitutos();
|
||||
|
||||
if (listaInstitutos != null) {
|
||||
|
||||
// Se prepara el AADD de Instituto para que se realice mediante Hibernate
|
||||
institutoDAO = new InstitutoDaoJPA();
|
||||
|
||||
for (Instituto instituto : listaInstitutos) {
|
||||
// Se obiene el instituto en la BBDD
|
||||
Instituto institutoBBDD = institutoDAO.obtenerInstitutoPorID(instituto.getIdentificador());
|
||||
|
||||
System.out.println("instituto: " + instituto);
|
||||
System.out.println("institutoBBDD: " + institutoBBDD);
|
||||
|
||||
if (institutoBBDD == null) // Si no existen en la BBDD se inserta
|
||||
institutoDAO.insertarInstituto(instituto);
|
||||
else // En caso contrario se actualizar
|
||||
institutoDAO.actualizarInstituto(instituto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tratamiento de información de Instituto Formación
|
||||
*
|
||||
* @throws FormacionException
|
||||
*/
|
||||
private void tratarInstitutoFormacion() throws FormacionException {
|
||||
|
||||
// Se obtiene la lista de Instituto Formación a partir de un fichero en CSV
|
||||
String rutaCSVInstitutoFormacion = GestorFicheroConfiguracion.obtenerValor("ruta.csv");
|
||||
ProcesadorDatos procesador = new ProcesadorDatos();
|
||||
List<InstitutoFormacion> listaInstitutosFormaciones = procesador
|
||||
.obtenerInstitutoFormacionDeFicheroCSV(rutaCSVInstitutoFormacion);
|
||||
|
||||
if (listaInstitutosFormaciones != null && listaInstitutosFormaciones.size() > 0) {
|
||||
// Se prepara el AADD de InstitutoFormacion para que se realice mediante
|
||||
// Hibernate
|
||||
IInstitutoFormacionDAO iInstitutoFormacionDAO = new InstitutoFormacionDaoHibernate();
|
||||
|
||||
for (InstitutoFormacion institutoFormacion : listaInstitutosFormaciones) {
|
||||
|
||||
System.out.println(institutoFormacion);
|
||||
iInstitutoFormacionDAO.insertarInstitutoFormacion(institutoFormacion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||
import org.comunidadmadrid.fp.dam2.vo.CicloFormativo;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 1 mar 2025
|
||||
*/
|
||||
public interface ICicloFormativoDAO {
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws FormacionException
|
||||
*/
|
||||
List<CicloFormativo> obtenerListCiclosFormativosActivos() throws FormacionException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ciclo
|
||||
* @throws FormacionException
|
||||
*/
|
||||
void insertarCicloFormativo(CicloFormativo ciclo) throws FormacionException;
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.dao;
|
||||
|
||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||
import org.comunidadmadrid.fp.dam2.vo.Formacion;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 1 mar 2025
|
||||
*/
|
||||
public interface IFormacionDAO {
|
||||
/**
|
||||
*
|
||||
* @param formacion
|
||||
* @throws FormacionException
|
||||
*/
|
||||
void insertarFormacion(Formacion formacion) throws FormacionException;
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||
import org.comunidadmadrid.fp.dam2.vo.Instituto;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 1 mar 2025
|
||||
*/
|
||||
public interface IInstitutoDAO {
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws FormacionException
|
||||
*/
|
||||
List<Instituto> obtenerListaInstitutos() throws FormacionException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param identificador
|
||||
* @return
|
||||
* @throws FormacionException
|
||||
*/
|
||||
Instituto obtenerInstitutoPorID(int identificador) throws FormacionException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param instituto
|
||||
* @throws FormacionException
|
||||
*/
|
||||
void insertarInstituto(Instituto instituto) throws FormacionException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param instituto
|
||||
* @throws FormacionException
|
||||
*/
|
||||
void actualizarInstituto(Instituto instituto) throws FormacionException;
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.dao;
|
||||
|
||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||
import org.comunidadmadrid.fp.dam2.vo.InstitutoFormacion;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 1 mar 2025
|
||||
*/
|
||||
public interface IInstitutoFormacionDAO {
|
||||
/**
|
||||
*
|
||||
* @param institutoFormacion
|
||||
* @throws FormacionException
|
||||
*/
|
||||
void insertarInstitutoFormacion(InstitutoFormacion institutoFormacion) throws FormacionException;
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.dao.hibernate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.comunidadmadrid.fp.dam2.dao.ICicloFormativoDAO;
|
||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||
import org.comunidadmadrid.fp.dam2.gestores.GestorSesionHibernate;
|
||||
import org.comunidadmadrid.fp.dam2.vo.CicloFormativo;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
/**
|
||||
* Organización: Virgen de la Paloma
|
||||
* Programador: Isidoro Nevares Martín
|
||||
* Fecha: 26 marzo 2026
|
||||
*/
|
||||
public class CicloFormativoDaoHibernate implements ICicloFormativoDAO {
|
||||
|
||||
@Override
|
||||
public List<CicloFormativo> obtenerListCiclosFormativosActivos() throws FormacionException {
|
||||
List<CicloFormativo> listaCiclosFormativos = null;
|
||||
|
||||
return listaCiclosFormativos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertarCicloFormativo(CicloFormativo ciclo) throws FormacionException {
|
||||
Transaction transaccion = null;
|
||||
|
||||
Session sesion = null;
|
||||
try {
|
||||
sesion = GestorSesionHibernate.getSession();
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
sesion.persist(ciclo);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
if (transaccion != null && transaccion.isActive()) {
|
||||
transaccion.rollback();
|
||||
}
|
||||
throw new FormacionException(e, FormacionException.ERROR_INSERCION, getClass());
|
||||
} finally {
|
||||
if (sesion != null) {
|
||||
sesion.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.dao.hibernate;
|
||||
|
||||
import org.comunidadmadrid.fp.dam2.dao.IFormacionDAO;
|
||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||
import org.comunidadmadrid.fp.dam2.gestores.GestorSesionHibernate;
|
||||
import org.comunidadmadrid.fp.dam2.vo.Formacion;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
/**
|
||||
* Organización: Virgen de la Paloma
|
||||
* Programador: Isidoro Nevares Martín
|
||||
* Fecha: 26 marzo 2026
|
||||
*/
|
||||
public class FormacionDaoHibernate implements IFormacionDAO{
|
||||
|
||||
@Override
|
||||
public void insertarFormacion(Formacion formacion) throws FormacionException {
|
||||
Transaction transaccion=null;
|
||||
|
||||
Session sesion = null;
|
||||
try {
|
||||
sesion = GestorSesionHibernate.getSession();
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
sesion.persist(formacion);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
if (transaccion != null && transaccion.isActive()) {
|
||||
transaccion.rollback();
|
||||
}
|
||||
throw new FormacionException(e, FormacionException.ERROR_INSERCION, getClass());
|
||||
} finally {
|
||||
if (sesion != null) {
|
||||
sesion.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.dao.hibernate;
|
||||
|
||||
import org.comunidadmadrid.fp.dam2.dao.IInstitutoFormacionDAO;
|
||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||
import org.comunidadmadrid.fp.dam2.gestores.GestorSesionHibernate;
|
||||
import org.comunidadmadrid.fp.dam2.vo.InstitutoFormacion;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
/**
|
||||
* Organización: Virgen de la Paloma
|
||||
* Programador: Isidoro Nevares Martín
|
||||
* Fecha: 26 marzo 2026
|
||||
*/
|
||||
public class InstitutoFormacionDaoHibernate implements IInstitutoFormacionDAO{
|
||||
@Override
|
||||
public void insertarInstitutoFormacion(InstitutoFormacion institutoFormacion) throws FormacionException {
|
||||
Transaction transaccion=null;
|
||||
|
||||
Session sesion = null;
|
||||
try {
|
||||
sesion = GestorSesionHibernate.getSession();
|
||||
transaccion = sesion.beginTransaction();
|
||||
|
||||
sesion.persist(institutoFormacion);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
if (transaccion != null && transaccion.isActive()) {
|
||||
transaccion.rollback();
|
||||
}
|
||||
throw new FormacionException(e, FormacionException.ERROR_INSERCION, getClass());
|
||||
} finally {
|
||||
if (sesion != null) {
|
||||
sesion.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.dao.jdbc;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.comunidadmadrid.fp.dam2.dao.ICicloFormativoDAO;
|
||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||
import org.comunidadmadrid.fp.dam2.gestores.GestorConexionJDBC;
|
||||
import org.comunidadmadrid.fp.dam2.vo.CicloFormativo;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 1 mar 2025
|
||||
*/
|
||||
public class CicloFormativoDaoJDBC implements ICicloFormativoDAO{
|
||||
private Connection conexion=null;
|
||||
|
||||
@Override
|
||||
public List<CicloFormativo> obtenerListCiclosFormativosActivos() throws FormacionException {
|
||||
List<CicloFormativo> listaCiclosFormativos=null;
|
||||
|
||||
String sentenciaSQL= """
|
||||
SELECT * FROM T_CICLO_FORMATIVO cf
|
||||
WHERE cf.activo='S'
|
||||
""";
|
||||
|
||||
ResultSet resultadoSentencia=null;
|
||||
// try con recursos "cerrables": Connection, Statement
|
||||
try (Connection conexion = GestorConexionJDBC.getConexionSGDB();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
|
||||
resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||
if (resultadoSentencia!= null)
|
||||
listaCiclosFormativos= new ArrayList<CicloFormativo>();
|
||||
|
||||
while (resultadoSentencia.next()) {
|
||||
|
||||
CicloFormativo cicloFormativo= new CicloFormativo();
|
||||
cicloFormativo.setIdentificador(resultadoSentencia.getInt("identificador"));
|
||||
cicloFormativo.setDescripcion(resultadoSentencia.getString("desc_ciclo") );
|
||||
cicloFormativo.setNombre(resultadoSentencia.getString("nom_corto"));
|
||||
cicloFormativo.setUrlLogo(resultadoSentencia.getString("url_img_logo"));
|
||||
|
||||
listaCiclosFormativos.add(cicloFormativo);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new FormacionException(e, FormacionException.ERROR_CONSULTA, getClass());
|
||||
}finally {
|
||||
if(conexion!=null) {
|
||||
try {
|
||||
conexion.close();
|
||||
} catch (SQLException e) {
|
||||
throw new FormacionException(e, FormacionException.ERROR_CONSULTA, getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return listaCiclosFormativos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertarCicloFormativo(CicloFormativo ciclo) throws FormacionException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.dao.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.comunidadmadrid.fp.dam2.dao.IInstitutoDAO;
|
||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||
import org.comunidadmadrid.fp.dam2.gestores.GestorEntityManagerJPA;
|
||||
import org.comunidadmadrid.fp.dam2.vo.Instituto;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 1 mar 2025
|
||||
*/
|
||||
public class InstitutoDaoJPA implements IInstitutoDAO {
|
||||
@Override
|
||||
public Instituto obtenerInstitutoPorID(int identificador) throws FormacionException {
|
||||
Instituto instituto =null;
|
||||
|
||||
EntityManager gestorEntidades = null;
|
||||
try {
|
||||
gestorEntidades= GestorEntityManagerJPA.getEntityManager();
|
||||
|
||||
instituto=gestorEntidades.find(Instituto.class, identificador);
|
||||
} catch (Exception e) {
|
||||
throw new FormacionException(e, FormacionException.ERROR_CONSULTA, getClass());
|
||||
}
|
||||
finally {
|
||||
if(gestorEntidades!=null) {
|
||||
gestorEntidades.close();
|
||||
}
|
||||
}
|
||||
|
||||
return instituto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertarInstituto(Instituto instituto) throws FormacionException {
|
||||
EntityManager gestorEntidades = null;
|
||||
EntityTransaction transaccion = null;
|
||||
|
||||
try {
|
||||
gestorEntidades = GestorEntityManagerJPA.getEntityManager();
|
||||
transaccion = gestorEntidades.getTransaction();
|
||||
transaccion.begin();
|
||||
|
||||
gestorEntidades.persist(instituto);
|
||||
|
||||
transaccion.commit();
|
||||
} catch (Exception e) {
|
||||
if (transaccion != null && transaccion.isActive()) {
|
||||
transaccion.rollback();
|
||||
}
|
||||
throw new FormacionException(e, FormacionException.ERROR_INSERCION, getClass());
|
||||
} finally {
|
||||
if (gestorEntidades != null) {
|
||||
gestorEntidades.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actualizarInstituto(Instituto instituto) throws FormacionException {
|
||||
EntityManager gestorEntidades = null;
|
||||
EntityTransaction transaccion = null;
|
||||
|
||||
try {
|
||||
gestorEntidades= GestorEntityManagerJPA.getEntityManager();
|
||||
transaccion=gestorEntidades.getTransaction();
|
||||
|
||||
// Inicia transacción
|
||||
transaccion.begin();
|
||||
|
||||
// Para poder actulizarse ha de encontarse en el ámbito del entityManager
|
||||
if (!gestorEntidades.contains(instituto))
|
||||
gestorEntidades.merge(instituto);
|
||||
|
||||
// Confirma transacción
|
||||
transaccion.commit();
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new FormacionException(e, FormacionException.ERROR_ACTUALIZACION, getClass());
|
||||
} finally {
|
||||
if(gestorEntidades!=null) {
|
||||
gestorEntidades.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Instituto> obtenerListaInstitutos() throws FormacionException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.dao.mongodb;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.comunidadmadrid.fp.dam2.dao.IInstitutoDAO;
|
||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||
import org.comunidadmadrid.fp.dam2.gestores.GestorConexionMongoDB;
|
||||
import org.comunidadmadrid.fp.dam2.vo.Instituto;
|
||||
|
||||
import com.mongodb.client.FindIterable;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 1 mar 2025
|
||||
*/
|
||||
public class InstitutoDaoMongoDB implements IInstitutoDAO{
|
||||
private final static String COLECCION = "c_instituto";
|
||||
@Override
|
||||
public List<Instituto> obtenerListaInstitutos() throws FormacionException {
|
||||
List<Instituto> listaInstitutos = null;
|
||||
|
||||
MongoCollection<Document> coleccionMongoDB = null;
|
||||
try {
|
||||
coleccionMongoDB = GestorConexionMongoDB.getMongoDatabase().getCollection(COLECCION);
|
||||
|
||||
// Obtener todos los documentos
|
||||
FindIterable<Document> documentosEncontrados = coleccionMongoDB.find();
|
||||
|
||||
// Crear una lista para almacenar los coches
|
||||
if (documentosEncontrados!=null) {
|
||||
listaInstitutos = new ArrayList<Instituto>();
|
||||
|
||||
// Iterar sobre los documentos y convertirlos en objetos Coche
|
||||
for (Document doc : documentosEncontrados) {
|
||||
String identificador= doc.getString("_id");
|
||||
String nombre = doc.getString("nombre");
|
||||
String direccion = doc.getString("direccion");
|
||||
String anyoCreacion = doc.getString("anyo_creacion");
|
||||
Document documentoContacto =(Document) doc.get("contacto");
|
||||
String email = documentoContacto.getString("email_contacto");
|
||||
String telefonoContacto = documentoContacto.getString("telefono_contacto");
|
||||
String urlPaginaWeb = documentoContacto.getString("url_pagina_web");
|
||||
|
||||
// Crear un objeto Instituto y agregarlo a la lista
|
||||
Instituto instituto = new Instituto();
|
||||
instituto.setIdentificador(Integer.parseInt(identificador));
|
||||
instituto.setNombre(nombre);
|
||||
instituto.setDireccion(direccion);
|
||||
instituto.setEmail(email);
|
||||
instituto.setTelefono(telefonoContacto);
|
||||
instituto.setPaginaWeb(urlPaginaWeb);
|
||||
instituto.setAnyoCreacion(Integer.parseInt(anyoCreacion));
|
||||
|
||||
listaInstitutos.add(instituto);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new FormacionException(e, FormacionException.ERROR_CONSULTA, getClass());
|
||||
}
|
||||
|
||||
|
||||
return listaInstitutos;
|
||||
|
||||
}
|
||||
@Override
|
||||
public void insertarInstituto(Instituto instituto) throws FormacionException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@Override
|
||||
public Instituto obtenerInstitutoPorID(int identificador) throws FormacionException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void actualizarInstituto(Instituto instituto) throws FormacionException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package org.comunidadmadrid.fp.dam2.excepcion;
|
||||
|
||||
public class FormacionException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
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;
|
||||
|
||||
private int codigoError;
|
||||
private Class<?> claseOrigen;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public FormacionException(Exception excepcion, int tipoError, Class claseOrigenError) {
|
||||
super(excepcion);
|
||||
this.codigoError = tipoError;
|
||||
this.claseOrigen = claseOrigenError;
|
||||
}
|
||||
|
||||
public int getCodigoError() {
|
||||
return codigoError;
|
||||
}
|
||||
|
||||
public void setCodigoError(int codigoError) {
|
||||
this.codigoError = codigoError;
|
||||
}
|
||||
|
||||
public Class<?> getClaseOrigen() {
|
||||
return claseOrigen;
|
||||
}
|
||||
|
||||
public void setClaseOrigen(Class<?> claseOrigen) {
|
||||
this.claseOrigen = claseOrigen;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package org.comunidadmadrid.fp.dam2.gestores;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||
|
||||
public class GestorConexionJDBC {
|
||||
|
||||
// Evita que pueda construirse un objeto de la clase.
|
||||
private GestorConexionJDBC() {}
|
||||
|
||||
public static Connection getConexionSGDB() throws FormacionException{
|
||||
Connection conexionSGDB = null;
|
||||
|
||||
// Datos URL
|
||||
String urlBBDD =GestorFicheroConfiguracion.obtenerValor("jdbc.url");
|
||||
|
||||
String usuario = GestorFicheroConfiguracion.obtenerValor("jdbc.usuario");
|
||||
String contrasenya =GestorFicheroConfiguracion.obtenerValor("jdbc.password");
|
||||
|
||||
try {
|
||||
String claseDriver= GestorFicheroConfiguracion.obtenerValor("jdbc.driver");
|
||||
Class.forName(claseDriver);
|
||||
|
||||
conexionSGDB = DriverManager.getConnection(urlBBDD, usuario, contrasenya);
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
throw new FormacionException(e, FormacionException.ERROR_GESTION_CONEXION, GestorConexionJDBC.class);
|
||||
}
|
||||
|
||||
return conexionSGDB;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package org.comunidadmadrid.fp.dam2.gestores;
|
||||
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
|
||||
/**
|
||||
*
|
||||
* GestorConexionMongoDB: Clase que realiza la gestión de Conexiones a MongoDB.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 30 enero 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class GestorConexionMongoDB {
|
||||
private static MongoDatabase mongoDBDatabase= null;
|
||||
|
||||
private GestorConexionMongoDB() { // Constructor privado para evitar instanciación
|
||||
}
|
||||
|
||||
// Carga la configuración desde META-INF/persistence.xml
|
||||
static {
|
||||
// Cadena de conexion con la base de datos MongoDB
|
||||
String uri = GestorFicheroConfiguracion.obtenerValor("mongodb.url");
|
||||
// Se abre la conexión con MongoDB
|
||||
MongoClient clienteMongo = MongoClients.create(uri);
|
||||
|
||||
// Obtener una base de datos MongoDB desde Java
|
||||
String bbddMongoDB= GestorFicheroConfiguracion.obtenerValor("mongodb.bbdd");
|
||||
mongoDBDatabase = clienteMongo.getDatabase(bbddMongoDB);
|
||||
}
|
||||
|
||||
public static MongoDatabase getMongoDatabase() {
|
||||
return mongoDBDatabase;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package org.comunidadmadrid.fp.dam2.gestores;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.Persistence;
|
||||
|
||||
/**
|
||||
*
|
||||
* GestorEntityManagerJPA: Clase que realiza la gestión de EntityManagers de JPA.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 4 dic 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class GestorEntityManagerJPA {
|
||||
private static EntityManagerFactory entityManagerFactory = null;
|
||||
|
||||
private GestorEntityManagerJPA() { // Constructor privado para evitar instanciación
|
||||
}
|
||||
|
||||
// Carga la configuración desde META-INF/persistence.xml
|
||||
static {
|
||||
try {
|
||||
entityManagerFactory = Persistence.createEntityManagerFactory("UP_FormacionFP_HBT");
|
||||
} catch (Throwable ex) {
|
||||
System.err.println("Error en EntityManagerFactory: " + ex);
|
||||
throw new ExceptionInInitializerError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityManager getEntityManager() {
|
||||
return entityManagerFactory.createEntityManager();
|
||||
}
|
||||
|
||||
|
||||
public static void closeEntityManagerFactory() {
|
||||
entityManagerFactory.close();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.gestores;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 20 feb 2026
|
||||
*
|
||||
*/
|
||||
public class GestorFicheroConfiguracion {
|
||||
private static final Properties PROPIEDADES = new Properties();
|
||||
|
||||
static {
|
||||
try (InputStream is = GestorFicheroConfiguracion.class.getClassLoader()
|
||||
.getResourceAsStream("formacion.properties")) {
|
||||
if (is != null) {
|
||||
PROPIEDADES.load(is);
|
||||
} else {
|
||||
throw new IllegalStateException("No se encontró application.properties en el classpath");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Error al cargar application.properties", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene el valor asociado a la clave especificada.
|
||||
*
|
||||
* @param clave la clave a buscar
|
||||
* @return el valor o {@code null} si no existe
|
||||
*/
|
||||
public static String obtenerValor(String clave) {
|
||||
return PROPIEDADES.getProperty(clave);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package org.comunidadmadrid.fp.dam2.gestores;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
/**
|
||||
*
|
||||
* GestorSesionesHibernate: Clase que gestiona las sesiones de Hibernate
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 20 feb 2026
|
||||
*
|
||||
*/
|
||||
|
||||
public class GestorSesionHibernate {
|
||||
private static SessionFactory sessionFactory = null;
|
||||
|
||||
private GestorSesionHibernate() {// Constructor privado para evitar instanciación
|
||||
}
|
||||
|
||||
// Carga la configuración desde hibernate.cfg.xml
|
||||
static {
|
||||
try {
|
||||
sessionFactory = new Configuration().configure().buildSessionFactory();
|
||||
} catch (Throwable ex) {
|
||||
System.err.println("Error en SessionFactory: " + ex);
|
||||
throw new ExceptionInInitializerError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Session getSession() {
|
||||
return sessionFactory.openSession();
|
||||
}
|
||||
|
||||
public static Session getCurrentSession() {
|
||||
return sessionFactory.getCurrentSession();
|
||||
}
|
||||
|
||||
public static void cerrarFactoria() {
|
||||
if (sessionFactory != null) {
|
||||
sessionFactory.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.procesamiento;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import tools.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 1 mar 2025
|
||||
*/
|
||||
|
||||
public class FormacionXML {
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "id_formacion")
|
||||
private int identificador;
|
||||
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "formacion_distancia")
|
||||
private String formacionDistantica;
|
||||
|
||||
@JsonProperty(value = "nombre_corto")
|
||||
private String nombreCorto;
|
||||
|
||||
@JsonProperty(value = "cod_ciclo_formativo")
|
||||
private int codigoCicloFormativo;
|
||||
|
||||
@JsonProperty(value = "es_formacion_stem")
|
||||
private int esFormacionSTEM;
|
||||
|
||||
@JsonProperty(value = "informacion_adicional")
|
||||
private Object informacionAdicional;
|
||||
|
||||
public int getIdentificador() {
|
||||
return identificador;
|
||||
}
|
||||
|
||||
public void setIdentificador(int identificador) {
|
||||
this.identificador = identificador;
|
||||
}
|
||||
|
||||
public String getFormacionDistantica() {
|
||||
return formacionDistantica;
|
||||
}
|
||||
|
||||
public void setFormacionDistantica(String formacionDistantica) {
|
||||
this.formacionDistantica = formacionDistantica;
|
||||
}
|
||||
|
||||
public String getNombreCorto() {
|
||||
return nombreCorto;
|
||||
}
|
||||
|
||||
public void setNombreCorto(String nombreCorto) {
|
||||
this.nombreCorto = nombreCorto;
|
||||
}
|
||||
|
||||
public int getCodigoCicloFormativo() {
|
||||
return codigoCicloFormativo;
|
||||
}
|
||||
|
||||
public void setCodigoCicloFormativo(int codigoCicloFormativo) {
|
||||
this.codigoCicloFormativo = codigoCicloFormativo;
|
||||
}
|
||||
|
||||
public int getEsFormacionSTEM() {
|
||||
return esFormacionSTEM;
|
||||
}
|
||||
|
||||
public void setEsFormacionSTEM(int esFormacionSTEM) {
|
||||
this.esFormacionSTEM = esFormacionSTEM;
|
||||
}
|
||||
|
||||
public Object getInformacionAdicional() {
|
||||
return informacionAdicional;
|
||||
}
|
||||
|
||||
public void setInformacionAdicional(Object informacionAdicional) {
|
||||
this.informacionAdicional = informacionAdicional;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.procesamiento;
|
||||
|
||||
import com.opencsv.bean.CsvBindByName;
|
||||
|
||||
/**
|
||||
* Organización: Virgen de la Paloma
|
||||
* Programador: Isidoro Nevares Martín
|
||||
* Fecha: 26 marzo 2026
|
||||
*/
|
||||
public class InstitutoFormacionCSV {
|
||||
@CsvBindByName(column = "a_tratar")
|
||||
private String filaTratar;
|
||||
|
||||
@CsvBindByName(column = "cod_instituto")
|
||||
private int codigoInstituto;
|
||||
|
||||
@CsvBindByName(column = "cod_formacion")
|
||||
private int codigoFormacio;
|
||||
|
||||
@CsvBindByName(column = "anyo")
|
||||
private int anyoAcademico;
|
||||
|
||||
public String getFilaTratar() {
|
||||
return filaTratar;
|
||||
}
|
||||
|
||||
public void setFilaTratar(String filaTratar) {
|
||||
this.filaTratar = filaTratar;
|
||||
}
|
||||
|
||||
public int getCodigoInstituto() {
|
||||
return codigoInstituto;
|
||||
}
|
||||
|
||||
public void setCodigoInstituto(int codigoInstituto) {
|
||||
this.codigoInstituto = codigoInstituto;
|
||||
}
|
||||
|
||||
public int getCodigoFormacio() {
|
||||
return codigoFormacio;
|
||||
}
|
||||
|
||||
public void setCodigoFormacio(int codigoFormacio) {
|
||||
this.codigoFormacio = codigoFormacio;
|
||||
}
|
||||
|
||||
public int getAnyoAcademico() {
|
||||
return anyoAcademico;
|
||||
}
|
||||
|
||||
public void setAnyoAcademico(int anyoAcademico) {
|
||||
this.anyoAcademico = anyoAcademico;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InstitutoFormacionCSV [filaTratar=" + filaTratar + ", codigoInstituto=" + codigoInstituto
|
||||
+ ", codigoFormacio=" + codigoFormacio + ", anyoAcademico=" + anyoAcademico + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,134 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.procesamiento;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.comunidadmadrid.fp.dam2.utilidades.GestorURLs;
|
||||
import org.comunidadmadrid.fp.dam2.vo.CicloFormativo;
|
||||
import org.comunidadmadrid.fp.dam2.vo.Formacion;
|
||||
import org.comunidadmadrid.fp.dam2.vo.InstitutoFormacion;
|
||||
import org.comunidadmadrid.fp.dam2.vo.InstitutoFormacion.InstitutoFormacionID;
|
||||
|
||||
import com.opencsv.bean.CsvToBeanBuilder;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.dataformat.xml.XmlMapper;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 1 mar 2025
|
||||
*/
|
||||
public class ProcesadorDatos {
|
||||
/**
|
||||
*
|
||||
* @param urlFormaciones
|
||||
* @return
|
||||
*/
|
||||
public List<Formacion> obtenerFormacionesDeURL(String urlFormaciones) {
|
||||
List<Formacion> listaFormaciones = null;
|
||||
|
||||
String informacionFormacionesXML = GestorURLs.getTextoFromURL(urlFormaciones);
|
||||
ObjectMapper mapeadorXML = new XmlMapper();
|
||||
|
||||
// obtener Formaciones XMl a partir de la URL
|
||||
FormacionXML[] arrayFormaciones = mapeadorXML.readValue(informacionFormacionesXML, FormacionXML[].class);
|
||||
if (arrayFormaciones != null && arrayFormaciones.length > 0) {
|
||||
listaFormaciones = new ArrayList<Formacion>();
|
||||
for (FormacionXML formacionXML : arrayFormaciones) {
|
||||
// Se convierte un onjeto de tipo Fomarciones XMl en otro de tipo Formacion
|
||||
Formacion formacion = obtenerFormacionDeFormacionXML(formacionXML);
|
||||
if (formacion != null)
|
||||
listaFormaciones.add(formacion);
|
||||
}
|
||||
}
|
||||
return listaFormaciones;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param rutaCSVInstitutoFormacion
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<InstitutoFormacion> obtenerInstitutoFormacionDeFicheroCSV(String rutaCSVInstitutoFormacion) {
|
||||
List<InstitutoFormacion> listaInstitutosFormaciones = null;
|
||||
|
||||
try {
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
// obtener InstitutoFormacion CSV a partir de la ruta del fichero CSV
|
||||
List<InstitutoFormacionCSV> listaInstitutosFormacionesCSV = new CsvToBeanBuilder(
|
||||
new FileReader(rutaCSVInstitutoFormacion)).withType(InstitutoFormacionCSV.class).withSeparator(',')
|
||||
.build().parse();
|
||||
if (listaInstitutosFormacionesCSV != null && listaInstitutosFormacionesCSV.size() > 0) {
|
||||
listaInstitutosFormaciones = new ArrayList<InstitutoFormacion>();
|
||||
for (InstitutoFormacionCSV institutoFormacionCSV : listaInstitutosFormacionesCSV) {
|
||||
// Se convierte un onjeto de tipo InstitutoFormacion CSV en otro de tipo
|
||||
// InstitutoFormacion
|
||||
InstitutoFormacion institutoFormacion = obtenerInstituoFormacionDeInstituoFormacionCSV(
|
||||
institutoFormacionCSV);
|
||||
if (institutoFormacion != null)
|
||||
listaInstitutosFormaciones.add(institutoFormacion);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IllegalStateException | FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return listaInstitutosFormaciones;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param formacionXML
|
||||
* @return
|
||||
*/
|
||||
private Formacion obtenerFormacionDeFormacionXML(FormacionXML formacionXML) {
|
||||
Formacion formacion = null;
|
||||
if (formacionXML != null) {
|
||||
formacion = new Formacion();
|
||||
formacion.setIdentificador(formacionXML.getIdentificador());
|
||||
int formacionSTEM = formacionXML.getEsFormacionSTEM();
|
||||
if (formacionSTEM == 1)
|
||||
formacion.setIndicadorSTEM(true);
|
||||
else
|
||||
formacion.setIndicadorSTEM(false);
|
||||
formacion.setNombreCorto(formacionXML.getNombreCorto());
|
||||
|
||||
CicloFormativo ciclo = new CicloFormativo();
|
||||
ciclo.setIdentificador(formacionXML.getCodigoCicloFormativo());
|
||||
formacion.setCicloFormativo(ciclo);
|
||||
}
|
||||
return formacion;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param institutoFormacionCSV
|
||||
* @return
|
||||
*/
|
||||
private InstitutoFormacion obtenerInstituoFormacionDeInstituoFormacionCSV(
|
||||
InstitutoFormacionCSV institutoFormacionCSV) {
|
||||
InstitutoFormacion institutoFormacion = null;
|
||||
if (institutoFormacionCSV != null) {
|
||||
if (institutoFormacionCSV.getFilaTratar().equals("S")) {
|
||||
institutoFormacion = new InstitutoFormacion();
|
||||
|
||||
InstitutoFormacionID claveInstitoFormacion = new InstitutoFormacionID(
|
||||
institutoFormacionCSV.getCodigoInstituto(), institutoFormacionCSV.getCodigoFormacio());
|
||||
institutoFormacion.setIdInstitutoFormacion(claveInstitoFormacion);
|
||||
|
||||
institutoFormacion.setAnyoAcademico(institutoFormacionCSV.getAnyoAcademico());
|
||||
}
|
||||
}
|
||||
return institutoFormacion;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.utilidades;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.net.http.HttpResponse.BodyHandlers;
|
||||
|
||||
/*
|
||||
Organización: Virgen de la Paloma
|
||||
Programador: Isidoro Nevares Martín
|
||||
Fecha: 12 dic 2024
|
||||
*/
|
||||
public class GestorURLs {
|
||||
|
||||
// Evita que pueda construirse un objeto de la clase.
|
||||
private GestorURLs() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param rutaURL
|
||||
* @return
|
||||
*/
|
||||
public static String getTextoFromURL(String rutaURL) {
|
||||
String resultadoURL = null;
|
||||
|
||||
HttpClient cliente = HttpClient.newHttpClient();
|
||||
URI uriPrueba = URI.create(rutaURL);
|
||||
HttpRequest request = HttpRequest.newBuilder().uri(uriPrueba).GET().build();
|
||||
try {
|
||||
HttpResponse<String> respuesta = cliente.send(request, BodyHandlers.ofString());
|
||||
resultadoURL = respuesta.body();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return resultadoURL;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param urlImagen
|
||||
* @return
|
||||
*/
|
||||
public static byte[] obtenerBytesImagenDeURL(String urlImagen) {
|
||||
byte[] bytesImagen = null;
|
||||
|
||||
HttpClient cliente = HttpClient.newHttpClient();
|
||||
URI uriImagen = URI.create(urlImagen);
|
||||
HttpRequest request = HttpRequest.newBuilder().uri(uriImagen).GET().build();
|
||||
try {
|
||||
HttpResponse<byte[]> respuesta = cliente.send(request, BodyHandlers.ofByteArray());
|
||||
bytesImagen = respuesta.body();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return bytesImagen;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.vo;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Lob;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/**
|
||||
* Organización: Virgen de la Paloma
|
||||
* Programador: Isidoro Nevares Martín
|
||||
* Fecha: 26 marzo 2026
|
||||
*/
|
||||
|
||||
@Entity
|
||||
@Table(name="T_CICLO_FORMATIVO")
|
||||
public class CicloFormativo {
|
||||
@Id
|
||||
private int identificador;
|
||||
|
||||
@Column(name="nombre")
|
||||
private String nombre;
|
||||
|
||||
@Column(name="descripcion")
|
||||
private String descripcion;
|
||||
|
||||
@Column(name="url_logo")
|
||||
private String urlLogo;
|
||||
|
||||
@Column(name="imagen_ciclo", columnDefinition = "LONGBLOB")
|
||||
@Lob
|
||||
private byte[] imagenCiclo;
|
||||
|
||||
public int getIdentificador() {
|
||||
return identificador;
|
||||
}
|
||||
|
||||
public void setIdentificador(int identificador) {
|
||||
this.identificador = identificador;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getDescripcion() {
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
public void setDescripcion(String descripcion) {
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
public String getUrlLogo() {
|
||||
return urlLogo;
|
||||
}
|
||||
|
||||
public void setUrlLogo(String urlLogo) {
|
||||
this.urlLogo = urlLogo;
|
||||
}
|
||||
|
||||
public byte[] getImagenCiclo() {
|
||||
return imagenCiclo;
|
||||
}
|
||||
|
||||
public void setImagenCiclo(byte[] imagenCiclo) {
|
||||
this.imagenCiclo = imagenCiclo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CicloFormativo [identificador=" + identificador + ", nombre=" + nombre + ", descripcion=" + descripcion
|
||||
+ ", urlLogo=" + urlLogo + ", imagenCiclo=" + Arrays.toString(imagenCiclo) + "]\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
72
src/main/java/org/comunidadmadrid/fp/dam2/vo/Formacion.java
Normal file
72
src/main/java/org/comunidadmadrid/fp/dam2/vo/Formacion.java
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.vo;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/**
|
||||
* Organización: Virgen de la Paloma
|
||||
* Programador: Isidoro Nevares Martín
|
||||
* Fecha: 26 marzo 2026
|
||||
*/
|
||||
@Entity
|
||||
@Table (name="T_FORMACION")
|
||||
public class Formacion {
|
||||
@Id
|
||||
private int identificador;
|
||||
|
||||
@Column(name="nombre_corto")
|
||||
private String nombreCorto;
|
||||
|
||||
@Column(name="indicador_stem")
|
||||
private boolean indicadorSTEM;
|
||||
|
||||
@ManyToOne()
|
||||
@JoinColumn(name="id_ciclo", nullable = false )
|
||||
private CicloFormativo cicloFormativo;
|
||||
|
||||
public int getIdentificador() {
|
||||
return identificador;
|
||||
}
|
||||
|
||||
public void setIdentificador(int identificador) {
|
||||
this.identificador = identificador;
|
||||
}
|
||||
|
||||
public String getNombreCorto() {
|
||||
return nombreCorto;
|
||||
}
|
||||
|
||||
public void setNombreCorto(String nombreCorto) {
|
||||
this.nombreCorto = nombreCorto;
|
||||
}
|
||||
|
||||
public boolean isIndicadorSTEM() {
|
||||
return indicadorSTEM;
|
||||
}
|
||||
|
||||
public void setIndicadorSTEM(boolean indicadorSTEM) {
|
||||
this.indicadorSTEM = indicadorSTEM;
|
||||
}
|
||||
|
||||
public CicloFormativo getCicloFormativo() {
|
||||
return cicloFormativo;
|
||||
}
|
||||
|
||||
public void setCicloFormativo(CicloFormativo cicloFormativo) {
|
||||
this.cicloFormativo = cicloFormativo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Formacion [identificador=" + identificador + ", nombreCorto=" + nombreCorto + ", indicadorSTEM="
|
||||
+ indicadorSTEM + ", cicloFormativo=" + cicloFormativo + "]\n";
|
||||
}
|
||||
|
||||
}
|
||||
103
src/main/java/org/comunidadmadrid/fp/dam2/vo/Instituto.java
Normal file
103
src/main/java/org/comunidadmadrid/fp/dam2/vo/Instituto.java
Normal file
@ -0,0 +1,103 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.vo;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/**
|
||||
* Organización: Virgen de la Paloma Programador: Isidoro Nevares Martín Fecha:
|
||||
* 26 marzo 2026
|
||||
*/
|
||||
|
||||
@Entity
|
||||
@Table(name = "T_INSTITUTO")
|
||||
public class Instituto {
|
||||
@Id
|
||||
private int identificador;
|
||||
|
||||
@Column(name = "nom_instituto")
|
||||
private String nombre;
|
||||
|
||||
@Column(name = "direccion")
|
||||
private String direccion;
|
||||
|
||||
@Column(name = "telefono")
|
||||
private String telefono;
|
||||
|
||||
@Column(name = "email")
|
||||
private String email;
|
||||
|
||||
@Column(name = "paginaWeb")
|
||||
private String paginaWeb;
|
||||
|
||||
@Column(name = "anyoCreacion")
|
||||
private int anyoCreacion;
|
||||
|
||||
public int getIdentificador() {
|
||||
return identificador;
|
||||
}
|
||||
|
||||
public void setIdentificador(int identificador) {
|
||||
this.identificador = identificador;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getDireccion() {
|
||||
return direccion;
|
||||
}
|
||||
|
||||
public void setDireccion(String direccion) {
|
||||
this.direccion = direccion;
|
||||
}
|
||||
|
||||
public String getTelefono() {
|
||||
return telefono;
|
||||
}
|
||||
|
||||
public void setTelefono(String telefono) {
|
||||
this.telefono = telefono;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPaginaWeb() {
|
||||
return paginaWeb;
|
||||
}
|
||||
|
||||
public void setPaginaWeb(String paginaWeb) {
|
||||
this.paginaWeb = paginaWeb;
|
||||
}
|
||||
|
||||
public int getAnyoCreacion() {
|
||||
return anyoCreacion;
|
||||
}
|
||||
|
||||
public void setAnyoCreacion(int anyoCreacion) {
|
||||
this.anyoCreacion = anyoCreacion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Instituto [identificador=" + identificador + ", nombre=" + nombre + ", direccion=" + direccion
|
||||
+ ", telefono=" + telefono + ", email=" + email + ", paginaWeb=" + paginaWeb + ", anyoCreacion="
|
||||
+ anyoCreacion + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,107 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.comunidadmadrid.fp.dam2.vo;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/**
|
||||
* Organización: Virgen de la Paloma
|
||||
* Programador: Isidoro Nevares Martín
|
||||
* Fecha: 26 marzo 2026
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="T_INSTITUTO_FORMACION")
|
||||
public class InstitutoFormacion {
|
||||
@EmbeddedId
|
||||
private InstitutoFormacionID idInstitutoFormacion;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="id_instituto", insertable=false, updatable=false)
|
||||
private Instituto instituto;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="id_formacion", insertable=false, updatable=false)
|
||||
private Formacion formacion;
|
||||
|
||||
@Column(name="anyo_academico")
|
||||
private int anyoAcademico;
|
||||
|
||||
@Embeddable
|
||||
public static class InstitutoFormacionID{
|
||||
public InstitutoFormacionID() {
|
||||
|
||||
}
|
||||
public InstitutoFormacionID(Integer idInstituto, Integer idFormacion) {
|
||||
this.idFormacion=idFormacion;
|
||||
this.idIntituto=idInstituto;
|
||||
|
||||
}
|
||||
@Column(name="id_instituto")
|
||||
private Integer idIntituto;
|
||||
|
||||
@Column(name="id_formacion")
|
||||
private Integer idFormacion;
|
||||
|
||||
|
||||
public boolean equals(Object o) {
|
||||
boolean resultado=false;
|
||||
if (o != null && o instanceof InstitutoFormacionID) {
|
||||
InstitutoFormacionID that = (InstitutoFormacionID) o;
|
||||
resultado= (this.idFormacion==that.idFormacion) && (this.idIntituto == that.idIntituto);
|
||||
}
|
||||
return resultado;
|
||||
}
|
||||
public int hashCode() {
|
||||
return Long.hashCode(idIntituto)+ Long.hashCode(idFormacion);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InstitutoFormacionID [idIntituto=" + idIntituto + ", idFormacion=" + idFormacion + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InstitutoFormacion [idInstitutoFormacion=" + idInstitutoFormacion + ", instituto=" + instituto
|
||||
+ ", formacion=" + formacion + ", anyoAcademico=" + anyoAcademico + "]";
|
||||
}
|
||||
|
||||
public InstitutoFormacionID getIdInstitutoFormacion() {
|
||||
return idInstitutoFormacion;
|
||||
}
|
||||
|
||||
public void setIdInstitutoFormacion(InstitutoFormacionID idInstitutoFormacion) {
|
||||
this.idInstitutoFormacion = idInstitutoFormacion;
|
||||
}
|
||||
|
||||
public Instituto getInstituto() {
|
||||
return instituto;
|
||||
}
|
||||
|
||||
public void setInstituto(Instituto instituto) {
|
||||
this.instituto = instituto;
|
||||
}
|
||||
|
||||
public Formacion getFormacion() {
|
||||
return formacion;
|
||||
}
|
||||
|
||||
public void setFormacion(Formacion formacion) {
|
||||
this.formacion = formacion;
|
||||
}
|
||||
|
||||
public int getAnyoAcademico() {
|
||||
return anyoAcademico;
|
||||
}
|
||||
|
||||
public void setAnyoAcademico(int anyoAcademico) {
|
||||
this.anyoAcademico = anyoAcademico;
|
||||
}
|
||||
}
|
||||
23
src/main/resources/META-INF/persistence.xml
Normal file
23
src/main/resources/META-INF/persistence.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
|
||||
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
|
||||
<!-- Unidad Persistencia Hibernate -->
|
||||
<persistence-unit name="UP_FormacionFP_HBT" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<!-- Clases a "mapear" -->
|
||||
<class>org.comunidadmadrid.fp.dam2.vo.Instituto</class>
|
||||
|
||||
<!-- Configuración para la conexión a la Base de Datos -->
|
||||
<properties>
|
||||
<property name="jakarta.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver" />
|
||||
<property name="jakarta.persistence.jdbc.url" value="jdbc:mysql://10.11.218.147:3306/formacionfp_dam2" />
|
||||
<property name="jakarta.persistence.jdbc.user" value="root" />
|
||||
<property name="jakarta.persistence.jdbc.password" value="mysql_123" />
|
||||
|
||||
<property name="hibernate.show_sql" value="true" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
</persistence>
|
||||
15
src/main/resources/formacion.properties
Normal file
15
src/main/resources/formacion.properties
Normal file
@ -0,0 +1,15 @@
|
||||
# Información sobre la Base de datos PostgreSQL
|
||||
jdbc.driver=org.postgresql.Driver
|
||||
jdbc.url=jdbc:postgresql://10.11.218.147:5432/formacionfp_postgresql
|
||||
jdbc.usuario=vdlp
|
||||
jdbc.password=postgresql_123
|
||||
|
||||
# Información sobre la Base de datos MongoDB
|
||||
mongodb.url=mongodb://localhost:27017/
|
||||
mongodb.bbdd=formacionfp_dam2
|
||||
|
||||
#ruta URL formaciones
|
||||
url.formaciones=https://dam2.decieloytierra.es/formacionfp/formaciones.xml
|
||||
|
||||
#ruta fichero csv
|
||||
ruta.csv=ficheros/formacion-Instituto.csv
|
||||
28
src/main/resources/hibernate.cfg.xml
Normal file
28
src/main/resources/hibernate.cfg.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="connection.url">jdbc:mysql://10.11.218.147:3306/formacionfp_dam2</property>
|
||||
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
|
||||
|
||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||
|
||||
<property name="connection.username">root</property>
|
||||
<property name="connection.password">mysql_123</property>
|
||||
|
||||
<!-- Configuración de Hibernate -->
|
||||
<property name="hibernate.hbm2ddl.auto">create-drop</property> <!-- 'update' para mantener el esquema en sincronía con las entidades -->
|
||||
<property name="hibernate.show_sql">true</property> <!-- Muestra las consultas SQL -->
|
||||
<property name="hibernate.format_sql">true</property> <!-- Da formato a las consultas SQL -->
|
||||
<property name="hibernate.use_sql_comments">false</property> <!-- Añade comentarios en las consultas SQL -->
|
||||
|
||||
<mapping class="org.comunidadmadrid.fp.dam2.vo.CicloFormativo"></mapping>
|
||||
<mapping class="org.comunidadmadrid.fp.dam2.vo.Instituto"></mapping>
|
||||
<mapping class="org.comunidadmadrid.fp.dam2.vo.Formacion"></mapping>
|
||||
<mapping class="org.comunidadmadrid.fp.dam2.vo.InstitutoFormacion"></mapping>
|
||||
|
||||
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
Loading…
Reference in New Issue
Block a user