use of com.alliander.osgp.dto.valueobjects.WindowTypeDto in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850SetScheduleCommand method convertToScheduleEntry.
private ScheduleEntry convertToScheduleEntry(final ScheduleDto schedule, final LightValueDto lightValue) throws ProtocolAdapterException {
final ScheduleEntry.Builder builder = new ScheduleEntry.Builder();
try {
if (schedule.getTime() != null) {
builder.time(this.convertTime(schedule.getTime()));
}
final WindowTypeDto triggerWindow = schedule.getTriggerWindow();
if (triggerWindow != null) {
if (triggerWindow.getMinutesBefore() > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Schedule TriggerWindow minutesBefore must not be greater than " + Integer.MAX_VALUE);
}
if (triggerWindow.getMinutesAfter() > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Schedule TriggerWindow minutesAfter must not be greater than " + Integer.MAX_VALUE);
}
builder.triggerWindowMinutesBefore((int) triggerWindow.getMinutesBefore());
builder.triggerWindowMinutesAfter((int) triggerWindow.getMinutesAfter());
}
builder.triggerType(this.extractTriggerType(schedule));
builder.enabled(schedule.getIsEnabled() == null ? true : schedule.getIsEnabled());
final WeekDayTypeDto weekDay = schedule.getWeekDay();
if (WeekDayTypeDto.ABSOLUTEDAY.equals(weekDay)) {
final DateTime specialDay = schedule.getStartDay();
if (specialDay == null) {
throw new IllegalArgumentException("Schedule startDay must not be null when weekDay equals ABSOLUTEDAY");
}
builder.specialDay(specialDay);
} else {
builder.weekday(ScheduleWeekday.valueOf(schedule.getWeekDay().name()));
}
builder.on(lightValue.isOn());
if (schedule.getMinimumLightsOn() != null) {
builder.minimumLightsOn(schedule.getMinimumLightsOn());
}
return builder.build();
} catch (IllegalStateException | IllegalArgumentException e) {
throw new ProtocolAdapterException("Error converting ScheduleDto and LightValueDto into a ScheduleEntry: " + e.getMessage(), e);
}
}
Aggregations