Commit Inicial
This commit is contained in:
commit
40447fc514
42
.classpath
Normal file
42
.classpath
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/aadd_act4_3"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/bin/
|
||||
*.class
|
||||
/target/
|
||||
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>aadd_act4_4_swing</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
8
.settings/org.eclipse.jdt.core.prefs
Normal file
8
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,8 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
2
config/config.properties
Normal file
2
config/config.properties
Normal file
@ -0,0 +1,2 @@
|
||||
url.proyectosies.ingresos=https://proylapaloma.decieloytierra.es/api/ingresos/proyecto/$id_proyecto/curso/$cod_curso
|
||||
url.proyectosies.gastos=https://proylapaloma.decieloytierra.es/api/gastos/proyecto/$id_proyecto/curso/$cod_curso
|
||||
23
pom.xml
Normal file
23
pom.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<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>aadd_act4_4_swing</groupId>
|
||||
<artifactId>aadd_act4_4_swing</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
|
||||
<!-- Jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Httpclient -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,488 @@
|
||||
package org.lapaloma.gui.proyectos;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.lapaloma.gui.proyectos.gestor.GestorFicheroConfiguracion;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import es.palomafp.aadd.inm.dao.IConceptoDAO;
|
||||
import es.palomafp.aadd.inm.dao.ICursoProyectoDAO;
|
||||
import es.palomafp.aadd.inm.dao.IOperacionesDAOEntidad;
|
||||
import es.palomafp.aadd.inm.dao.IPatrocinadorDAO;
|
||||
import es.palomafp.aadd.inm.dao.IProyectoDAO;
|
||||
import es.palomafp.aadd.inm.dao.jpa.ConceptoDaoJPA;
|
||||
import es.palomafp.aadd.inm.dao.jpa.CursoAcademicoDaoJPA;
|
||||
import es.palomafp.aadd.inm.dao.jpa.CursoProyectoDaoJPA;
|
||||
import es.palomafp.aadd.inm.dao.jpa.GastoDaoJPA;
|
||||
import es.palomafp.aadd.inm.dao.jpa.IngresoDaoJPA;
|
||||
import es.palomafp.aadd.inm.dao.jpa.PatrocinadorDaoJPA;
|
||||
import es.palomafp.aadd.inm.dao.jpa.ProyectoDaoJPA;
|
||||
import es.palomafp.aadd.inm.excepcion.ProyectosIESException;
|
||||
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.Ingreso;
|
||||
import es.palomafp.aadd.inm.vo.Patrocinador;
|
||||
import es.palomafp.aadd.inm.vo.Proyecto;
|
||||
|
||||
public class AppProyectosIESSwing {
|
||||
|
||||
// Clase interna para representar el objetos con Clave y Valor (para curso y
|
||||
// proyecto)
|
||||
static class ClaseClaveValor {
|
||||
private String codigo;
|
||||
private String nombre;
|
||||
|
||||
public ClaseClaveValor(String nombre, String codigo) {
|
||||
this.nombre = nombre;
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public String getCodigo() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// Esto define cómo se mostrará en el JComboBox
|
||||
return nombre;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Crear la ventana principal
|
||||
JFrame frame = new JFrame("Selección de Curso y Proyecto");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
// Establecer el tamaño de la ventana a 600x400 píxeles
|
||||
frame.setSize(600, 400);
|
||||
|
||||
// Centrar la ventana en la pantalla
|
||||
frame.setLocationRelativeTo(null);
|
||||
|
||||
// Configurar el layout del frame
|
||||
frame.setLayout(new BorderLayout());
|
||||
|
||||
// Crear panel para los JComboBox (Curso y Proyecto)
|
||||
JPanel panelComboBoxes = new JPanel();
|
||||
panelComboBoxes.setLayout(new GridBagLayout()); // Usar GridBagLayout para mayor control de los márgenes
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
|
||||
// Crear los cursos con su nombre y código
|
||||
ArrayList<ClaseClaveValor> cursosAcademicos = new ArrayList<>();
|
||||
cursosAcademicos.add(new ClaseClaveValor("Curso 2022/2023", "2022-2023"));
|
||||
cursosAcademicos.add(new ClaseClaveValor("Curso 2023/2024", "2023-2024"));
|
||||
|
||||
// Crear JComboBox para cursos académicos usando los objetos Curso
|
||||
JComboBox<ClaseClaveValor> comboCursos = new JComboBox<>(cursosAcademicos.toArray(new ClaseClaveValor[0]));
|
||||
comboCursos.setPreferredSize(new Dimension(150, 25));
|
||||
|
||||
// Crear los proyectos con su nombre y código
|
||||
ArrayList<ClaseClaveValor> proyectos = new ArrayList<>();
|
||||
proyectos.add(new ClaseClaveValor("Hiperbaric", "1"));
|
||||
proyectos.add(new ClaseClaveValor("EcoMotors", "2"));
|
||||
proyectos.add(new ClaseClaveValor("Speedster", "3"));
|
||||
|
||||
// Crear JComboBox para proyectos usando los objetos Proyecto
|
||||
JComboBox<ClaseClaveValor> comboProyectos = new JComboBox<>(proyectos.toArray(new ClaseClaveValor[0]));
|
||||
comboProyectos.setPreferredSize(new Dimension(150, 25));
|
||||
|
||||
// Establecer los márgenes entre los componentes con GridBagConstraints
|
||||
gbc.insets = new Insets(15, 0, 15, 0); // Espacio de 15px entre filas
|
||||
|
||||
// Añadir componentes al panel con GridBagLayout
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
panelComboBoxes.add(new JLabel("Curso Académico: "), gbc);
|
||||
|
||||
gbc.gridx = 1;
|
||||
panelComboBoxes.add(comboCursos, gbc);
|
||||
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
panelComboBoxes.add(new JLabel(" Proyecto: "), gbc);
|
||||
|
||||
gbc.gridx = 1;
|
||||
panelComboBoxes.add(comboProyectos, gbc);
|
||||
|
||||
// Crear panel para el botón y centrarlo
|
||||
JPanel panelBoton = new JPanel();
|
||||
panelBoton.setLayout(new FlowLayout(FlowLayout.CENTER)); // Centrar el botón
|
||||
|
||||
// Crear botón "Migrar a MongoDB"
|
||||
JButton botonMigrar = new JButton("Procesar URL -> ObjectDB");
|
||||
|
||||
// Añadir ActionListener al botón
|
||||
botonMigrar.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// Obtener el curso y el proyecto seleccionados
|
||||
String codigoProyecto = ((ClaseClaveValor) comboProyectos.getSelectedItem()).getCodigo();
|
||||
String codigoCursoSeleccionado = ((ClaseClaveValor) comboCursos.getSelectedItem()).getCodigo();
|
||||
|
||||
try {
|
||||
|
||||
// Cargar los ingresos del proyecto IES a ObjectDB
|
||||
cargarIngresosProyectoIESObjectDB(codigoProyecto, codigoCursoSeleccionado);
|
||||
|
||||
// Cargar los gastos del proyecto IES a ObjectDB
|
||||
cargarGastosProyectoIESObjectDB(codigoProyecto, codigoCursoSeleccionado);
|
||||
|
||||
} catch (ProyectosIESException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// Añadir el botón al panel
|
||||
panelBoton.add(botonMigrar);
|
||||
|
||||
// Añadir los paneles al frame
|
||||
frame.add(panelComboBoxes, BorderLayout.CENTER); // Panel con los JComboBox en el centro
|
||||
frame.add(panelBoton, BorderLayout.SOUTH); // Panel con el botón en la parte inferior
|
||||
|
||||
// Hacer visible la ventana
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private static void cargarIngresosProyectoIESObjectDB(String codigoProyecto, String codigoCurso)
|
||||
throws ProyectosIESException {
|
||||
System.out.println("Inicio proceso de carga de INGRESOS en ObjectDB para proyecto: " + codigoProyecto
|
||||
+ " y curso: " + codigoCurso);
|
||||
|
||||
// Obtener el endpoint URL desde el fichero de configuración
|
||||
String urlPeticionIngresos = GestorFicheroConfiguracion.getValorfromClave("url.proyectosies.ingresos");
|
||||
|
||||
urlPeticionIngresos = urlPeticionIngresos.replace("$id_proyecto", codigoProyecto).replace("$cod_curso",
|
||||
codigoCurso);
|
||||
|
||||
System.out.println(urlPeticionIngresos);
|
||||
|
||||
// Procesar la petición HTTP y cargar los datos de INGRESOS en ObjectDB
|
||||
|
||||
try {
|
||||
JsonNode nodoIngresos = obtenerJNodeDeURL(urlPeticionIngresos);
|
||||
for (JsonNode nodoIngreso : nodoIngresos) {
|
||||
// Datos del ingreso
|
||||
int idIngreso = nodoIngreso.get("identificador").asInt();
|
||||
String sFecha = nodoIngreso.get("fecha").asText();
|
||||
int cantidad = nodoIngreso.get("cantidad").asInt();
|
||||
String observacion = nodoIngreso.get("observacion").asText();
|
||||
// String sFechaCreacion = nodoIngreso.get("fechaCreacion").asText();
|
||||
// String sFechaModificacion = nodoIngreso.get("fechaModificacion").asText();
|
||||
Ingreso ingreso = new Ingreso();
|
||||
ingreso.setIdentificador(idIngreso);
|
||||
ingreso.setCantidad(cantidad);
|
||||
ingreso.setObservacion(observacion);
|
||||
// La fecha viene en formato dd-MM-yyyy
|
||||
LocalDate ldFecha = LocalDate.parse(sFecha);
|
||||
ingreso.setFecha(ldFecha);
|
||||
|
||||
// Datos del patrocinador que realiza el ingreso
|
||||
JsonNode nodoPatrocinador = nodoIngreso.get("patrocinador");
|
||||
int idPatrocinador = nodoPatrocinador.get("identificador").asInt();
|
||||
String nombre = nodoPatrocinador.get("nombre").asText();
|
||||
byte[] bytesImagen = nodoPatrocinador.get("imagen").binaryValue();
|
||||
Patrocinador patrocinador = new Patrocinador();
|
||||
patrocinador.setIdentificador(idPatrocinador);
|
||||
patrocinador.setNombre(nombre);
|
||||
patrocinador.setImagenLogo(bytesImagen);
|
||||
ingreso.setPatrocinador(patrocinador);
|
||||
|
||||
// Datos del Proyecto y curso en para el que se realiza el ingreso
|
||||
JsonNode nodoProyectoCurso = nodoIngreso.get("proyectoCurso");
|
||||
int idProyectoCurso = nodoProyectoCurso.get("identificador").asInt();
|
||||
|
||||
JsonNode nodoCurso = nodoProyectoCurso.get("curso");
|
||||
String codigoCursoJson = nodoCurso.get("codigo").asText();
|
||||
String sFechaInicioCurso = nodoCurso.get("fechaInicio").asText();
|
||||
// La fecha viene en formato dd-MM-yyyy
|
||||
LocalDate ldFechaInicioCurso = LocalDate.parse(sFechaInicioCurso);
|
||||
String sFechaFinCurso = nodoCurso.get("fechaFin").asText();
|
||||
// La fecha viene en formato dd-MM-yyyy
|
||||
LocalDate ldFechaFinCurso = LocalDate.parse(sFechaFinCurso);
|
||||
String nombreCurso = nodoCurso.get("nombre").asText();
|
||||
|
||||
CursoAcademico cursoAcademico = new CursoAcademico();
|
||||
cursoAcademico.setCodigo(codigoCursoJson);
|
||||
cursoAcademico.setNombre(nombreCurso);
|
||||
cursoAcademico.setFechaInicio(ldFechaInicioCurso);
|
||||
cursoAcademico.setFechaFin(ldFechaFinCurso);
|
||||
|
||||
JsonNode nodoProyecto = nodoProyectoCurso.get("proyecto");
|
||||
int idProyecto = nodoProyecto.get("identificador").asInt();
|
||||
String nombreProyecto = nodoProyecto.get("nombre").asText();
|
||||
String descripcionProyecto = nodoProyecto.get("descripcion").asText();
|
||||
String urlImagenProyecto = null;
|
||||
if (nodoPatrocinador.get("urlLogo") != null)
|
||||
urlImagenProyecto = nodoPatrocinador.get("urlLogo").asText();
|
||||
Proyecto proyecto = new Proyecto();
|
||||
proyecto.setIdentificador(idProyecto);
|
||||
proyecto.setNombre(nombreProyecto);
|
||||
proyecto.setDescripcion(descripcionProyecto);
|
||||
proyecto.setUrlLogo(urlImagenProyecto);
|
||||
|
||||
CursoProyecto cursoProyecto = new CursoProyecto();
|
||||
cursoProyecto.setIdentificador(idProyectoCurso);
|
||||
cursoProyecto.setCursoAcademico(cursoAcademico);
|
||||
cursoProyecto.setProyecto(proyecto);
|
||||
|
||||
ingreso.setCursoProyecto(cursoProyecto);
|
||||
System.out.println(ingreso);
|
||||
|
||||
// Almacenar los ingresos en ObjectDB
|
||||
almacenarIngresoEnObjectDB(ingreso);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("Fin proceso de carga de INGRESOS en ObjectDB.\n");
|
||||
}
|
||||
|
||||
private static void cargarGastosProyectoIESObjectDB(String codigoProyecto, String codigoCurso) throws ProyectosIESException {
|
||||
|
||||
// Procesar la petición HTTP y cargar los datos de GASTOS en ObjectDB
|
||||
System.out.println("Inicio proceso de carga de GASTOS en ObjectDB para proyecto: " + codigoProyecto
|
||||
+ " y curso: " + codigoCurso);
|
||||
|
||||
// Obtener el endpoint URL desde el fichero de configuración
|
||||
String urlPeticionGastos = GestorFicheroConfiguracion.getValorfromClave("url.proyectosies.gastos");
|
||||
|
||||
urlPeticionGastos = urlPeticionGastos.replace("$id_proyecto", codigoProyecto).replace("$cod_curso",
|
||||
codigoCurso);
|
||||
|
||||
System.out.println(urlPeticionGastos);
|
||||
|
||||
// Procesar la petición HTTP y cargar los datos de GASTOS en ObjectDB
|
||||
try {
|
||||
JsonNode nodoGastos = obtenerJNodeDeURL(urlPeticionGastos);
|
||||
for (JsonNode nodoGasto : nodoGastos) {
|
||||
// Datos del gasto
|
||||
int idGasto = nodoGasto.get("identificador").asInt();
|
||||
String sFechaGasto = nodoGasto.get("fecha").asText();
|
||||
// La fecha viene en formato dd-MM-yyyy
|
||||
LocalDate ldFechaGasto = LocalDate.parse(sFechaGasto);
|
||||
|
||||
int numeroUnidades = nodoGasto.get("numeroUnidades").asInt();
|
||||
double precioUnitario = nodoGasto.get("precioUnitario").asDouble();
|
||||
|
||||
|
||||
Gasto gasto = new Gasto();
|
||||
gasto.setIdentificador(idGasto);
|
||||
gasto.setNumeroUnidades(numeroUnidades);
|
||||
gasto.setPrecioUnidad(precioUnitario);
|
||||
gasto.setFecha(ldFechaGasto);
|
||||
|
||||
// Datos del patrocinador que realiza el ingreso
|
||||
JsonNode nodoConcepto = nodoGasto.get("concepto");
|
||||
int idPatrocinador = nodoConcepto.get("identificador").asInt();
|
||||
String nombre = nodoConcepto.get("nombre").asText();
|
||||
String descripcionConcepto = nodoConcepto.get("descripcion").asText();
|
||||
Concepto concepto = new Concepto();
|
||||
concepto.setIdentificador(idPatrocinador);
|
||||
concepto.setNombre(nombre);
|
||||
concepto.setDescripcion(descripcionConcepto);
|
||||
|
||||
gasto.setConcepto(concepto);
|
||||
|
||||
// Datos del Proyecto y curso en para el que se realiza el ingreso
|
||||
JsonNode nodoProyectoCurso = nodoGasto.get("proyectoCurso");
|
||||
int idProyectoCurso = nodoProyectoCurso.get("identificador").asInt();
|
||||
|
||||
JsonNode nodoCurso = nodoProyectoCurso.get("curso");
|
||||
String codigoCursoJson = nodoCurso.get("codigo").asText();
|
||||
String sFechaInicioCurso = nodoCurso.get("fechaInicio").asText();
|
||||
// La fecha viene en formato dd-MM-yyyy
|
||||
LocalDate ldFechaInicioCurso = LocalDate.parse(sFechaInicioCurso);
|
||||
String sFechaFinCurso = nodoCurso.get("fechaFin").asText();
|
||||
// La fecha viene en formato dd-MM-yyyy
|
||||
LocalDate ldFechaFinCurso = LocalDate.parse(sFechaFinCurso);
|
||||
String nombreCurso = nodoCurso.get("nombre").asText();
|
||||
|
||||
CursoAcademico cursoAcademico = new CursoAcademico();
|
||||
cursoAcademico.setCodigo(codigoCursoJson);
|
||||
cursoAcademico.setNombre(nombreCurso);
|
||||
cursoAcademico.setFechaInicio(ldFechaInicioCurso);
|
||||
cursoAcademico.setFechaFin(ldFechaFinCurso);
|
||||
|
||||
JsonNode nodoProyecto = nodoProyectoCurso.get("proyecto");
|
||||
int idProyecto = nodoProyecto.get("identificador").asInt();
|
||||
String nombreProyecto = nodoProyecto.get("nombre").asText();
|
||||
String descripcionProyecto = nodoProyecto.get("descripcion").asText();
|
||||
String urlImagenProyecto = null;
|
||||
|
||||
Proyecto proyecto = new Proyecto();
|
||||
proyecto.setIdentificador(idProyecto);
|
||||
proyecto.setNombre(nombreProyecto);
|
||||
proyecto.setDescripcion(descripcionProyecto);
|
||||
proyecto.setUrlLogo(urlImagenProyecto);
|
||||
|
||||
CursoProyecto cursoProyecto = new CursoProyecto();
|
||||
cursoProyecto.setIdentificador(idProyectoCurso);
|
||||
cursoProyecto.setCursoAcademico(cursoAcademico);
|
||||
cursoProyecto.setProyecto(proyecto);
|
||||
|
||||
gasto.setCursoProyecto(cursoProyecto);
|
||||
System.out.println(gasto);
|
||||
|
||||
// Almacenar los gastos en ObjectDB
|
||||
almacenarGastoEnObjectDB(gasto);
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("Fin proceso de carga de GASTOS en ObjectDB.\n");
|
||||
}
|
||||
|
||||
private static JsonNode obtenerJNodeDeURL(String urlPeticion) throws IOException {
|
||||
JsonNode nodoRespuestaURL = null;
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(urlPeticion)).GET().build();
|
||||
|
||||
HttpResponse<InputStream> response = null;
|
||||
try {
|
||||
response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
nodoRespuestaURL = mapper.readTree(response.body());
|
||||
|
||||
return nodoRespuestaURL;
|
||||
}
|
||||
|
||||
private static void almacenarIngresoEnObjectDB(Ingreso ingreso) throws ProyectosIESException {
|
||||
almacenarCursoAcademicoEnObjectDB(ingreso.getCursoProyecto().getCursoAcademico());
|
||||
almacenarProyectoEnObjectDB(ingreso.getCursoProyecto().getProyecto());
|
||||
almacenarCursoAcademicoProyectoEnObjectDB(ingreso.getCursoProyecto());
|
||||
almacenarPatrocinadorEnObjectDB(ingreso.getPatrocinador());
|
||||
|
||||
IOperacionesDAOEntidad<Ingreso, Integer> ingresoDAO = new IngresoDaoJPA();
|
||||
ingresoDAO.crearEntidad(ingreso);
|
||||
|
||||
}
|
||||
|
||||
private static void almacenarGastoEnObjectDB(Gasto gasto) throws ProyectosIESException {
|
||||
almacenarCursoAcademicoEnObjectDB(gasto.getCursoProyecto().getCursoAcademico());
|
||||
almacenarProyectoEnObjectDB(gasto.getCursoProyecto().getProyecto());
|
||||
almacenarCursoAcademicoProyectoEnObjectDB(gasto.getCursoProyecto());
|
||||
almacenarConceptoEnObjectDB(gasto.getConcepto());
|
||||
|
||||
IOperacionesDAOEntidad<Gasto, Integer> gastoDAO = new GastoDaoJPA();
|
||||
gastoDAO.crearEntidad(gasto);
|
||||
|
||||
}
|
||||
|
||||
private static void almacenarConceptoEnObjectDB(Concepto concepto) throws ProyectosIESException {
|
||||
if(concepto!=null) {
|
||||
IConceptoDAO conceptoDAO = new ConceptoDaoJPA();
|
||||
Concepto conceptoBBDD = conceptoDAO.obtenerConceptoPorNombre(concepto.getNombre());
|
||||
|
||||
// Inserción el concepto o actualizarlo en función de si existe o no en la base de datos.
|
||||
if(conceptoBBDD==null) {
|
||||
conceptoDAO.crearEntidad(concepto);
|
||||
}else {
|
||||
conceptoDAO.actualizarEntidad(concepto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void almacenarPatrocinadorEnObjectDB(Patrocinador patrocinador) throws ProyectosIESException {
|
||||
if(patrocinador!=null) {
|
||||
IPatrocinadorDAO patrocinadorDAO = new PatrocinadorDaoJPA();
|
||||
Patrocinador patrocinadorBBDD = patrocinadorDAO.obtenerPatrocinadorPorNombre(patrocinador.getNombre());
|
||||
|
||||
// Inserción el patrocinador o actualizarlo en función de si existe o no en la base de datos.
|
||||
if(patrocinadorBBDD==null) {
|
||||
patrocinadorDAO.crearEntidad(patrocinador);
|
||||
}else {
|
||||
patrocinadorDAO.actualizarEntidad(patrocinador);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void almacenarCursoAcademicoEnObjectDB(CursoAcademico curso) throws ProyectosIESException {
|
||||
if(curso!=null) {
|
||||
IOperacionesDAOEntidad<CursoAcademico, String> cursoAcademicoDAO = new CursoAcademicoDaoJPA();
|
||||
CursoAcademico cursoBBDD = cursoAcademicoDAO.obtenerEntidadPorID(curso.getCodigo());
|
||||
|
||||
// Inserción el curso o actualizarlo en función de si existe o no en la base de datos.
|
||||
if(cursoBBDD==null) {
|
||||
cursoAcademicoDAO.crearEntidad(curso);
|
||||
}else {
|
||||
cursoAcademicoDAO.actualizarEntidad(curso);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void almacenarProyectoEnObjectDB(Proyecto proyecto) throws ProyectosIESException {
|
||||
if(proyecto!=null) {
|
||||
IProyectoDAO proyectoDAO = new ProyectoDaoJPA();
|
||||
Proyecto proyectoBBDD = proyectoDAO.obtenerProyectoPorNombre(proyecto.getNombre());
|
||||
|
||||
// Inserción el proyecto o actualizarlo en función de si existe o no en la base de datos.
|
||||
if(proyectoBBDD==null) {
|
||||
proyectoDAO.crearEntidad(proyecto);
|
||||
}else {
|
||||
proyectoDAO.actualizarEntidad(proyecto);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void almacenarCursoAcademicoProyectoEnObjectDB(CursoProyecto cursoProyecto) throws ProyectosIESException {
|
||||
if(cursoProyecto!=null) {
|
||||
ICursoProyectoDAO cursoProyectoDAO = new CursoProyectoDaoJPA();
|
||||
CursoProyecto cursoProyectoBBDD = cursoProyectoDAO.obtenerCursoProyectoPorCursoYProyecto(cursoProyecto.getCursoAcademico().getCodigo(), cursoProyecto.getProyecto().getIdentificador());
|
||||
|
||||
// Inserción el cursoProyecto o actualizarlo en función de si existe o no en la base de datos.
|
||||
if(cursoProyectoBBDD==null) {
|
||||
cursoProyectoDAO.crearEntidad(cursoProyecto);
|
||||
}else {
|
||||
cursoProyectoDAO.actualizarEntidad(cursoProyecto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package org.lapaloma.gui.proyectos.gestor;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
*
|
||||
* GestorConfiguracion: Clase que se encarga de gestionar la configuración de
|
||||
* los ficheros.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 10 oct 2025
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class GestorFicheroConfiguracion {
|
||||
private final static String RUTA_FICHERO_CONFIGURACION = "config/config.properties";
|
||||
private static Properties propiedades = null;
|
||||
|
||||
private GestorFicheroConfiguracion() {
|
||||
// Constructor privado para evitar instanciación
|
||||
}
|
||||
|
||||
// Bloque estático que se ejecuta una única vez al cargar la clase
|
||||
static {
|
||||
cargarPropiedadesFichero();
|
||||
}
|
||||
|
||||
private static void cargarPropiedadesFichero() {
|
||||
propiedades = new Properties();
|
||||
try {
|
||||
// Fichero con ruta relativa al proyecto
|
||||
propiedades.load(new FileInputStream(RUTA_FICHERO_CONFIGURACION));
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getValorfromClave(String clave) {
|
||||
return propiedades.getProperty(clave);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user