use of org.opensmartgridplatform.shared.infra.jms.RequestMessage in project open-smart-grid-platform by OSGP.
the class DlmsChannelHandlerServer method processPushedSms.
private void processPushedSms(final DlmsPushNotification message, final String correlationId, final String deviceIdentification, final String ipAddress) {
this.logMessage(message);
final PushNotificationSmsDto pushNotificationSms = new PushNotificationSmsDto(deviceIdentification, ipAddress);
final RequestMessage requestMessage = new RequestMessage(correlationId, "no-organisation", deviceIdentification, ipAddress, null, null, pushNotificationSms);
log.info("Sending push notification sms wakeup to GXF with correlation ID: {}", correlationId);
this.osgpRequestMessageSender.send(requestMessage, MessageType.PUSH_NOTIFICATION_SMS.name(), null);
}
use of org.opensmartgridplatform.shared.infra.jms.RequestMessage in project open-smart-grid-platform by OSGP.
the class DomainRequestMessageSender method sendMessage.
private static void sendMessage(final RequestMessage requestMessage, final String messageType, final JmsTemplate jmsTemplate) {
LOGGER.info("Sending request message to incoming domain requests queue, messageType: {} organisationIdentification: {} deviceIdentification: {}", messageType, requestMessage.getOrganisationIdentification(), requestMessage.getDeviceIdentification());
jmsTemplate.send(new MessageCreator() {
@Override
public Message createMessage(final Session session) throws JMSException {
final ObjectMessage objectMessage = session.createObjectMessage(requestMessage);
objectMessage.setJMSCorrelationID(requestMessage.getCorrelationUid());
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 GetFirmwareFileMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
MessageMetadata metadata = null;
Device device = null;
String firmwareFileIdentification = StringUtils.EMPTY;
try {
metadata = MessageMetadata.fromMessage(message);
LOGGER.info("[{}] - Received message of messageType: {}, organisationIdentification: {}, deviceIdentification: {}", metadata.getCorrelationUid(), metadata.getMessageType(), metadata.getOrganisationIdentification(), metadata.getDeviceIdentification());
device = this.deviceRepository.findByDeviceIdentification(metadata.getDeviceIdentification());
final RequestMessage requestMessage = (RequestMessage) message.getObject();
final UpdateFirmwareRequestDto updateFirmwareRequestDto = (UpdateFirmwareRequestDto) requestMessage.getRequest();
firmwareFileIdentification = updateFirmwareRequestDto.getFirmwareIdentification();
final FirmwareFile firmwareFile = this.firmwareFileRepository.findByIdentificationOnly(firmwareFileIdentification);
final FirmwareFileDto firmwareFileDto = new FirmwareFileDto(firmwareFileIdentification, updateFirmwareRequestDto.getDeviceIdentification(), firmwareFile.getFile(), firmwareFile.getImageIdentifier());
this.sendSuccesResponse(metadata, device.getProtocolInfo(), firmwareFileDto);
} catch (final Exception e) {
LOGGER.error("Exception while retrieving firmware file: {}", firmwareFileIdentification);
final OsgpException osgpException = new OsgpException(ComponentType.OSGP_CORE, "Exception while retrieving firmware file.", e);
this.sendFailureResponse(metadata, device.getProtocolInfo(), osgpException);
}
}
use of org.opensmartgridplatform.shared.infra.jms.RequestMessage in project open-smart-grid-platform by OSGP.
the class PushNotificationSmsMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
final MessageMetadata metadata = MessageMetadata.fromMessage(message);
LOGGER.info("Received message of messageType: {} organisationIdentification: {} deviceIdentification: {}", this.messageType, metadata.getOrganisationIdentification(), metadata.getDeviceIdentification());
final RequestMessage requestMessage = (RequestMessage) message.getObject();
final Object dataObject = requestMessage.getRequest();
try {
final Device device = this.getDevice(metadata.getDeviceIdentification());
final PushNotificationSmsDto pushNotificationSms = (PushNotificationSmsDto) dataObject;
this.storeSmsAsEvent(pushNotificationSms);
if (pushNotificationSms.getIpAddress() != null && !"".equals(pushNotificationSms.getIpAddress())) {
LOGGER.info("Updating device {} IP address from {} to {}", metadata.getDeviceIdentification(), requestMessage.getIpAddress(), pushNotificationSms.getIpAddress());
// Convert the IP address from String to InetAddress.
final InetAddress address = InetAddress.getByName(pushNotificationSms.getIpAddress());
device.updateRegistrationData(address, device.getDeviceType());
device.updateConnectionDetailsToSuccess();
this.deviceRepository.save(device);
} else {
LOGGER.warn("Sms notification request for device = {} has no new IP address. Discard request.", metadata.getDeviceIdentification());
}
} catch (final UnknownHostException | FunctionalException e) {
final String errorMessage = String.format("%s occurred, reason: %s", e.getClass().getName(), e.getMessage());
LOGGER.error(errorMessage, e);
throw new JMSException(errorMessage);
}
}
use of org.opensmartgridplatform.shared.infra.jms.RequestMessage in project open-smart-grid-platform by OSGP.
the class PushNotificationAlarmMessageProcessorTest method init.
@BeforeEach
public void init() throws JMSException, UnknownEntityException {
final String correlationUid = "corr-uid-1";
final String organisationIdentification = "test-org";
final String ipAddress = "127.0.0.1";
final RequestMessage requestMessage = new RequestMessage(correlationUid, organisationIdentification, DEVICE_IDENTIFICATION, ipAddress, null, null, this.pushNotificationAlarm);
this.message = new ObjectMessageBuilder().withCorrelationUid(correlationUid).withMessageType(MessageType.PUSH_NOTIFICATION_ALARM.name()).withDeviceIdentification(DEVICE_IDENTIFICATION).withObject(requestMessage).build();
this.device = new Device(DEVICE_IDENTIFICATION);
when(this.deviceRepository.findByDeviceIdentification(DEVICE_IDENTIFICATION)).thenReturn(this.device);
when(this.deviceRepository.save(this.device)).thenAnswer((Answer<Void>) invocationOnMock -> null);
doNothing().when(this.eventNotificationMessageService).handleEvent(any(String.class), any(Date.class), any(EventType.class), any(String.class), any(Integer.class));
when(this.deviceAuthorizationRepository.findByDeviceAndFunctionGroup(this.device, DeviceFunctionGroup.OWNER)).thenReturn(Collections.singletonList(this.deviceAuthorization));
when(this.deviceAuthorization.getOrganisation()).thenReturn(this.organisation);
when(this.organisation.getOrganisationIdentification()).thenReturn(requestMessage.getOrganisationIdentification());
when(this.domainInfoRepository.findAll()).thenReturn(Collections.singletonList(this.domainInfo));
when(this.domainInfo.getDomain()).thenReturn("SMART_METERING");
when(this.domainInfo.getDomainVersion()).thenReturn("1.0");
doNothing().when(this.domainRequestService).send(any(RequestMessage.class), any(String.class), any(DomainInfo.class));
}
Aggregations