Persistencia de Gastos
This commit is contained in:
parent
6f0b89e8a3
commit
77cc793ac1
@ -25,12 +25,12 @@ public class AppProyectosIES {
|
|||||||
delete from t_curso_proyecto;
|
delete from t_curso_proyecto;
|
||||||
delete from t_concepto ;
|
delete from t_concepto ;
|
||||||
delete from t_patrocinador;
|
delete from t_patrocinador;
|
||||||
|
delete from t_curso_academico ;
|
||||||
delete from t_proyecto ;
|
delete from t_proyecto ;
|
||||||
delete from t_proyecto
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Generar la estructura de la base de datos en PostgreSQL
|
// Generar la estructura de la base de datos en PostgreSQL
|
||||||
GestorSesionesHibernate.getSession();
|
// GestorSesionesHibernate.getSession();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
app.procesarFicheros();
|
app.procesarFicheros();
|
||||||
@ -65,11 +65,11 @@ public class AppProyectosIES {
|
|||||||
private void procesarFicheros() throws ProyectosIESException {
|
private void procesarFicheros() throws ProyectosIESException {
|
||||||
// Procesar datos de catálogos
|
// Procesar datos de catálogos
|
||||||
ProcesadorFicheroXML procesadorFicheroXML = new ProcesadorFicheroXML();
|
ProcesadorFicheroXML procesadorFicheroXML = new ProcesadorFicheroXML();
|
||||||
procesadorFicheroXML.procesarFicheroXMLCatalogos();
|
// procesadorFicheroXML.procesarFicheroXMLCatalogos();
|
||||||
|
|
||||||
// Procesar datos de Gastos
|
// Procesar datos de Gastos
|
||||||
ProcesadorFicheroJSON procesadorFicheroJSON = new ProcesadorFicheroJSON();
|
ProcesadorFicheroJSON procesadorFicheroJSON = new ProcesadorFicheroJSON();
|
||||||
procesadorFicheroJSON.procesarFicheroJSONGastos();
|
// procesadorFicheroJSON.procesarFicheroJSONGastos();
|
||||||
|
|
||||||
// Procesar datos de Ingresos
|
// Procesar datos de Ingresos
|
||||||
ProcesadorFicheroCSV procesadorFicheroCSV = new ProcesadorFicheroCSV();
|
ProcesadorFicheroCSV procesadorFicheroCSV = new ProcesadorFicheroCSV();
|
||||||
|
|||||||
@ -4,8 +4,26 @@ import java.io.BufferedReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IConceptoDAO;
|
||||||
|
import es.palomafp.aadd.inm.dao.ICursoProyectoDAO;
|
||||||
|
import es.palomafp.aadd.inm.dao.IGastoDAO;
|
||||||
|
import es.palomafp.aadd.inm.dao.IProyectoDAO;
|
||||||
|
import es.palomafp.aadd.inm.dao.hbm.ConceptoDaoHibernate;
|
||||||
|
import es.palomafp.aadd.inm.dao.hbm.CursoProyectoDaoHibernate;
|
||||||
|
import es.palomafp.aadd.inm.dao.hbm.GastoDaoHibernate;
|
||||||
|
import es.palomafp.aadd.inm.dao.hbm.ProyectoDaoHibernate;
|
||||||
|
import es.palomafp.aadd.inm.dao.jpa.CursoProyectoDaoJPA;
|
||||||
|
import es.palomafp.aadd.inm.dao.jpa.GastoDaoJPA;
|
||||||
import es.palomafp.aadd.inm.gestor.GestorFicheroConfiguracion;
|
import es.palomafp.aadd.inm.gestor.GestorFicheroConfiguracion;
|
||||||
|
import es.palomafp.aadd.inm.vo.Concepto;
|
||||||
|
import es.palomafp.aadd.inm.vo.CursoAcademico;
|
||||||
|
import es.palomafp.aadd.inm.vo.CursoProyecto;
|
||||||
|
import es.palomafp.aadd.inm.vo.Gasto;
|
||||||
|
import es.palomafp.aadd.inm.vo.Proyecto;
|
||||||
|
import tools.jackson.databind.JsonNode;
|
||||||
|
import tools.jackson.databind.node.ArrayNode;
|
||||||
|
|
||||||
public class ProcesadorFicheroCSV {
|
public class ProcesadorFicheroCSV {
|
||||||
|
|
||||||
@ -24,15 +42,72 @@ public class ProcesadorFicheroCSV {
|
|||||||
// Procesar la línea leída
|
// Procesar la línea leída
|
||||||
String[] campos = linea.split(",");
|
String[] campos = linea.split(",");
|
||||||
// Suponiendo que el CSV tiene dos columnas: id, ingreso
|
// Suponiendo que el CSV tiene dos columnas: id, ingreso
|
||||||
String id = campos[0];
|
String codCursoAcademico = campos[0];
|
||||||
String ingreso = campos[1];
|
String nombreProyecto= campos[1];
|
||||||
|
String nombrePatrocinador= campos[2];
|
||||||
|
String ingreso = campos[3];
|
||||||
|
String fecha= campos[4];
|
||||||
// Aquí iría la lógica para procesar cada línea
|
// Aquí iría la lógica para procesar cada línea
|
||||||
|
System.out.println(codCursoAcademico+ nombreProyecto + nombrePatrocinador + ingreso + fecha );
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
CursoAcademico cursoAcademico = new CursoAcademico();
|
||||||
|
cursoAcademico.setCodigo(codigoCurso);
|
||||||
|
IProyectoDAO proyectoDAO = new ProyectoDaoHibernate();
|
||||||
|
Proyecto proyecto = proyectoDAO.obtenerProyectoPorNombre(nombreProyecto);
|
||||||
|
|
||||||
|
CursoProyecto cursoProyecto = new CursoProyecto();
|
||||||
|
cursoProyecto.setCursoAcademico(cursoAcademico);
|
||||||
|
cursoProyecto.setProyecto(proyecto);
|
||||||
|
|
||||||
|
// Inserción en PostgreSQL con Hibernate
|
||||||
|
ICursoProyectoDAO operacionesDAOCursoProyecto = new CursoProyectoDaoHibernate();
|
||||||
|
operacionesDAOCursoProyecto.crearEntidad(cursoProyecto);
|
||||||
|
// Inserción en ObjectDB con JPA
|
||||||
|
operacionesDAOCursoProyecto = new CursoProyectoDaoJPA();
|
||||||
|
operacionesDAOCursoProyecto.crearEntidad(cursoProyecto);
|
||||||
|
|
||||||
|
// Se obtiene el CursoProyecto ya persistido
|
||||||
|
cursoProyecto = operacionesDAOCursoProyecto.obtenerCursoProyectoPorCursoYProyecto(codigoCurso,
|
||||||
|
proyecto.getIdentificador());
|
||||||
|
|
||||||
|
JsonNode nodoGastos = root.get("gastos");
|
||||||
|
// Se obtienen los nodos Gasto
|
||||||
|
ArrayNode nodosGasto = convertirJsonNodeEnArrayNode(nodoGastos);
|
||||||
|
|
||||||
|
for (JsonNode gastoNode : nodosGasto) {
|
||||||
|
String nombreConcepto = gastoNode.get("concepto").asString();
|
||||||
|
double precioUnitario = gastoNode.get("precio_unitario").asDouble();
|
||||||
|
int unidades = gastoNode.get("unidades").asInt();
|
||||||
|
String sFecha = gastoNode.get("fecha").asString();
|
||||||
|
LocalDate fecha = LocalDate.parse(sFecha);
|
||||||
|
|
||||||
|
Gasto gasto = new Gasto();
|
||||||
|
gasto.setFecha(fecha);
|
||||||
|
gasto.setNumeroUnidades(unidades);
|
||||||
|
gasto.setPrecioUnidad(precioUnitario);
|
||||||
|
|
||||||
|
// Obtener el concepto para asociárselo al gasto
|
||||||
|
IConceptoDAO conceptoDAO = new ConceptoDaoHibernate();
|
||||||
|
Concepto concepto = conceptoDAO.obtenerConceptoPorNombre(nombreConcepto);
|
||||||
|
gasto.setConcepto(concepto);
|
||||||
|
gasto.setCursoProyecto(cursoProyecto);
|
||||||
|
|
||||||
|
// Inserción en PostgreSQL con Hibernate
|
||||||
|
IGastoDAO operacionesDAOGasto = new GastoDaoHibernate();
|
||||||
|
operacionesDAOGasto.crearEntidad(gasto);
|
||||||
|
// Inserción en ObjectDB con JPA
|
||||||
|
operacionesDAOGasto = new GastoDaoJPA();
|
||||||
|
operacionesDAOGasto.crearEntidad(gasto);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,6 @@ import tools.jackson.databind.node.ArrayNode;
|
|||||||
|
|
||||||
public class ProcesadorFicheroJSON {
|
public class ProcesadorFicheroJSON {
|
||||||
|
|
||||||
|
|
||||||
public void procesarFicheroJSONGastos() throws ProyectosIESException {
|
public void procesarFicheroJSONGastos() throws ProyectosIESException {
|
||||||
String rutaFichero = GestorFicheroConfiguracion.getValorfromClave("gastos.fichero.json.ruta");
|
String rutaFichero = GestorFicheroConfiguracion.getValorfromClave("gastos.fichero.json.ruta");
|
||||||
File fichero = new File(rutaFichero);
|
File fichero = new File(rutaFichero);
|
||||||
@ -34,15 +33,15 @@ public class ProcesadorFicheroJSON {
|
|||||||
// Se asume que la información de Paises es correcta y ya existe en la BD
|
// Se asume que la información de Paises es correcta y ya existe en la BD
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JsonNode root = mapper.readTree(fichero);
|
JsonNode root = mapper.readTree(fichero);
|
||||||
|
|
||||||
String codigoCurso= root.get("curso").asString();
|
String codigoCurso = root.get("curso").asString();
|
||||||
String nombreProyecto = root.get("proyecto").asString();
|
String nombreProyecto = root.get("proyecto").asString();
|
||||||
|
|
||||||
CursoAcademico cursoAcademico = new CursoAcademico();
|
CursoAcademico cursoAcademico = new CursoAcademico();
|
||||||
cursoAcademico.setCodigo(codigoCurso);
|
cursoAcademico.setCodigo(codigoCurso);
|
||||||
IProyectoDAO proyectoDAO = new ProyectoDaoHibernate();
|
IProyectoDAO proyectoDAO = new ProyectoDaoHibernate();
|
||||||
Proyecto proyecto = proyectoDAO.obtenerProyectoPorNombre(nombreProyecto);
|
Proyecto proyecto = proyectoDAO.obtenerProyectoPorNombre(nombreProyecto);
|
||||||
|
|
||||||
CursoProyecto cursoProyecto = new CursoProyecto();
|
CursoProyecto cursoProyecto = new CursoProyecto();
|
||||||
cursoProyecto.setCursoAcademico(cursoAcademico);
|
cursoProyecto.setCursoAcademico(cursoAcademico);
|
||||||
cursoProyecto.setProyecto(proyecto);
|
cursoProyecto.setProyecto(proyecto);
|
||||||
@ -55,14 +54,15 @@ public class ProcesadorFicheroJSON {
|
|||||||
operacionesDAOCursoProyecto.crearEntidad(cursoProyecto);
|
operacionesDAOCursoProyecto.crearEntidad(cursoProyecto);
|
||||||
|
|
||||||
// Se obtiene el CursoProyecto ya persistido
|
// Se obtiene el CursoProyecto ya persistido
|
||||||
cursoProyecto = operacionesDAOCursoProyecto.obtenerCursoProyectoPorCursoYProyecto(codigoCurso, proyecto.getIdentificador());
|
cursoProyecto = operacionesDAOCursoProyecto.obtenerCursoProyectoPorCursoYProyecto(codigoCurso,
|
||||||
|
proyecto.getIdentificador());
|
||||||
JsonNode nodoGastos= root.get("gastos");
|
|
||||||
|
JsonNode nodoGastos = root.get("gastos");
|
||||||
// Se obtienen los nodos Gasto
|
// Se obtienen los nodos Gasto
|
||||||
ArrayNode nodosGasto= convertirJsonNodeEnArrayNode(nodoGastos.get("gasto"));
|
ArrayNode nodosGasto = convertirJsonNodeEnArrayNode(nodoGastos);
|
||||||
|
|
||||||
for (JsonNode gastoNode : nodosGasto) {
|
for (JsonNode gastoNode : nodosGasto) {
|
||||||
String nombreConcepto=gastoNode.get("concepto").asString();
|
String nombreConcepto = gastoNode.get("concepto").asString();
|
||||||
double precioUnitario = gastoNode.get("precio_unitario").asDouble();
|
double precioUnitario = gastoNode.get("precio_unitario").asDouble();
|
||||||
int unidades = gastoNode.get("unidades").asInt();
|
int unidades = gastoNode.get("unidades").asInt();
|
||||||
String sFecha = gastoNode.get("fecha").asString();
|
String sFecha = gastoNode.get("fecha").asString();
|
||||||
@ -72,13 +72,13 @@ public class ProcesadorFicheroJSON {
|
|||||||
gasto.setFecha(fecha);
|
gasto.setFecha(fecha);
|
||||||
gasto.setNumeroUnidades(unidades);
|
gasto.setNumeroUnidades(unidades);
|
||||||
gasto.setPrecioUnidad(precioUnitario);
|
gasto.setPrecioUnidad(precioUnitario);
|
||||||
|
|
||||||
// Obtener el concepto para asociárselo al gasto
|
// Obtener el concepto para asociárselo al gasto
|
||||||
IConceptoDAO conceptoDAO = new ConceptoDaoHibernate();
|
IConceptoDAO conceptoDAO = new ConceptoDaoHibernate();
|
||||||
Concepto concepto=conceptoDAO.obtenerConceptoPorNombre(nombreConcepto);
|
Concepto concepto = conceptoDAO.obtenerConceptoPorNombre(nombreConcepto);
|
||||||
gasto.setConcepto(concepto);
|
gasto.setConcepto(concepto);
|
||||||
|
gasto.setCursoProyecto(cursoProyecto);
|
||||||
|
|
||||||
|
|
||||||
// Inserción en PostgreSQL con Hibernate
|
// Inserción en PostgreSQL con Hibernate
|
||||||
IGastoDAO operacionesDAOGasto = new GastoDaoHibernate();
|
IGastoDAO operacionesDAOGasto = new GastoDaoHibernate();
|
||||||
operacionesDAOGasto.crearEntidad(gasto);
|
operacionesDAOGasto.crearEntidad(gasto);
|
||||||
@ -87,9 +87,6 @@ public class ProcesadorFicheroJSON {
|
|||||||
operacionesDAOGasto.crearEntidad(gasto);
|
operacionesDAOGasto.crearEntidad(gasto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
System.out.println("nodoGastos:" + nodoGastos);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayNode convertirJsonNodeEnArrayNode(JsonNode node) {
|
private ArrayNode convertirJsonNodeEnArrayNode(JsonNode node) {
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
<!-- Configuración de propiedades del SGDB (ObjectDB)-->
|
<!-- Configuración de propiedades del SGDB (ObjectDB)-->
|
||||||
<properties>
|
<properties>
|
||||||
<property name="jakarta.persistence.jdbc.url" value="objectdb://10.19.0.253:6136/proyectos_ies.odb" />
|
<property name="jakarta.persistence.jdbc.url" value="objectdb://localhost/proyectos_ies.odb" />
|
||||||
<property name="jakarta.persistence.jdbc.user" value="admin"/>
|
<property name="jakarta.persistence.jdbc.user" value="admin"/>
|
||||||
<property name="jakarta.persistence.jdbc.password" value="admin"/>
|
<property name="jakarta.persistence.jdbc.password" value="admin"/>
|
||||||
</properties>
|
</properties>
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||||
<hibernate-configuration>
|
<hibernate-configuration>
|
||||||
<session-factory>
|
<session-factory>
|
||||||
<property name="connection.url">jdbc:postgresql://10.19.0.221:5432/proyectos_ies</property>
|
<property name="connection.url">jdbc:postgresql://10.13.0.130:5432/proyectos_ies</property>
|
||||||
<property name="connection.driver_class">org.postgresql.Driver</property>
|
<property name="connection.driver_class">org.postgresql.Driver</property>
|
||||||
|
|
||||||
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
|
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user