Search in sources :

Example 1 with SetScheduleDeviceRequest

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest in project open-smart-grid-platform by OSGP.

the class PublicLightingSetScheduleRequestMessageProcessor method handleSetScheduleGetConfigurationResponse.

private void handleSetScheduleGetConfigurationResponse(final SetScheduleDeviceRequest deviceRequest, final GetConfigurationDeviceResponse deviceResponse) {
    // Configuration is retrieved, so now continue with setting the
    // astronomical offsets
    LOGGER.info(LOG_MESSAGE_CALL_DEVICE_SERVICE, deviceRequest.getMessageType(), ScheduleMessageTypeDto.SET_ASTRONOMICAL_OFFSETS, deviceRequest.getDomain(), deviceRequest.getDomainVersion());
    final ScheduleMessageTypeDto nextRequest = this.determineNextRequest(deviceRequest, deviceResponse);
    LOGGER.info("Request after getConfiguration: {}", nextRequest);
    final ScheduleMessageDataContainerDto dataContainer = new ScheduleMessageDataContainerDto.Builder(deviceRequest.getScheduleMessageDataContainer().getSchedule()).withConfiguration(deviceResponse.getConfiguration()).withScheduleMessageType(nextRequest).build();
    final SetScheduleDeviceRequest newDeviceRequest = new SetScheduleDeviceRequest(createDeviceRequestBuilder(deviceRequest), dataContainer, RelayTypeDto.LIGHT);
    this.deviceService.setSchedule(newDeviceRequest);
}
Also used : ScheduleMessageTypeDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageTypeDto) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest)

Example 2 with SetScheduleDeviceRequest

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest in project open-smart-grid-platform by OSGP.

the class PublicLightingSetScheduleRequestMessageProcessor method processSignedOslpEnvelope.

@Override
public void processSignedOslpEnvelope(final String deviceIdentification, final SignedOslpEnvelopeDto signedOslpEnvelopeDto) {
    final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = signedOslpEnvelopeDto.getUnsignedOslpEnvelopeDto();
    final OslpEnvelope oslpEnvelope = signedOslpEnvelopeDto.getOslpEnvelope();
    final String correlationUid = unsignedOslpEnvelopeDto.getCorrelationUid();
    final String organisationIdentification = unsignedOslpEnvelopeDto.getOrganisationIdentification();
    final String domain = unsignedOslpEnvelopeDto.getDomain();
    final String domainVersion = unsignedOslpEnvelopeDto.getDomainVersion();
    final String messageType = unsignedOslpEnvelopeDto.getMessageType();
    final int messagePriority = unsignedOslpEnvelopeDto.getMessagePriority();
    final String ipAddress = unsignedOslpEnvelopeDto.getIpAddress();
    final int retryCount = unsignedOslpEnvelopeDto.getRetryCount();
    final boolean isScheduled = unsignedOslpEnvelopeDto.isScheduled();
    final ScheduleMessageDataContainerDto dataContainer = (ScheduleMessageDataContainerDto) unsignedOslpEnvelopeDto.getExtraData();
    final DeviceRequest.Builder builder = DeviceRequest.newBuilder().organisationIdentification(organisationIdentification).deviceIdentification(deviceIdentification).correlationUid(correlationUid).domain(domain).domainVersion(domainVersion).messageType(messageType).messagePriority(messagePriority).ipAddress(ipAddress).retryCount(retryCount).isScheduled(isScheduled);
    final SetScheduleDeviceRequest deviceRequest = new SetScheduleDeviceRequest(builder, dataContainer, RelayTypeDto.LIGHT);
    final DeviceResponseHandler deviceResponseHandler = new DeviceResponseHandler() {

        @Override
        public void handleResponse(final DeviceResponse deviceResponse) {
            PublicLightingSetScheduleRequestMessageProcessor.this.handleResponse(deviceResponse, deviceRequest);
        }

        @Override
        public void handleException(final Throwable t, final DeviceResponse deviceResponse) {
            PublicLightingSetScheduleRequestMessageProcessor.this.handleUnableToConnectDeviceResponse(deviceResponse, t, domain, domainVersion, messageType, isScheduled, retryCount);
        }
    };
    try {
        this.deviceService.doSetSchedule(oslpEnvelope, deviceRequest, deviceResponseHandler, ipAddress, domain, domainVersion, messageType, messagePriority, retryCount, isScheduled, dataContainer.getPageInfo());
    } catch (final IOException e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, messagePriority, retryCount);
    }
}
Also used : UnsignedOslpEnvelopeDto(org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) IOException(java.io.IOException) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope) GetConfigurationDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetConfigurationDeviceResponse) DeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponse) DeviceResponseHandler(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponseHandler) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) DeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest)

Example 3 with SetScheduleDeviceRequest

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest 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 SetScheduleDeviceRequest

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest in project open-smart-grid-platform by OSGP.

the class DeviceManagementService method handleSetSchedule.

public void handleSetSchedule(final String deviceUid) throws TechnicalException {
    final List<PendingSetScheduleRequest> pendingSetScheduleRequestList = this.pendingSetScheduleRequestService.getAllByDeviceUidNotExpired(deviceUid);
    if (pendingSetScheduleRequestList.isEmpty()) {
        // schedule with astronomical offsets
        return;
    }
    if (pendingSetScheduleRequestList.size() > 1) {
        throw new TechnicalException(String.format("Currently there are %d pending set schedule requests for device %s. Only one is allowed.", pendingSetScheduleRequestList.size(), deviceUid));
    }
    final PendingSetScheduleRequest pendingSetScheduleRequest = pendingSetScheduleRequestList.get(0);
    final ScheduleMessageDataContainerDto dto = pendingSetScheduleRequest.getScheduleMessageDataContainerDto();
    ScheduleMessageDataContainerDto.Builder builder = new ScheduleMessageDataContainerDto.Builder(dto.getSchedule());
    builder = builder.withScheduleMessageType(ScheduleMessageTypeDto.SET_SCHEDULE);
    final ScheduleMessageDataContainerDto scheduleMessageDataContainer = builder.build();
    final DeviceRequest deviceRequest = pendingSetScheduleRequest.getDeviceRequest();
    final MessageMetadata messageMetadata = this.getMessageMetadataFromDeviceRequest(deviceRequest);
    final SetScheduleDeviceRequest newDeviceRequest = new SetScheduleDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), scheduleMessageDataContainer, RelayTypeDto.LIGHT);
    this.deviceService.setSchedule(newDeviceRequest);
    this.pendingSetScheduleRequestService.remove(pendingSetScheduleRequest);
}
Also used : PendingSetScheduleRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) DeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest)

Example 5 with SetScheduleDeviceRequest

use of org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest in project open-smart-grid-platform by OSGP.

the class TariffSwitchingSetScheduleRequestMessageProcessor method processSignedOslpEnvelope.

@Override
public void processSignedOslpEnvelope(final String deviceIdentification, final SignedOslpEnvelopeDto signedOslpEnvelopeDto) {
    final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = signedOslpEnvelopeDto.getUnsignedOslpEnvelopeDto();
    final OslpEnvelope oslpEnvelope = signedOslpEnvelopeDto.getOslpEnvelope();
    final String correlationUid = unsignedOslpEnvelopeDto.getCorrelationUid();
    final String organisationIdentification = unsignedOslpEnvelopeDto.getOrganisationIdentification();
    final String domain = unsignedOslpEnvelopeDto.getDomain();
    final String domainVersion = unsignedOslpEnvelopeDto.getDomainVersion();
    final String messageType = unsignedOslpEnvelopeDto.getMessageType();
    final int messagePriority = unsignedOslpEnvelopeDto.getMessagePriority();
    final String ipAddress = unsignedOslpEnvelopeDto.getIpAddress();
    final int retryCount = unsignedOslpEnvelopeDto.getRetryCount();
    final boolean isScheduled = unsignedOslpEnvelopeDto.isScheduled();
    final ScheduleMessageDataContainerDto dataContainer = (ScheduleMessageDataContainerDto) unsignedOslpEnvelopeDto.getExtraData();
    final DeviceResponseHandler deviceResponseHandler = new DeviceResponseHandler() {

        @Override
        public void handleResponse(final DeviceResponse deviceResponse) {
            TariffSwitchingSetScheduleRequestMessageProcessor.this.handleEmptyDeviceResponse(deviceResponse, TariffSwitchingSetScheduleRequestMessageProcessor.this.responseMessageSender, domain, domainVersion, messageType, retryCount);
        }

        @Override
        public void handleException(final Throwable t, final DeviceResponse deviceResponse) {
            TariffSwitchingSetScheduleRequestMessageProcessor.this.handleUnableToConnectDeviceResponse(deviceResponse, t, domain, domainVersion, messageType, isScheduled, retryCount);
        }
    };
    final DeviceRequest.Builder builder = DeviceRequest.newBuilder().organisationIdentification(organisationIdentification).deviceIdentification(deviceIdentification).correlationUid(correlationUid).domain(domain).domainVersion(domainVersion).messageType(messageType).messagePriority(messagePriority).ipAddress(ipAddress).retryCount(retryCount).isScheduled(isScheduled);
    final SetScheduleDeviceRequest deviceRequest = new SetScheduleDeviceRequest(builder, dataContainer, RelayTypeDto.TARIFF);
    try {
        this.deviceService.doSetSchedule(oslpEnvelope, deviceRequest, deviceResponseHandler, ipAddress, domain, domainVersion, messageType, messagePriority, retryCount, isScheduled, dataContainer.getPageInfo());
    } catch (final IOException e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, messagePriority, retryCount);
    }
}
Also used : UnsignedOslpEnvelopeDto(org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto) ScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto) IOException(java.io.IOException) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope) DeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponse) DeviceResponseHandler(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponseHandler) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest) DeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest) SetScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest)

Aggregations

SetScheduleDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest)7 ScheduleMessageDataContainerDto (org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto)7 DeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest)3 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)3 IOException (java.io.IOException)2 JMSException (javax.jms.JMSException)2 DeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponse)2 DeviceResponseHandler (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponseHandler)2 PendingSetScheduleRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.PendingSetScheduleRequest)2 ScheduleDto (org.opensmartgridplatform.dto.valueobjects.ScheduleDto)2 OslpEnvelope (org.opensmartgridplatform.oslp.OslpEnvelope)2 UnsignedOslpEnvelopeDto (org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto)2 GetConfigurationDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetConfigurationDeviceResponse)1 ScheduleMessageTypeDto (org.opensmartgridplatform.dto.valueobjects.ScheduleMessageTypeDto)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1