Skip to content

Commit

Permalink
Merge pull request #67 from jkuznik/Task-54-Modular-Monolith
Browse files Browse the repository at this point in the history
Task 54 modular monolith
  • Loading branch information
jkuznik authored Dec 5, 2024
2 parents 32cfcb5 + 6143a2e commit d563af8
Show file tree
Hide file tree
Showing 42 changed files with 203 additions and 140 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.API;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package pl.ateam.disasteralerts.API;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class WeatherMonitoringFacade {

private final WeatherMonitoringService weatherMonitoringService;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.API;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterDTO;
import pl.ateam.disasteralerts.disaster.DisasterFacade;
import pl.ateam.disasteralerts.util.enums.DisasterType;
import pl.ateam.disasteralerts.disaster.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterDTO;
import pl.ateam.disasteralerts.util.CitiesInPoland;

import java.util.List;
Expand All @@ -22,7 +24,7 @@ class WeatherMonitoringService {
public static final String DESCRIPTION_HURRICANE = "Uwaga! Silne wichury";
public static final String DESCRIPTION_HEAT = "Uwaga! Upały";
private final OpenWeatherClient openWeatherClient;
private final DisasterService disasterService;
private final DisasterFacade disasterFacade;
private final String API_AS_DISASTER_SOURCE = "Weather Monitoring System";

private final List<String> monitoredLocations = CitiesInPoland.getList();
Expand All @@ -48,15 +50,15 @@ void monitorWeather() {

private void handleWindDisaster(double windSpeed, String location) {
if (windSpeed > 10.0) {
Optional<DisasterDTO> existingDisaster = disasterService.getActiveDisasterForTypeAndLocation(DisasterType.HURRICANE, location);
Optional<DisasterDTO> existingDisaster = disasterFacade.getActiveDisasterForTypeAndLocation(DisasterType.HURRICANE, location);
if (existingDisaster.isEmpty()) {
DisasterAddDTO disaster = new DisasterAddDTO(
DisasterType.HURRICANE,
DESCRIPTION_HURRICANE,
location,
UUID.randomUUID() //TODO: wygenerować uuid dedykowane dla WeatherMonitoring i na sztywno przypisać
);
disasterService.createDisaster(disaster, API_AS_DISASTER_SOURCE);
disasterFacade.createDisaster(disaster, API_AS_DISASTER_SOURCE);
log.info("New wind disaster recorded for location: {}", location);
} else {
log.info("Wind disaster already exists for location: {}. Skipping.", location);
Expand All @@ -66,15 +68,15 @@ private void handleWindDisaster(double windSpeed, String location) {

private void handleHeatDisaster(double temperature, String location) {
if (temperature > 35.0) {
Optional<DisasterDTO> existingDisaster = disasterService.getActiveDisasterForTypeAndLocation(DisasterType.HEAT, location);
Optional<DisasterDTO> existingDisaster = disasterFacade.getActiveDisasterForTypeAndLocation(DisasterType.HEAT, location);
if (existingDisaster.isEmpty()) {
DisasterAddDTO disaster = new DisasterAddDTO(
DisasterType.DROUGHT,
DESCRIPTION_HEAT,
location,
UUID.randomUUID() //TODO: wygenerować uuid dedykowane dla WeatherMonitoring i na sztywno przypisać
);
disasterService.createDisaster(disaster, API_AS_DISASTER_SOURCE);
disasterFacade.createDisaster(disaster, API_AS_DISASTER_SOURCE);
log.info("New heat disaster recorded for location: {}", location);
} else {
log.info("Heat disaster already exists for location: {}. Skipping.", location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterAddDTO;

@Component
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterAddDTO;

@Service
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.alert;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
Expand All @@ -7,8 +7,6 @@
import lombok.Setter;
import pl.ateam.disasteralerts.util.EntityAudit;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.UUID;

@Entity
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/pl/ateam/disasteralerts/alert/AlertFacade.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package pl.ateam.disasteralerts.alert;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import pl.ateam.disasteralerts.alert.dto.AlertAddDTO;
import pl.ateam.disasteralerts.alert.dto.AlertDTO;

@Component
@RequiredArgsConstructor
public class AlertFacade {

private final AlertServiceImpl alertService;

public AlertDTO createAlert(AlertAddDTO alertAddDTO) {
return alertService.createAlert(alertAddDTO);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.alert;

import org.mapstruct.Mapper;
import pl.ateam.disasteralerts.disasteralert.dto.AlertAddDTO;
import pl.ateam.disasteralerts.disasteralert.dto.AlertDTO;
import pl.ateam.disasteralerts.alert.dto.AlertAddDTO;
import pl.ateam.disasteralerts.alert.dto.AlertDTO;

@Mapper(componentModel = "spring")
interface AlertMapper {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.alert;

import org.springframework.data.jpa.repository.JpaRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.alert;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import pl.ateam.disasteralerts.disasteralert.dto.AlertAddDTO;
import pl.ateam.disasteralerts.disasteralert.dto.AlertDTO;
import pl.ateam.disasteralerts.alert.dto.AlertAddDTO;
import pl.ateam.disasteralerts.alert.dto.AlertDTO;

@Validated
interface AlertService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.alert;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import pl.ateam.disasteralerts.disasteralert.dto.AlertAddDTO;
import pl.ateam.disasteralerts.disasteralert.dto.AlertDTO;
import pl.ateam.disasteralerts.alert.dto.AlertAddDTO;
import pl.ateam.disasteralerts.alert.dto.AlertDTO;
import pl.ateam.disasteralerts.notification.NotificationFacade;
import pl.ateam.disasteralerts.user.UserFacade;
import pl.ateam.disasteralerts.user.dto.UserDTO;

Expand All @@ -16,7 +17,7 @@
class AlertServiceImpl implements AlertService {

private final AlertRepository alertRepository;
private final NotificationManager notificationManager;
private final NotificationFacade notificationFacade;
private final UserFacade userFacade;
private final AlertMapper mapper;

Expand All @@ -37,17 +38,16 @@ public AlertDTO createAlert(AlertAddDTO alertAddDTO) {
void sendNotifications(AlertAddDTO alertAddDTO) {
Set<UserDTO> interestedUsers = userFacade.getInterestedUsers(alertAddDTO.location());

interestedUsers.stream()
.forEach(user -> {
interestedUsers.forEach(user -> {
if (user.phoneNumber() != null && !user.phoneNumber().isEmpty()) {
notificationManager.addSMSService();
notificationFacade.addSMSService();
}
if (user.email() != null && !user.email().isEmpty()) {
notificationManager.addEmailService();
notificationFacade.addEmailService();
}

notificationManager.sendNotifications(alertAddDTO, user);
notificationManager.clearNotificationServices();
notificationFacade.sendNotifications(alertAddDTO, user);
notificationFacade.clearNotificationServices();
});
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package pl.ateam.disasteralerts.disasteralert.dto;
package pl.ateam.disasteralerts.alert.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

import java.time.LocalDateTime;
import java.util.UUID;

public record AlertAddDTO(@NotNull UUID disasterId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.ateam.disasteralerts.disasteralert.dto;
package pl.ateam.disasteralerts.alert.dto;

import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.disaster;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -10,7 +10,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import pl.ateam.disasteralerts.util.enums.DisasterStatus;
import pl.ateam.disasteralerts.util.EntityAudit;
import pl.ateam.disasteralerts.util.enums.DisasterType;

import java.time.LocalDateTime;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.disaster;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -9,9 +9,10 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterDTO;
import pl.ateam.disasteralerts.security.AppUser;
import pl.ateam.disasteralerts.util.enums.DisasterType;

@RestController
@RequestMapping(DisasterController.DISASTERS_BASE_URL)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.disaster;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterDTO;
import pl.ateam.disasteralerts.util.enums.DisasterType;

import java.util.List;
import java.util.Map;
Expand All @@ -16,7 +17,7 @@
@Component
@Validated
@RequiredArgsConstructor
public class DisasterAlertFacade {
public class DisasterFacade {
private final DisasterService disasterService;

public DisasterDTO createDisaster(@NotNull @Valid DisasterAddDTO disasterAddDTO, @NotNull @NotBlank String source) {
Expand All @@ -30,4 +31,8 @@ public List<DisasterDTO> interestingDisasters(Optional<DisasterType> type, Optio
public Map<String, Integer> inLocationDisastersAmount() {
return disasterService.inLocationDisastersAmount();
}

public Optional<DisasterDTO> getActiveDisasterForTypeAndLocation(DisasterType type, String location) {
return disasterService.getActiveDisasterForTypeAndLocation(type, location);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.disaster;

import org.mapstruct.Mapper;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterDTO;

@Mapper(componentModel = "spring")
interface DisasterMapper {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.disaster;

import org.springframework.data.jpa.repository.JpaRepository;
import pl.ateam.disasteralerts.util.enums.DisasterStatus;
import pl.ateam.disasteralerts.util.enums.DisasterType;

import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.disaster;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterDTO;
import pl.ateam.disasteralerts.util.enums.DisasterType;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package pl.ateam.disasteralerts.disasteralert;
package pl.ateam.disasteralerts.disaster;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pl.ateam.disasteralerts.airiskassessment.RiskAssessmentFacade;
import pl.ateam.disasteralerts.disasteralert.dto.AlertAddDTO;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disasteralert.dto.DisasterDTO;
import pl.ateam.disasteralerts.alert.AlertFacade;
import pl.ateam.disasteralerts.alert.dto.AlertAddDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterAddDTO;
import pl.ateam.disasteralerts.disaster.dto.DisasterDTO;
import pl.ateam.disasteralerts.util.enums.DisasterStatus;
import pl.ateam.disasteralerts.util.enums.DisasterType;

import java.util.*;
import java.util.stream.Collectors;
Expand All @@ -15,7 +18,7 @@
@RequiredArgsConstructor
class DisasterServiceImpl implements DisasterService {
private final DisasterRepository disasterRepository;
private final AlertService alertService;
private final AlertFacade alertFacade;
private final DisasterMapper mapper;
private final RiskAssessmentFacade riskAssessment;

Expand Down Expand Up @@ -49,7 +52,7 @@ void generateAlert(UUID disasterId) {
disasterDTO.description(),
disasterDTO.location());

alertService.createAlert(alertAddDTO);
alertFacade.createAlert(alertAddDTO);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pl.ateam.disasteralerts.disasteralert.dto;
package pl.ateam.disasteralerts.disaster.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import pl.ateam.disasteralerts.disasteralert.DisasterType;
import pl.ateam.disasteralerts.util.enums.DisasterType;

import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pl.ateam.disasteralerts.disasteralert.dto;
package pl.ateam.disasteralerts.disaster.dto;

import pl.ateam.disasteralerts.disasteralert.DisasterStatus;
import pl.ateam.disasteralerts.disasteralert.DisasterType;
import pl.ateam.disasteralerts.util.enums.DisasterStatus;
import pl.ateam.disasteralerts.util.enums.DisasterType;

import java.time.LocalDateTime;
import java.util.UUID;
Expand Down
Loading

0 comments on commit d563af8

Please sign in to comment.