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,9 @@
|
|||||||
|
# Elegir nombres de entradas que sean SIGNIFICATIVOS
|
||||||
|
# y que no se repitan con otras entradas de la misma aplicación
|
||||||
|
|
||||||
|
# Información relativa Continentes
|
||||||
|
continente.ruta.fichero=C:\\Users\\ineva\\INM\\tmp\\aadd\\fic09\\informacion_continentes.csv
|
||||||
|
continente.csv.separador=#
|
||||||
|
|
||||||
|
# Información relativa Países
|
||||||
|
pais.ruta.fichero=C:\\Users\\ineva\\INM\\tmp\\aadd\\fic04\\informacion_paises.txt
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package org.palomafp.aadd.inm;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.inm.dao.IContinenteDAO;
|
||||||
|
import org.palomafp.aadd.inm.dao.impl.ContinenteDaoCSV;
|
||||||
|
import org.palomafp.aadd.inm.model.Continente;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* AppPrincipal: Clase que realiza el tratamiento de un fichero con información
|
||||||
|
* de países usando patrón DAO.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 24 sept 2026
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GestorMapaMundi {
|
||||||
|
private IContinenteDAO continenteDAO = new ContinenteDaoCSV();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
GestorMapaMundi gestor = new GestorMapaMundi();
|
||||||
|
|
||||||
|
String operacion = args[0];
|
||||||
|
switch (operacion) {
|
||||||
|
case "1": {
|
||||||
|
System.out.println("Obtener lista de Continentes");
|
||||||
|
List<Continente> continentes = gestor.obtenerListaDeContinentes();
|
||||||
|
System.out.println(continentes);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "2": {
|
||||||
|
String codigoContinente = args[1];
|
||||||
|
System.out.println("Obtener Continente por código: " + codigoContinente);
|
||||||
|
Continente continente = gestor.obtenerContinenteDeCodigo(codigoContinente);
|
||||||
|
System.out.println(continente);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "3": {
|
||||||
|
String codigoContinente = args[1];
|
||||||
|
String nombreContinente = args[2];
|
||||||
|
System.out.println("Insertar Continente: " + codigoContinente + " con nombre: " + nombreContinente);
|
||||||
|
gestor.insertarContinente(codigoContinente, nombreContinente);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "4": {
|
||||||
|
String codigoContinente = args[1];
|
||||||
|
System.out.println("Borrar continente: " + codigoContinente);
|
||||||
|
gestor.borrarContinente(codigoContinente);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "5": {
|
||||||
|
String codigoContinente = args[1];
|
||||||
|
String nombreContinente = args[2];
|
||||||
|
System.out.println("Actualizar Continente: " + codigoContinente + " con nombre: " + nombreContinente);
|
||||||
|
gestor.actualizarContinente(codigoContinente, nombreContinente);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
System.out.println("Operación no válida");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void actualizarContinente(String codigoContinente, String nombreContinente) {
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codigoContinente);
|
||||||
|
continente.setNombre(nombreContinente);
|
||||||
|
|
||||||
|
Continente continenteFichero = continenteDAO.obtenerContinentePorCodigo(codigoContinente);
|
||||||
|
if (continenteFichero != null) {
|
||||||
|
continenteDAO.actualizarContinente(continente);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void borrarContinente(String codigoContinente) {
|
||||||
|
Continente continenteFichero = continenteDAO.obtenerContinentePorCodigo(codigoContinente);
|
||||||
|
if (continenteFichero != null) {
|
||||||
|
continenteDAO.borrarContinente(codigoContinente);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void insertarContinente(String codigoContinente, String nombreContinente) {
|
||||||
|
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codigoContinente);
|
||||||
|
continente.setNombre(nombreContinente);
|
||||||
|
|
||||||
|
Continente continenteFichero = continenteDAO.obtenerContinentePorCodigo(codigoContinente);
|
||||||
|
if (continenteFichero == null) {
|
||||||
|
continenteDAO.insertarContinente(continente);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Continente obtenerContinenteDeCodigo(String codigoContinente) {
|
||||||
|
Continente continente = continenteDAO.obtenerContinentePorCodigo(codigoContinente);
|
||||||
|
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Continente> obtenerListaDeContinentes() {
|
||||||
|
List<Continente> listaContinentes = continenteDAO.obtenerListaContinentes();
|
||||||
|
|
||||||
|
return listaContinentes;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.palomafp.aadd.inm.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.inm.model.Continente;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* IPaisDAO: Interfaz que contiene los métodos para obtener información de continentes desde un origen de datos.
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 26 sept 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface IContinenteDAO {
|
||||||
|
List<Continente> obtenerListaContinentes();
|
||||||
|
Continente obtenerContinentePorCodigo(String codigoContinente);
|
||||||
|
void insertarContinente(Continente continente);
|
||||||
|
void actualizarContinente(Continente continente);
|
||||||
|
void borrarContinente(String codigoContinente);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package org.palomafp.aadd.inm.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.inm.model.Pais;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* IPaisDAO: Interfaz que contiene los métodos para obtener información de países desde un origen de datos.
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 26 sept 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface IPaisDAO {
|
||||||
|
Pais obtenerPaisPorID(int identificador);
|
||||||
|
|
||||||
|
List<Pais> obtenerPaisesPorContinente(String codContinente);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
package org.palomafp.aadd.inm.dao.impl;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.inm.dao.IContinenteDAO;
|
||||||
|
import org.palomafp.aadd.inm.gestores.GestorConfiguracion;
|
||||||
|
import org.palomafp.aadd.inm.model.Continente;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PaisDaoText: Clase que realiza la implementación de la interfaz
|
||||||
|
* IContinenteDAO para obtener información de continentes desde un origen de
|
||||||
|
* datos basado en texto.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 26 sept 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ContinenteDaoCSV implements IContinenteDAO {
|
||||||
|
private static final String RUTA_FICHERO = GestorConfiguracion.getRutaFicheroContinente();
|
||||||
|
private static final String SEPARADOR_CSV = GestorConfiguracion.getSeparadorCsvFicheroContinente();
|
||||||
|
private static final String RUTA_FICHERO_TEMPORAL = "archivo.tmp";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Continente obtenerContinentePorCodigo(String codigoContinente) {
|
||||||
|
Continente continenteEncontrado = null;
|
||||||
|
|
||||||
|
Path rutaFicheroContinentes = Path.of(RUTA_FICHERO);
|
||||||
|
|
||||||
|
try (var reader = Files.newBufferedReader(rutaFicheroContinentes, StandardCharsets.UTF_8)) {
|
||||||
|
String linea = null;
|
||||||
|
|
||||||
|
// Nos saltamos la primera línea que contiene los nombres de los campos.
|
||||||
|
reader.readLine();
|
||||||
|
|
||||||
|
while ((linea = reader.readLine()) != null) {
|
||||||
|
|
||||||
|
String[] camposContinente = linea.split(SEPARADOR_CSV);
|
||||||
|
String codContinente = camposContinente[1].trim().replace("\"", "");
|
||||||
|
|
||||||
|
// Comprobamos si el código de continente coincide con el que estamos
|
||||||
|
// buscando.
|
||||||
|
if (codContinente.equals(codigoContinente)) {
|
||||||
|
String nombreContinente = camposContinente[2].trim().replace("\"", "");
|
||||||
|
|
||||||
|
continenteEncontrado = obtenerContinenteDeLinea(codigoContinente, nombreContinente);
|
||||||
|
|
||||||
|
break; // Salimos del bucle ya que hemos encontrado el continente.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return continenteEncontrado;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Continente> obtenerListaContinentes() {
|
||||||
|
List<Continente> listaContinentes = null;
|
||||||
|
|
||||||
|
Path rutaFicheroContinentes = Path.of(RUTA_FICHERO);
|
||||||
|
|
||||||
|
try (var reader = Files.newBufferedReader(rutaFicheroContinentes, StandardCharsets.UTF_8)) {
|
||||||
|
String linea = null;
|
||||||
|
|
||||||
|
// Nos saltamos la primera línea que contiene los nombres de los campos.
|
||||||
|
reader.readLine();
|
||||||
|
|
||||||
|
while ((linea = reader.readLine()) != null) {
|
||||||
|
|
||||||
|
// La primera vez que entramos en este bloque, inicializamos la lista de
|
||||||
|
// continentes
|
||||||
|
if (listaContinentes == null) {
|
||||||
|
listaContinentes = new ArrayList<Continente>();
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] camposContinente = linea.split(SEPARADOR_CSV);
|
||||||
|
String codContinente = camposContinente[1].trim().replace("\"", "");
|
||||||
|
String nombreContinente = camposContinente[2].trim().replace("\"", "");
|
||||||
|
|
||||||
|
// Se añade un nuevo continente a la lista de continentes obtenidos.
|
||||||
|
listaContinentes.add(obtenerContinenteDeLinea(codContinente, nombreContinente));
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println(e);
|
||||||
|
}
|
||||||
|
return listaContinentes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertarContinente(Continente continente) {
|
||||||
|
|
||||||
|
try (var writer = Files.newBufferedWriter(Path.of(RUTA_FICHERO), StandardCharsets.UTF_8,
|
||||||
|
StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.APPEND)) {
|
||||||
|
|
||||||
|
writer.write(System.lineSeparator());
|
||||||
|
|
||||||
|
String lineaContinente = String.format("2026" + SEPARADOR_CSV + "%s" + SEPARADOR_CSV + "%s",
|
||||||
|
continente.getCodigo(), continente.getNombre());
|
||||||
|
|
||||||
|
writer.write(lineaContinente);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarContinente(Continente continente) {
|
||||||
|
Path rutaFicheroOriginal = Path.of(RUTA_FICHERO);
|
||||||
|
Path rutaFicheroTemporal = Path.of(RUTA_FICHERO_TEMPORAL);
|
||||||
|
|
||||||
|
boolean actualizado = false;
|
||||||
|
|
||||||
|
// 1. Leer el original y generar el temporal
|
||||||
|
try (var readerOriginal = Files.newBufferedReader(rutaFicheroOriginal, StandardCharsets.UTF_8);
|
||||||
|
var writerTemporal = Files.newBufferedWriter(rutaFicheroTemporal, StandardCharsets.UTF_8)) {
|
||||||
|
|
||||||
|
String linea=null;
|
||||||
|
boolean primeraLinea = true;
|
||||||
|
|
||||||
|
while ((linea = readerOriginal.readLine()) != null) {
|
||||||
|
|
||||||
|
if (linea.trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] campos = linea.split(SEPARADOR_CSV, -1);
|
||||||
|
|
||||||
|
if (campos.length < 3) {
|
||||||
|
throw new IOException("Línea CSV no válida: " + linea);
|
||||||
|
}
|
||||||
|
|
||||||
|
String anyo = campos[0].trim().replace("\"", "");
|
||||||
|
String codContinente = campos[1].trim().replace("\"", "");
|
||||||
|
|
||||||
|
if (!primeraLinea) {
|
||||||
|
writerTemporal.newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codContinente.equals(continente.getCodigo())) {
|
||||||
|
String nuevaLinea = String.join(SEPARADOR_CSV, anyo, continente.getCodigo(),
|
||||||
|
continente.getNombre());
|
||||||
|
|
||||||
|
writerTemporal.write(nuevaLinea);
|
||||||
|
actualizado = true;
|
||||||
|
} else {
|
||||||
|
writerTemporal.write(linea);
|
||||||
|
}
|
||||||
|
|
||||||
|
primeraLinea = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Error al procesar el CSV: " + e.getMessage());
|
||||||
|
return; // No sustituimos el original si falla la escritura
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Sustituir el original solo si se ha actualizado el registro
|
||||||
|
if (!actualizado) {
|
||||||
|
System.err.println("No se encontró el continente que se desea actualizar.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.move(rutaFicheroTemporal, rutaFicheroOriginal, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("No se pudo sustituir el fichero original: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarContinente(String codigoContinente) {
|
||||||
|
Path rutaFicheroOriginal = Path.of(RUTA_FICHERO);
|
||||||
|
Path rutaFicheroTemporal = Path.of(RUTA_FICHERO_TEMPORAL);
|
||||||
|
|
||||||
|
// 1. Leer el original y generar el temporal
|
||||||
|
try (var readerOriginal = Files.newBufferedReader(rutaFicheroOriginal, StandardCharsets.UTF_8);
|
||||||
|
var writerTemporal = Files.newBufferedWriter(rutaFicheroTemporal, StandardCharsets.UTF_8)) {
|
||||||
|
|
||||||
|
String linea = null;
|
||||||
|
boolean primeraLinea = true;
|
||||||
|
|
||||||
|
while ((linea = readerOriginal.readLine()) != null) {
|
||||||
|
|
||||||
|
String[] camposContinente = linea.split(SEPARADOR_CSV);
|
||||||
|
String codContinente = camposContinente[1].trim().replace("\"", "");
|
||||||
|
|
||||||
|
// 2. Escribimos todas las líneas excepto la que queremos eliminar
|
||||||
|
if (!codContinente.equals(codigoContinente)) {
|
||||||
|
if (!primeraLinea) {
|
||||||
|
writerTemporal.write(System.lineSeparator());
|
||||||
|
}
|
||||||
|
writerTemporal.write(linea);
|
||||||
|
primeraLinea = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.move(
|
||||||
|
rutaFicheroTemporal,
|
||||||
|
rutaFicheroOriginal,
|
||||||
|
StandardCopyOption.REPLACE_EXISTING
|
||||||
|
);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println(
|
||||||
|
"No se pudo sustituir el fichero original: " + e.getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Continente obtenerContinenteDeLinea(String codigoContinente, String nombreContiente) {
|
||||||
|
// Obtenemos el objeto Continente a partir del código.
|
||||||
|
Continente continente = new Continente();
|
||||||
|
|
||||||
|
continente.setCodigo(codigoContinente);
|
||||||
|
continente.setNombre(nombreContiente);
|
||||||
|
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package org.palomafp.aadd.inm.dao.impl;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.inm.dao.IContinenteDAO;
|
||||||
|
import org.palomafp.aadd.inm.dao.IPaisDAO;
|
||||||
|
import org.palomafp.aadd.inm.gestores.GestorConfiguracion;
|
||||||
|
import org.palomafp.aadd.inm.model.Continente;
|
||||||
|
import org.palomafp.aadd.inm.model.Pais;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PaisDaoText: Clase que realiza la implementación de la interfaz IPaisDAO para
|
||||||
|
* obtener información de países desde un origen de datos basado en texto.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 26 sept 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PaisDaoText implements IPaisDAO {
|
||||||
|
private static final String RUTA_FICHERO = GestorConfiguracion.getRutaFicheroPais();
|
||||||
|
private IContinenteDAO continenteDao;
|
||||||
|
|
||||||
|
public PaisDaoText(IContinenteDAO continenteDao) {
|
||||||
|
this.continenteDao = (ContinenteDaoCSV) continenteDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pais obtenerPaisPorID(int identificador) {
|
||||||
|
Pais paisEncontrado = null;
|
||||||
|
|
||||||
|
Path rutaFicheroContinentes = Path.of(RUTA_FICHERO);
|
||||||
|
|
||||||
|
try (var reader = Files.newBufferedReader(rutaFicheroContinentes, StandardCharsets.UTF_8)) {
|
||||||
|
String linea = null;
|
||||||
|
|
||||||
|
while ((linea = reader.readLine()) != null) {
|
||||||
|
|
||||||
|
// Nos saltamos las líneas que comienzan con el carácter #, que son comentarios.
|
||||||
|
if (linea.trim().startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] camposPais = linea.split(",");
|
||||||
|
|
||||||
|
String idPais = camposPais[1].trim();
|
||||||
|
// Comprobamos si el identificador del país coincide con el que estamos
|
||||||
|
// buscando.
|
||||||
|
if (Integer.parseInt(idPais) == identificador) {
|
||||||
|
String codigoContinente = camposPais[0].trim().replace("\"", "");
|
||||||
|
String nombrePais = camposPais[2].trim().replace("\"", "");
|
||||||
|
String capitalPais = camposPais[3].trim().replace("\"", "");
|
||||||
|
|
||||||
|
paisEncontrado = obtenerPaisDeLinea(codigoContinente, Integer.parseInt(idPais), nombrePais,
|
||||||
|
capitalPais);
|
||||||
|
|
||||||
|
break; // Salimos del bucle ya que hemos encontrado el país.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println(e);
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
return paisEncontrado;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pais> obtenerPaisesPorContinente(String codContinente) {
|
||||||
|
List<Pais> listaPaisesEncontrados = null;
|
||||||
|
|
||||||
|
Path rutaFicheroContinentes = Path.of(RUTA_FICHERO);
|
||||||
|
|
||||||
|
try (var reader = Files.newBufferedReader(rutaFicheroContinentes, StandardCharsets.UTF_8)) {
|
||||||
|
String linea = null;
|
||||||
|
|
||||||
|
while ((linea = reader.readLine()) != null) {
|
||||||
|
|
||||||
|
// Nos saltamos las líneas que comienzan con el carácter #, que son comentarios.
|
||||||
|
if (linea.trim().startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] camposPais = linea.split(",");
|
||||||
|
|
||||||
|
String codigoContinente = camposPais[0].trim().replace("\"", "");
|
||||||
|
if (codigoContinente.equals(codContinente)) {
|
||||||
|
// La primera vez que entramos en este bloque, inicializamos la lista de países
|
||||||
|
// encontrados.
|
||||||
|
if (listaPaisesEncontrados == null) {
|
||||||
|
listaPaisesEncontrados = new ArrayList<Pais>();
|
||||||
|
}
|
||||||
|
String idPais = camposPais[1].trim();
|
||||||
|
String nombrePais = camposPais[2].trim().replace("\"", "");
|
||||||
|
String capitalPais = camposPais[3].trim().replace("\"", "");
|
||||||
|
|
||||||
|
Pais pais = obtenerPaisDeLinea(codigoContinente, Integer.parseInt(idPais), nombrePais, capitalPais);
|
||||||
|
|
||||||
|
listaPaisesEncontrados.add(pais);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return listaPaisesEncontrados;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Pais obtenerPaisDeLinea(String codigoContinente, int identificador, String nombrePais, String capitalPais) {
|
||||||
|
// Obtenemos el objeto Continente a partir del código.
|
||||||
|
Continente continente = continenteDao.obtenerContinentePorCodigo(codigoContinente);
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
pais.setIdentificador(identificador);
|
||||||
|
pais.setNombre(nombrePais);
|
||||||
|
pais.setCapital(capitalPais);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package org.palomafp.aadd.inm.gestores;
|
||||||
|
|
||||||
|
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 = "/application.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
|
||||||
|
.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 getRutaFicheroContinente() {
|
||||||
|
return PROPIEDADES_CONFIGURACION.getProperty("continente.ruta.fichero");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSeparadorCsvFicheroContinente() {
|
||||||
|
return PROPIEDADES_CONFIGURACION.getProperty("continente.csv.separador");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getRutaFicheroPais() {
|
||||||
|
return PROPIEDADES_CONFIGURACION.getProperty("pais.ruta.fichero");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package org.palomafp.aadd.inm.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Continente: Clase que se asocia a la información de un continente.
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 24 sept 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
private String codigo;
|
||||||
|
private String nombre;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Continente [codigo=" + codigo + ", nombre=" + nombre + "]\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package org.palomafp.aadd.inm.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Pais Clase que se asocia a la información de un país.
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 24 sept 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String capital;
|
||||||
|
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
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 getCapital() {
|
||||||
|
return capital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCapital(String capital) {
|
||||||
|
this.capital = capital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Continente getContinente() {
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContinente(Continente continente) {
|
||||||
|
this.continente = continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Pais [identificador=" + identificador + ", nombre=" + nombre + ", capital=" + capital + ", continente="
|
||||||
|
+ continente + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user