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));
}
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);
}
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);
}
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;
}
});
}
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());
}
Aggregations