Search in sources :

Example 16 with DeviceResponseHandler

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

the class PublicLightingSetTransitionRequestMessageProcessor 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 DeviceResponseHandler deviceResponseHandler = new DeviceResponseHandler() {

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

        @Override
        public void handleException(final Throwable t, final DeviceResponse deviceResponse) {
            PublicLightingSetTransitionRequestMessageProcessor.this.handleUnableToConnectDeviceResponse(deviceResponse, t, domain, domainVersion, messageType, isScheduled, retryCount);
        }
    };
    final DeviceRequest deviceRequest = new DeviceRequest(organisationIdentification, deviceIdentification, correlationUid, messagePriority);
    try {
        this.deviceService.doSetTransition(oslpEnvelope, deviceRequest, deviceResponseHandler, ipAddress);
    } catch (final IOException e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, messagePriority, retryCount);
    }
}
Also used : UnsignedOslpEnvelopeDto(org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto) DeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponse) DeviceResponseHandler(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponseHandler) DeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest) SetTransitionDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetTransitionDeviceRequest) IOException(java.io.IOException) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope)

Example 17 with DeviceResponseHandler

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

Example 18 with DeviceResponseHandler

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

the class CommonRebootRequestMessageProcessor 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 DeviceResponseHandler deviceResponseHandler = this.createSetRebootDeviceResponseHandler(domain, domainVersion, messageType, retryCount, isScheduled);
    final DeviceRequest deviceRequest = new DeviceRequest(organisationIdentification, deviceIdentification, correlationUid, messagePriority);
    try {
        this.deviceService.doSetReboot(oslpEnvelope, deviceRequest, deviceResponseHandler, ipAddress);
    } catch (final IOException e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, messagePriority, retryCount);
    }
}
Also used : UnsignedOslpEnvelopeDto(org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto) DeviceResponseHandler(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponseHandler) DeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest) IOException(java.io.IOException) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope)

Example 19 with DeviceResponseHandler

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

the class CommonGetStatusRequestMessageProcessor 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 DeviceResponseHandler deviceResponseHandler = new DeviceResponseHandler() {

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

        @Override
        public void handleException(final Throwable t, final DeviceResponse deviceResponse) {
            CommonGetStatusRequestMessageProcessor.this.handleUnableToConnectDeviceResponse(deviceResponse, t, domain, domainVersion, messageType, isScheduled, retryCount);
        }
    };
    final GetStatusDeviceRequest deviceRequest = new GetStatusDeviceRequest(organisationIdentification, deviceIdentification, correlationUid, null, messagePriority);
    try {
        this.deviceService.doGetStatus(oslpEnvelope, deviceRequest, deviceResponseHandler, ipAddress);
    } catch (final IOException e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, messagePriority, retryCount);
    }
}
Also used : UnsignedOslpEnvelopeDto(org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto) GetStatusDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) DeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponse) DeviceResponseHandler(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponseHandler) IOException(java.io.IOException) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope) GetStatusDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.GetStatusDeviceRequest)

Example 20 with DeviceResponseHandler

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

the class PublicLightingSetLightRequestMessageProcessor 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 DeviceResponseHandler setLightDeviceResponseHandler = new DeviceResponseHandler() {

        @Override
        public void handleResponse(final DeviceResponse deviceResponse) {
            if (((EmptyDeviceResponse) deviceResponse).getStatus().equals(DeviceMessageStatus.OK)) {
                // If the response is OK, just log it. The resumeSchedule()
                // function will be called next.
                LOGGER.info("setLight() successful for device : {}", deviceResponse.getDeviceIdentification());
            } else {
                // If the response is not OK, send a response message to the
                // responses queue.
                PublicLightingSetLightRequestMessageProcessor.this.handleEmptyDeviceResponse(deviceResponse, PublicLightingSetLightRequestMessageProcessor.this.responseMessageSender, domain, domainVersion, messageType, retryCount);
            }
        }

        @Override
        public void handleException(final Throwable t, final DeviceResponse deviceResponse) {
            PublicLightingSetLightRequestMessageProcessor.this.handleUnableToConnectDeviceResponse(deviceResponse, t, domain, domainVersion, messageType, isScheduled, retryCount);
        }
    };
    final DeviceRequest setLightDeviceRequest = DeviceRequest.newBuilder().organisationIdentification(organisationIdentification).deviceIdentification(deviceIdentification).correlationUid(correlationUid).domain(domain).domainVersion(domainVersion).messageType(messageType).messagePriority(messagePriority).ipAddress(ipAddress).retryCount(retryCount).isScheduled(isScheduled).build();
    // Execute a ResumeSchedule call with 'immediate = false' and 'index
    // = 0' as arguments.
    final ResumeScheduleMessageDataContainerDto resumeScheduleMessageDataContainer = new ResumeScheduleMessageDataContainerDto(0, false);
    final DeviceResponseHandler resumeScheduleDeviceResponseHandler = this.publicLightingResumeScheduleRequestMessageProcessor.createResumeScheduleDeviceResponseHandler(domain, domainVersion, MessageType.RESUME_SCHEDULE.name(), retryCount, isScheduled);
    final ResumeScheduleDeviceRequest resumeScheduleDeviceRequest = new ResumeScheduleDeviceRequest(DeviceRequest.newBuilder().organisationIdentification(organisationIdentification).deviceIdentification(deviceIdentification).correlationUid(correlationUid).domain(domain).domainVersion(domainVersion).messageType(MessageType.RESUME_SCHEDULE.name()).messagePriority(messagePriority).ipAddress(ipAddress).retryCount(retryCount).isScheduled(isScheduled), resumeScheduleMessageDataContainer);
    try {
        this.deviceService.doSetLight(oslpEnvelope, setLightDeviceRequest, resumeScheduleDeviceRequest, setLightDeviceResponseHandler, resumeScheduleDeviceResponseHandler, ipAddress);
    } catch (final IOException e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, messagePriority, retryCount);
    }
}
Also used : UnsignedOslpEnvelopeDto(org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto) DeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponse) EmptyDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.EmptyDeviceResponse) DeviceResponseHandler(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponseHandler) DeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest) ResumeScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.ResumeScheduleDeviceRequest) SetLightDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetLightDeviceRequest) IOException(java.io.IOException) ResumeScheduleMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.ResumeScheduleMessageDataContainerDto) ResumeScheduleDeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.ResumeScheduleDeviceRequest) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope)

Aggregations

IOException (java.io.IOException)20 DeviceResponseHandler (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponseHandler)20 OslpEnvelope (org.opensmartgridplatform.oslp.OslpEnvelope)20 UnsignedOslpEnvelopeDto (org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto)20 DeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponse)18 DeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest)17 GetStatusDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.GetStatusDeviceRequest)3 GetStatusDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse)3 ResumeScheduleDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.ResumeScheduleDeviceRequest)2 SetScheduleDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest)2 EmptyDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.EmptyDeviceResponse)2 GetConfigurationDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetConfigurationDeviceResponse)2 ResumeScheduleMessageDataContainerDto (org.opensmartgridplatform.dto.valueobjects.ResumeScheduleMessageDataContainerDto)2 ScheduleMessageDataContainerDto (org.opensmartgridplatform.dto.valueobjects.ScheduleMessageDataContainerDto)2 SetConfigurationDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetConfigurationDeviceRequest)1 SetDeviceVerificationKeyDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetDeviceVerificationKeyDeviceRequest)1 SetEventNotificationsDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetEventNotificationsDeviceRequest)1 SetLightDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetLightDeviceRequest)1 SetTransitionDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SetTransitionDeviceRequest)1 SwitchFirmwareDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.SwitchFirmwareDeviceRequest)1