use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail 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.domain.core.valueobjects.smartmetering.EventDetail in project open-smart-grid-platform by OSGP.
the class EventConverter method convertFrom.
@Override
public Event convertFrom(final org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Event source, final Type<Event> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
final DateTime timestamp = new DateTime(source.getTimestamp().toGregorianCalendar().getTime());
final org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventLogCategory eventLogCategory = org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventLogCategory.fromValue(source.getEventLogCategory().value());
final org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventType eventType = org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventType.fromValue(source.getEventType().value());
final List<EventDetail> eventDetails = source.getEventDetails().stream().map(sourceEventDetail -> new EventDetail(sourceEventDetail.getName(), sourceEventDetail.getValue())).collect(Collectors.toList());
return new Event(timestamp, eventType, source.getEventCounter(), eventLogCategory, eventDetails);
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail in project open-smart-grid-platform by OSGP.
the class EventConverter method convertTo.
@Override
public org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Event convertTo(final Event source, final Type<org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Event> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
try {
final XMLGregorianCalendar timestamp = DatatypeFactory.newInstance().newXMLGregorianCalendar(source.getTimestamp().toGregorianCalendar());
final org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Event event = new org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Event();
event.setEventCode(source.getEventCode());
event.setEventType(EventType.fromValue(source.getEventType().name()));
event.setTimestamp(timestamp);
event.setEventCounter(source.getEventCounter());
event.setEventLogCategory(EventLogCategory.fromValue(source.getEventLogCategory().name()));
for (final EventDetail sourceEventDetail : source.getEventDetails()) {
final org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.EventDetail eventDetail = new org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.EventDetail();
eventDetail.setName(sourceEventDetail.getName());
eventDetail.setValue(sourceEventDetail.getValue());
event.getEventDetails().add(eventDetail);
}
return event;
} catch (final DatatypeConfigurationException e) {
LOGGER.error("DatatypeConfigurationException", e);
}
return null;
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail in project open-smart-grid-platform by OSGP.
the class ListEventMappingTest method testFilledListEventMapping.
/**
* Tests if mapping a List, typed to Event, succeeds if the List is filled.
*/
@Test
void testFilledListEventMapping() {
// build test data
final DateTime timestamp = new DateTime();
final List<EventDetail> eventDetails = Collections.singletonList(new EventDetail("A", "B"));
final Event event = new Event(timestamp, EVENT_TYPE, EVENT_COUNTER, EventLogCategory.STANDARD_EVENT_LOG, eventDetails);
final List<Event> listOriginal = new ArrayList<>();
listOriginal.add(event);
// actual mapping
final List<org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Event> listMapped = this.managementMapper.mapAsList(listOriginal, org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Event.class);
// check mapping
assertThat(listMapped).isNotNull();
assertThat(listMapped.get(0)).isNotNull();
assertThat(listMapped.get(0).getEventCounter()).isNotNull();
assertThat(listMapped.get(0).getEventType()).isNotNull();
assertThat(listMapped.get(0).getTimestamp()).isNotNull();
assertThat(listMapped.get(0).getEventLogCategory()).isNotNull();
assertThat(listMapped.get(0).getTimestamp().getYear()).isEqualTo(timestamp.getYear());
assertThat(listMapped.get(0).getTimestamp().getMonth()).isEqualTo(timestamp.getMonthOfYear());
assertThat(listMapped.get(0).getTimestamp().getDay()).isEqualTo(timestamp.getDayOfMonth());
assertThat(listMapped.get(0).getTimestamp().getHour()).isEqualTo(timestamp.getHourOfDay());
assertThat(listMapped.get(0).getTimestamp().getMinute()).isEqualTo(timestamp.getMinuteOfHour());
assertThat(listMapped.get(0).getTimestamp().getSecond()).isEqualTo(timestamp.getSecondOfMinute());
assertThat(listMapped.get(0).getEventType().name()).isEqualTo(EVENT_TYPE.name());
assertThat(listMapped.get(0).getEventCode()).isEqualTo(EVENT_TYPE.getEventCode());
assertThat(listMapped.get(0).getEventCounter()).isEqualTo(EVENT_COUNTER);
assertThat(listMapped.get(0).getEventLogCategory()).isEqualTo(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.EventLogCategory.STANDARD_EVENT_LOG);
assertThat(listMapped.get(0).getEventDetails().size()).isOne();
final org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.EventDetail eventDetail = listMapped.get(0).getEventDetails().get(0);
assertThat(eventDetail.getName()).isEqualTo("A");
assertThat(eventDetail.getValue()).isEqualTo("B");
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail 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;
}
Aggregations