Search in sources :

Example 11 with CorrelationIds

use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds 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");
    String correlationUid = null;
    String messageType = null;
    int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
    String organisationIdentification = null;
    String deviceIdentification = null;
    Object dataObject;
    Long scheduleTime = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        if (message.propertyExists(Constants.SCHEDULE_TIME)) {
            scheduleTime = message.getLongProperty(Constants.SCHEDULE_TIME);
        }
        dataObject = message.getObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("messagePriority: {}", messagePriority);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        return;
    }
    try {
        LOGGER.info("Calling application service function: {}", messageType);
        final Schedule schedule = (Schedule) dataObject;
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.scheduleManagementService.setLightSchedule(ids, schedule, scheduleTime, messageType, messagePriority);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
    }
}
Also used : Schedule(org.opensmartgridplatform.domain.core.valueobjects.Schedule) JMSException(javax.jms.JMSException) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) JMSException(javax.jms.JMSException)

Example 12 with CorrelationIds

use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.

the class PublicLightingGetLightSensorStatusResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing public lighting get light sensor status response message");
    String correlationUid = null;
    String messageType = null;
    int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    Object dataObject;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
        dataObject = responseMessage.getDataObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("messagePriority: {}", messagePriority);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("osgpException: ", osgpException);
        return;
    }
    try {
        LOGGER.info("Calling application service function to handle response: {}", messageType);
        final LightSensorStatusDto lightSensorStatus = (LightSensorStatusDto) dataObject;
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.adHocManagementService.handleGetLightSensorStatusResponse(lightSensorStatus, ids, messageType, messagePriority, responseMessageResultType, osgpException);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) LightSensorStatusDto(org.opensmartgridplatform.dto.valueobjects.LightSensorStatusDto) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Example 13 with CorrelationIds

use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.

the class PublicLightingSetScheduleResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing public lighting set schedule response message");
    String correlationUid = null;
    String messageType = null;
    int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("messagePriority: {}", messagePriority);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("osgpException", osgpException);
        return;
    }
    try {
        LOGGER.info("Calling application service function to handle response: {}", messageType);
        // If the set light schedule response is OK, set hasSchedule to
        // true.
        this.scheduleManagementService.setHasSchedule(deviceIdentification, responseMessageResultType == ResponseMessageResultType.OK);
        // Then send a default response message to web service adapter.
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.defaultDeviceResponseService.handleDefaultDeviceResponse(ids, messageType, messagePriority, responseMessageResultType, osgpException);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Example 14 with CorrelationIds

use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.

the class CommonGetConfigurationResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing common get configuration response message");
    String correlationUid = null;
    String messageType = null;
    int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    Object dataObject;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
        dataObject = responseMessage.getDataObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("messagePriority: {}", messagePriority);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("osgpException", osgpException);
        return;
    }
    try {
        LOGGER.info("Calling application service function to handle response: {}", messageType);
        final ConfigurationDto configurationDto = (ConfigurationDto) dataObject;
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.configurationManagementService.handleGetConfigurationResponse(configurationDto, ids, messageType, messagePriority, responseMessageResultType, osgpException);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Example 15 with CorrelationIds

use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.

the class DomainResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing distribution automation response message");
    String correlationUid = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    final String notificationMessage;
    final NotificationType notificationType;
    final ResponseMessageResultType resultType;
    final String resultDescription;
    final Serializable dataObject;
    try {
        correlationUid = message.getJMSCorrelationID();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        messageType = message.getJMSType();
        validateMessageType(messageType);
        resultType = ResponseMessageResultType.valueOf(message.getStringProperty(Constants.RESULT));
        resultDescription = message.getStringProperty(Constants.DESCRIPTION);
        notificationMessage = message.getStringProperty(Constants.DESCRIPTION);
        notificationType = NotificationType.valueOf(messageType);
        dataObject = message.getObject();
    } catch (final IllegalArgumentException e) {
        LOGGER.error("UNRECOVERABLE ERROR, received messageType {} is unknown.", messageType, e);
        logDebugInformation(messageType, correlationUid, organisationIdentification, deviceIdentification);
        return;
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        logDebugInformation(messageType, correlationUid, organisationIdentification, deviceIdentification);
        return;
    }
    try {
        LOGGER.info("Calling application service function to handle response: {}", messageType);
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.handleMessage(ids, messageType, resultType, resultDescription, dataObject);
        // Send notification indicating data is available.
        this.notificationService.sendNotification(this.webserviceNotificationOrganisation, deviceIdentification, resultType.name(), correlationUid, notificationMessage, notificationType);
    } catch (final RuntimeException e) {
        handleError(e, correlationUid, notificationType);
    }
}
Also used : Serializable(java.io.Serializable) NotificationType(org.opensmartgridplatform.adapter.ws.schema.distributionautomation.notification.NotificationType) JMSException(javax.jms.JMSException) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds)

Aggregations

CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)42 JMSException (javax.jms.JMSException)31 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)24 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)18 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)18 Test (org.junit.jupiter.api.Test)7 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)7 Serializable (java.io.Serializable)6 FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)5 Date (java.util.Date)4 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)4 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)4 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)4 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 DeviceStatusDto (org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto)3 ApplicationDataLookupKey (org.opensmartgridplatform.adapter.ws.domain.entities.ApplicationDataLookupKey)2 GenericNotification (org.opensmartgridplatform.adapter.ws.schema.shared.notification.GenericNotification)2 Schedule (org.opensmartgridplatform.domain.core.valueobjects.Schedule)2 GetPQValuesResponseDto (org.opensmartgridplatform.dto.da.GetPQValuesResponseDto)2