Search in sources :

Example 1 with Type

use of ma.glasnost.orika.metadata.Type 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 Type

use of ma.glasnost.orika.metadata.Type 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)

Aggregations

List (java.util.List)2 Collectors (java.util.stream.Collectors)2 MappingContext (ma.glasnost.orika.MappingContext)2 BidirectionalConverter (ma.glasnost.orika.converter.BidirectionalConverter)2 Type (ma.glasnost.orika.metadata.Type)2 Event (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event)2 EventDetail (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail)2 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 DatatypeFactory (javax.xml.datatype.DatatypeFactory)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 DateTime (org.joda.time.DateTime)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 EventDetailDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto)1 EventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto)1 EventTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventTypeDto)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1