Search in sources :

Example 26 with RequestMessage

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

the class SystemEventMessageProcessorTest method init.

@BeforeEach
public void init() throws JMSException {
    final String correlationUid = "corr-uid-1";
    final String organisationIdentification = "test-org";
    final String ipAddress = "127.0.0.1";
    final String domain = "SMART_METERING";
    final String domainVersion = "1.0";
    final RequestMessage requestMessage = new RequestMessage(correlationUid, organisationIdentification, DEVICE_IDENTIFICATION, ipAddress, null, null, this.systemEventDto);
    this.message = new ObjectMessageBuilder().withCorrelationUid(correlationUid).withMessageType(MessageType.SYSTEM_EVENT.name()).withDeviceIdentification(DEVICE_IDENTIFICATION).withObject(requestMessage).build();
    this.message.setStringProperty(Constants.DOMAIN, domain);
    this.message.setStringProperty(Constants.DOMAIN_VERSION, domainVersion);
    when(this.domainInfoRepository.findByDomainAndDomainVersion(domain, domainVersion)).thenReturn(this.domainInfo);
    doNothing().when(this.domainRequestService).send(any(RequestMessage.class), any(String.class), any(DomainInfo.class));
}
Also used : RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) DomainInfo(org.opensmartgridplatform.domain.core.entities.DomainInfo) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 27 with RequestMessage

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

the class EventNotificationMessageService method sendRequestMessageToDomainCore.

/**
 * Send a request message to OSGP-ADAPTER-DOMAIN-CORE.
 */
private void sendRequestMessageToDomainCore(final String messageType, final String deviceIdentification, final Serializable dataObject) {
    final String correlationUid = this.correlationIdProviderTimestampService.getCorrelationId(this.netmanagementOrganisation, deviceIdentification);
    final RequestMessage message = new RequestMessage(correlationUid, this.netmanagementOrganisation, deviceIdentification, dataObject);
    final DomainInfo domainInfo = this.eventNotificationHelperService.findDomainInfo("CORE", "1.0");
    this.domainRequestService.send(message, messageType, domainInfo);
}
Also used : RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) DomainInfo(org.opensmartgridplatform.domain.core.entities.DomainInfo)

Example 28 with RequestMessage

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

the class GetFirmwareFileMessageProcessorTest method processMessageShouldSendFirmwareFile.

@Test
public void processMessageShouldSendFirmwareFile() throws JMSException {
    // arrange
    final String correlationUid = "corr-uid-1";
    final String organisationIdentification = "test-org";
    final String deviceIdentification = "dvc-1";
    final String firmwareFileIdentification = "fw";
    final byte[] firmwareFileBytes = firmwareFileIdentification.getBytes();
    final UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareFileIdentification, deviceIdentification);
    final RequestMessage requestMessage = new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, updateFirmwareRequestDto);
    final ObjectMessage message = new ObjectMessageBuilder().withCorrelationUid(correlationUid).withMessageType(DeviceFunction.GET_FIRMWARE_FILE.name()).withDeviceIdentification(deviceIdentification).withObject(requestMessage).build();
    when(this.deviceMock.getDeviceIdentification()).thenReturn(deviceIdentification);
    when(this.deviceRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(this.deviceMock);
    when(this.firmwareFileMock.getFilename()).thenReturn(firmwareFileIdentification);
    when(this.firmwareFileMock.getFile()).thenReturn(firmwareFileBytes);
    when(this.firmwareFileRepository.findByIdentificationOnly(firmwareFileIdentification)).thenReturn(this.firmwareFileMock);
    final byte[] expectedFile = firmwareFileBytes;
    final String expectedMessageType = DeviceFunction.GET_FIRMWARE_FILE.name();
    final ArgumentCaptor<ProtocolResponseMessage> responseMessageArgumentCaptor = ArgumentCaptor.forClass(ProtocolResponseMessage.class);
    final ArgumentCaptor<String> messageTypeCaptor = ArgumentCaptor.forClass(String.class);
    // act
    this.getFirmwareFileMessageProcessor.processMessage(message);
    // assert
    verify(this.protocolResponseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture(), messageTypeCaptor.capture(), nullable(ProtocolInfo.class), any(MessageMetadata.class));
    final FirmwareFileDto actualFirmwareFileDto = (FirmwareFileDto) responseMessageArgumentCaptor.getValue().getDataObject();
    final String actualMessageType = messageTypeCaptor.getValue();
    assertThat(actualFirmwareFileDto.getFirmwareFile()).isEqualTo(expectedFile);
    assertThat(actualFirmwareFileDto.getDeviceIdentification()).isEqualTo(deviceIdentification);
    assertThat(actualFirmwareFileDto.getFirmwareIdentification()).isEqualTo(firmwareFileIdentification);
    assertThat(actualMessageType).isEqualTo(expectedMessageType);
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ObjectMessage(javax.jms.ObjectMessage) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 29 with RequestMessage

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

the class OsgpRequestMessageSender method send.

public void send(final RequestMessage requestMessage, final String messageType) {
    LOGGER.info("Sending request message to OSGP.");
    this.jmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage(requestMessage);
            objectMessage.setJMSType(messageType);
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, requestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, requestMessage.getDeviceIdentification());
            return objectMessage;
        }
    });
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 30 with RequestMessage

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

the class DeviceManagementService method addEventNotifications.

/**
 * Send an event notification to OSGP Core.
 *
 * @param deviceIdentification The identification of the device.
 * @param eventNotifications The event notifications.
 * @throws ProtocolAdapterException In case the device can not be found in the database.
 */
@Transactional(value = "iec61850OsgpCoreDbApiTransactionManager", readOnly = true)
public void addEventNotifications(final String deviceIdentification, final List<EventNotificationDto> eventNotifications) throws ProtocolAdapterException {
    final Ssld ssldDevice = this.ssldDataRepository.findByDeviceIdentification(deviceIdentification);
    if (ssldDevice == null) {
        final LightMeasurementDevice lmd = this.lmdDataRepository.findByDeviceIdentification(deviceIdentification);
        if (lmd == null) {
            throw new ProtocolAdapterException("Unable to find device using deviceIdentification: " + deviceIdentification);
        }
    }
    LOGGER.info("addEventNotifications called for device {}: {}", deviceIdentification, eventNotifications);
    final RequestMessage requestMessage = new RequestMessage(NO_CORRELATION_UID, NO_ORGANISATION, deviceIdentification, new ArrayList<>(eventNotifications));
    this.osgpRequestMessageSender.send(requestMessage, MessageType.EVENT_NOTIFICATION.name());
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.core.db.api.iec61850.entities.LightMeasurementDevice) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) Ssld(org.opensmartgridplatform.core.db.api.iec61850.entities.Ssld) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)79 Device (org.opensmartgridplatform.domain.core.entities.Device)33 JMSException (javax.jms.JMSException)18 ObjectMessage (javax.jms.ObjectMessage)13 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)11 Test (org.junit.jupiter.api.Test)9 DomainInfo (org.opensmartgridplatform.domain.core.entities.DomainInfo)7 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)6 Message (javax.jms.Message)5 Session (javax.jms.Session)5 RtuDevice (org.opensmartgridplatform.domain.core.entities.RtuDevice)5 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)5 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)4 MessageCreator (org.springframework.jms.core.MessageCreator)4 Transactional (org.springframework.transaction.annotation.Transactional)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 CdmaDevice (org.opensmartgridplatform.domain.core.valueobjects.CdmaDevice)3 EventNotificationDto (org.opensmartgridplatform.dto.valueobjects.EventNotificationDto)3 SystemEventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SystemEventDto)3 ObjectMessageBuilder (org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder)3