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;
}
Aggregations