From 188d13591fa87f8d4646e8a42332dab5efdeb276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Wed, 11 Sep 2024 16:26:51 +0200 Subject: [PATCH] Astro entity removed --- .../angular/src/app/api/schedule/Schedule.ts | 3 - .../homeautomation/schedule/ScheduleDto.java | 7 +- .../schedule/ScheduleMapper.java | 8 +-- .../homeautomation/schedule/astro/Astro.java | 44 ------------ .../schedule/astro/AstroDto.java | 37 ---------- .../schedule/astro/AstroRepository.java | 11 --- .../schedule/astro/AstroService.java | 69 ------------------- 7 files changed, 2 insertions(+), 177 deletions(-) delete mode 100644 src/main/java/de/ph87/homeautomation/schedule/astro/Astro.java delete mode 100644 src/main/java/de/ph87/homeautomation/schedule/astro/AstroDto.java delete mode 100644 src/main/java/de/ph87/homeautomation/schedule/astro/AstroRepository.java delete mode 100644 src/main/java/de/ph87/homeautomation/schedule/astro/AstroService.java diff --git a/src/main/angular/src/app/api/schedule/Schedule.ts b/src/main/angular/src/app/api/schedule/Schedule.ts index 108441d..56267d5 100644 --- a/src/main/angular/src/app/api/schedule/Schedule.ts +++ b/src/main/angular/src/app/api/schedule/Schedule.ts @@ -1,6 +1,5 @@ import {validateBooleanNotNull, validateListOrEmpty, validateNumberNotNull, validateStringNotEmptyNotNull} from "../validators"; import {ScheduleEntry} from "./entry/ScheduleEntry"; -import {Astro} from "../astro/Astro"; export class Schedule { @@ -13,7 +12,6 @@ export class Schedule { readonly enabled: boolean, readonly title: string, readonly entries: ScheduleEntry[], - readonly astros: Astro[], ) { this.next = entries.filter(e => e.nextFuzzyTimestamp).sort((a, b) => a.nextFuzzyTimestamp.date.getTime() - b.nextFuzzyTimestamp.date.getTime())[0]; this.last = entries.filter(e => e.lastFuzzyTimestamp).sort((a, b) => b.lastFuzzyTimestamp.date.getTime() - a.lastFuzzyTimestamp.date.getTime())[0]; @@ -25,7 +23,6 @@ export class Schedule { validateBooleanNotNull(json['enabled']), validateStringNotEmptyNotNull(json['title']), validateListOrEmpty(json['entries'], ScheduleEntry.fromJson, ScheduleEntry.comparePosition), - validateListOrEmpty(json['astros'], Astro.fromJson), ); } diff --git a/src/main/java/de/ph87/homeautomation/schedule/ScheduleDto.java b/src/main/java/de/ph87/homeautomation/schedule/ScheduleDto.java index c06b506..5622db6 100644 --- a/src/main/java/de/ph87/homeautomation/schedule/ScheduleDto.java +++ b/src/main/java/de/ph87/homeautomation/schedule/ScheduleDto.java @@ -1,11 +1,9 @@ package de.ph87.homeautomation.schedule; -import de.ph87.homeautomation.schedule.astro.AstroDto; import de.ph87.homeautomation.schedule.entry.ScheduleEntryDto; import lombok.Getter; import java.io.Serializable; -import java.util.List; import java.util.Set; @Getter @@ -19,14 +17,11 @@ public class ScheduleDto implements Serializable { private final Set entries; - private final List astros; - - public ScheduleDto(final Schedule schedule, final Set entries, final List astros) { + public ScheduleDto(final Schedule schedule, final Set entries) { this.id = schedule.getId(); this.enabled = schedule.isEnabled(); this.title = schedule.getTitle(); this.entries = entries; - this.astros = astros; } } diff --git a/src/main/java/de/ph87/homeautomation/schedule/ScheduleMapper.java b/src/main/java/de/ph87/homeautomation/schedule/ScheduleMapper.java index 3c8ee95..de08735 100644 --- a/src/main/java/de/ph87/homeautomation/schedule/ScheduleMapper.java +++ b/src/main/java/de/ph87/homeautomation/schedule/ScheduleMapper.java @@ -1,7 +1,5 @@ package de.ph87.homeautomation.schedule; -import de.ph87.homeautomation.schedule.astro.AstroDto; -import de.ph87.homeautomation.schedule.astro.AstroService; import de.ph87.homeautomation.schedule.entry.ScheduleEntryDto; import de.ph87.homeautomation.schedule.entry.ScheduleEntryMapper; import de.ph87.homeautomation.web.WebSocketService; @@ -10,7 +8,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -24,12 +21,9 @@ public class ScheduleMapper { private final WebSocketService webSocketService; - private final AstroService astroService; - public ScheduleDto toDto(final Schedule schedule) { final Set entries = schedule.getEntries().stream().map(scheduleEntryMapper::toDto).collect(Collectors.toSet()); - final List astros = astroService.findAllNext(); - return new ScheduleDto(schedule, entries, astros); + return new ScheduleDto(schedule, entries); } public void publish(final Schedule schedule, final boolean existing) { diff --git a/src/main/java/de/ph87/homeautomation/schedule/astro/Astro.java b/src/main/java/de/ph87/homeautomation/schedule/astro/Astro.java deleted file mode 100644 index 9763d57..0000000 --- a/src/main/java/de/ph87/homeautomation/schedule/astro/Astro.java +++ /dev/null @@ -1,44 +0,0 @@ -package de.ph87.homeautomation.schedule.astro; - -import jakarta.persistence.*; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; - -@Entity -@Getter -@ToString -@NoArgsConstructor -public class Astro { - - @Id - @GeneratedValue - private long id; - - @Version - private long version; - - @Setter - private boolean enabled = true; - - @Setter - private String error; - - @Column(unique = true) - private double zenith; - - @Column(nullable = false) - private String name; - - private String differentNameForSunset; - - public Astro(final double zenith, @NonNull final String name, @Nullable final String differentNameForSunset) { - this.zenith = zenith; - this.name = name; - this.differentNameForSunset = differentNameForSunset; - } - -} diff --git a/src/main/java/de/ph87/homeautomation/schedule/astro/AstroDto.java b/src/main/java/de/ph87/homeautomation/schedule/astro/AstroDto.java deleted file mode 100644 index 34de8a3..0000000 --- a/src/main/java/de/ph87/homeautomation/schedule/astro/AstroDto.java +++ /dev/null @@ -1,37 +0,0 @@ -package de.ph87.homeautomation.schedule.astro; - -import lombok.Getter; -import lombok.ToString; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; - -import java.time.ZonedDateTime; - -@Getter -@ToString -public class AstroDto { - - @NonNull - private final double zenith; - - @NonNull - private final ZonedDateTime sunrise; - - @NonNull - private final ZonedDateTime sunset; - - @NonNull - private final String sunriseName; - - @Nullable - private final String sunsetName; - - public AstroDto(@NonNull final Astro astro, @NonNull final ZonedDateTime sunrise, @NonNull final ZonedDateTime sunset) { - this.zenith = astro.getZenith(); - this.sunrise = sunrise; - this.sunset = sunset; - this.sunriseName = astro.getName(); - this.sunsetName = astro.getDifferentNameForSunset() == null ? astro.getName() : astro.getDifferentNameForSunset(); - } - -} diff --git a/src/main/java/de/ph87/homeautomation/schedule/astro/AstroRepository.java b/src/main/java/de/ph87/homeautomation/schedule/astro/AstroRepository.java deleted file mode 100644 index e6a6ba3..0000000 --- a/src/main/java/de/ph87/homeautomation/schedule/astro/AstroRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.ph87.homeautomation.schedule.astro; - -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -public interface AstroRepository extends JpaRepository { - - List findAllByEnabledTrue(); - -} diff --git a/src/main/java/de/ph87/homeautomation/schedule/astro/AstroService.java b/src/main/java/de/ph87/homeautomation/schedule/astro/AstroService.java deleted file mode 100644 index c1b975b..0000000 --- a/src/main/java/de/ph87/homeautomation/schedule/astro/AstroService.java +++ /dev/null @@ -1,69 +0,0 @@ -package de.ph87.homeautomation.schedule.astro; - -import lombok.*; -import org.springframework.boot.context.event.*; -import org.springframework.context.event.EventListener; -import org.springframework.transaction.annotation.*; -import org.springframework.web.bind.annotation.*; - -import java.time.*; -import java.util.*; - -@RestController -@Transactional -@RequestMapping("Astro") -@RequiredArgsConstructor -public class AstroService { - - private final AstroRepository astroRepository; - - private final AstroCalculator astroCalculator; - - @EventListener(ApplicationStartedEvent.class) - public void startup() { - if (astroRepository.count() == 0) { - astroRepository.save(new Astro(71.0000, "Aufgang +++++", "Untergang +++++")); - astroRepository.save(new Astro(75.0000, "Aufgang ++++", "Untergang ++++")); - astroRepository.save(new Astro(80.0000, "Aufgang +++", "Untergang +++")); - astroRepository.save(new Astro(85.0000, "Aufgang ++", "Untergang ++")); - astroRepository.save(new Astro(90.0000, "Aufgang +", "Untergang +")); - astroRepository.save(new Astro(90.8333, "Aufgang", "Untergang")); - astroRepository.save(new Astro(92.0000, "Aufgang -", "Untergang -")); - astroRepository.save(new Astro(93.0000, "Aufgang --", "Untergang --")); - astroRepository.save(new Astro(94.0000, "Bürgerlich ++", null)); - astroRepository.save(new Astro(95.0000, "Bürgerlich +", null)); - astroRepository.save(new Astro(96.0000, "Bürgerlich", null)); - astroRepository.save(new Astro(97.0000, "Bürgerlich -", null)); - astroRepository.save(new Astro(98.0000, "Bürgerlich --", null)); - astroRepository.save(new Astro(99.0000, "Bürgerlich ---", null)); - astroRepository.save(new Astro(100.000, "Nautisch ++", null)); - astroRepository.save(new Astro(101.000, "Nautisch +", null)); - astroRepository.save(new Astro(102.000, "Nautisch", null)); - astroRepository.save(new Astro(103.000, "Nautisch -", null)); - astroRepository.save(new Astro(104.000, "Nautisch --", null)); - astroRepository.save(new Astro(105.000, "Nautisch ---", null)); - astroRepository.save(new Astro(106.000, "Astronomisch ++", null)); - astroRepository.save(new Astro(107.000, "Astronomisch +", null)); - astroRepository.save(new Astro(108.000, "Astronomisch", null)); - astroRepository.save(new Astro(110.000, "Astronomisch -", null)); - astroRepository.save(new Astro(120.000, "Astronomisch --", null)); - } - } - - public List findAllNext() { - final ZonedDateTime now = ZonedDateTime.now(); - return astroRepository.findAllByEnabledTrue().stream().map(astro -> next(now, astro)).filter(Objects::nonNull).toList(); - } - - private AstroDto next(final ZonedDateTime now, final Astro astro) { - final ZonedDateTime sunrise = astroCalculator.next(now, true, astro.getZenith()); - final ZonedDateTime sunset = astroCalculator.next(now, false, astro.getZenith()); - if (sunrise == null || sunset == null) { - astro.setEnabled(false); - astro.setError("sunrise (%s) or sunset (%s) NULL for %s".formatted(sunrise, sunset, now)); - return null; - } - return new AstroDto(astro, sunrise, sunset); - } - -}