primero
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package aadd.palomafp.anp;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import aadd.palomafp.anp.conexion.ConexionDB;
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
import aadd.palomafp.anp.service.impl.CicloFormativoServiceImpl;
|
||||
import aadd.palomafp.anp.service.impl.FamiliaProfesionalServiceImpl;
|
||||
import aadd.palomafp.anp.service.CicloFormativoService;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws FormationException {
|
||||
|
||||
|
||||
|
||||
try (Connection conexion = ConexionDB.getConexion()) {
|
||||
|
||||
if (conexion != null && !conexion.isClosed()) {
|
||||
System.out.println("OK: ¡Conexión establecida con éxito con la base de datos!");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
System.err.println("ERROR: No se pudo establecer la conexión.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
FamiliaProfesionalServiceImpl service = new FamiliaProfesionalServiceImpl();
|
||||
|
||||
List<String> informe = service.procesarFicheroFamilia();
|
||||
|
||||
informe.forEach(System.out::println);
|
||||
|
||||
try {
|
||||
CicloFormativoService servicioCiclo = new CicloFormativoServiceImpl();
|
||||
List<String> informeCiclos = servicioCiclo.cargarFamiliasDesdeXML();
|
||||
informeCiclos.forEach(System.out::println);
|
||||
|
||||
} catch (FormationException e) {
|
||||
System.err.println("Error durante la ejecución: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package aadd.palomafp.anp.conexion;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ConexionDB {
|
||||
|
||||
public static Connection getConexion() throws SQLException {
|
||||
|
||||
try {
|
||||
Class.forName(ConfigConexion.get("db.driver"));
|
||||
|
||||
return DriverManager.getConnection(
|
||||
ConfigConexion.get("db.url"),
|
||||
ConfigConexion.get("db.user"),
|
||||
ConfigConexion.get("db.password")
|
||||
);
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new SQLException("No se ha encontrado el driver de la base de datos", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package aadd.palomafp.anp.conexion;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
public class ConfigConexion {
|
||||
|
||||
private static final String RUTA_CONFIG = "ficheros/config.properties";
|
||||
private static final Properties PROPS = new Properties();
|
||||
|
||||
static {
|
||||
try (FileInputStream fis = new FileInputStream(RUTA_CONFIG)) {
|
||||
PROPS.load(fis);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("No se pudo leer" + RUTA_CONFIG, e);
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigConexion() {}
|
||||
public static String get(String clave) {
|
||||
String valor = PROPS.getProperty(clave);
|
||||
if (valor == null) {
|
||||
System.out.println("Falta la propiedad: " + clave);
|
||||
}
|
||||
|
||||
return valor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package aadd.palomafp.anp.dao;
|
||||
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
import aadd.palomafp.anp.model.CicloFormativo;
|
||||
import aadd.palomafp.anp.model.FamiliaProfesional;
|
||||
|
||||
public interface CicloFormativoDAO {
|
||||
|
||||
|
||||
void insert(CicloFormativo cf) throws FormationException;
|
||||
CicloFormativo findById(String codigo) throws FormationException;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package aadd.palomafp.anp.dao;
|
||||
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
import aadd.palomafp.anp.model.FamiliaProfesional;
|
||||
|
||||
|
||||
public interface FamiliaProfesionalDAO {
|
||||
|
||||
|
||||
void insert(FamiliaProfesional fa) throws FormationException;
|
||||
|
||||
boolean update(FamiliaProfesional fa) throws FormationException;
|
||||
|
||||
FamiliaProfesional findById(String codigo) throws FormationException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package aadd.palomafp.anp.dao;
|
||||
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
import aadd.palomafp.anp.model.TipoFormacion;
|
||||
|
||||
public interface TipoFormacionDAO {
|
||||
TipoFormacion findById(String codigo) throws FormationException;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package aadd.palomafp.anp.dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import aadd.palomafp.anp.conexion.ConexionDB;
|
||||
import aadd.palomafp.anp.conexion.ConfigConexion;
|
||||
import aadd.palomafp.anp.dao.CicloFormativoDAO;
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
import aadd.palomafp.anp.model.CicloFormativo;
|
||||
|
||||
public class CicloFormativoDAOImpl implements CicloFormativoDAO {
|
||||
|
||||
@Override
|
||||
public CicloFormativo findById(String codigo) throws FormationException {
|
||||
String sql = ConfigConexion.get("sql.ciclo.porId");
|
||||
try (Connection con = ConexionDB.getConexion();
|
||||
PreparedStatement ps = con.prepareStatement(sql)) {
|
||||
|
||||
ps.setString(1, codigo);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CicloFormativo(
|
||||
rs.getString("codigo"),
|
||||
rs.getString("nombre_corto"),
|
||||
rs.getString("nombre_largo"),
|
||||
rs.getInt("horas_duracion"),
|
||||
rs.getString("codigo_familia"),
|
||||
rs.getString("codigo_tipo_formacion")
|
||||
);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
throw new FormationException(
|
||||
"Error al consultar el ciclo formativo " + codigo + ": " + e.getMessage(), e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insert(CicloFormativo cf) throws FormationException {
|
||||
String sql = ConfigConexion.get("sql.ciclo.insert");
|
||||
try (Connection con = ConexionDB.getConexion();
|
||||
PreparedStatement ps = con.prepareStatement(sql)) {
|
||||
|
||||
ps.setString(1, cf.getCodigo());
|
||||
ps.setString(2, cf.getNombre_corto());
|
||||
ps.setString(3, cf.getNombre_largo());
|
||||
ps.setInt(4, cf.getHoras_duracion());
|
||||
ps.setString(5, cf.getCodigo_familia());
|
||||
ps.setString(6, cf.getcodTipoFormacion());
|
||||
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
throw new FormationException(
|
||||
"Error al insertar el ciclo formativo " + cf.getCodigo() + ": " + e.getMessage(), e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package aadd.palomafp.anp.dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import aadd.palomafp.anp.conexion.ConexionDB;
|
||||
import aadd.palomafp.anp.conexion.ConfigConexion;
|
||||
import aadd.palomafp.anp.dao.FamiliaProfesionalDAO;
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
import aadd.palomafp.anp.model.FamiliaProfesional;
|
||||
|
||||
|
||||
public class FamiliaProfesionalDAOImpl implements FamiliaProfesionalDAO {
|
||||
|
||||
@Override
|
||||
public void insert(FamiliaProfesional fa) throws FormationException {
|
||||
String sql = ConfigConexion.get("sql.familia.insert");
|
||||
try (Connection con = ConexionDB.getConexion();
|
||||
PreparedStatement ps = con.prepareStatement(sql)) {
|
||||
|
||||
ps.setString(1, fa.getCodigo());
|
||||
ps.setString(2, fa.getNombre());
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
throw new FormationException(
|
||||
"Error al consultar la familia " + fa.getCodigo() + ": " + e.getMessage(), e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(FamiliaProfesional fa) throws FormationException {
|
||||
String sql = ConfigConexion.get("sql.familia.update");
|
||||
try (Connection con = ConexionDB.getConexion();
|
||||
PreparedStatement ps = con.prepareStatement(sql)) {
|
||||
ps.setString(1, fa.getNombre());
|
||||
ps.setString(2, fa.getCodigo());
|
||||
|
||||
return ps.executeUpdate() > 0;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
throw new FormationException(
|
||||
"Error al consultar la familia " + fa.getCodigo() + ": " + e.getMessage(), e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FamiliaProfesional findById(String codigo) throws FormationException {
|
||||
String sql = ConfigConexion.get("sql.familia.porId");
|
||||
try (Connection con = ConexionDB.getConexion();
|
||||
PreparedStatement ps = con.prepareStatement(sql)) {
|
||||
|
||||
ps.setString(1, codigo);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new FamiliaProfesional(rs.getString("codigo"), rs.getString("nombre"));
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
throw new FormationException(
|
||||
"Error al consultar la familia "+ codigo + ": " + e.getMessage(), e
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package aadd.palomafp.anp.dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import aadd.palomafp.anp.conexion.ConexionDB;
|
||||
import aadd.palomafp.anp.conexion.ConfigConexion;
|
||||
import aadd.palomafp.anp.dao.TipoFormacionDAO;
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
import aadd.palomafp.anp.model.TipoFormacion;
|
||||
|
||||
public class TipoFormacionDAOImpl implements TipoFormacionDAO {
|
||||
|
||||
@Override
|
||||
public TipoFormacion findById(String codigo) throws FormationException {
|
||||
String sql = ConfigConexion.get("sql.tipo.porId");
|
||||
try (Connection con = ConexionDB.getConexion();
|
||||
PreparedStatement ps = con.prepareStatement(sql)) {
|
||||
|
||||
ps.setString(1, codigo);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
return null;
|
||||
}
|
||||
return new TipoFormacion(
|
||||
rs.getString("codigo"),
|
||||
rs.getString("nombre_corto"),
|
||||
rs.getString("nombre_largo")
|
||||
);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
throw new FormationException(
|
||||
"Error al consultar el tipo de formación " + codigo + ": " + e.getMessage(), e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package aadd.palomafp.anp.exception;
|
||||
|
||||
public class FormationException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FormationException(String mensaje) {
|
||||
super(mensaje);
|
||||
}
|
||||
|
||||
public FormationException(String mensaje, Throwable causa) {
|
||||
super(mensaje, causa);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
|
||||
package aadd.palomafp.anp.fichero;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import aadd.palomafp.anp.conexion.ConfigConexion;
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
import aadd.palomafp.anp.model.CicloFormativo;
|
||||
|
||||
|
||||
|
||||
public class CicloFormativoXMLReader {
|
||||
|
||||
public List<CicloFormativo> leer(String ruta) throws FormationException {
|
||||
|
||||
List<CicloFormativo> ciclos = new ArrayList<>();
|
||||
|
||||
try {
|
||||
DocumentBuilderFactory factory =
|
||||
DocumentBuilderFactory.newInstance();
|
||||
|
||||
factory.setFeature(
|
||||
XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document doc = builder.parse(new File(ruta));
|
||||
|
||||
NodeList nodosCiclos = doc.getElementsByTagName(
|
||||
ConfigConexion.get("xml.ciclos_formativos"));
|
||||
|
||||
if (nodosCiclos.getLength() == 0) {
|
||||
throw new FormationException("No se encontraron ciclos formativos");
|
||||
}
|
||||
|
||||
Element elementoCiclos = (Element) nodosCiclos.item(0);
|
||||
|
||||
NodeList listaCiclo = elementoCiclos.getElementsByTagName(
|
||||
ConfigConexion.get("xml.ciclo"));
|
||||
|
||||
for (int i = 0; i < listaCiclo.getLength(); i++) {
|
||||
Node nodo = listaCiclo.item(i);
|
||||
|
||||
if (nodo.getNodeType() == Node.ELEMENT_NODE) {
|
||||
ciclos.add(construirCiclo((Element) nodo));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
throw new FormationException("Error al leer el XML de ciclos formativos", e);
|
||||
}
|
||||
|
||||
return ciclos;
|
||||
}
|
||||
|
||||
private CicloFormativo construirCiclo(Element el)
|
||||
throws FormationException {
|
||||
|
||||
String codigo = el.getAttribute(
|
||||
ConfigConexion.get("xml.ciclo.cod_cf"));
|
||||
|
||||
CicloFormativo ciclo = new CicloFormativo();
|
||||
|
||||
ciclo.setCodigo(codigo);
|
||||
ciclo.setNombre_corto(texto(el, "xml.ciclo.nomb_corto"));
|
||||
ciclo.setNombre_largo(texto(el, "xml.ciclo.nombrelargo"));
|
||||
ciclo.setHoras_duracion(
|
||||
Integer.parseInt(texto(el, "xml.ciclo.num_horas_duracion")));
|
||||
ciclo.setCodigo_familia(texto(el, "xml.ciclo.codigo_familia"));
|
||||
ciclo.setCodigo_tipo_formacion(texto(el, "xml.ciclo.codigo_tipoestudio"));
|
||||
|
||||
return ciclo;
|
||||
}
|
||||
|
||||
private String texto(Element padre, String claveEtiqueta)
|
||||
throws FormationException {
|
||||
|
||||
String etiqueta = ConfigConexion.get(claveEtiqueta);
|
||||
NodeList nodos = padre.getElementsByTagName(etiqueta);
|
||||
|
||||
if (nodos.getLength() == 0) {
|
||||
throw new FormationException(
|
||||
"No se encontró la etiqueta XML: " + etiqueta);
|
||||
}
|
||||
|
||||
return nodos.item(0).getTextContent().trim();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package aadd.palomafp.anp.fichero;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import aadd.palomafp.anp.conexion.ConfigConexion;
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
import aadd.palomafp.anp.model.FamiliaProfesional;
|
||||
|
||||
|
||||
public class FamiliasProfesionalesCsv {
|
||||
|
||||
public List<FamiliaProfesional> leer(String ruta) throws FormationException {
|
||||
|
||||
List<FamiliaProfesional> operaciones = new ArrayList<>();
|
||||
|
||||
String separador = ConfigConexion.get("csv.separador");
|
||||
|
||||
int columnasEsperadas = Integer.parseInt(ConfigConexion.get("csv.columnas"));
|
||||
Charset charset = Charset.forName(ConfigConexion.get("csv.encoding"));
|
||||
|
||||
try (BufferedReader br = Files.newBufferedReader(Paths.get(ruta), charset)) {
|
||||
|
||||
|
||||
br.readLine();
|
||||
String linea;
|
||||
|
||||
while ((linea = br.readLine()) != null) {
|
||||
if (linea.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
String[] campos = linea.split(separador, -1);
|
||||
if (campos.length != columnasEsperadas) {
|
||||
throw new FormationException("Error de formato en la línea "
|
||||
+ ". Se esperaban " + columnasEsperadas + " columnas pero hay " + campos.length);
|
||||
}
|
||||
|
||||
try {
|
||||
String codigo = campos[0].trim();
|
||||
String fechaCarga = campos[1].trim();
|
||||
String codTipoFam = campos[2].trim();
|
||||
String nombre = campos[3].trim();
|
||||
|
||||
|
||||
operaciones.add(
|
||||
new FamiliaProfesional(codigo, nombre));
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
throw new FormationException("Error numérico en la línea " + e);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new FormationException("Error al leer el archivo CSV de cocheras", e);
|
||||
}
|
||||
|
||||
return operaciones;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package aadd.palomafp.anp.model;
|
||||
|
||||
public class CicloFormativo {
|
||||
|
||||
private String codigo;
|
||||
private String nombreCorto;
|
||||
private String nombreLargo;
|
||||
private int horas_duracion;
|
||||
private String codFamilia;
|
||||
private String codTipoFormacion;
|
||||
|
||||
public CicloFormativo() {
|
||||
|
||||
}
|
||||
|
||||
public CicloFormativo(String codigo, String nombre_corto, String nombre_largo, int horas_duracion,
|
||||
String codigo_familia, String codTipoFormacion) {
|
||||
super();
|
||||
this.codigo = codigo;
|
||||
this.nombreCorto = nombre_corto;
|
||||
this.nombreLargo = nombre_largo;
|
||||
this.horas_duracion = horas_duracion;
|
||||
this.codFamilia = codigo_familia;
|
||||
this.codTipoFormacion = codTipoFormacion;
|
||||
}
|
||||
|
||||
public String getCodigo() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
public void setCodigo(String codigo) {
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
public String getNombre_corto() {
|
||||
return nombreCorto;
|
||||
}
|
||||
|
||||
public void setNombre_corto(String nombre_corto) {
|
||||
this.nombreCorto = nombre_corto;
|
||||
}
|
||||
|
||||
public String getNombre_largo() {
|
||||
return nombreLargo;
|
||||
}
|
||||
|
||||
public void setNombre_largo(String nombre_largo) {
|
||||
this.nombreLargo = nombre_largo;
|
||||
}
|
||||
|
||||
public int getHoras_duracion() {
|
||||
return horas_duracion;
|
||||
}
|
||||
|
||||
public void setHoras_duracion(int horas_duracion) {
|
||||
this.horas_duracion = horas_duracion;
|
||||
}
|
||||
|
||||
public String getCodigo_familia() {
|
||||
return codFamilia;
|
||||
}
|
||||
|
||||
public void setCodigo_familia(String codigo_familia) {
|
||||
this.codFamilia = codigo_familia;
|
||||
}
|
||||
|
||||
public String getcodTipoFormacion() {
|
||||
return codTipoFormacion;
|
||||
}
|
||||
|
||||
public void setCodigo_tipo_formacion(String codTipoFormacion) {
|
||||
this.codTipoFormacion = codTipoFormacion;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package aadd.palomafp.anp.model;
|
||||
|
||||
public class FamiliaProfesional {
|
||||
|
||||
private String codigo;
|
||||
private String nombre;
|
||||
|
||||
public FamiliaProfesional () {
|
||||
|
||||
}
|
||||
|
||||
public FamiliaProfesional(String codigo, String nombre) {
|
||||
super();
|
||||
this.codigo = codigo;
|
||||
this.nombre = 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package aadd.palomafp.anp.model;
|
||||
|
||||
public class TipoFormacion {
|
||||
|
||||
private String codigo;
|
||||
private String nombreCorto;
|
||||
private String nombreLargo;
|
||||
|
||||
public TipoFormacion () {
|
||||
|
||||
}
|
||||
|
||||
public TipoFormacion(String codigo, String nombreCorto, String nombreLargo) {
|
||||
super();
|
||||
this.codigo = codigo;
|
||||
this.nombreCorto = nombreCorto;
|
||||
this.nombreLargo = nombreLargo;
|
||||
}
|
||||
|
||||
public String getCodigo() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
public void setCodigo(String codigo) {
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
public String getNombreCorto() {
|
||||
return nombreCorto;
|
||||
}
|
||||
|
||||
public void setNombreCorto(String nombreCorto) {
|
||||
this.nombreCorto = nombreCorto;
|
||||
}
|
||||
|
||||
public String getNombreLargo() {
|
||||
return nombreLargo;
|
||||
}
|
||||
|
||||
public void setNombreLargo(String nombreLargo) {
|
||||
this.nombreLargo = nombreLargo;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package aadd.palomafp.anp.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
|
||||
public interface CicloFormativoService {
|
||||
|
||||
public List<String> cargarFamiliasDesdeXML() throws FormationException;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package aadd.palomafp.anp.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
|
||||
public interface FamiliaProfesionalService {
|
||||
|
||||
List<String> procesarFicheroFamilia() throws FormationException;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package aadd.palomafp.anp.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import aadd.palomafp.anp.conexion.ConfigConexion;
|
||||
import aadd.palomafp.anp.dao.CicloFormativoDAO;
|
||||
import aadd.palomafp.anp.dao.FamiliaProfesionalDAO;
|
||||
import aadd.palomafp.anp.dao.TipoFormacionDAO;
|
||||
import aadd.palomafp.anp.dao.impl.CicloFormativoDAOImpl;
|
||||
import aadd.palomafp.anp.dao.impl.FamiliaProfesionalDAOImpl;
|
||||
import aadd.palomafp.anp.dao.impl.TipoFormacionDAOImpl;
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
import aadd.palomafp.anp.fichero.CicloFormativoXMLReader;
|
||||
import aadd.palomafp.anp.model.CicloFormativo;
|
||||
import aadd.palomafp.anp.service.CicloFormativoService;
|
||||
|
||||
public class CicloFormativoServiceImpl implements CicloFormativoService {
|
||||
|
||||
private CicloFormativoDAO cicloDAO = new CicloFormativoDAOImpl();
|
||||
private FamiliaProfesionalDAO familiaDAO = new FamiliaProfesionalDAOImpl();
|
||||
private TipoFormacionDAO tipoFormacionDAO = new TipoFormacionDAOImpl();
|
||||
private CicloFormativoXMLReader reader = new CicloFormativoXMLReader();
|
||||
|
||||
@Override
|
||||
public List<String> cargarFamiliasDesdeXML() throws FormationException {
|
||||
List<String> informe = new ArrayList<>();
|
||||
String rutaXml = ConfigConexion.get("rutaXml");
|
||||
|
||||
List<CicloFormativo> ciclosLeidos = reader.leer(rutaXml);
|
||||
int insertados = 0;
|
||||
|
||||
for (CicloFormativo ciclo : ciclosLeidos) {
|
||||
String codFamilia = ciclo.getCodigo_familia();
|
||||
String codTipoFormacion = ciclo.getcodTipoFormacion();
|
||||
|
||||
boolean existeFamilia = (familiaDAO.findById(codFamilia) != null);
|
||||
boolean existeTipoFormacion = (tipoFormacionDAO.findById(codTipoFormacion) != null);
|
||||
|
||||
if (existeFamilia && existeTipoFormacion) {
|
||||
cicloDAO.insert(ciclo);
|
||||
insertados++;
|
||||
informe.add("Ciclo insertado: " + ciclo.getCodigo() + " - " + ciclo.getNombre_corto());
|
||||
} else {
|
||||
informe.add("Ciclo omitido (familia o tipo de formación no encontrados en BD): " + ciclo.getCodigo());
|
||||
}
|
||||
}
|
||||
|
||||
informe.add("Proceso finalizado. Se han insertado " + insertados + " ciclos formativos.");
|
||||
return informe;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package aadd.palomafp.anp.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import aadd.palomafp.anp.dao.impl.FamiliaProfesionalDAOImpl;
|
||||
import aadd.palomafp.anp.exception.FormationException;
|
||||
import aadd.palomafp.anp.fichero.FamiliasProfesionalesCsv;
|
||||
import aadd.palomafp.anp.model.FamiliaProfesional;
|
||||
import aadd.palomafp.anp.service.FamiliaProfesionalService;
|
||||
import aadd.palomafp.anp.conexion.ConfigConexion;
|
||||
import aadd.palomafp.anp.dao.FamiliaProfesionalDAO;
|
||||
|
||||
|
||||
public class FamiliaProfesionalServiceImpl implements FamiliaProfesionalService {
|
||||
|
||||
private final FamiliaProfesionalDAO familiaProfesionalDAO = new FamiliaProfesionalDAOImpl();
|
||||
private final FamiliasProfesionalesCsv lector = new FamiliasProfesionalesCsv();
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> procesarFicheroFamilia() throws FormationException {
|
||||
|
||||
List<FamiliaProfesional> operaciones =
|
||||
lector.leer(ConfigConexion.get("fichero.familias"));
|
||||
|
||||
List<String> informe = new ArrayList<>();
|
||||
|
||||
for (FamiliaProfesional fa : operaciones) {
|
||||
|
||||
String cod = fa.getCodigo();
|
||||
String nombre = fa.getNombre();
|
||||
|
||||
try {
|
||||
|
||||
FamiliaProfesional familia =
|
||||
familiaProfesionalDAO.findById(cod);
|
||||
|
||||
if (familia == null) {
|
||||
|
||||
familiaProfesionalDAO.insert(fa);
|
||||
|
||||
informe.add("Se ha introducido la familia profesional: "
|
||||
+ cod + " - " + nombre);
|
||||
|
||||
} else {
|
||||
|
||||
familiaProfesionalDAO.update(fa);
|
||||
|
||||
informe.add("Se ha actualizado la familia profesional: "
|
||||
+ cod + " - " + nombre);
|
||||
}
|
||||
|
||||
} catch (FormationException e) {
|
||||
|
||||
informe.add("Error en la operación para el código "
|
||||
+ cod + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return informe;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user