use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto 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.EventDto 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.EventDto in project open-smart-grid-platform by OSGP.
the class DataObjectToEventListConverter method convert.
public List<EventDto> convert(final DataObject source, final EventLogCategoryDto eventLogCategory) throws ProtocolAdapterException {
final List<EventDto> eventList = new ArrayList<>();
if (source == null) {
throw new ProtocolAdapterException("DataObject should not be null");
}
final List<DataObject> listOfEvents = source.getValue();
for (final DataObject eventDataObject : listOfEvents) {
eventList.add(this.getEvent(eventDataObject, eventLogCategory));
}
return eventList;
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.
the class DataObjectToEventListConverter method getEvent.
private EventDto getEvent(final DataObject eventDataObject, final EventLogCategoryDto eventLogCategory) throws ProtocolAdapterException {
final List<DataObject> eventData = eventDataObject.getValue();
if (eventData == null) {
throw new ProtocolAdapterException("eventData DataObject should not be null");
}
final int numberOfEventElements = eventLogCategory.getDetailsType().getNumberOfEventElements();
if (eventData.size() != numberOfEventElements) {
throw new ProtocolAdapterException("eventData size should be " + numberOfEventElements);
}
// extract values from List<DataObject> eventData.
final DateTime dateTime = this.extractDateTime(eventData);
final Integer code = this.extractCode(eventData);
final Integer eventCounter = this.extractEventCounter(eventLogCategory, eventData);
final String eventLogCategoryName = eventLogCategory.name();
log.info("Event time is {}, event code is {}, event category is {} and event counter is {}", dateTime, code, eventLogCategoryName, eventCounter);
// build a new EventDto with those values.
final EventDto event = new EventDto(dateTime, code, eventCounter, eventLogCategoryName);
// add details
event.addEventDetails(this.extractEventDetails(eventLogCategory, eventData));
return event;
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.
the class FindEventsCommandExecutorTest method testRetrievalOfPowerQualityEvents.
@Test
void testRetrievalOfPowerQualityEvents() throws ProtocolAdapterException, IOException {
// SETUP
when(this.getResult.getResultCode()).thenReturn(AccessResultCode.SUCCESS);
when(this.getResult.getResultData()).thenReturn(this.resultData);
when(this.resultData.getValue()).thenReturn(this.generateDataObjects());
// CALL
final List<EventDto> events = this.executor.execute(this.conn, this.DLMS_DEVICE_5_1, this.findEventsRequestDto, this.messageMetadata);
// VERIFY
assertThat(events.size()).isEqualTo(13);
int firstEventCode = 77;
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