Primer commit
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
# Eclipse
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
|
||||
# Compilación Java
|
||||
bin/
|
||||
target/
|
||||
*.class
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Sistema operativo
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
@@ -0,0 +1,15 @@
|
||||
# Configuración de la aplicación AgenciaESA
|
||||
# Parámetros de una conexión a un SGBD MySQL
|
||||
sgdb.conexion.url=jdbc:mysql://192.168.1.36:3306/
|
||||
bbdd.nombre=agencia_esa_inm
|
||||
bbdd.usuario=root
|
||||
bbdd.clave=mysql_123
|
||||
|
||||
|
||||
# Fichero CSV
|
||||
tripulante.fichero.csv=ficheros-datos/tripulantes_sinmision.csv
|
||||
tripulante.csv.cabecera=num_tripulante|nombre|apellidos|id_esa|especialidad|fecha_ingreso
|
||||
tripulante.csv.separador=|
|
||||
|
||||
# Fichero XML Lectura
|
||||
misionesesa.fichero.xml=ficheros-datos/operaciones_esa.xml
|
||||
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<operacionesESA fecha_generacion="2040-11-12"
|
||||
centro_control_origen="ESOC Darmstadt"
|
||||
version_xml="3.0"
|
||||
md5="F1C92A88E23DF00A44AB9FF9982DE0AC">
|
||||
|
||||
<misiones>
|
||||
|
||||
<mision fecha_inicio="2034-04-02"
|
||||
fecha_fin_estimada="2034-04-25"
|
||||
estado="En curso">
|
||||
|
||||
<nombre>Reabastecimiento Ares I</nombre>
|
||||
<cod_nave>ESA-TRANS-02</cod_nave>
|
||||
<cuerpo_celeste>Plutón</cuerpo_celeste>
|
||||
<objetivo>Entrega ampliada de repuestos en Base Ares</objetivo>
|
||||
<presupuesto>18950000</presupuesto>
|
||||
|
||||
</mision>
|
||||
|
||||
<mision fecha_inicio="2034-08-10"
|
||||
fecha_fin_estimada="2034-12-10"
|
||||
estado="Planificada">
|
||||
|
||||
<nombre>Atmósfera Olympus I</nombre>
|
||||
<cod_nave>ESA-SCIEN-03</cod_nave>
|
||||
<cuerpo_celeste>Marte</cuerpo_celeste>
|
||||
<objetivo>Estudio atmosférico marciano</objetivo>
|
||||
<presupuesto>14000000</presupuesto>
|
||||
|
||||
</mision>
|
||||
|
||||
<mision fecha_inicio="2036-02-01"
|
||||
fecha_fin_estimada="2037-10-10"
|
||||
estado="Planificada">
|
||||
|
||||
<nombre>Mantenimiento Avanzado Selene III</nombre>
|
||||
<cod_nave>ESA-MANT-01</cod_nave>
|
||||
<cuerpo_celeste>Luna</cuerpo_celeste>
|
||||
<objetivo>Mantenimiento avanzado de sistemas térmicos</objetivo>
|
||||
<presupuesto>6900000</presupuesto>
|
||||
<prioridad>Alta</prioridad>
|
||||
<riesgo_estimado>Bajo</riesgo_estimado>
|
||||
<comentarios_operativos>Prueba de nuevos trajes de aislamiento</comentarios_operativos>
|
||||
|
||||
</mision>
|
||||
|
||||
<mision fecha_inicio="2040-03-01"
|
||||
fecha_fin_estimada="2040-05-20"
|
||||
estado="Planificada">
|
||||
|
||||
<nombre>Exploración Criogénica Europa II</nombre>
|
||||
<cod_nave>ESA-SCIEN-03</cod_nave>
|
||||
<cuerpo_celeste>Europa</cuerpo_celeste>
|
||||
<objetivo>Análisis espectral del hielo profundo</objetivo>
|
||||
<presupuesto>21200000</presupuesto>
|
||||
<comentarios_operativos>Se requieren sondas perforadoras reforzadas</comentarios_operativos>
|
||||
|
||||
</mision>
|
||||
|
||||
</misiones>
|
||||
|
||||
</operacionesESA>
|
||||
@@ -0,0 +1,4 @@
|
||||
num_tripulante|nombre|apellidos|id_esa|especialidad|fecha_ingreso
|
||||
18|Nicola|Winter|2018|Ingeniería|2022-11-23
|
||||
19|John|McFall|2019|Comunicaciones|2022-11-23
|
||||
20|Paolo|Nespoli|2020|Ingeniería|1998-05-01
|
||||
|
@@ -0,0 +1,29 @@
|
||||
<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>AgenciaESA_Examen1</groupId>
|
||||
<artifactId>AgenciaESA_Examen1</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<!-- Source: https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>26.10.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<release>24</release>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,106 @@
|
||||
package eu.esa.gemis.eva1;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import eu.esa.gemis.eva1.eva1.util.ConversorTiposDatosYFormatos;
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
import eu.esa.gemis.eva1.model.Mision;
|
||||
import eu.esa.gemis.eva1.procesos.ProcesadorTripulantesCSV;
|
||||
import eu.esa.gemis.eva1.procesos.ProcesadorXMLMisiones;
|
||||
import eu.esa.gemis.eva1.service.MisionService;
|
||||
|
||||
/**
|
||||
*
|
||||
* AplicacionAgenciaESA: Clase que realiza el tratamiento principal de la
|
||||
* aplicación.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 8 oct 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class AplicacionAgenciaESA {
|
||||
|
||||
public static void main(String[] args) {
|
||||
AplicacionAgenciaESA app = new AplicacionAgenciaESA();
|
||||
|
||||
try {
|
||||
// Tratamiento de lógica de negocio
|
||||
app.realizarTratamientoAgenciaESA();
|
||||
|
||||
} catch (AgenciaEsaException e) {
|
||||
System.err.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void realizarTratamientoAgenciaESA() throws AgenciaEsaException {
|
||||
Scanner entrada = new Scanner(System.in);
|
||||
|
||||
System.out.println("Menú:");
|
||||
System.out.println(" 1: Almacenar en CSV los tripulantes sin misiones asignadas.");
|
||||
System.out.println(" 2: Procesar fichero operaciones_esa.xml");
|
||||
System.out.println(" 3: Imprimir en consola el listado de misiones inciadas en un año.");
|
||||
System.out.println("----------------------------------------------------------");
|
||||
System.out.println("Introduce la operación a realizar:");
|
||||
// Operación recogida
|
||||
String operacion = entrada.nextLine().trim();
|
||||
|
||||
while (!("123".contains(operacion))) {
|
||||
System.out.println("Has seleccionado un operación errónea (ha de ser un número entre 1 y 3)");
|
||||
System.out.print("Introduce la operación a realizar:");
|
||||
|
||||
// Operación recogida
|
||||
operacion = entrada.nextLine();
|
||||
}
|
||||
System.out.println("Operación a realizar: " + operacion);
|
||||
// Cerrar la entrada del Scanner
|
||||
entrada.close();
|
||||
|
||||
ejecutarFuncionalidades(operacion);
|
||||
}
|
||||
|
||||
public void ejecutarFuncionalidades(String operacion) throws AgenciaEsaException {
|
||||
switch (operacion) {
|
||||
case "1": { // Almacenar en CSV los tripulantes sin misiones asignadas
|
||||
// Almacenar tripulantes en fichero CSV
|
||||
ProcesadorTripulantesCSV procesadorTripulantesCSV = new ProcesadorTripulantesCSV();
|
||||
procesadorTripulantesCSV.almacenarTripulantesSinMisionEnFicheroCSV();
|
||||
System.out.println("Tripulantes sin misión almacenados en fichero tripulantes_sin_mision.csv");
|
||||
break;
|
||||
}
|
||||
case "2": { // Procesar Fichero operaciones_esa.xml
|
||||
System.out.println("Ejecutar procesamiento fichero operaciones_esa.xml");
|
||||
|
||||
ProcesadorXMLMisiones procesadorXMLMision = new ProcesadorXMLMisiones();
|
||||
procesadorXMLMision.procesarFicheroXMLMisiones();
|
||||
|
||||
break;
|
||||
}
|
||||
case "3": { // Imprimir en consola el listado de misiones inciadas en un año.
|
||||
System.out.println("Obtener e imprimir en consola el listado de misiones iniciadas en un año.");
|
||||
MisionService misionService= new MisionService();
|
||||
List<Mision> listaMisiones = misionService.obtenerMisionesIniciadasEnAnyo(2034);
|
||||
|
||||
for (Mision mision : listaMisiones) {
|
||||
// System.out.println(mision);
|
||||
// Formatear fecha a dd/MM/yyyy
|
||||
String fechaFormateada = ConversorTiposDatosYFormatos.convertirAFechaConFormato(mision.getFechaInicio(),
|
||||
"dd/MM/yyyy");
|
||||
|
||||
String textoImprimir = "La misión %s comenzó el %s con destino a %s (%s) utilizando la nave %s con capacidad para %d tripulantes.";
|
||||
textoImprimir = String.format(textoImprimir, mision.getNombre(), fechaFormateada,
|
||||
mision.getCuerpoCeleste().getNombre(), mision.getCuerpoCeleste().getTipo(),
|
||||
mision.getNave().getCodigo(), mision.getNave().getCapacidadTripulacion());
|
||||
System.out.println(textoImprimir);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* ICuerpoCelesteDAO: Interfaz DAO para la entidad Cuerpo Celeste.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 08 nov 2026
|
||||
*/
|
||||
package eu.esa.gemis.eva1.dao;
|
||||
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
import eu.esa.gemis.eva1.model.CuerpoCeleste;
|
||||
|
||||
public interface ICuerpoCelesteDAO {
|
||||
|
||||
CuerpoCeleste obtenerCuerpoCelestePorNombre(String nombreCuerpoCeleste) throws AgenciaEsaException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* IMisionDAO: Interfaz DAO para la entidad Mision.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 08 nov 2026
|
||||
*/
|
||||
package eu.esa.gemis.eva1.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
import eu.esa.gemis.eva1.model.Mision;
|
||||
|
||||
public interface IMisionDAO {
|
||||
|
||||
List<Mision> obtenerMisionesIniciadasEnAnyo(int anyo) throws AgenciaEsaException;
|
||||
|
||||
boolean existeMisionPorNaveYCuerpoCeleste(Mision mision) throws AgenciaEsaException;
|
||||
|
||||
void insertarMision(Mision mision) throws AgenciaEsaException;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* INaveDAO: Interfaz DAO para la entidad Nave.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 08 nov 2026
|
||||
*/
|
||||
package eu.esa.gemis.eva1.dao;
|
||||
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
|
||||
public interface INaveDAO {
|
||||
|
||||
boolean existeNavePorCodigo(String codigoNave) throws AgenciaEsaException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* ITripulanteDAO: Interfaz DAO para la entidad Tripulante.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 08 nov 2026
|
||||
*/
|
||||
package eu.esa.gemis.eva1.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
import eu.esa.gemis.eva1.model.Tripulante;
|
||||
|
||||
public interface ITripulanteDAO {
|
||||
|
||||
List<Tripulante> obtenerTripulantesSinMision() throws AgenciaEsaException;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package eu.esa.gemis.eva1.dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import eu.esa.gemis.eva1.dao.ICuerpoCelesteDAO;
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
import eu.esa.gemis.eva1.model.CuerpoCeleste;
|
||||
|
||||
/**
|
||||
*
|
||||
* CuerpoCelesteDaoJDBC: Clase que realiza la implementación del interfaz
|
||||
* ICuerpoCelesteDAO.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 08 nov 2026
|
||||
*
|
||||
*/
|
||||
|
||||
public class CuerpoCelesteDaoJDBC implements ICuerpoCelesteDAO {
|
||||
private final Connection conexion;
|
||||
|
||||
public CuerpoCelesteDaoJDBC(Connection conexion) {
|
||||
this.conexion = conexion;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CuerpoCeleste obtenerCuerpoCelestePorNombre(String nombreCuerpoCeleste) throws AgenciaEsaException {
|
||||
CuerpoCeleste cuerpoCeleste=null;
|
||||
String sentenciaSQL = """
|
||||
SELECT identificador, nombre, tipo, gravedad_superficie_ms2
|
||||
FROM T_CUERPO_CELESTE
|
||||
WHERE nombre = ?
|
||||
""";
|
||||
// try con recursos "cerrables": PreparedStatement, ResultSet
|
||||
try (PreparedStatement pstm = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
// Establecer los parámetros de la sentencia
|
||||
pstm.setString(1, nombreCuerpoCeleste);
|
||||
// System.out.println(pstm);
|
||||
|
||||
ResultSet resultadoSentencia = pstm.executeQuery();
|
||||
if (resultadoSentencia.next()) {
|
||||
int identificador = resultadoSentencia.getInt("identificador");
|
||||
String nombre = resultadoSentencia.getString("nombre");
|
||||
String tipo = resultadoSentencia.getString("tipo");
|
||||
double gravedadSuperficie = resultadoSentencia.getDouble("gravedad_superficie_ms2");
|
||||
|
||||
cuerpoCeleste= new CuerpoCeleste();
|
||||
cuerpoCeleste.setIdentificador(identificador);
|
||||
cuerpoCeleste.setNombre(nombre);
|
||||
cuerpoCeleste.setTipo(tipo);
|
||||
cuerpoCeleste.setGravedadSuperficieMs2(gravedadSuperficie);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new AgenciaEsaException("Error al obtener información de un cuerpo celeste a partir de su nombre.", e);
|
||||
}
|
||||
return cuerpoCeleste;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package eu.esa.gemis.eva1.dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Date;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import eu.esa.gemis.eva1.dao.IMisionDAO;
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
import eu.esa.gemis.eva1.model.CuerpoCeleste;
|
||||
import eu.esa.gemis.eva1.model.Mision;
|
||||
import eu.esa.gemis.eva1.model.Nave;
|
||||
|
||||
/**
|
||||
*
|
||||
* MisionDaoJDBC: Clase que realiza la implementación del interfaz IMisionDAO.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 08 nov 2026
|
||||
*
|
||||
*/
|
||||
|
||||
public class MisionDaoJDBC implements IMisionDAO {
|
||||
private final Connection conexion;
|
||||
|
||||
public MisionDaoJDBC(Connection conexion) {
|
||||
this.conexion = conexion;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Mision> obtenerMisionesIniciadasEnAnyo(int anyo) throws AgenciaEsaException {
|
||||
List<Mision> listaMisiones = null;
|
||||
|
||||
String sentenciaSQL = """
|
||||
select tm.nombre as nombre_mision, tm.fecha_inicio,
|
||||
tn.codigo as codigo_nave, tn.capacidad_tripulacion,
|
||||
tcc.nombre as nombre_cuerpo_celeste, tcc.tipo
|
||||
from T_MISION tm join T_NAVE tn
|
||||
on tm.cod_nave = tn.codigo
|
||||
join T_CUERPO_CELESTE tcc
|
||||
on tm.id_cuerpo_celeste = tcc.identificador
|
||||
where year(tm.fecha_inicio) = ?
|
||||
""";
|
||||
// try con recursos "cerrables": PreparedStatement, ResultSet
|
||||
try (PreparedStatement pstm = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
// Establecer los parámetros de la sentencia
|
||||
pstm.setInt(1, anyo);
|
||||
// System.out.println(pstm);
|
||||
|
||||
ResultSet resultadoSentencia = pstm.executeQuery();
|
||||
if (resultadoSentencia != null) {
|
||||
listaMisiones = new ArrayList<Mision>();
|
||||
}
|
||||
while (resultadoSentencia.next()) {
|
||||
Mision mision = new Mision();
|
||||
String nombre = resultadoSentencia.getString("nombre_mision");
|
||||
LocalDate fechaInicio = resultadoSentencia.getDate("tm.fecha_inicio").toLocalDate();
|
||||
|
||||
Nave nave = new Nave();
|
||||
nave.setCodigo(resultadoSentencia.getString("codigo_nave"));
|
||||
nave.setCapacidadTripulacion(resultadoSentencia.getInt("capacidad_tripulacion"));
|
||||
|
||||
CuerpoCeleste cuerpoCeleste = new CuerpoCeleste();
|
||||
cuerpoCeleste.setNombre(resultadoSentencia.getString("nombre_cuerpo_celeste"));
|
||||
cuerpoCeleste.setTipo(resultadoSentencia.getString("tipo"));
|
||||
|
||||
mision.setNombre(nombre);
|
||||
mision.setFechaInicio(fechaInicio);
|
||||
mision.setNave(nave);
|
||||
mision.setCuerpoCeleste(cuerpoCeleste);
|
||||
|
||||
listaMisiones.add(mision);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new AgenciaEsaException("Error al obtener la información de una misión.", e);
|
||||
}
|
||||
|
||||
return listaMisiones;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertarMision(Mision mision) throws AgenciaEsaException {
|
||||
String sentenciaSQL = """
|
||||
INSERT INTO T_MISION (nombre, cod_nave, id_cuerpo_celeste, fecha_inicio, fecha_fin_estimado, fecha_fin,
|
||||
estado, objetivo_principal, presupuesto_asignado)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""";
|
||||
|
||||
// try con recursos "cerrables": PreparedStatement
|
||||
try (PreparedStatement pstm = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
// Establecer los parámetros de la sentencia
|
||||
pstm.setString(1, mision.getNombre());
|
||||
pstm.setString(2, mision.getNave().getCodigo());
|
||||
pstm.setInt(3, mision.getCuerpoCeleste().getIdentificador());
|
||||
pstm.setDate(4, Date.valueOf(mision.getFechaInicio()));
|
||||
pstm.setDate(5, Date.valueOf(mision.getFechaFinEstimado()));
|
||||
Date fechaFin = mision.getFechaFin() != null ? Date.valueOf(mision.getFechaFin()) : null;
|
||||
pstm.setDate(6, fechaFin);
|
||||
pstm.setString(7, mision.getEstado());
|
||||
pstm.setString(8, mision.getObjetivoPrincipal());
|
||||
pstm.setInt(9, mision.getPresupuestoAsignado());
|
||||
|
||||
//System.out.println(pstm);
|
||||
|
||||
pstm.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new AgenciaEsaException("Error al insertar una misión.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean existeMisionPorNaveYCuerpoCeleste(Mision mision) throws AgenciaEsaException {
|
||||
boolean existeMision=false;
|
||||
String sentenciaSQL = """
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM T_MISION
|
||||
WHERE cod_nave =?
|
||||
AND id_cuerpo_celeste=?
|
||||
) AS existe_mision
|
||||
""";
|
||||
// try con recursos "cerrables": PreparedStatement, ResultSet
|
||||
try (PreparedStatement pstm = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
// Establecer los parámetros de la sentencia
|
||||
pstm.setString(1, mision.getNave().getCodigo());
|
||||
pstm.setInt(2, mision.getCuerpoCeleste().getIdentificador());
|
||||
// System.out.println(pstm);
|
||||
|
||||
ResultSet resultadoSentencia = pstm.executeQuery();
|
||||
if (resultadoSentencia.next()) {
|
||||
existeMision = resultadoSentencia.getBoolean("existe_mision");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new AgenciaEsaException("Error al validar si existe una misión a partir de la información de nave y cuerpo celeste.", e);
|
||||
}
|
||||
return existeMision;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package eu.esa.gemis.eva1.dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import eu.esa.gemis.eva1.dao.INaveDAO;
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
|
||||
/**
|
||||
*
|
||||
* NaveDaoJDBC: Clase que realiza la implementación del interfaz
|
||||
* INaveDAO.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 08 nov 2026
|
||||
*
|
||||
*/
|
||||
|
||||
public class NaveDaoJDBC implements INaveDAO{
|
||||
private final Connection conexion;
|
||||
|
||||
public NaveDaoJDBC(Connection conexion) {
|
||||
this.conexion = conexion;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean existeNavePorCodigo(String codigoNave) throws AgenciaEsaException {
|
||||
boolean existeNave=false;
|
||||
String sentenciaSQL = """
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM T_NAVE
|
||||
WHERE codigo = ?
|
||||
) AS existe_nave
|
||||
""";
|
||||
// try con recursos "cerrables": PreparedStatement, ResultSet
|
||||
try (PreparedStatement pstm = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
// Establecer los parámetros de la sentencia
|
||||
pstm.setString(1, codigoNave);
|
||||
// System.out.println(pstm);
|
||||
|
||||
ResultSet resultadoSentencia = pstm.executeQuery();
|
||||
if (resultadoSentencia.next()) {
|
||||
existeNave = resultadoSentencia.getBoolean("existe_nave");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new AgenciaEsaException("Error al validar si existe una nave a partir de su código.", e);
|
||||
}
|
||||
return existeNave;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package eu.esa.gemis.eva1.dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import eu.esa.gemis.eva1.dao.ITripulanteDAO;
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
import eu.esa.gemis.eva1.model.Tripulante;
|
||||
|
||||
/**
|
||||
*
|
||||
* TripulanteDaoJDBC: Clase que realiza la implementación del interfaz
|
||||
* ITripulanteDAO.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 08 nov 2026
|
||||
*
|
||||
*/
|
||||
|
||||
public class TripulanteDaoJDBC implements ITripulanteDAO {
|
||||
private final Connection conexion;
|
||||
|
||||
public TripulanteDaoJDBC(Connection conexion) {
|
||||
this.conexion = conexion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tripulante> obtenerTripulantesSinMision() throws AgenciaEsaException {
|
||||
List<Tripulante> listaTripulantes = null;
|
||||
|
||||
String sentenciaSQL = """
|
||||
select tt.numero_tripulante, tt.nombre, tt.apellidos, tt.identificador_esa,
|
||||
tt.nivel_experiencia, tt.especialidad, tt.fecha_ingreso_esa
|
||||
from T_TRIPULANTE tt
|
||||
where tt.numero_tripulante not in (select ttm.num_tripulante
|
||||
from T_TRIPULANTE_MISION ttm )
|
||||
""";
|
||||
/* Alternativa con LEFT JOIN y IS NULL
|
||||
*
|
||||
* SELECT t.numero_tripulante, t.nombre, t.apellidos, t.identificador_esa, t.nivel_experiencia, t.especialidad, t.fecha_ingreso_esa
|
||||
* FROM T_TRIPULANTE t LEFT JOIN T_TRIPULANTE_MISION tm
|
||||
* ON t.numero_tripulante = tm.num_tripulante
|
||||
* WHERE tm.id_mision IS NULL
|
||||
*/
|
||||
|
||||
// try con recursos "cerrables": Statement, ResultSet
|
||||
try (PreparedStatement pstm = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
System.out.println(pstm);
|
||||
|
||||
ResultSet resultadoSentencia = pstm.executeQuery();
|
||||
if (resultadoSentencia != null) {
|
||||
listaTripulantes = new ArrayList<Tripulante>();
|
||||
}
|
||||
while (resultadoSentencia.next()) {
|
||||
int numeroTripulante = resultadoSentencia.getInt("tt.numero_tripulante");
|
||||
String nombre = resultadoSentencia.getString("tt.nombre");
|
||||
String apellidos = resultadoSentencia.getString("tt.apellidos");
|
||||
int identificadorEsa = resultadoSentencia.getInt("tt.identificador_esa");
|
||||
int nivelExperiencia = resultadoSentencia.getInt("tt.nivel_experiencia");
|
||||
String especialidad = resultadoSentencia.getString("tt.especialidad");
|
||||
LocalDate fechaIngresoEsa = resultadoSentencia.getDate("tt.fecha_ingreso_esa").toLocalDate();
|
||||
|
||||
Tripulante tripulante = new Tripulante();
|
||||
tripulante.setNumeroTripulante(numeroTripulante);
|
||||
tripulante.setNombre(nombre);
|
||||
tripulante.setApellidos(apellidos);
|
||||
tripulante.setIdentificadorEsa(identificadorEsa);
|
||||
tripulante.setNivelExperiencia(nivelExperiencia);
|
||||
tripulante.setEspecialidad(especialidad);
|
||||
tripulante.setFechaIngresoEsa(fechaIngresoEsa);
|
||||
|
||||
listaTripulantes.add(tripulante);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new AgenciaEsaException("Error al obtener tripulantes sin misión.", e);
|
||||
}
|
||||
|
||||
return listaTripulantes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.esa.gemis.eva1.eva1.util;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
*
|
||||
* ConversorTiposDatos: Clase que realiza conversiones entre tipos de datos y formatos.
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 14 nov 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class ConversorTiposDatosYFormatos {
|
||||
public static String convertirAFechaConFormato(LocalDate fecha, String formato) {
|
||||
String fechaFormateada = null;
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formato);
|
||||
fechaFormateada = fecha.format(formatter);
|
||||
|
||||
|
||||
return fechaFormateada;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package eu.esa.gemis.eva1.excepcion;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* FormacionException: Clase abstracta que representa la excepción base del proyecto Formacion
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 15 oct 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class AgenciaEsaException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public AgenciaEsaException(String mensaje) {
|
||||
super(mensaje);
|
||||
}
|
||||
|
||||
public AgenciaEsaException(String mensaje, Throwable causa) {
|
||||
super(mensaje, causa);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package eu.esa.gemis.eva1.gestor;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
*
|
||||
* GestorConfiguracion: Clase que carga la configuración de la aplicación desde
|
||||
* un fichero de propiedades
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 8 oct 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class GestorConexionesJDBC {
|
||||
|
||||
// Constructor privado: de esta manera conseguimos que esta clase no se puede
|
||||
// instanciar.
|
||||
private GestorConexionesJDBC() {
|
||||
}
|
||||
|
||||
public static Connection obtenerConexion() throws SQLException {
|
||||
Connection conexion = null;
|
||||
|
||||
String urlConexionCompleta = GestorConfiguracion.getConexionURL() + GestorConfiguracion.getNombreBBDD();
|
||||
String usuarioBBDD = GestorConfiguracion.getUsuarioBBDD();
|
||||
String claveBBDD = GestorConfiguracion.getClaveBBDD();
|
||||
conexion = DriverManager.getConnection(urlConexionCompleta, usuarioBBDD, claveBBDD);
|
||||
|
||||
return conexion;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package eu.esa.gemis.eva1.gestor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
*
|
||||
* GestorConfiguracion: Clase que carga la configuración de la aplicación desde
|
||||
* un fichero de propiedades
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 8 oct 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class GestorConfiguracion {
|
||||
private static final String RUTA_FICHERO_CONFIGURACION = "aplicacion.properties";
|
||||
private static final Properties PROPIEDADES_CONFIGURACION = new Properties();
|
||||
|
||||
// Constructor privado: de esta manera conseguimos que esta clase no se puede
|
||||
// instanciar.
|
||||
private GestorConfiguracion() {
|
||||
}
|
||||
|
||||
// Este bloque se ejecuta una sola vez, cuando se carga la clase
|
||||
// GestorConfiguracion
|
||||
static {
|
||||
try (InputStream inputStream = GestorConfiguracion.class.getClassLoader()
|
||||
.getResourceAsStream(RUTA_FICHERO_CONFIGURACION);) {
|
||||
|
||||
if (inputStream == null) {
|
||||
throw new IOException("No se encuentra " + RUTA_FICHERO_CONFIGURACION + " en el classpath");
|
||||
}
|
||||
PROPIEDADES_CONFIGURACION.load(inputStream);
|
||||
// System.out.println(PROPIEDADES_CONFIGURACION);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("No se ha podido cargar el fichero de configuración", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getConexionURL() {
|
||||
return PROPIEDADES_CONFIGURACION.getProperty("sgdb.conexion.url");
|
||||
}
|
||||
|
||||
public static String getNombreBBDD() {
|
||||
return PROPIEDADES_CONFIGURACION.getProperty("bbdd.nombre");
|
||||
}
|
||||
|
||||
public static String getUsuarioBBDD() {
|
||||
return PROPIEDADES_CONFIGURACION.getProperty("bbdd.usuario");
|
||||
}
|
||||
|
||||
public static String getClaveBBDD() {
|
||||
return PROPIEDADES_CONFIGURACION.getProperty("bbdd.clave");
|
||||
}
|
||||
|
||||
public static String getRutaFicheroCSVTripulante() {
|
||||
return PROPIEDADES_CONFIGURACION.getProperty("tripulante.fichero.csv");
|
||||
}
|
||||
|
||||
public static String getSeparadorFicheroCSVTripulante() {
|
||||
return PROPIEDADES_CONFIGURACION.getProperty("tripulante.csv.separador");
|
||||
}
|
||||
|
||||
public static String getCabeceraFicheroCSVTripulante() {
|
||||
return PROPIEDADES_CONFIGURACION.getProperty("tripulante.csv.cabecera");
|
||||
}
|
||||
|
||||
public static String getRutaFicheroMisionesESAXML() {
|
||||
return PROPIEDADES_CONFIGURACION.getProperty("misionesesa.fichero.xml");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* CuerpoCeleste: "VO" que representa un cuerpo celeste (planeta, satélite, etc.).
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 8 oct 2026
|
||||
*/
|
||||
package eu.esa.gemis.eva1.model;
|
||||
|
||||
public class CuerpoCeleste {
|
||||
private int identificador;
|
||||
private String nombre;
|
||||
private String tipo;
|
||||
private double gravedadSuperficieMs2;
|
||||
|
||||
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 getTipo() {
|
||||
return tipo;
|
||||
}
|
||||
|
||||
public void setTipo(String tipo) {
|
||||
this.tipo = tipo;
|
||||
}
|
||||
|
||||
public double getGravedadSuperficieMs2() {
|
||||
return gravedadSuperficieMs2;
|
||||
}
|
||||
|
||||
public void setGravedadSuperficieMs2(double gravedadSuperficieMs2) {
|
||||
this.gravedadSuperficieMs2 = gravedadSuperficieMs2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CuerpoCeleste [identificador=" + identificador + ", nombre=" + nombre + ", tipo=" + tipo
|
||||
+ ", gravedadSuperficieMs2=" + gravedadSuperficieMs2 + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* Mision: "VO" que representa una misión espacial.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 8 oct 2026
|
||||
*/
|
||||
package eu.esa.gemis.eva1.model;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class Mision {
|
||||
private int identificador;
|
||||
private String nombre;
|
||||
private Nave nave;
|
||||
private CuerpoCeleste cuerpoCeleste;
|
||||
private LocalDate fechaInicio;
|
||||
private LocalDate fechaFinEstimado;
|
||||
private LocalDate fechaFin;
|
||||
private String estado;
|
||||
private String objetivoPrincipal;
|
||||
private int presupuestoAsignado;
|
||||
|
||||
public Nave getNave() {
|
||||
return nave;
|
||||
}
|
||||
|
||||
public void setNave(Nave nave) {
|
||||
this.nave = nave;
|
||||
}
|
||||
|
||||
public int getIdentificador() {
|
||||
return identificador;
|
||||
}
|
||||
|
||||
public void setIdentificador(int identificador) {
|
||||
this.identificador = identificador;
|
||||
}
|
||||
|
||||
public CuerpoCeleste getCuerpoCeleste() {
|
||||
return cuerpoCeleste;
|
||||
}
|
||||
|
||||
public void setCuerpoCeleste(CuerpoCeleste cuerpoCeleste) {
|
||||
this.cuerpoCeleste = cuerpoCeleste;
|
||||
}
|
||||
|
||||
public LocalDate getFechaInicio() {
|
||||
return fechaInicio;
|
||||
}
|
||||
|
||||
public void setFechaInicio(LocalDate fechaInicio) {
|
||||
this.fechaInicio = fechaInicio;
|
||||
}
|
||||
|
||||
public LocalDate getFechaFinEstimado() {
|
||||
return fechaFinEstimado;
|
||||
}
|
||||
|
||||
public void setFechaFinEstimado(LocalDate fechaFinEstimado) {
|
||||
this.fechaFinEstimado = fechaFinEstimado;
|
||||
}
|
||||
|
||||
public LocalDate getFechaFin() {
|
||||
return fechaFin;
|
||||
}
|
||||
|
||||
public void setFechaFin(LocalDate fechaFin) {
|
||||
this.fechaFin = fechaFin;
|
||||
}
|
||||
|
||||
public String getEstado() {
|
||||
return estado;
|
||||
}
|
||||
|
||||
public void setEstado(String estado) {
|
||||
this.estado = estado;
|
||||
}
|
||||
|
||||
public String getObjetivoPrincipal() {
|
||||
return objetivoPrincipal;
|
||||
}
|
||||
|
||||
public void setObjetivoPrincipal(String objetivoPrincipal) {
|
||||
this.objetivoPrincipal = objetivoPrincipal;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public int getPresupuestoAsignado() {
|
||||
return presupuestoAsignado;
|
||||
}
|
||||
|
||||
public void setPresupuestoAsignado(int presupuestoAsignado) {
|
||||
this.presupuestoAsignado = presupuestoAsignado;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Mision [identificador=" + identificador + ", nombre=" + nombre + ", nave=" + nave + ", cuerpoCeleste="
|
||||
+ cuerpoCeleste + ", fechaInicio=" + fechaInicio + ", fechaFinEstimado=" + fechaFinEstimado
|
||||
+ ", fechaFin=" + fechaFin + ", estado=" + estado + ", objetivoPrincipal=" + objetivoPrincipal
|
||||
+ ", presupuestoAsignado=" + presupuestoAsignado + "]\n";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Nave: "VO" que representa una nave espacial.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 8 oct 2026
|
||||
*/
|
||||
package eu.esa.gemis.eva1.model;
|
||||
|
||||
public class Nave {
|
||||
private String codigo;
|
||||
private String nombre;
|
||||
private String tipo;
|
||||
private int capacidadTripulacion;
|
||||
private short autonomiaDias;
|
||||
|
||||
public String getCodigo() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
public void setCodigo(String codigo) {
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getTipo() {
|
||||
return tipo;
|
||||
}
|
||||
|
||||
public void setTipo(String tipo) {
|
||||
this.tipo = tipo;
|
||||
}
|
||||
|
||||
public int getCapacidadTripulacion() {
|
||||
return capacidadTripulacion;
|
||||
}
|
||||
|
||||
public void setCapacidadTripulacion(int capacidadTripulacion) {
|
||||
this.capacidadTripulacion = capacidadTripulacion;
|
||||
}
|
||||
|
||||
public short getAutonomiaDias() {
|
||||
return autonomiaDias;
|
||||
}
|
||||
|
||||
public void setAutonomiaDias(short autonomiaDias) {
|
||||
this.autonomiaDias = autonomiaDias;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Nave [codigo=" + codigo + ", nombre=" + nombre + ", tipo=" + tipo + ", capacidadTripulacion="
|
||||
+ capacidadTripulacion + ", autonomiaDias=" + autonomiaDias + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Tripulante: "VO" que representa a un miembro del personal de la ESA.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 8 oct 2026
|
||||
*/
|
||||
package eu.esa.gemis.eva1.model;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class Tripulante {
|
||||
private int numeroTripulante;
|
||||
private String nombre;
|
||||
private String apellidos;
|
||||
private int identificadorEsa;
|
||||
private int nivelExperiencia;
|
||||
private String especialidad;
|
||||
private LocalDate fechaIngresoEsa;
|
||||
|
||||
public int getNumeroTripulante() {
|
||||
return numeroTripulante;
|
||||
}
|
||||
|
||||
public void setNumeroTripulante(int numeroTripulante) {
|
||||
this.numeroTripulante = numeroTripulante;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getApellidos() {
|
||||
return apellidos;
|
||||
}
|
||||
|
||||
public void setApellidos(String apellidos) {
|
||||
this.apellidos = apellidos;
|
||||
}
|
||||
|
||||
public int getIdentificadorEsa() {
|
||||
return identificadorEsa;
|
||||
}
|
||||
|
||||
public void setIdentificadorEsa(int identificadorEsa) {
|
||||
this.identificadorEsa = identificadorEsa;
|
||||
}
|
||||
|
||||
public int getNivelExperiencia() {
|
||||
return nivelExperiencia;
|
||||
}
|
||||
|
||||
public void setNivelExperiencia(int nivelExperiencia) {
|
||||
this.nivelExperiencia = nivelExperiencia;
|
||||
}
|
||||
|
||||
public String getEspecialidad() {
|
||||
return especialidad;
|
||||
}
|
||||
|
||||
public void setEspecialidad(String especialidad) {
|
||||
this.especialidad = especialidad;
|
||||
}
|
||||
|
||||
public LocalDate getFechaIngresoEsa() {
|
||||
return fechaIngresoEsa;
|
||||
}
|
||||
|
||||
public void setFechaIngresoEsa(LocalDate fechaIngresoEsa) {
|
||||
this.fechaIngresoEsa = fechaIngresoEsa;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Tripulante [numeroTripulante=" + numeroTripulante + ", nombre=" + nombre + ", apellidos=" + apellidos
|
||||
+ ", identificadorEsa=" + identificadorEsa + ", nivelExperiencia=" + nivelExperiencia
|
||||
+ ", especialidad=" + especialidad + ", fechaIngresoEsa=" + fechaIngresoEsa + "]\n";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package eu.esa.gemis.eva1.procesos;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
import eu.esa.gemis.eva1.gestor.GestorConfiguracion;
|
||||
import eu.esa.gemis.eva1.model.Tripulante;
|
||||
import eu.esa.gemis.eva1.service.TripulanteService;
|
||||
|
||||
/**
|
||||
*
|
||||
* ProcesadorTripulantesCSV: Clase que realiza el tratamiuento de tripulantes
|
||||
* para almacenarlos en ficheros CSV.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 8 oct 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class ProcesadorTripulantesCSV {
|
||||
private static final String SEPARADOR_CSV = GestorConfiguracion.getSeparadorFicheroCSVTripulante();
|
||||
private static final String CABECERA_CSV = GestorConfiguracion.getCabeceraFicheroCSVTripulante();
|
||||
private String rutaFicheroCSV = GestorConfiguracion.getRutaFicheroCSVTripulante();
|
||||
|
||||
public void almacenarTripulantesSinMisionEnFicheroCSV() throws AgenciaEsaException {
|
||||
File ficheroCSV = new File(rutaFicheroCSV);
|
||||
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(ficheroCSV));) {
|
||||
|
||||
// Escribimos la cabecera
|
||||
writer.write(CABECERA_CSV);
|
||||
writer.newLine();
|
||||
|
||||
TripulanteService tripulanteService= new TripulanteService();
|
||||
List<Tripulante> listaTripulantesSinMision = tripulanteService.obtenerTripulantesSinMision();
|
||||
|
||||
// Recorremos la lista de tripulantes y los escribimos en el fichero
|
||||
for (Tripulante tripulante : listaTripulantesSinMision) {
|
||||
writer.write(tripulante.getNumeroTripulante() + SEPARADOR_CSV + tripulante.getNombre() + SEPARADOR_CSV
|
||||
+ tripulante.getApellidos() + SEPARADOR_CSV + tripulante.getIdentificadorEsa() + SEPARADOR_CSV
|
||||
+ tripulante.getEspecialidad() + SEPARADOR_CSV + tripulante.getFechaIngresoEsa());
|
||||
writer.newLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new AgenciaEsaException("Error al guardar tripulantes en el fichero CSV.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package eu.esa.gemis.eva1.procesos;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
import eu.esa.gemis.eva1.gestor.GestorConfiguracion;
|
||||
import eu.esa.gemis.eva1.model.CuerpoCeleste;
|
||||
import eu.esa.gemis.eva1.model.Mision;
|
||||
import eu.esa.gemis.eva1.model.Nave;
|
||||
import eu.esa.gemis.eva1.service.MisionService;
|
||||
|
||||
/**
|
||||
*
|
||||
* ProcesadorXMLMisiones: Clase que realiza el procesamiento de ficheros XML de
|
||||
* misiones.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 26 nov 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class ProcesadorXMLMisiones {
|
||||
|
||||
public void procesarFicheroXMLMisiones() throws AgenciaEsaException {
|
||||
Document documentoMisionesDOM = cargarArbolDOMFicheroXML();
|
||||
NodeList listaNodosMision = documentoMisionesDOM.getElementsByTagName("mision");
|
||||
|
||||
// Tratamiento de nodos Misión
|
||||
for (int i = 0; i < listaNodosMision.getLength(); i++) {
|
||||
Element elementoMision = (Element) listaNodosMision.item(i);
|
||||
|
||||
String fechaInicio = elementoMision.getAttribute("fecha_inicio");
|
||||
String fechaFinEstimado = elementoMision.getAttribute("fecha_fin_estimada");
|
||||
String estado = elementoMision.getAttribute("estado");
|
||||
String nombre = elementoMision.getElementsByTagName("nombre").item(0).getTextContent();
|
||||
String codigoNave = elementoMision.getElementsByTagName("cod_nave").item(0).getTextContent();
|
||||
String nombreCuerpoCeleste = elementoMision.getElementsByTagName("cuerpo_celeste").item(0).getTextContent();
|
||||
String objetivo = elementoMision.getElementsByTagName("objetivo").item(0).getTextContent();
|
||||
String presupuesto = elementoMision.getElementsByTagName("presupuesto").item(0).getTextContent();
|
||||
|
||||
Mision mision = new Mision();
|
||||
mision.setNombre(nombre);
|
||||
mision.setObjetivoPrincipal(objetivo);
|
||||
mision.setFechaInicio(LocalDate.parse(fechaInicio));
|
||||
mision.setFechaFinEstimado(LocalDate.parse(fechaFinEstimado));
|
||||
mision.setEstado(estado);
|
||||
mision.setPresupuestoAsignado(Integer.parseInt(presupuesto));
|
||||
|
||||
CuerpoCeleste cuerpoCeleste = new CuerpoCeleste();
|
||||
cuerpoCeleste.setNombre(nombreCuerpoCeleste);
|
||||
mision.setCuerpoCeleste(cuerpoCeleste);
|
||||
|
||||
Nave nave = new Nave();
|
||||
nave.setCodigo(codigoNave);
|
||||
mision.setNave(nave);
|
||||
|
||||
MisionService misionService= new MisionService();
|
||||
misionService.insertarMision(mision);
|
||||
}
|
||||
}
|
||||
|
||||
private Document cargarArbolDOMFicheroXML() throws AgenciaEsaException {
|
||||
Document document = null;
|
||||
|
||||
try {
|
||||
// 1. Crear la fábrica
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
// 2. Crear el parser que se usará para obtener el árbol DOM
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
|
||||
// 3. Leer el fichero XML y lo parseamos para obtener el árbol DOM
|
||||
File fichero = new File(GestorConfiguracion.getRutaFicheroMisionesESAXML());
|
||||
document = builder.parse(fichero);
|
||||
|
||||
// 4. Obtener el documento raíz normalizado
|
||||
document.getDocumentElement().normalize();
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new AgenciaEsaException("Error al abrirl el fichero XML con misiones.", e);
|
||||
}
|
||||
return document;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package eu.esa.gemis.eva1.service;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import eu.esa.gemis.eva1.dao.ICuerpoCelesteDAO;
|
||||
import eu.esa.gemis.eva1.dao.IMisionDAO;
|
||||
import eu.esa.gemis.eva1.dao.INaveDAO;
|
||||
import eu.esa.gemis.eva1.dao.impl.CuerpoCelesteDaoJDBC;
|
||||
import eu.esa.gemis.eva1.dao.impl.MisionDaoJDBC;
|
||||
import eu.esa.gemis.eva1.dao.impl.NaveDaoJDBC;
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
import eu.esa.gemis.eva1.gestor.GestorConexionesJDBC;
|
||||
import eu.esa.gemis.eva1.model.CuerpoCeleste;
|
||||
import eu.esa.gemis.eva1.model.Mision;
|
||||
|
||||
/**
|
||||
*
|
||||
* TripulanteService: Clase que realiza la lógica de negocio de un tripulante.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 8 nov 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class MisionService {
|
||||
|
||||
public List<Mision> obtenerMisionesIniciadasEnAnyo(int anyo) throws AgenciaEsaException {
|
||||
List<Mision> listaMisiones;
|
||||
|
||||
try (Connection conexion = GestorConexionesJDBC.obtenerConexion();) {
|
||||
IMisionDAO iMisionDAO = new MisionDaoJDBC(conexion);
|
||||
listaMisiones = iMisionDAO.obtenerMisionesIniciadasEnAnyo(anyo);
|
||||
} catch (SQLException e) {
|
||||
throw new AgenciaEsaException("Error al obtener la conexión.", e);
|
||||
}
|
||||
return listaMisiones;
|
||||
}
|
||||
|
||||
|
||||
public void insertarMision(Mision mision) throws AgenciaEsaException {
|
||||
|
||||
try (Connection conexion = GestorConexionesJDBC.obtenerConexion();) {
|
||||
|
||||
// Obtener información del cuerpo celeste y asignarlo a la misión.
|
||||
ICuerpoCelesteDAO iCuerpoCelesteDAO = new CuerpoCelesteDaoJDBC(conexion);
|
||||
CuerpoCeleste cuerpoCeleste = iCuerpoCelesteDAO
|
||||
.obtenerCuerpoCelestePorNombre(mision.getCuerpoCeleste().getNombre());
|
||||
mision.setCuerpoCeleste(cuerpoCeleste);
|
||||
|
||||
// Comprobar si la nave existe en la base de datos.
|
||||
INaveDAO iNaveDAO = new NaveDaoJDBC(conexion);
|
||||
boolean existeNave = iNaveDAO.existeNavePorCodigo(mision.getNave().getCodigo());
|
||||
|
||||
IMisionDAO iMisionDAO = new MisionDaoJDBC(conexion);
|
||||
if (cuerpoCeleste != null && existeNave) {
|
||||
// Si el cuerpo celeste existe y la nave existe, insertar la misión.
|
||||
boolean existeMision = iMisionDAO.existeMisionPorNaveYCuerpoCeleste(mision);
|
||||
if (!existeMision) {
|
||||
iMisionDAO.insertarMision(mision);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new AgenciaEsaException("Error al obtener la conexión.", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package eu.esa.gemis.eva1.service;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import eu.esa.gemis.eva1.dao.ITripulanteDAO;
|
||||
import eu.esa.gemis.eva1.dao.impl.TripulanteDaoJDBC;
|
||||
import eu.esa.gemis.eva1.excepcion.AgenciaEsaException;
|
||||
import eu.esa.gemis.eva1.gestor.GestorConexionesJDBC;
|
||||
import eu.esa.gemis.eva1.model.Tripulante;
|
||||
|
||||
/**
|
||||
*
|
||||
* TripulanteService: Clase que realiza la lógica de negocio de un tripulante.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 8 nov 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class TripulanteService {
|
||||
public List<Tripulante> obtenerTripulantesSinMision() throws AgenciaEsaException {
|
||||
List<Tripulante> listaTripulantes;
|
||||
try (Connection conexion = GestorConexionesJDBC.obtenerConexion();) {
|
||||
ITripulanteDAO iTripulanteDAO = new TripulanteDaoJDBC(conexion);
|
||||
listaTripulantes = iTripulanteDAO.obtenerTripulantesSinMision();
|
||||
} catch (SQLException e) {
|
||||
throw new AgenciaEsaException("Error al obtener la conexión.", e);
|
||||
}
|
||||
return listaTripulantes;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user