Incluye MongoDB
This commit is contained in:
parent
034e14b67d
commit
ae3441237a
@ -0,0 +1,86 @@
|
|||||||
|
package eu.agenciaesa.inm.dao.mngdb;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
|
||||||
|
import com.mongodb.client.FindIterable;
|
||||||
|
import com.mongodb.client.MongoCollection;
|
||||||
|
|
||||||
|
import eu.agenciaesa.inm.dao.IExperimentoDao;
|
||||||
|
import eu.agenciaesa.inm.excepciones.AgenciaESAException;
|
||||||
|
import eu.agenciaesa.inm.gestores.GestorConexionMongoDB;
|
||||||
|
import eu.agenciaesa.inm.vo.Experimento;
|
||||||
|
import eu.agenciaesa.inm.vo.Modulo;
|
||||||
|
import eu.agenciaesa.inm.vo.TipoExperimento;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ExperimientoDaoMongoDB: Clase que se encarga de ...
|
||||||
|
*
|
||||||
|
* @autor: Isidoro Nevares Martín (IES Virgen de la Paloma)
|
||||||
|
* @date: 24 feb 2026
|
||||||
|
*/
|
||||||
|
public class ExperimientoDaoMongoDB implements IExperimentoDao{
|
||||||
|
private final static String COLECCION = "C_EXPERIMENTO";
|
||||||
|
@Override
|
||||||
|
public void insertarListaExperimentos(List<Experimento> listaExperimentos) throws AgenciaESAException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Experimento> obtenerListaExperimentos() throws AgenciaESAException {
|
||||||
|
List<Experimento> listaExperimentos = new ArrayList<>();
|
||||||
|
|
||||||
|
MongoCollection<Document> coleccionMongoDB = null;
|
||||||
|
try {
|
||||||
|
coleccionMongoDB = GestorConexionMongoDB.getMongoDatabase().getCollection(COLECCION);
|
||||||
|
|
||||||
|
|
||||||
|
FindIterable<Document> documentos = coleccionMongoDB.find();
|
||||||
|
for (Document documento : documentos) {
|
||||||
|
String nombreExperimento = documento.getString("nombre");
|
||||||
|
String sTipoExperimiento = documento.getString("tipo");
|
||||||
|
TipoExperimento tipoExperimento=TipoExperimento.valueOf(sTipoExperimiento);
|
||||||
|
String resultadoExperimento = null;
|
||||||
|
|
||||||
|
Document documentoDatos = documento.get("datos", Document.class);
|
||||||
|
if(tipoExperimento == TipoExperimento.Geológico) {
|
||||||
|
String tipoRoca = documentoDatos.getString("tipo_roca");
|
||||||
|
Integer profundidad = documentoDatos.getInteger("profundidad_muestra_m");
|
||||||
|
|
||||||
|
resultadoExperimento = "Muestra de " + tipoRoca + " obtenida a " + profundidad + "m de profundidad.";
|
||||||
|
} else if(tipoExperimento == TipoExperimento.Biológico) {
|
||||||
|
String tipoMuestra = documentoDatos.getString("tipo_muestra");
|
||||||
|
Integer nivel = documentoDatos.getInteger("nivel_bioseguridad");
|
||||||
|
|
||||||
|
resultadoExperimento = "Análisis de " + tipoMuestra + " realizado bajo nivel " + nivel + " de bioseguridad.";
|
||||||
|
} else {
|
||||||
|
Integer duracion = documentoDatos.getInteger("duracion_dias");
|
||||||
|
String frecuencia = documentoDatos.getString("frecuencia");
|
||||||
|
String parametro = documentoDatos.getString("parametro_estudio");
|
||||||
|
|
||||||
|
resultadoExperimento = "Estudio de " + parametro + " durante " + duracion + " días con frecuencia " + frecuencia;
|
||||||
|
}
|
||||||
|
|
||||||
|
String codigoModulo = documento.getString("modulo_id");
|
||||||
|
Modulo modulo = new Modulo();
|
||||||
|
modulo.setCodigo(codigoModulo);
|
||||||
|
|
||||||
|
Experimento experimento = new Experimento();
|
||||||
|
experimento.setNombre(nombreExperimento);
|
||||||
|
experimento.setTipo(tipoExperimento);
|
||||||
|
experimento.setResultado(resultadoExperimento);
|
||||||
|
experimento.setModulo(modulo);
|
||||||
|
|
||||||
|
listaExperimentos.add(experimento);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new AgenciaESAException(e, AgenciaESAException.ERROR_CONSULTA , getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
return listaExperimentos;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -8,7 +8,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eu.agenciaesa.inm.gestores.GestorFicheroConfiguracion;
|
|
||||||
import eu.agenciaesa.inm.utilidades.GestorURLs;
|
import eu.agenciaesa.inm.utilidades.GestorURLs;
|
||||||
import eu.agenciaesa.inm.vo.Base;
|
import eu.agenciaesa.inm.vo.Base;
|
||||||
import eu.agenciaesa.inm.vo.CuerpoCeleste;
|
import eu.agenciaesa.inm.vo.CuerpoCeleste;
|
||||||
@ -18,9 +17,9 @@ import eu.agenciaesa.inm.vo.Generador;
|
|||||||
import eu.agenciaesa.inm.vo.Modulo;
|
import eu.agenciaesa.inm.vo.Modulo;
|
||||||
import eu.agenciaesa.inm.vo.TipoExperimento;
|
import eu.agenciaesa.inm.vo.TipoExperimento;
|
||||||
import eu.agenciaesa.inm.vo.TipoGenerador;
|
import eu.agenciaesa.inm.vo.TipoGenerador;
|
||||||
|
|
||||||
import tools.jackson.databind.JsonNode;
|
import tools.jackson.databind.JsonNode;
|
||||||
import tools.jackson.databind.ObjectMapper;
|
import tools.jackson.databind.ObjectMapper;
|
||||||
|
import tools.jackson.databind.node.ArrayNode;
|
||||||
import tools.jackson.dataformat.xml.XmlMapper;
|
import tools.jackson.dataformat.xml.XmlMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -377,4 +376,17 @@ public class ProcesadorDatos {
|
|||||||
|
|
||||||
return generador;
|
return generador;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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