Search in sources :

Example 1 with ResumeScheduleMessageDataContainerDto

use of com.alliander.osgp.dto.valueobjects.ResumeScheduleMessageDataContainerDto in project Protocol-Adapter-OSLP by OSGP.

the class PublicLightingResumeScheduleRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing public lighting resume schedule request message");
    String correlationUid = null;
    String domain = null;
    String domainVersion = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    String ipAddress = null;
    int retryCount = 0;
    boolean isScheduled = false;
    try {
        correlationUid = message.getJMSCorrelationID();
        domain = message.getStringProperty(Constants.DOMAIN);
        domainVersion = message.getStringProperty(Constants.DOMAIN_VERSION);
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        ipAddress = message.getStringProperty(Constants.IP_ADDRESS);
        retryCount = message.getIntProperty(Constants.RETRY_COUNT);
        isScheduled = message.propertyExists(Constants.IS_SCHEDULED) ? message.getBooleanProperty(Constants.IS_SCHEDULED) : false;
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("domain: {}", domain);
        LOGGER.debug("domainVersion: {}", domainVersion);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("ipAddress: {}", ipAddress);
        return;
    }
    try {
        final ResumeScheduleMessageDataContainerDto resumeScheduleMessageDataContainer = (ResumeScheduleMessageDataContainerDto) message.getObject();
        LOGGER.info("Calling DeviceService function: {} for domain: {} {}", messageType, domain, domainVersion);
        final ResumeScheduleDeviceRequest deviceRequest = new ResumeScheduleDeviceRequest(organisationIdentification, deviceIdentification, correlationUid, resumeScheduleMessageDataContainer, domain, domainVersion, messageType, ipAddress, retryCount, isScheduled);
        this.deviceService.resumeSchedule(deviceRequest);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, retryCount);
    }
}
Also used : JMSException(javax.jms.JMSException) ResumeScheduleMessageDataContainerDto(com.alliander.osgp.dto.valueobjects.ResumeScheduleMessageDataContainerDto) ResumeScheduleDeviceRequest(com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.ResumeScheduleDeviceRequest) IOException(java.io.IOException) JMSException(javax.jms.JMSException)

Example 2 with ResumeScheduleMessageDataContainerDto

use of com.alliander.osgp.dto.valueobjects.ResumeScheduleMessageDataContainerDto in project Protocol-Adapter-OSLP 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 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, unsignedOslpEnvelopeDto.getExtraData(), PublicLightingSetLightRequestMessageProcessor.this.responseMessageSender, deviceResponse, domain, domainVersion, messageType, isScheduled, retryCount);
        }
    };
    final DeviceRequest setLightdeviceRequest = new DeviceRequest(organisationIdentification, deviceIdentification, correlationUid, domain, domainVersion, messageType, ipAddress, retryCount, isScheduled);
    // 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, DeviceRequestMessageType.RESUME_SCHEDULE.name(), retryCount, resumeScheduleMessageDataContainer, isScheduled);
    // The data of the setLightdeviceRequest can be reused
    final ResumeScheduleDeviceRequest resumeScheduleDeviceRequest = new ResumeScheduleDeviceRequest(setLightdeviceRequest.getOrganisationIdentification(), setLightdeviceRequest.getDeviceIdentification(), setLightdeviceRequest.getCorrelationUid(), resumeScheduleMessageDataContainer, setLightdeviceRequest.getDomain(), setLightdeviceRequest.getDomainVersion(), DeviceRequestMessageType.RESUME_SCHEDULE.name(), setLightdeviceRequest.getIpAddress(), setLightdeviceRequest.getRetryCount(), setLightdeviceRequest.isScheduled());
    try {
        this.deviceService.doSetLight(oslpEnvelope, setLightdeviceRequest, resumeScheduleDeviceRequest, setLightDeviceResponseHandler, resumeScheduleDeviceResponseHandler, ipAddress);
    } catch (final IOException e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, retryCount);
    }
}
Also used : UnsignedOslpEnvelopeDto(com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto) EmptyDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.EmptyDeviceResponse) DeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceResponse) DeviceResponseHandler(com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceResponseHandler) SetLightDeviceRequest(com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.SetLightDeviceRequest) DeviceRequest(com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceRequest) ResumeScheduleDeviceRequest(com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.ResumeScheduleDeviceRequest) IOException(java.io.IOException) ResumeScheduleMessageDataContainerDto(com.alliander.osgp.dto.valueobjects.ResumeScheduleMessageDataContainerDto) ResumeScheduleDeviceRequest(com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.ResumeScheduleDeviceRequest) OslpEnvelope(com.alliander.osgp.oslp.OslpEnvelope)

Aggregations

ResumeScheduleDeviceRequest (com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.ResumeScheduleDeviceRequest)2 ResumeScheduleMessageDataContainerDto (com.alliander.osgp.dto.valueobjects.ResumeScheduleMessageDataContainerDto)2 IOException (java.io.IOException)2 DeviceRequest (com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceRequest)1 DeviceResponse (com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceResponse)1 DeviceResponseHandler (com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceResponseHandler)1 SetLightDeviceRequest (com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.SetLightDeviceRequest)1 EmptyDeviceResponse (com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.EmptyDeviceResponse)1 OslpEnvelope (com.alliander.osgp.oslp.OslpEnvelope)1 UnsignedOslpEnvelopeDto (com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto)1 JMSException (javax.jms.JMSException)1