Search in sources :

Example 1 with ScheduleDto

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);
}
Also used : Iec61850DeviceResponseHandler(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.requests.SetScheduleDeviceRequest) JMSException(javax.jms.JMSException) DeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.requests.SetScheduleDeviceRequest) RequestMessageData(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Example 2 with ScheduleDto

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);
    }
}
Also used : ScheduleEntryDto(org.opensmartgridplatform.dto.valueobjects.ScheduleEntryDto) Iec61850SetScheduleFunction(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Iec61850SetScheduleFunction) ArrayList(java.util.ArrayList) List(java.util.List) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) RelayTypeDto(org.opensmartgridplatform.dto.valueobjects.RelayTypeDto) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Example 3 with ScheduleDto

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);
    }
}
Also used : PendingSetScheduleRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) JMSException(javax.jms.JMSException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Example 4 with ScheduleDto

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);
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Example 5 with ScheduleDto

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);
    }
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) JMSException(javax.jms.JMSException) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Aggregations

ScheduleDto (org.opensmartgridplatform.dto.valueobjects.ScheduleDto)10 ScheduleMessageDataContainerDto (org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto)5 JMSException (javax.jms.JMSException)4 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)4 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)3 DeviceRequest (org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest)2 SetScheduleDeviceRequest (org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.requests.SetScheduleDeviceRequest)2 RequestMessageData (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)2 Iec61850DeviceResponseHandler (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler)2 SetScheduleDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest)2 Device (org.opensmartgridplatform.domain.core.entities.Device)2 Oslp (org.opensmartgridplatform.oslp.Oslp)2 SetScheduleRequest (org.opensmartgridplatform.oslp.Oslp.SetScheduleRequest)2 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 Iec61850SetScheduleFunction (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Iec61850SetScheduleFunction)1 PendingSetScheduleRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest)1 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)1