Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added Cambios.txt
Empty file.
22 changes: 22 additions & 0 deletions src/main/java/ar/utn/ba/ddsi/mailing/models/entities/Alerta.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ar.utn.ba.ddsi.mailing.models.entities;

import ar.utn.ba.ddsi.mailing.models.entities.Clima.Clima;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;

@Getter
@Setter
public class Alerta {
public Long id;
public Clima clima;
public boolean comunicada;
public LocalDateTime horaDeGeneracion;

public Alerta(Clima clima){
this.clima = clima;
comunicada = false;
horaDeGeneracion = LocalDateTime.now();
}
}
26 changes: 0 additions & 26 deletions src/main/java/ar/utn/ba/ddsi/mailing/models/entities/Clima.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ar.utn.ba.ddsi.mailing.models.entities.Clima;

import ar.utn.ba.ddsi.mailing.models.entities.Ubicacion.Ubicacion;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime;

@Getter
@Setter
public class Clima {
private Long id;
private Ubicacion ubicacion;
private Temperatura temperatura;
private String condicion;
private VelocidadViento velocidadViento;
private Integer humedad;
private LocalDateTime fechaActualizacion;
private boolean procesado;

public Clima() {
this.fechaActualizacion = LocalDateTime.now();
this.procesado = false;
}

public String getCiudad(){
return this.ubicacion.getNombreCiudad();
}

public double getTemperaturaCelsius(){
return this.getTemperaturaCelsius();
}

public double getVelocidadVientoKmh(){
return this.getVelocidadVientoKmh();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ar.utn.ba.ddsi.mailing.models.entities.Clima;


public class Temperatura {
private final double celsius;

public Temperatura(double celsius) {
this.celsius = celsius;
}

public double enCelsius() {
return celsius;
}

public double enFahrenheit() {
return celsius * 9 / 5 + 32;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ar.utn.ba.ddsi.mailing.models.entities.Clima;

public class VelocidadViento {
private final double velocidadKmh;

public VelocidadViento(double velocidadKmh) {
this.velocidadKmh = velocidadKmh;
}

public double getVelocidadKmh() {
return velocidadKmh;
}

public double getVelociddadMph(){
return velocidadKmh*0.621371;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Email {
private String remitente;
private String asunto;
private String contenido;
private boolean enviado;
private boolean enviado; // lo podria sacar.

public Email(String destinatario, String remitente, String asunto, String contenido) {
this.destinatario = destinatario;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ar.utn.ba.ddsi.mailing.models.entities.Ubicacion;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Ciudad {
private Long id;
private String nombre;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ar.utn.ba.ddsi.mailing.models.entities.Ubicacion;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Pais {
private Long id;
private String nombre;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ar.utn.ba.ddsi.mailing.models.entities.Ubicacion;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Region {
private Long id;
private String nombre;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ar.utn.ba.ddsi.mailing.models.entities.Ubicacion;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Ubicacion {
private Long id;
private Ciudad ciudad;
private Region region;
private Pais pais;

public String getNombreCiudad(){
return this.ciudad.getNombre();
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ar.utn.ba.ddsi.mailing.models.repositories;

import ar.utn.ba.ddsi.mailing.models.entities.Alerta;

import java.util.List;
import java.util.Optional;

public interface IAlertaRepository {
Alerta save(Alerta Alerta);
List<Alerta> findAll();
Optional<Alerta> findById(Long id);
List<Alerta> findByComunicado(boolean comunicado);
void delete(Alerta Alerta);
}


Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ar.utn.ba.ddsi.mailing.models.repositories;

import ar.utn.ba.ddsi.mailing.models.entities.Clima;
import ar.utn.ba.ddsi.mailing.models.entities.Clima.Clima;
import java.util.List;
import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package ar.utn.ba.ddsi.mailing.models.repositories.impl;

import ar.utn.ba.ddsi.mailing.models.entities.Alerta;
import ar.utn.ba.ddsi.mailing.models.repositories.IAlertaRepository;
import org.springframework.stereotype.Repository;

import java.util.*;
import java.util.concurrent.atomic.AtomicLong;

@Repository
public class AlertaRepository implements IAlertaRepository {
private final Map<Long, Alerta> Alertas = new HashMap<>();
private final Map<String, Long> ciudadToId = new HashMap<>();
private final AtomicLong idGenerator = new AtomicLong(1);

@Override
public Alerta save(Alerta Alerta) {
if (Alerta.getId() == null) {
Long id = idGenerator.getAndIncrement();
Alerta.setId(id);
Alertas.put(id, Alerta);
} else {
Alertas.put(Alerta.getId(), Alerta);
}
return Alerta;
}

@Override
public List<Alerta> findAll() {
return new ArrayList<>(Alertas.values());
}

@Override
public Optional<Alerta> findById(Long id) {
return Optional.ofNullable(Alertas.get(id));
}

@Override
public List<Alerta> findByComunicado(boolean comunicado) {
return Alertas.values().stream()
.filter(c -> c.comunicada == comunicado)
.toList();
}

@Override
public void delete(Alerta Alerta) {
if (Alerta.getId() != null) {
Alertas.remove(Alerta.getId());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ar.utn.ba.ddsi.mailing.models.repositories.impl;

import ar.utn.ba.ddsi.mailing.models.entities.Clima;
import ar.utn.ba.ddsi.mailing.models.entities.Clima.Clima;
import ar.utn.ba.ddsi.mailing.models.repositories.IClimaRepository;
import org.springframework.stereotype.Repository;
import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public AlertasScheduler(IAlertasService alertasService) {

@Scheduled(fixedRate = 60000) // Cada 1 minuto
public void procesarAlertas() {
alertasService.generarAlertasYAvisar()
alertasService.generarAlertas()
.doOnSuccess(v -> logger.info("Procesamiento de alertas completado"))
.doOnError(e -> logger.error("Error en el procesamiento de alertas: {}", e.getMessage()))
.subscribe();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ar.utn.ba.ddsi.mailing.schedulers;

import ar.utn.ba.ddsi.mailing.services.INotificacionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;

public class NotificacionesScheduler {
private static final Logger logger = LoggerFactory.getLogger(NotificacionesScheduler.class);
private final INotificacionService notificacionService;

public NotificacionesScheduler(INotificacionService NotificacionesService) {
this.notificacionService = NotificacionesService;
}

@Scheduled(fixedRate = 60000) // Cada 1 minuto
public void procesarNotificaciones() {
notificacionService.ProcesarAlertarPendientes()
.doOnSuccess(v -> logger.info("Procesamiento de Notificaciones completado"))
.doOnError(e -> logger.error("Error en el procesamiento de Notificaciones: {}", e.getMessage()))
.subscribe();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import reactor.core.publisher.Mono;

public interface IAlertasService {
Mono<Void> generarAlertasYAvisar();
Mono<Void> generarAlertas();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ar.utn.ba.ddsi.mailing.services;

import ar.utn.ba.ddsi.mailing.services.impl.AlertasService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;

public interface INotificacionService {
Mono<Void> ProcesarAlertarPendientes();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ar.utn.ba.ddsi.mailing.services.ServiciosDeDominio;


import ar.utn.ba.ddsi.mailing.models.entities.Clima.Clima;

public class CondicionadorDeAlertas {
private static final double TEMPERATURA_ALERTA = 35.0;
private static final int HUMEDAD_ALERTA = 60;

public boolean debeGenerarAlerta(Clima clima) {
return esTemperaturaCritica(clima) && esHumedadCritica(clima);
}

private boolean esTemperaturaCritica(Clima clima) {
return clima.getTemperaturaCelsius() > TEMPERATURA_ALERTA;
}

private boolean esHumedadCritica(Clima clima) {
return clima.getHumedad() > HUMEDAD_ALERTA;
}
}
Loading