Incluir Procesador URLs
This commit is contained in:
parent
9be3bf651b
commit
cc22926d49
@ -26,7 +26,7 @@
|
|||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-25">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="module" value="true"/>
|
<attribute name="module" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
|||||||
7
pom.xml
7
pom.xml
@ -4,6 +4,13 @@
|
|||||||
<artifactId>aadd_act3_3</artifactId>
|
<artifactId>aadd_act3_3</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- JACKSON para XML y JSON -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>tools.jackson.dataformat</groupId>
|
||||||
|
<artifactId>jackson-dataformat-xml</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Hibernate Core -->
|
<!-- Hibernate Core -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate.orm</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
|
|||||||
@ -1,15 +1,24 @@
|
|||||||
package org.lapaloma.aadd.redmetro;
|
package org.lapaloma.aadd.redmetro;
|
||||||
|
|
||||||
import org.lapaloma.aadd.redmetro.gestores.GestorSesionesHibernate;
|
import org.lapaloma.aadd.redmetro.gestores.GestorEntityManagerJPA;
|
||||||
|
import org.lapaloma.aadd.redmetro.procesador.ProcesadorURLs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clase principal que inicia la sesión de Hibernate.
|
* Clase principal que inicia la sesión de Hibernate. Al iniciar la sesión,
|
||||||
* Al iniciar la sesión, Hibernate ejecutará hbm2ddl.auto=create y recreará la base de datos
|
* Hibernate ejecutará hbm2ddl.auto=create y recreará la base de datos según las
|
||||||
* según las entidades definidas.
|
* entidades definidas.
|
||||||
*/
|
*/
|
||||||
public class AppRedMetro {
|
public class AppRedMetro {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
AppRedMetro app = new AppRedMetro();
|
||||||
// Obtiene la Session de forma estática
|
// Obtiene la Session de forma estática
|
||||||
GestorSesionesHibernate.getSession();
|
// GestorEntityManagerJPA.getEntityManager();
|
||||||
|
|
||||||
|
app.procesasrURLs();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void procesasrURLs() {
|
||||||
|
ProcesadorURLs procesadorURLs = new ProcesadorURLs();
|
||||||
|
procesadorURLs.procesarURLEstacionesXML();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
package org.lapaloma.aadd.redmetro.dao;
|
||||||
|
|
||||||
|
public interface IEstacionDAO {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package org.lapaloma.aadd.redmetro.dao;
|
||||||
|
|
||||||
|
public interface ILineaEstacionDAO {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package org.lapaloma.aadd.redmetro.dao.jpa;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.redmetro.dao.IEstacionDAO;
|
||||||
|
|
||||||
|
public class EstacionDaoJPA implements IEstacionDAO{
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package org.lapaloma.aadd.redmetro.dao.jpa;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.redmetro.dao.ILineaEstacionDAO;
|
||||||
|
|
||||||
|
public class LineaEstacionDaoJPA implements ILineaEstacionDAO{
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
package org.lapaloma.aadd.redmetro.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_PROYECTOSIES_ODB");
|
||||||
|
} 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,45 @@
|
|||||||
|
package org.lapaloma.aadd.redmetro.gestores;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* GestorConfiguracion: Clase que se encarga de gestionar la configuración de
|
||||||
|
* los ficheros.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 10 oct 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GestorFicheroConfiguracion {
|
||||||
|
private final static String RUTA_FICHERO_CONFIGURACION = "conf.properties";
|
||||||
|
private static Properties propiedades = null;
|
||||||
|
|
||||||
|
private GestorFicheroConfiguracion() {
|
||||||
|
// Constructor privado para evitar instanciación
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bloque estático que se ejecuta una única vez al cargar la clase
|
||||||
|
static {
|
||||||
|
cargarPropiedadesFichero();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void cargarPropiedadesFichero() {
|
||||||
|
propiedades = new Properties();
|
||||||
|
try {
|
||||||
|
propiedades
|
||||||
|
.load(GestorFicheroConfiguracion.class.getClassLoader()
|
||||||
|
.getResourceAsStream(RUTA_FICHERO_CONFIGURACION));
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getValorfromClave(String clave) {
|
||||||
|
return propiedades.getProperty(clave);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,42 +0,0 @@
|
|||||||
package org.lapaloma.aadd.redmetro.gestores;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.SessionFactory;
|
|
||||||
import org.hibernate.cfg.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* GestorSesionesHibernate: Clase que realiza ....
|
|
||||||
*
|
|
||||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
|
||||||
* @date 4 dic 2025
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class GestorSesionesHibernate {
|
|
||||||
private static SessionFactory sessionFactory = null;
|
|
||||||
|
|
||||||
private GestorSesionesHibernate() {// 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 void cerrarFactoria() {
|
|
||||||
if (sessionFactory != null) {
|
|
||||||
sessionFactory.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
package org.lapaloma.aadd.redmetro.procesador;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.lapaloma.aadd.redmetro.gestores.GestorFicheroConfiguracion;
|
||||||
|
import org.lapaloma.aadd.redmetro.vo.Estacion;
|
||||||
|
|
||||||
|
import tools.jackson.databind.JsonNode;
|
||||||
|
import tools.jackson.databind.ObjectMapper;
|
||||||
|
import tools.jackson.dataformat.xml.XmlMapper;
|
||||||
|
|
||||||
|
public class ProcesadorURLs {
|
||||||
|
public void procesarURLEstacionesXML() {
|
||||||
|
|
||||||
|
String urlXMLEstaciones = GestorFicheroConfiguracion.getValorfromClave("url.xml.estacion");
|
||||||
|
|
||||||
|
URL url = null;
|
||||||
|
try {
|
||||||
|
url = new URI(urlXMLEstaciones).toURL();
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Procesar con Jackson XML
|
||||||
|
ObjectMapper mapper = new XmlMapper();
|
||||||
|
|
||||||
|
try (InputStream is = url.openStream()) {
|
||||||
|
JsonNode root = mapper.readTree(is);
|
||||||
|
JsonNode nodosEstacion = root.path("estaciones").path("estacion");
|
||||||
|
for (JsonNode nodoEstacion : nodosEstacion) {
|
||||||
|
String nombre = nodoEstacion.path("nombre").asString();
|
||||||
|
String direccion = nodoEstacion.path("direccion").asString();
|
||||||
|
int id = nodoEstacion.path("id").asInt();
|
||||||
|
|
||||||
|
System.out.println("Nombre: " + nombre);
|
||||||
|
System.out.println("Dirección: " + direccion);
|
||||||
|
System.out.println("ID: " + id);
|
||||||
|
|
||||||
|
Estacion estacion = new Estacion();
|
||||||
|
estacion.setCodigo(id);
|
||||||
|
estacion.setNombre(nombre);
|
||||||
|
estacion.setDireccion(direccion);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,10 +1,7 @@
|
|||||||
# Información sobre fichero XML
|
# Información sobre Estaciones (XML)
|
||||||
catalogos.fichero.xml.ruta=ficheros/catalogos.xml
|
url.xml.estacion=https://dam2.decieloytierra.es/trenes_estaciones_accesos.xml
|
||||||
|
|
||||||
|
|
||||||
# Información sobre fichero JSON
|
# Información sobre Linea Estación (JSON)
|
||||||
gastos.fichero.json.ruta=ficheros/gastos.json
|
url.json.lineaestacion=https://dam2.decieloytierra.es/estaciones-lineas.json
|
||||||
|
|
||||||
|
|
||||||
# Información sobre fichero CSV
|
|
||||||
ingresos.fichero.csv.ruta=ficheros/ingresos.csv
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user