ScheduleController::findAll

This commit is contained in:
Patrick Haßel 2021-10-03 21:50:50 +02:00
parent 25d78dc32a
commit f67a0497cb
8 changed files with 121 additions and 7 deletions

View File

@ -44,10 +44,10 @@ public class KnxGroup {
private int readInterval; private int readInterval;
@Embedded @Embedded
private ComInfo read = new ComInfo(); private KnxGroupLinkInfo read = new KnxGroupLinkInfo();
@Embedded @Embedded
private ComInfo send = new ComInfo(); private KnxGroupLinkInfo send = new KnxGroupLinkInfo();
public void setAddress(final int rawAddress) { public void setAddress(final int rawAddress) {
setAddress(new GroupAddress(rawAddress)); setAddress(new GroupAddress(rawAddress));

View File

@ -11,7 +11,7 @@ import java.time.ZonedDateTime;
@Setter @Setter
@ToString @ToString
@Embeddable @Embeddable
public class ComInfo { public class KnxGroupLinkInfo {
private boolean able = true; private boolean able = true;

View File

@ -93,8 +93,8 @@ public class KnxGroupLinkService {
} }
public ZonedDateTime getNextTimestamp() { public ZonedDateTime getNextTimestamp() {
final Optional<ZonedDateTime> sendOptional = knxGroupRepository.findFirstBySend_NextTimestampNotNullOrderBySend_NextTimestampAsc().map(KnxGroup::getSend).map(ComInfo::getNextTimestamp); final Optional<ZonedDateTime> sendOptional = knxGroupRepository.findFirstBySend_NextTimestampNotNullOrderBySend_NextTimestampAsc().map(KnxGroup::getSend).map(KnxGroupLinkInfo::getNextTimestamp);
final Optional<ZonedDateTime> readOptional = knxGroupRepository.findFirstByRead_NextTimestampNotNullOrderByRead_NextTimestampAsc().map(KnxGroup::getRead).map(ComInfo::getNextTimestamp); final Optional<ZonedDateTime> readOptional = knxGroupRepository.findFirstByRead_NextTimestampNotNullOrderByRead_NextTimestampAsc().map(KnxGroup::getRead).map(KnxGroupLinkInfo::getNextTimestamp);
if (sendOptional.isEmpty()) { if (sendOptional.isEmpty()) {
return readOptional.orElse(null); return readOptional.orElse(null);
} }

View File

@ -26,8 +26,9 @@ public class Schedule {
@Column(nullable = false, unique = true) @Column(nullable = false, unique = true)
private String name; private String name;
// TODO move ownership of relation to ScheduleEntry ???
@ToString.Exclude @ToString.Exclude
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
private Set<ScheduleEntry> entries = new HashSet<>(); private Set<ScheduleEntry> entries = new HashSet<>();
} }

View File

@ -0,0 +1,23 @@
package de.ph87.homeautomation.schedule;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("schedule")
@RequiredArgsConstructor
public class ScheduleController {
private final ScheduleRepository scheduleRepository;
@GetMapping("findAll")
public List<ScheduleDto> findAll() {
return scheduleRepository.findAll().stream().map(ScheduleDto::new).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,27 @@
package de.ph87.homeautomation.schedule;
import de.ph87.homeautomation.schedule.entry.ScheduleEntryDto;
import lombok.Data;
import java.util.Set;
import java.util.stream.Collectors;
@Data
public class ScheduleDto {
private long id;
private boolean enabled;
private String name;
private Set<ScheduleEntryDto> entries;
public ScheduleDto(final Schedule schedule) {
id = schedule.getId();
enabled = schedule.isEnabled();
name = schedule.getName();
entries = schedule.getEntries().stream().map(ScheduleEntryDto::new).collect(Collectors.toSet());
}
}

View File

@ -49,7 +49,7 @@ public class ScheduleEntry {
private ZonedDateTime nextDateTime; private ZonedDateTime nextDateTime;
@ElementCollection @ElementCollection(fetch = FetchType.EAGER)
private Map<String, String> properties = new HashMap<>(); private Map<String, String> properties = new HashMap<>();
public void setWorkday(final boolean enabled) { public void setWorkday(final boolean enabled) {

View File

@ -0,0 +1,63 @@
package de.ph87.homeautomation.schedule.entry;
import lombok.Data;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;
@Data
public class ScheduleEntryDto {
private long id;
private boolean enabled;
private boolean monday;
private boolean tuesday;
private boolean wednesday;
private boolean thursday;
private boolean friday;
private boolean saturday;
private boolean sunday;
private ScheduleEntryType type;
private double zenith;
private int hour;
private int minute;
private int second;
private ZonedDateTime nextDateTime;
private Map<String, String> properties;
public ScheduleEntryDto(final ScheduleEntry scheduleEntry) {
id = scheduleEntry.getId();
enabled = scheduleEntry.isEnabled();
monday = scheduleEntry.isMonday();
tuesday = scheduleEntry.isTuesday();
wednesday = scheduleEntry.isWednesday();
thursday = scheduleEntry.isThursday();
friday = scheduleEntry.isFriday();
saturday = scheduleEntry.isSaturday();
sunday = scheduleEntry.isSunday();
type = scheduleEntry.getType();
zenith = scheduleEntry.getZenith();
hour = scheduleEntry.getHour();
minute = scheduleEntry.getMinute();
second = scheduleEntry.getSecond();
nextDateTime = scheduleEntry.getNextDateTime();
properties = new HashMap<>(scheduleEntry.getProperties());
}
}