use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SystemEventDto in project open-smart-grid-platform by OSGP.
the class SystemEventService method verifySystemEventThresholdReachedEvent.
public void verifySystemEventThresholdReachedEvent(final DlmsDevice device, final MessageMetadata sourceMessageMetadata) {
if (device.getInvocationCounter() == null || device.getInvocationCounter() < this.invocationCounterEventThreshold) {
return;
}
final String message = String.format("Invocation counter for device %s, has a higher value %s than the threshold configured %s, an event will be published", device.getDeviceIdentification(), device.getInvocationCounter(), this.invocationCounterEventThreshold);
log.info(message);
final SystemEventDto systemEventDto = new SystemEventDto(device.getDeviceIdentification(), SystemEventTypeDto.INVOCATION_COUNTER_THRESHOLD_REACHED, new Date(), message);
final String correlationId = this.correlationIdProviderService.getCorrelationId(sourceMessageMetadata.getOrganisationIdentification(), device.getDeviceIdentification());
final MessageMetadata messageMetadata = new Builder().withDeviceIdentification(device.getDeviceIdentification()).withCorrelationUid(correlationId).withOrganisationIdentification(sourceMessageMetadata.getOrganisationIdentification()).withIpAddress(sourceMessageMetadata.getIpAddress()).withMessagePriority(MessagePriorityEnum.HIGH.getPriority()).withMessageType(MessageType.SYSTEM_EVENT.name()).withDomain(sourceMessageMetadata.getDomain()).withDomainVersion(sourceMessageMetadata.getDomainVersion()).build();
final RequestMessage requestMessage = new RequestMessage(messageMetadata, systemEventDto);
log.info("Sending system event to GXF with correlation ID: {}", correlationId);
this.osgpRequestMessageSender.send(requestMessage, MessageType.SYSTEM_EVENT.name(), messageMetadata);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SystemEventDto in project open-smart-grid-platform by OSGP.
the class SystemEventServiceTest method verifyMaxValueReachedEvent.
@Test
void verifyMaxValueReachedEvent() {
final DlmsDevice device = new DlmsDeviceBuilder().withDeviceIdentification("device-1").withInvocationCounter(this.invocationCounterEventThreshold).build();
final MessageMetadata messageMetadata = new Builder().withIpAddress("127.0-.0.1").withOrganisationIdentification("org-id").withDomain("domain").withDomainVersion("1.0").build();
when(this.correlationIdProviderService.getCorrelationId(messageMetadata.getOrganisationIdentification(), device.getDeviceIdentification())).thenReturn("corr-id");
this.service.verifySystemEventThresholdReachedEvent(device, messageMetadata);
final ArgumentCaptor<MessageMetadata> messageMetadataCaptor = ArgumentCaptor.forClass(MessageMetadata.class);
final ArgumentCaptor<RequestMessage> requestMessageCaptor = ArgumentCaptor.forClass(RequestMessage.class);
verify(this.osgpRequestMessageSender).send(requestMessageCaptor.capture(), eq(MessageType.SYSTEM_EVENT.name()), messageMetadataCaptor.capture());
final RequestMessage requestMessage = requestMessageCaptor.getValue();
assertThat(requestMessage.getDeviceIdentification()).isEqualTo(device.getDeviceIdentification());
assertThat(requestMessage.getCorrelationUid()).isEqualTo("corr-id");
assertThat(requestMessage.getOrganisationIdentification()).isEqualTo(messageMetadata.getOrganisationIdentification());
assertThat(requestMessage.getIpAddress()).isEqualTo(messageMetadata.getIpAddress());
assertThat(requestMessage.getRequest()).isInstanceOf(SystemEventDto.class);
final SystemEventDto systemEventDto = (SystemEventDto) requestMessage.getRequest();
assertThat(systemEventDto.getDeviceIdentification()).isEqualTo(device.getDeviceIdentification());
assertThat(systemEventDto.getSystemEventType()).isEqualTo(SystemEventTypeDto.INVOCATION_COUNTER_THRESHOLD_REACHED);
assertThat(systemEventDto.getTimestamp()).isNotNull();
final MessageMetadata metadata = messageMetadataCaptor.getValue();
assertThat(metadata.getDeviceIdentification()).isEqualTo(device.getDeviceIdentification());
assertThat(metadata.getCorrelationUid()).isEqualTo("corr-id");
assertThat(metadata.getOrganisationIdentification()).isEqualTo(messageMetadata.getOrganisationIdentification());
assertThat(metadata.getIpAddress()).isEqualTo(messageMetadata.getIpAddress());
assertThat(metadata.getMessagePriority()).isEqualTo(MessagePriorityEnum.HIGH.getPriority());
assertThat(metadata.getMessageType()).isEqualTo(MessageType.SYSTEM_EVENT.name());
assertThat(metadata.getDomain()).isEqualTo(messageMetadata.getDomain());
assertThat(metadata.getDomainVersion()).isEqualTo(messageMetadata.getDomainVersion());
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SystemEventDto in project open-smart-grid-platform by OSGP.
the class SystemEventMappingTest method testWithNonEmptyValue.
// is not empty
@Test
void testWithNonEmptyValue() {
// build test data
final String deviceId = "deviceId";
final SystemEventTypeDto systemEventType = SystemEventTypeDto.INVOCATION_COUNTER_THRESHOLD_REACHED;
final Date timestamp = new Date();
final String reason = "reason123";
final SystemEventDto systemEventDto = new SystemEventDto(deviceId, systemEventType, timestamp, reason);
// actual mapping
final SystemEvent systemEvent = this.mapperFactory.getMapperFacade().map(systemEventDto, SystemEvent.class);
// test mapping
assertThat(systemEvent).isNotNull();
assertThat(systemEvent.getDeviceIdentification()).isEqualTo(deviceId);
assertThat(systemEvent.getSystemEventType().name()).isEqualTo(systemEventType.name());
assertThat(systemEvent.getTimestamp()).isEqualTo(timestamp);
assertThat(systemEvent.getReason()).isEqualTo(reason);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SystemEventDto in project open-smart-grid-platform by OSGP.
the class SystemEventMappingTest method testWithNullVariables.
// Test if mapping a SystemEvent object succeeds with null
// variables, although it
@Test
void testWithNullVariables() {
// build test data
final String deviceId = null;
final SystemEventTypeDto systemEventType = null;
final Date timestamp = null;
final String reason = null;
final SystemEventDto systemEventDto = new SystemEventDto(deviceId, systemEventType, timestamp, reason);
// actual mapping
final SystemEvent systemEvent = this.mapperFactory.getMapperFacade().map(systemEventDto, SystemEvent.class);
// test mapping
assertThat(systemEvent).isNotNull();
assertThat(systemEvent.getDeviceIdentification()).isNull();
assertThat(systemEvent.getSystemEventType()).isNull();
assertThat(systemEvent.getTimestamp()).isNull();
assertThat(systemEvent.getReason()).isNull();
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SystemEventDto in project open-smart-grid-platform by OSGP.
the class SystemEventMessageProcessor 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();
final SystemEventDto systemEvent = (SystemEventDto) dataObject;
final RequestMessage request = new RequestMessage(requestMessage.getCorrelationUid(), metadata.getOrganisationIdentification(), requestMessage.getDeviceIdentification(), requestMessage.getIpAddress(), requestMessage.getBaseTransceiverStationId(), requestMessage.getCellId(), systemEvent);
final DomainInfo domainInfo = this.domainInfoRepository.findByDomainAndDomainVersion(metadata.getDomain(), metadata.getDomainVersion());
this.domainRequestService.send(request, DeviceFunction.SYSTEM_EVENT.name(), domainInfo);
}
Aggregations