use of org.opensmartgridplatform.dto.valueobjects.ScheduleDto in project open-smart-grid-platform by OSGP.
the class PublicLightingSetScheduleRequestMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
LOGGER.debug("Processing public lighting set schedule request message");
MessageMetadata messageMetadata;
ScheduleDto scheduleDto;
try {
messageMetadata = MessageMetadata.fromMessage(message);
scheduleDto = (ScheduleDto) message.getObject();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
return;
}
final RequestMessageData requestMessageData = RequestMessageData.newBuilder().messageMetadata(messageMetadata).build();
this.printDomainInfo(requestMessageData);
final Iec61850DeviceResponseHandler iec61850DeviceResponseHandler = this.createIec61850DeviceResponseHandler(requestMessageData, message);
final DeviceRequest.Builder deviceRequestBuilder = DeviceRequest.newBuilder().messageMetaData(messageMetadata);
this.deviceService.setSchedule(new SetScheduleDeviceRequest(deviceRequestBuilder, scheduleDto, RelayTypeDto.LIGHT), iec61850DeviceResponseHandler);
}
use of org.opensmartgridplatform.dto.valueobjects.ScheduleDto in project open-smart-grid-platform by OSGP.
the class Iec61850SetScheduleCommand method setScheduleOnDevice.
public void setScheduleOnDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final SetScheduleDeviceRequest deviceRequest, final Ssld ssld) throws ProtocolAdapterException {
final ScheduleDto scheduleDto = deviceRequest.getSchedule();
final RelayTypeDto relayType = deviceRequest.getRelayType();
final List<ScheduleEntryDto> scheduleList = scheduleDto.getScheduleList();
try {
// Creating a list of all Schedule entries, grouped by relay index.
final Map<Integer, List<ScheduleEntry>> relaySchedulesEntries = this.createScheduleEntries(scheduleList, ssld, relayType);
final Function<Void> function = new Iec61850SetScheduleFunction(iec61850Client, deviceConnection, deviceRequest, ssld, relaySchedulesEntries, this.loggingService, this.ssldDataService);
iec61850Client.sendCommandWithRetry(function, "SetSchedule", deviceConnection.getDeviceIdentification());
} catch (final FunctionalException e) {
throw new ProtocolAdapterException(e.getMessage(), e);
}
}
use of org.opensmartgridplatform.dto.valueobjects.ScheduleDto in project open-smart-grid-platform by OSGP.
the class PublicLightingSetScheduleRequestMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) {
LOGGER.debug("Processing public lighting set schedule request message");
final MessageMetadata messageMetadata;
final ScheduleDto schedule;
try {
messageMetadata = MessageMetadata.fromMessage(message);
schedule = (ScheduleDto) message.getObject();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
return;
}
try {
this.pendingSetScheduleRequestService.removeExpiredPendingSetScheduleRequestRecords(messageMetadata.getDeviceIdentification());
final List<PendingSetScheduleRequest> pendingSetScheduleRequestList = this.pendingSetScheduleRequestService.getAllByDeviceIdentificationNotExpired(messageMetadata.getDeviceIdentification());
if (!pendingSetScheduleRequestList.isEmpty()) {
throw new FunctionalException(FunctionalExceptionType.SET_SCHEDULE_WITH_ASTRONOMICAL_OFFSETS_IN_PROGRESS, ComponentType.PROTOCOL_OSLP, new Throwable(String.format("A set schedule with astronomical offsets is already in progress for device %s", messageMetadata.getDeviceIdentification())));
}
ScheduleMessageDataContainerDto.Builder builder = new ScheduleMessageDataContainerDto.Builder(schedule);
if (schedule.getAstronomicalSunriseOffset() != null || schedule.getAstronomicalSunsetOffset() != null) {
LOGGER.info("Set a schedule for a device with astronomical offsets");
builder = builder.withScheduleMessageType(ScheduleMessageTypeDto.RETRIEVE_CONFIGURATION);
}
final ScheduleMessageDataContainerDto scheduleMessageDataContainer = builder.build();
this.printDomainInfo(messageMetadata.getMessageType(), messageMetadata.getDomain(), messageMetadata.getDomainVersion());
final SetScheduleDeviceRequest deviceRequest = new SetScheduleDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), scheduleMessageDataContainer, RelayTypeDto.LIGHT);
this.deviceService.setSchedule(deviceRequest);
} catch (final RuntimeException e) {
this.handleError(e, messageMetadata);
} catch (final FunctionalException e) {
this.handleFunctionalException(e, messageMetadata);
}
}
use of org.opensmartgridplatform.dto.valueobjects.ScheduleDto in project open-smart-grid-platform by OSGP.
the class ScheduleManagementService method setLightSchedule.
// === SET LIGHT SCHEDULE ===
/**
* Set a light schedule.
*/
public void setLightSchedule(final CorrelationIds ids, final Schedule schedule, final Long scheduleTime, final String messageType, final int messagePriority) throws FunctionalException {
LOGGER.info("setSchedule called with organisation {} and device {}.", ids.getOrganisationIdentification(), ids.getDeviceIdentification());
this.findOrganisation(ids.getOrganisationIdentification());
final Device device = this.findActiveDevice(ids.getDeviceIdentification());
final ScheduleDto scheduleDto = this.domainCoreMapper.map(schedule, ScheduleDto.class);
this.osgpCoreRequestMessageSender.send(new RequestMessage(ids, scheduleDto), messageType, messagePriority, device.getIpAddress(), scheduleTime);
}
use of org.opensmartgridplatform.dto.valueobjects.ScheduleDto in project open-smart-grid-platform by OSGP.
the class TariffSwitchingSetScheduleRequestMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) {
LOGGER.debug("Processing tariff switching set schedule request message");
MessageMetadata messageMetadata;
ScheduleDto schedule;
try {
messageMetadata = MessageMetadata.fromMessage(message);
schedule = (ScheduleDto) message.getObject();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
return;
}
try {
final ScheduleMessageDataContainerDto scheduleMessageDataContainer = new ScheduleMessageDataContainerDto.Builder(schedule).build();
this.printDomainInfo(messageMetadata.getMessageType(), messageMetadata.getDomain(), messageMetadata.getDomainVersion());
final SetScheduleDeviceRequest deviceRequest = new SetScheduleDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), scheduleMessageDataContainer, RelayTypeDto.TARIFF);
this.deviceService.setSchedule(deviceRequest);
} catch (final RuntimeException e) {
this.handleError(e, messageMetadata);
}
}
Aggregations