Search in sources :

Example 1 with WindowTypeDto

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);
    }
}
Also used : ScheduleEntry(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.ScheduleEntry) WindowTypeDto(com.alliander.osgp.dto.valueobjects.WindowTypeDto) WeekDayTypeDto(com.alliander.osgp.dto.valueobjects.WeekDayTypeDto) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) DateTime(org.joda.time.DateTime)

Aggregations

ScheduleEntry (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.ScheduleEntry)1 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 WeekDayTypeDto (com.alliander.osgp.dto.valueobjects.WeekDayTypeDto)1 WindowTypeDto (com.alliander.osgp.dto.valueobjects.WindowTypeDto)1 DateTime (org.joda.time.DateTime)1