Search in sources :

Example 1 with ScheduleDto

use of com.alliander.osgp.dto.valueobjects.ScheduleDto in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850SetScheduleCommand method createScheduleEntries.

/**
     * Returns a map of schedule entries, grouped by the internal index.
     */
private Map<Integer, List<ScheduleEntry>> createScheduleEntries(final List<ScheduleDto> scheduleList, final Ssld ssld, final RelayTypeDto relayTypeDto, final SsldDataService ssldDataService) throws FunctionalException {
    final Map<Integer, List<ScheduleEntry>> relaySchedulesEntries = new HashMap<>();
    final RelayType relayType = RelayType.valueOf(relayTypeDto.name());
    for (final ScheduleDto schedule : scheduleList) {
        for (final LightValueDto lightValue : schedule.getLightValue()) {
            final List<Integer> indexes = new ArrayList<>();
            if (lightValue.getIndex() == 0 && (RelayType.TARIFF.equals(relayType) || RelayType.TARIFF_REVERSED.equals(relayType))) {
                // Index 0 is not allowed for tariff switching.
                throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.PROTOCOL_IEC61850);
            } else if (lightValue.getIndex() == 0 && RelayType.LIGHT.equals(relayType)) {
                // Index == 0, getting all light relays and adding their
                // internal indexes to the indexes list.
                final List<DeviceOutputSetting> settings = ssldDataService.findByRelayType(ssld, relayType);
                for (final DeviceOutputSetting deviceOutputSetting : settings) {
                    indexes.add(deviceOutputSetting.getInternalId());
                }
            } else {
                // Index != 0, adding just the one index to the list.
                indexes.add(ssldDataService.convertToInternalIndex(ssld, lightValue.getIndex()));
            }
            ScheduleEntry scheduleEntry;
            try {
                scheduleEntry = this.convertToScheduleEntry(schedule, lightValue);
            } catch (final ProtocolAdapterException e) {
                throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.PROTOCOL_IEC61850, e);
            }
            for (final Integer internalIndex : indexes) {
                if (relaySchedulesEntries.containsKey(internalIndex)) {
                    // Internal index already in the Map, adding to the List
                    relaySchedulesEntries.get(internalIndex).add(scheduleEntry);
                } else {
                    // First time we come across this relay, checking its
                    // type.
                    this.checkRelayForSchedules(ssldDataService.getDeviceOutputSettingForInternalIndex(ssld, internalIndex).getRelayType(), relayType, internalIndex);
                    // Adding it to scheduleEntries.
                    final List<ScheduleEntry> scheduleEntries = new ArrayList<>();
                    scheduleEntries.add(scheduleEntry);
                    relaySchedulesEntries.put(internalIndex, scheduleEntries);
                }
            }
        }
    }
    return relaySchedulesEntries;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DeviceOutputSetting(com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting) ScheduleDto(com.alliander.osgp.dto.valueobjects.ScheduleDto) LightValueDto(com.alliander.osgp.dto.valueobjects.LightValueDto) RelayType(com.alliander.osgp.core.db.api.iec61850valueobjects.RelayType) ScheduleEntry(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.ScheduleEntry) ArrayList(java.util.ArrayList) List(java.util.List) FunctionalException(com.alliander.osgp.shared.exceptionhandling.FunctionalException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Aggregations

ScheduleEntry (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.ScheduleEntry)1 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)1 RelayType (com.alliander.osgp.core.db.api.iec61850valueobjects.RelayType)1 LightValueDto (com.alliander.osgp.dto.valueobjects.LightValueDto)1 ScheduleDto (com.alliander.osgp.dto.valueobjects.ScheduleDto)1 FunctionalException (com.alliander.osgp.shared.exceptionhandling.FunctionalException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1