Search in sources :

Example 1 with EventNotificationMessageDataContainer

use of org.opensmartgridplatform.domain.core.valueobjects.EventNotificationMessageDataContainer in project open-smart-grid-platform by OSGP.

the class DeviceManagementService method enqueueSetEventNotificationsRequest.

// === SET EVENT NOTIFICATIONS ===
@Transactional(value = "transactionManager")
public String enqueueSetEventNotificationsRequest(@Identification final String organisationIdentification, @Identification final String deviceIdentification, final List<EventNotificationType> eventNotifications, final int messagePriority) throws FunctionalException {
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    final Device device = this.domainHelperService.findActiveDevice(deviceIdentification);
    this.domainHelperService.isAllowed(organisation, device, DeviceFunction.SET_EVENT_NOTIFICATIONS);
    this.domainHelperService.isInMaintenance(device);
    LOGGER.debug("enqueueSetEventNotificationsRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
    final EventNotificationMessageDataContainer eventNotificationMessageDataContainer = new EventNotificationMessageDataContainer(eventNotifications);
    final MessageMetadata messageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.SET_EVENT_NOTIFICATIONS.name()).withMessagePriority(messagePriority).build();
    final CommonRequestMessage message = new CommonRequestMessage.Builder().messageMetadata(messageMetadata).request(eventNotificationMessageDataContainer).build();
    this.commonRequestMessageSender.send(message);
    return correlationUid;
}
Also used : CommonRequestMessage(org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device) EventNotificationMessageDataContainer(org.opensmartgridplatform.domain.core.valueobjects.EventNotificationMessageDataContainer) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with EventNotificationMessageDataContainer

use of org.opensmartgridplatform.domain.core.valueobjects.EventNotificationMessageDataContainer in project open-smart-grid-platform by OSGP.

the class CommonSetEventNotificationsRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing common set event notifications request message");
    String correlationUid = null;
    String messageType = null;
    int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
    String organisationIdentification = null;
    String deviceIdentification = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
    } 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 {
        final EventNotificationMessageDataContainer eventNotificationMessageDataContainer = (EventNotificationMessageDataContainer) message.getObject();
        LOGGER.info("Calling application service function: {}", messageType);
        this.deviceManagementService.setEventNotifications(organisationIdentification, deviceIdentification, correlationUid, eventNotificationMessageDataContainer.getEventNotifications(), messageType, messagePriority);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
    }
}
Also used : EventNotificationMessageDataContainer(org.opensmartgridplatform.domain.core.valueobjects.EventNotificationMessageDataContainer) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException)

Aggregations

EventNotificationMessageDataContainer (org.opensmartgridplatform.domain.core.valueobjects.EventNotificationMessageDataContainer)2 JMSException (javax.jms.JMSException)1 CommonRequestMessage (org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)1 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)1 Transactional (org.springframework.transaction.annotation.Transactional)1