use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto in project open-smart-grid-platform by OSGP.
the class DataObjectToEventListConverterTest method testEventsWithEventDetails.
@Test
void testEventsWithEventDetails() throws ProtocolAdapterException {
// GIVEN
final DateTime dateTime1 = new DateTime(2021, 9, 16, 10, 35, 10, DateTimeZone.UTC);
final DateTime dateTime2 = new DateTime(2021, 9, 17, 11, 22, 45, DateTimeZone.UTC);
final DataObject eventDataObject1 = this.createEventDataObject(dateTime1, 1, 11, 21);
final DataObject eventDataObject2 = this.createEventDataObject(dateTime2, 2, 12, 22);
final String MAGNITUDE = "magnitude";
final String DURATION = "duration";
final DataObject source = DataObject.newArrayData(Arrays.asList(eventDataObject1, eventDataObject2));
final EventDto expectedEvent1 = new EventDto(dateTime1, 1, null, EventLogCategoryDto.POWER_QUALITY_EXTENDED_EVENT_LOG.name());
expectedEvent1.addEventDetail(new EventDetailDto(MAGNITUDE, "1.1 V"));
expectedEvent1.addEventDetail(new EventDetailDto(DURATION, "2.1 s"));
final EventDto expectedEvent2 = new EventDto(dateTime2, 2, null, EventLogCategoryDto.POWER_QUALITY_EXTENDED_EVENT_LOG.name());
expectedEvent2.addEventDetail(new EventDetailDto(MAGNITUDE, "1.2 V"));
expectedEvent2.addEventDetail(new EventDetailDto(DURATION, "2.2 s"));
// WHEN
final List<EventDto> events = this.converter.convert(source, EventLogCategoryDto.POWER_QUALITY_EXTENDED_EVENT_LOG);
// THEN
assertThat(events).usingRecursiveFieldByFieldElementComparator().containsExactly(expectedEvent1, expectedEvent2);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto in project open-smart-grid-platform by OSGP.
the class EventServiceTest method assertEventType.
private void assertEventType(final int eventCode, final String protocol, final EventTypeDto expectedEventTypeDto) throws FunctionalException {
final ProtocolInfo protocolInfo = mock(ProtocolInfo.class);
when(protocolInfo.getProtocol()).thenReturn(protocol);
when(this.smartMeter.getProtocolInfo()).thenReturn(protocolInfo);
final EventDto event = new EventDto(new DateTime(), eventCode, 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(responseDto.getEvents().size()).isOne();
final EventDto eventDto = responseDto.getEvents().get(0);
assertThat(eventDto.getEventTypeDto()).isEqualTo(expectedEventTypeDto);
assertThat(eventDto.getEventCode()).isEqualTo(eventCode);
final List<EventDetailDto> eventDetails = eventDto.getEventDetails();
assertThat(eventDetails.size()).isZero();
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto in project open-smart-grid-platform by OSGP.
the class EventsConverter method convertFrom.
@Override
public EventDto convertFrom(final Event source, final Type<EventDto> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
final EventDto eventDto = new EventDto(source.getTimestamp(), source.getEventCode(), source.getEventCounter(), source.getEventLogCategory().name());
eventDto.setEventTypeDto(EventTypeDto.valueOf(source.getEventType().name()));
for (final EventDetail sourceEventDetail : source.getEventDetails()) {
eventDto.addEventDetail(new EventDetailDto(sourceEventDetail.getName(), sourceEventDetail.getValue()));
}
return eventDto;
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto in project open-smart-grid-platform by OSGP.
the class DataObjectToEventListConverter method extractMagnitudeAndDuration.
private List<EventDetailDto> extractMagnitudeAndDuration(final List<DataObject> eventData) throws ProtocolAdapterException {
final List<EventDetailDto> eventDetails = new ArrayList<>();
this.checkIsNumber(eventData.get(2), MAGNITUDE);
eventDetails.add(new EventDetailDto(MAGNITUDE, this.readValueWithScalerAndUnit(eventData.get(2), BigDecimal.valueOf(0.1), "V")));
this.checkIsNumber(eventData.get(3), DURATION);
eventDetails.add(new EventDetailDto(DURATION, this.readValueWithScalerAndUnit(eventData.get(3), BigDecimal.valueOf(0.1), "s")));
return eventDetails;
}
Aggregations