Search in sources :

Example 1 with EventDetail

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);
}
Also used : BidirectionalConverter(ma.glasnost.orika.converter.BidirectionalConverter) EventLogCategory(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventLogCategory) EventType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventType) List(java.util.List) EventDetailDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto) Type(ma.glasnost.orika.metadata.Type) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) EventDetail(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail) Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event) EventTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventTypeDto) Collectors(java.util.stream.Collectors) MappingContext(ma.glasnost.orika.MappingContext) EventType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventType) Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event) EventDetail(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail)

Example 2 with EventDetail

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);
}
Also used : BidirectionalConverter(ma.glasnost.orika.converter.BidirectionalConverter) Logger(org.slf4j.Logger) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Type(ma.glasnost.orika.metadata.Type) DateTime(org.joda.time.DateTime) LoggerFactory(org.slf4j.LoggerFactory) Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event) DatatypeFactory(javax.xml.datatype.DatatypeFactory) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Collectors(java.util.stream.Collectors) MappingContext(ma.glasnost.orika.MappingContext) List(java.util.List) EventLogCategory(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.EventLogCategory) EventType(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.EventType) EventDetail(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail) Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event) EventDetail(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail) DateTime(org.joda.time.DateTime)

Example 3 with EventDetail

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;
}
Also used : EventDetail(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event)

Example 4 with EventDetail

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");
}
Also used : ArrayList(java.util.ArrayList) EventDetail(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail) DateTime(org.joda.time.DateTime) Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event) Test(org.junit.jupiter.api.Test)

Example 5 with EventDetail

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

Aggregations

EventDetail (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail)5 Event (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event)4 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 MappingContext (ma.glasnost.orika.MappingContext)2 BidirectionalConverter (ma.glasnost.orika.converter.BidirectionalConverter)2 Type (ma.glasnost.orika.metadata.Type)2 DateTime (org.joda.time.DateTime)2 EventDetailDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto)2 EventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto)2 ArrayList (java.util.ArrayList)1 DatatypeFactory (javax.xml.datatype.DatatypeFactory)1 Test (org.junit.jupiter.api.Test)1 EventLogCategory (org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.EventLogCategory)1 EventType (org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.EventType)1 EventLogCategory (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventLogCategory)1 EventType (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventType)1 EventTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventTypeDto)1