use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.
the class ManagementService method findEvents.
// === FIND EVENTS ===
public EventMessageDataResponseDto findEvents(final DlmsConnectionManager conn, final DlmsDevice device, final FindEventsRequestList findEventsQueryMessageDataContainer, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final List<EventDto> events = new ArrayList<>();
log.info("findEvents setting up connection with meter {}", device.getDeviceIdentification());
for (final FindEventsRequestDto findEventsQuery : findEventsQueryMessageDataContainer.getFindEventsQueryList()) {
log.info("findEventsQuery.eventLogCategory: {}, findEventsQuery.from: {}, findEventsQuery.until: {}", findEventsQuery.getEventLogCategory().toString(), findEventsQuery.getFrom(), findEventsQuery.getUntil());
events.addAll(this.findEventsCommandExecutor.execute(conn, device, findEventsQuery, messageMetadata));
}
return new EventMessageDataResponseDto(events);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.
the class EventService method enrichEvents.
public void enrichEvents(final MessageMetadata deviceMessageMetadata, final EventMessageDataResponseDto responseDto) throws FunctionalException {
LOGGER.info("Enrich EventMessageDataResponse with EventTypes for device: {}", deviceMessageMetadata.getDeviceIdentification());
final SmartMeter smartMeter = this.domainHelperService.findSmartMeter(deviceMessageMetadata.getDeviceIdentification());
for (final EventDto eventDto : responseDto.getEvents()) {
final String protocolName = smartMeter.getProtocolInfo() != null ? smartMeter.getProtocolInfo().getProtocol() : null;
final EventTypeDto eventTypeDto = this.determineEventType(eventDto, protocolName);
eventDto.setEventTypeDto(eventTypeDto);
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.
the class EventServiceTest method testWrongEventCode.
@Test
void testWrongEventCode() {
final FunctionalException functionalException = Assertions.assertThrows(FunctionalException.class, () -> {
final ProtocolInfo protocolInfo = mock(ProtocolInfo.class);
when(protocolInfo.getProtocol()).thenReturn("SMR");
when(this.smartMeter.getProtocolInfo()).thenReturn(protocolInfo);
final EventDto event = new EventDto(new DateTime(), 266, 2, "STANDARD_EVENT_LOG");
final ArrayList<EventDto> events = new ArrayList<>();
events.add(event);
final EventMessageDataResponseDto responseDto = new EventMessageDataResponseDto(events);
this.eventService.enrichEvents(this.deviceMessageMetadata, responseDto);
});
assertThat(functionalException.getExceptionType()).isEqualTo(FunctionalExceptionType.VALIDATION_ERROR);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.
the class EventsConverter method convertTo.
@Override
public Event convertTo(final EventDto source, final Type<Event> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
final EventType eventType = EventType.valueOf(source.getEventTypeDto().name());
final List<EventDetail> eventDetails = source.getEventDetails().stream().map(sourceDetail -> new EventDetail(sourceDetail.getName(), sourceDetail.getValue())).collect(Collectors.toList());
return new Event(source.getTimestamp(), eventType, source.getEventCounter(), EventLogCategory.fromValue(source.getEventLogCategoryName()), eventDetails);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.
the class FindEventsCommandExecutorTest method testRetrievalOfAuxiliaryLogEvents.
@Test
void testRetrievalOfAuxiliaryLogEvents() throws ProtocolAdapterException, IOException {
// SETUP
this.findEventsRequestDto = new FindEventsRequestDto(EventLogCategoryDto.AUXILIARY_EVENT_LOG, DateTime.now().minusDays(70), DateTime.now());
when(this.getResult.getResultCode()).thenReturn(AccessResultCode.SUCCESS);
when(this.getResult.getResultData()).thenReturn(this.resultData);
when(this.resultData.getValue()).thenReturn(this.generateDataObjectsAuxiliary());
// CALL
final List<EventDto> events = this.executor.execute(this.conn, this.DLMS_DEVICE_5_1, this.findEventsRequestDto, this.messageMetadata);
// VERIFY
assertThat(events.size()).isEqualTo(34);
int firstEventCode = 33664;
for (final EventDto event : events) {
assertThat(event.getEventCode()).isEqualTo(firstEventCode++);
}
verify(this.dlmsHelper, times(events.size())).convertDataObjectToDateTime(any(DataObject.class));
verify(this.conn).getDlmsMessageListener();
verify(this.conn).getConnection();
verify(this.dlmsConnection).get(any(AttributeAddress.class));
}
Aggregations