use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class DeviceInstallationService method enqueueStartDeviceTestRequest.
// === START DEVICE TEST ===
@Transactional(value = "transactionManager")
public String enqueueStartDeviceTestRequest(@Identification final String organisationIdentification, @Identification final String deviceIdentification, final int messagePriority) throws FunctionalException {
LOGGER.debug("Queue start device test request");
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
final Device device = this.domainHelperService.findActiveDevice(deviceIdentification);
this.domainHelperService.isAllowed(organisation, device, DeviceFunction.START_SELF_TEST);
LOGGER.debug("enqueueStartDeviceTestRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
final MessageMetadata messageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.START_SELF_TEST.name()).withMessagePriority(messagePriority).build();
final CommonRequestMessage message = new CommonRequestMessage.Builder().messageMetadata(messageMetadata).build();
this.commonRequestMessageSender.send(message);
return correlationUid;
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class DeviceInstallationService method enqueueGetStatusRequest.
// === GET STATUS ===
@Transactional(value = "transactionManager")
public String enqueueGetStatusRequest(@Identification final String organisationIdentification, @Identification final String deviceIdentification, 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.GET_STATUS);
LOGGER.debug("enqueueGetStatusRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
final MessageMetadata messageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.GET_STATUS.name()).withMessagePriority(messagePriority).build();
final CommonRequestMessage message = new CommonRequestMessage.Builder().messageMetadata(messageMetadata).build();
this.commonRequestMessageSender.send(message);
return correlationUid;
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutor method execute.
@Override
public GetGsmDiagnosticResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final GetGsmDiagnosticRequestDto getGsmDiagnosticQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final DlmsObject dlmsObject = this.dlmsObjectConfigService.getDlmsObjectForCommunicationMethod(device, DlmsObjectType.GSM_DIAGNOSTIC);
final AttributeAddress[] addresses = this.createAttributeAddresses(dlmsObject);
final String addressesDescriptions = JdlmsObjectToStringUtil.describeAttributes(addresses);
conn.getDlmsMessageListener().setDescription("Get GsmDiagnostic, retrieve attributes: " + addressesDescriptions);
LOGGER.info("Get GsmDiagnostic, retrieve attributes: {}", addressesDescriptions);
final List<GetResult> getResultList = this.dlmsHelper.getAndCheck(conn, device, "Get GsmDiagnostic", addresses);
LOGGER.info("GetResultList: {}", describeGetResults(getResultList));
if (!getResultList.stream().allMatch(result -> result.getResultCode() == AccessResultCode.SUCCESS)) {
throw new ProtocolAdapterException("Get gsm diagnostic failed for " + device.getDeviceId());
}
return this.createGetGsmDiagnosticResponse(getResultList);
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class ProtocolResponseMessageSendingHandler method handlePublishedMessage.
/**
* Handles the {@code payload} as UTF-8 bytes for which the textual form is sent to the outbound
* OSGP Core responses queue.
*/
@Override
public void handlePublishedMessage(final String topic, final byte[] payload) {
final String payloadAsText = new String(payload, StandardCharsets.UTF_8);
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withOrganisationIdentification(this.organisationIdentification).withDeviceIdentification(this.deviceIdentification).withCorrelationUid(this.correlationIdProviderService.getCorrelationId(this.organisationIdentification, topic)).withMessageType(MessageType.GET_DATA.name()).withDomain("DISTRIBUTION_AUTOMATION").withDomainVersion("1.0").withBypassRetry(true).withScheduled(false).build();
LOGGER.info("Handling message published on topic {}, received payload: {}", topic, payloadAsText);
final ResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).dataObject(payloadAsText).result(ResponseMessageResultType.OK).build();
this.outboundOsgpCoreResponseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class ProtocolResponseMessageSendingHandlerTest method sendsProtocolResponseMessageThatAvoidsRetries.
@Test
void sendsProtocolResponseMessageThatAvoidsRetries() {
final ProtocolResponseMessageSendingHandler protocolResponseMessageSendingHandler = this.aProtocolResponseMessageSendingHandler();
protocolResponseMessageSendingHandler.handlePublishedMessage("any/topic", "any-payload".getBytes(StandardCharsets.UTF_8));
verify(this.outboundOsgpCoreResponseMessageSender).send(this.responseMessageCaptor.capture());
final ResponseMessage actualResponseMessage = this.responseMessageCaptor.getValue();
final MessageMetadata actualMessageMetadata = actualResponseMessage.messageMetadata();
assertThat(actualMessageMetadata.isScheduled()).isFalse();
assertThat(actualMessageMetadata.isBypassRetry()).isTrue();
final RetryHeader retryHeader = actualResponseMessage.getRetryHeader();
if (retryHeader != null) {
assertThat(retryHeader.getScheduledRetryTime()).isNull();
assertThat(retryHeader.getMaxRetries()).isZero();
}
}
Aggregations