Search in sources :

Example 1 with EventDetailDto

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);
}
Also used : EventDetailDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 2 with EventDetailDto

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();
}
Also used : EventDetailDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) ArrayList(java.util.ArrayList) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) EventMessageDataResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto) DateTime(org.joda.time.DateTime)

Example 3 with EventDetailDto

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;
}
Also used : EventDetailDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) EventDetail(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail)

Example 4 with EventDetailDto

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;
}
Also used : EventDetailDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto) ArrayList(java.util.ArrayList)

Aggregations

EventDetailDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto)4 EventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto)3 ArrayList (java.util.ArrayList)2 DateTime (org.joda.time.DateTime)2 Test (org.junit.jupiter.api.Test)1 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 ProtocolInfo (org.opensmartgridplatform.domain.core.entities.ProtocolInfo)1 EventDetail (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail)1 EventMessageDataResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto)1