Cambio en forma procesamiento
This commit is contained in:
parent
0392095663
commit
00a7255659
@ -6,17 +6,24 @@ package org.comunidadmadrid.fp.dam2;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.comunidadmadrid.fp.dam2.dao.ICicloFormativoDAO;
|
import org.comunidadmadrid.fp.dam2.dao.ICicloFormativoDAO;
|
||||||
|
import org.comunidadmadrid.fp.dam2.dao.IFormacionDAO;
|
||||||
import org.comunidadmadrid.fp.dam2.dao.IInstitutoDAO;
|
import org.comunidadmadrid.fp.dam2.dao.IInstitutoDAO;
|
||||||
|
import org.comunidadmadrid.fp.dam2.dao.IInstitutoFormacionDAO;
|
||||||
import org.comunidadmadrid.fp.dam2.dao.hibernate.CicloFormativoDaoHibernate;
|
import org.comunidadmadrid.fp.dam2.dao.hibernate.CicloFormativoDaoHibernate;
|
||||||
|
import org.comunidadmadrid.fp.dam2.dao.hibernate.FormacionDaoHibernate;
|
||||||
|
import org.comunidadmadrid.fp.dam2.dao.hibernate.InstitutoFormacionDaoHibernate;
|
||||||
import org.comunidadmadrid.fp.dam2.dao.jdbc.CicloFormativoDaoJDBC;
|
import org.comunidadmadrid.fp.dam2.dao.jdbc.CicloFormativoDaoJDBC;
|
||||||
import org.comunidadmadrid.fp.dam2.dao.jpa.InstitutoDaoJPA;
|
import org.comunidadmadrid.fp.dam2.dao.jpa.InstitutoDaoJPA;
|
||||||
import org.comunidadmadrid.fp.dam2.dao.mongodb.InstitutoDaoMongoDB;
|
import org.comunidadmadrid.fp.dam2.dao.mongodb.InstitutoDaoMongoDB;
|
||||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||||
import org.comunidadmadrid.fp.dam2.gestores.GestorSesionHibernate;
|
import org.comunidadmadrid.fp.dam2.gestores.GestorSesionHibernate;
|
||||||
import org.comunidadmadrid.fp.dam2.procesamiento.ProcesadorDatos;
|
import org.comunidadmadrid.fp.dam2.procesamiento.ProcesadorFormacionInstitutoCSV;
|
||||||
|
import org.comunidadmadrid.fp.dam2.procesamiento.ProcesadorFormacionesURL;
|
||||||
import org.comunidadmadrid.fp.dam2.utilidades.GestorURLs;
|
import org.comunidadmadrid.fp.dam2.utilidades.GestorURLs;
|
||||||
import org.comunidadmadrid.fp.dam2.vo.CicloFormativo;
|
import org.comunidadmadrid.fp.dam2.vo.CicloFormativo;
|
||||||
|
import org.comunidadmadrid.fp.dam2.vo.Formacion;
|
||||||
import org.comunidadmadrid.fp.dam2.vo.Instituto;
|
import org.comunidadmadrid.fp.dam2.vo.Instituto;
|
||||||
|
import org.comunidadmadrid.fp.dam2.vo.InstitutoFormacion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Organización: Virgen de la Paloma Programador: Isidoro Nevares Martín Fecha:
|
* Organización: Virgen de la Paloma Programador: Isidoro Nevares Martín Fecha:
|
||||||
@ -40,6 +47,7 @@ public class ClasePrincipal {
|
|||||||
appPrincipal.tratarFormaciones();
|
appPrincipal.tratarFormaciones();
|
||||||
|
|
||||||
appPrincipal.tratarInstitutoFormacion();
|
appPrincipal.tratarInstitutoFormacion();
|
||||||
|
|
||||||
} catch (FormacionException e) {
|
} catch (FormacionException e) {
|
||||||
String mensajeError = "Error en la clase %s al realizar una operación de %s";
|
String mensajeError = "Error en la clase %s al realizar una operación de %s";
|
||||||
String operacion = "Operación desconocida";
|
String operacion = "Operación desconocida";
|
||||||
@ -106,9 +114,26 @@ public class ClasePrincipal {
|
|||||||
* @throws FormacionException
|
* @throws FormacionException
|
||||||
*/
|
*/
|
||||||
private void tratarFormaciones() throws FormacionException {
|
private void tratarFormaciones() throws FormacionException {
|
||||||
ProcesadorDatos procesador = new ProcesadorDatos();
|
ProcesadorFormacionesURL procesador = new ProcesadorFormacionesURL();
|
||||||
procesador.procesarFormacionesDeURL();
|
List<Formacion> listaFormaciones = procesador.obtenerListaFormacionesDeURL();
|
||||||
|
|
||||||
|
if (listaFormaciones != null) {
|
||||||
|
|
||||||
|
// Se prepara el AADD de Instituto para que se realice mediante Hibernate
|
||||||
|
IFormacionDAO iFormacionDAO = new FormacionDaoHibernate();
|
||||||
|
for (Formacion formacion : listaFormaciones) {
|
||||||
|
|
||||||
|
// Se obiene la formación en la BBDD
|
||||||
|
Formacion formacionBBDD = iFormacionDAO.obtenerFormacionPorID(formacion.getIdentificador());
|
||||||
|
|
||||||
|
// Si no existen en la BBDD se inserta, en caso contrario se actualiza.
|
||||||
|
if (formacionBBDD == null) {
|
||||||
|
iFormacionDAO.insertarFormacion(formacion);
|
||||||
|
} else {
|
||||||
|
iFormacionDAO.actualizarFormacion(formacion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,8 +174,40 @@ public class ClasePrincipal {
|
|||||||
*/
|
*/
|
||||||
private void tratarInstitutoFormacion() throws FormacionException {
|
private void tratarInstitutoFormacion() throws FormacionException {
|
||||||
|
|
||||||
ProcesadorDatos procesador = new ProcesadorDatos();
|
ProcesadorFormacionInstitutoCSV procesador = new ProcesadorFormacionInstitutoCSV();
|
||||||
procesador.procesarFormacionesInstitutoCSV();
|
List<InstitutoFormacion> listaInstitutoFormacion = procesador.obtenerInstitutoFormacionesDeCSV();
|
||||||
|
|
||||||
|
if (listaInstitutoFormacion != null) {
|
||||||
|
|
||||||
|
// Se prepara el AADD de InstitutoFormacion para que se realice mediante
|
||||||
|
// Hibernate
|
||||||
|
IInstitutoFormacionDAO institutoFormacionDAO = new InstitutoFormacionDaoHibernate();
|
||||||
|
IFormacionDAO iFormacionDAO = new FormacionDaoHibernate();
|
||||||
|
IInstitutoDAO iInstitutoDAO = new InstitutoDaoJPA();
|
||||||
|
|
||||||
|
for (InstitutoFormacion institutoFormacion : listaInstitutoFormacion) {
|
||||||
|
// Se obiene el instituto en la BBDD
|
||||||
|
InstitutoFormacion institutoFormacionBBDD = institutoFormacionDAO
|
||||||
|
.obtenerInstitutoFormacionPorID(institutoFormacion.getIdInstitutoFormacion());
|
||||||
|
|
||||||
|
// Si no existe información en la Base de datos.
|
||||||
|
if (institutoFormacionBBDD == null) {
|
||||||
|
|
||||||
|
// Sólo se insertará el InstitutoFormacion si existen tanto el Instituto como la
|
||||||
|
// Formación en la Base de datos.
|
||||||
|
Instituto instituto = iInstitutoDAO
|
||||||
|
.obtenerInstitutoPorID(institutoFormacion.getInstituto().getIdentificador());
|
||||||
|
Formacion formacion = iFormacionDAO
|
||||||
|
.obtenerFormacionPorID(institutoFormacion.getFormacion().getIdentificador());
|
||||||
|
if (instituto != null && formacion != null) {
|
||||||
|
institutoFormacion.setInstituto(instituto);
|
||||||
|
institutoFormacion.setFormacion(formacion);
|
||||||
|
institutoFormacionDAO.insertarInstitutoFormacion(institutoFormacion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,175 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.comunidadmadrid.fp.dam2.procesamiento;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.comunidadmadrid.fp.dam2.dao.IFormacionDAO;
|
|
||||||
import org.comunidadmadrid.fp.dam2.dao.IInstitutoDAO;
|
|
||||||
import org.comunidadmadrid.fp.dam2.dao.IInstitutoFormacionDAO;
|
|
||||||
import org.comunidadmadrid.fp.dam2.dao.hibernate.FormacionDaoHibernate;
|
|
||||||
import org.comunidadmadrid.fp.dam2.dao.hibernate.InstitutoFormacionDaoHibernate;
|
|
||||||
import org.comunidadmadrid.fp.dam2.dao.jpa.InstitutoDaoJPA;
|
|
||||||
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
|
||||||
import org.comunidadmadrid.fp.dam2.gestores.GestorFicheroConfiguracion;
|
|
||||||
import org.comunidadmadrid.fp.dam2.utilidades.GestorURLs;
|
|
||||||
import org.comunidadmadrid.fp.dam2.vo.CicloFormativo;
|
|
||||||
import org.comunidadmadrid.fp.dam2.vo.Formacion;
|
|
||||||
import org.comunidadmadrid.fp.dam2.vo.Instituto;
|
|
||||||
import org.comunidadmadrid.fp.dam2.vo.InstitutoFormacion;
|
|
||||||
import org.comunidadmadrid.fp.dam2.vo.InstitutoFormacion.InstitutoFormacionID;
|
|
||||||
|
|
||||||
import tools.jackson.databind.JsonNode;
|
|
||||||
import tools.jackson.databind.ObjectMapper;
|
|
||||||
import tools.jackson.databind.node.ArrayNode;
|
|
||||||
import tools.jackson.dataformat.xml.XmlMapper;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Organización: Virgen de la Paloma
|
|
||||||
Programador: Isidoro Nevares Martín
|
|
||||||
Fecha: 1 mar 2025
|
|
||||||
*/
|
|
||||||
public class ProcesadorDatos {
|
|
||||||
public void procesarFormacionesDeURL() {
|
|
||||||
String urlFormaciones = GestorFicheroConfiguracion.obtenerValor("url.formaciones");
|
|
||||||
|
|
||||||
String informacionFormacionesXML = GestorURLs.getTextoFromURL(urlFormaciones);
|
|
||||||
ObjectMapper mapeadorXML = new XmlMapper();
|
|
||||||
|
|
||||||
try {
|
|
||||||
// obtener Formaciones XMl a partir de la URL
|
|
||||||
JsonNode nodoRaiz = mapeadorXML.readTree(informacionFormacionesXML);
|
|
||||||
|
|
||||||
if (nodoRaiz != null) {
|
|
||||||
|
|
||||||
JsonNode nodosFormacion = nodoRaiz.has("formacion") ? nodoRaiz.get("formacion") : nodoRaiz;
|
|
||||||
|
|
||||||
IFormacionDAO iFormacionDAO = new FormacionDaoHibernate();
|
|
||||||
JsonNode arrayNodosFormacion = convertirJsonNodeEnArrayNode(nodosFormacion);
|
|
||||||
for (JsonNode nodoFormacion : arrayNodosFormacion) {
|
|
||||||
Formacion formacion = obtenerFormacionDeJsonNode(nodoFormacion);
|
|
||||||
if (formacion != null) {
|
|
||||||
Formacion formacionBBDD = iFormacionDAO.obtenerFormacionPorID(formacion.getIdentificador());
|
|
||||||
if (formacionBBDD == null) {
|
|
||||||
iFormacionDAO.insertarFormacion(formacion);
|
|
||||||
} else {
|
|
||||||
iFormacionDAO.actualizarFormacion(formacion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println("Error procesando XML con JsonNode: " + e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Procesar las formaciones que se encuentran en el fichero CSV y almacenarlas
|
|
||||||
* en la Base de datos.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
public void procesarFormacionesInstitutoCSV() throws FormacionException {
|
|
||||||
String rutaFicheroCSV = GestorFicheroConfiguracion.obtenerValor("ruta.csv");
|
|
||||||
|
|
||||||
try (BufferedReader br = new BufferedReader(new FileReader(rutaFicheroCSV))) {
|
|
||||||
String linea;
|
|
||||||
|
|
||||||
// Saltar cabecera
|
|
||||||
br.readLine();
|
|
||||||
|
|
||||||
IInstitutoFormacionDAO institutoFormacionDAO = new InstitutoFormacionDaoHibernate();
|
|
||||||
IFormacionDAO iFormacionDAO = new FormacionDaoHibernate();
|
|
||||||
IInstitutoDAO iInstitutoDAO = new InstitutoDaoJPA();
|
|
||||||
while ((linea = br.readLine()) != null) {
|
|
||||||
|
|
||||||
String[] partes = linea.split(",");
|
|
||||||
String registroATratar = partes[0];
|
|
||||||
int idFormacion = Integer.parseInt(partes[1].trim());
|
|
||||||
int idInstituto = Integer.parseInt(partes[2].trim());
|
|
||||||
int anyo = Integer.parseInt(partes[3].trim());
|
|
||||||
|
|
||||||
// Si el registro es de tipo "S" se tratará para insertarse en la Base de datos.
|
|
||||||
if (registroATratar.equals("S")) {
|
|
||||||
InstitutoFormacionID institutoFormacionID = new InstitutoFormacionID(idInstituto, idFormacion);
|
|
||||||
InstitutoFormacion institutoFormacionBBDD = institutoFormacionDAO
|
|
||||||
.obtenerInstitutoFormacionPorID(institutoFormacionID);
|
|
||||||
// Si no existe información en la Base de datos.
|
|
||||||
if (institutoFormacionBBDD == null) {
|
|
||||||
InstitutoFormacion institutoFormacion = new InstitutoFormacion();
|
|
||||||
|
|
||||||
// Sólo se insertará el InstitutoFormacion si existen tanto el Instituto como la
|
|
||||||
// Formación en la Base de datos.
|
|
||||||
Instituto instituto = iInstitutoDAO.obtenerInstitutoPorID(idInstituto);
|
|
||||||
Formacion formacion = iFormacionDAO.obtenerFormacionPorID(idFormacion);
|
|
||||||
if (instituto != null && formacion != null) {
|
|
||||||
institutoFormacion.setIdInstitutoFormacion(institutoFormacionID);
|
|
||||||
institutoFormacion.setInstituto(instituto);
|
|
||||||
institutoFormacion.setFormacion(formacion);
|
|
||||||
institutoFormacion.setAnyoAcademico(anyo);
|
|
||||||
|
|
||||||
institutoFormacionDAO.insertarInstitutoFormacion(institutoFormacion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convierte un JsonNode que representa una formación en el objeto Formacion
|
|
||||||
* correspondiente.
|
|
||||||
*
|
|
||||||
* @param nodoJson
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Formacion obtenerFormacionDeJsonNode(JsonNode nodoJson) {
|
|
||||||
Formacion formacion = null;
|
|
||||||
if (nodoJson != null && !nodoJson.isNull()) {
|
|
||||||
formacion = new Formacion();
|
|
||||||
|
|
||||||
// Atributos mapeados como nodos en Jackson
|
|
||||||
if (nodoJson.has("id_formacion")) {
|
|
||||||
formacion.setIdentificador(nodoJson.get("id_formacion").asInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
int formacionSTEM = 0;
|
|
||||||
if (nodoJson.has("es_formacion_stem")) {
|
|
||||||
formacionSTEM = nodoJson.get("es_formacion_stem").asInt();
|
|
||||||
}
|
|
||||||
formacion.setIndicadorSTEM(formacionSTEM == 1);
|
|
||||||
|
|
||||||
if (nodoJson.has("nombre_corto")) {
|
|
||||||
formacion.setNombreCorto(nodoJson.get("nombre_corto").asString());
|
|
||||||
}
|
|
||||||
|
|
||||||
CicloFormativo ciclo = new CicloFormativo();
|
|
||||||
if (nodoJson.has("cod_ciclo_formativo")) {
|
|
||||||
ciclo.setIdentificador(nodoJson.get("cod_ciclo_formativo").asInt());
|
|
||||||
}
|
|
||||||
formacion.setCicloFormativo(ciclo);
|
|
||||||
}
|
|
||||||
return formacion;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArrayNode convertirJsonNodeEnArrayNode(JsonNode node) {
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
if (node.isArray()) {
|
|
||||||
return (ArrayNode) node;
|
|
||||||
} else {
|
|
||||||
ArrayNode arrayNode = mapper.createArrayNode();
|
|
||||||
if (!node.isMissingNode()) {
|
|
||||||
arrayNode.add(node);
|
|
||||||
}
|
|
||||||
return arrayNode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.comunidadmadrid.fp.dam2.procesamiento;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.comunidadmadrid.fp.dam2.excepcion.FormacionException;
|
||||||
|
import org.comunidadmadrid.fp.dam2.gestores.GestorFicheroConfiguracion;
|
||||||
|
import org.comunidadmadrid.fp.dam2.vo.Formacion;
|
||||||
|
import org.comunidadmadrid.fp.dam2.vo.Instituto;
|
||||||
|
import org.comunidadmadrid.fp.dam2.vo.InstitutoFormacion;
|
||||||
|
import org.comunidadmadrid.fp.dam2.vo.InstitutoFormacion.InstitutoFormacionID;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Organización: Virgen de la Paloma
|
||||||
|
Programador: Isidoro Nevares Martín
|
||||||
|
Fecha: 1 mar 2025
|
||||||
|
*/
|
||||||
|
public class ProcesadorFormacionInstitutoCSV {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Procesar las formaciones que se encuentran en el fichero CSV y almacenarlas
|
||||||
|
* en la Base de datos.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public List<InstitutoFormacion> obtenerInstitutoFormacionesDeCSV() throws FormacionException {
|
||||||
|
List<InstitutoFormacion> listaInstitutoFormacion = null;
|
||||||
|
|
||||||
|
String rutaFicheroCSV = GestorFicheroConfiguracion.obtenerValor("ruta.csv");
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(rutaFicheroCSV))) {
|
||||||
|
String linea;
|
||||||
|
|
||||||
|
// Saltar cabecera
|
||||||
|
br.readLine();
|
||||||
|
listaInstitutoFormacion = new ArrayList<InstitutoFormacion>();
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
|
||||||
|
String[] partes = linea.split(",");
|
||||||
|
String registroATratar = partes[0];
|
||||||
|
int idFormacion = Integer.parseInt(partes[1].trim());
|
||||||
|
int idInstituto = Integer.parseInt(partes[2].trim());
|
||||||
|
int anyo = Integer.parseInt(partes[3].trim());
|
||||||
|
|
||||||
|
// Si el registro es de tipo "S" se tratará para insertarse en la Base de datos.
|
||||||
|
if (registroATratar.equals("S")) {
|
||||||
|
InstitutoFormacion institutoFormacion = new InstitutoFormacion();
|
||||||
|
InstitutoFormacionID institutoFormacionID = new InstitutoFormacionID(idInstituto, idFormacion);
|
||||||
|
|
||||||
|
Instituto instituto = new Instituto();
|
||||||
|
instituto.setIdentificador(idInstituto);
|
||||||
|
Formacion formacion = new Formacion();
|
||||||
|
formacion.setIdentificador(idFormacion);
|
||||||
|
|
||||||
|
institutoFormacion.setIdInstitutoFormacion(institutoFormacionID);
|
||||||
|
institutoFormacion.setInstituto(instituto);
|
||||||
|
institutoFormacion.setFormacion(formacion);
|
||||||
|
institutoFormacion.setAnyoAcademico(anyo);
|
||||||
|
|
||||||
|
listaInstitutoFormacion.add(institutoFormacion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return listaInstitutoFormacion;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,106 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.comunidadmadrid.fp.dam2.procesamiento;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.comunidadmadrid.fp.dam2.gestores.GestorFicheroConfiguracion;
|
||||||
|
import org.comunidadmadrid.fp.dam2.utilidades.GestorURLs;
|
||||||
|
import org.comunidadmadrid.fp.dam2.vo.CicloFormativo;
|
||||||
|
import org.comunidadmadrid.fp.dam2.vo.Formacion;
|
||||||
|
|
||||||
|
import tools.jackson.databind.JsonNode;
|
||||||
|
import tools.jackson.databind.ObjectMapper;
|
||||||
|
import tools.jackson.databind.node.ArrayNode;
|
||||||
|
import tools.jackson.dataformat.xml.XmlMapper;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Organización: Virgen de la Paloma
|
||||||
|
Programador: Isidoro Nevares Martín
|
||||||
|
Fecha: 1 mar 2025
|
||||||
|
*/
|
||||||
|
public class ProcesadorFormacionesURL {
|
||||||
|
public List<Formacion> obtenerListaFormacionesDeURL() {
|
||||||
|
List<Formacion> listaFormaciones = null;
|
||||||
|
|
||||||
|
String urlFormaciones = GestorFicheroConfiguracion.obtenerValor("url.formaciones");
|
||||||
|
|
||||||
|
String informacionFormacionesXML = GestorURLs.getTextoFromURL(urlFormaciones);
|
||||||
|
ObjectMapper mapeadorXML = new XmlMapper();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// obtener Formaciones XMl a partir de la URL
|
||||||
|
JsonNode nodoRaiz = mapeadorXML.readTree(informacionFormacionesXML);
|
||||||
|
|
||||||
|
if (nodoRaiz != null) {
|
||||||
|
|
||||||
|
JsonNode nodosFormacion = nodoRaiz.has("formacion") ? nodoRaiz.get("formacion") : nodoRaiz;
|
||||||
|
|
||||||
|
JsonNode arrayNodosFormacion = convertirJsonNodeEnArrayNode(nodosFormacion);
|
||||||
|
listaFormaciones= new ArrayList<Formacion>();
|
||||||
|
for (JsonNode nodoFormacion : arrayNodosFormacion) {
|
||||||
|
Formacion formacion = obtenerFormacionDeJsonNode(nodoFormacion);
|
||||||
|
|
||||||
|
listaFormaciones.add(formacion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Error procesando XML con JsonNode: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return listaFormaciones;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convierte un JsonNode que representa una formación en el objeto Formacion
|
||||||
|
* correspondiente.
|
||||||
|
*
|
||||||
|
* @param nodoJson
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Formacion obtenerFormacionDeJsonNode(JsonNode nodoJson) {
|
||||||
|
Formacion formacion = null;
|
||||||
|
if (nodoJson != null && !nodoJson.isNull()) {
|
||||||
|
formacion = new Formacion();
|
||||||
|
|
||||||
|
// Atributos mapeados como nodos en Jackson
|
||||||
|
if (nodoJson.has("id_formacion")) {
|
||||||
|
formacion.setIdentificador(nodoJson.get("id_formacion").asInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
int formacionSTEM = 0;
|
||||||
|
if (nodoJson.has("es_formacion_stem")) {
|
||||||
|
formacionSTEM = nodoJson.get("es_formacion_stem").asInt();
|
||||||
|
}
|
||||||
|
formacion.setIndicadorSTEM(formacionSTEM == 1);
|
||||||
|
|
||||||
|
if (nodoJson.has("nombre_corto")) {
|
||||||
|
formacion.setNombreCorto(nodoJson.get("nombre_corto").asString());
|
||||||
|
}
|
||||||
|
|
||||||
|
CicloFormativo ciclo = new CicloFormativo();
|
||||||
|
if (nodoJson.has("cod_ciclo_formativo")) {
|
||||||
|
ciclo.setIdentificador(nodoJson.get("cod_ciclo_formativo").asInt());
|
||||||
|
}
|
||||||
|
formacion.setCicloFormativo(ciclo);
|
||||||
|
}
|
||||||
|
return formacion;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayNode convertirJsonNodeEnArrayNode(JsonNode node) {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
if (node.isArray()) {
|
||||||
|
return (ArrayNode) node;
|
||||||
|
} else {
|
||||||
|
ArrayNode arrayNode = mapper.createArrayNode();
|
||||||
|
if (!node.isMissingNode()) {
|
||||||
|
arrayNode.add(node);
|
||||||
|
}
|
||||||
|
return arrayNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user