Search in sources :

Example 1 with Event

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event in project open-smart-grid-platform by OSGP.

the class ListEventMappingTest method checkEventsMappedToWsSchema.

private void checkEventsMappedToWsSchema(final List<Event> originalEvents, final List<org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Event> mappedEvents) {
    assertThat(mappedEvents.size()).as(NUMBER_OF_EVENTS).isEqualTo(originalEvents.size());
    for (int i = 0; i < originalEvents.size(); i++) {
        final Event originalEvent = originalEvents.get(i);
        final org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Event mappedEvent = mappedEvents.get(i);
        assertThat(EventType.valueOf(mappedEvent.getEventType().name()).getEventCode()).as(EVENT_CODE_WITH_MAPPING_OF + originalEvent).isEqualTo(originalEvent.getEventCode().intValue());
        assertThat(mappedEvent.getEventCounter()).as(EVENT_COUNTER_WITH_MAPPING_OF + originalEvent).isEqualTo(originalEvent.getEventCounter());
        assertThat(new DateTime(mappedEvent.getTimestamp().toGregorianCalendar())).as(TIMESTAMP_WITH_MAPPING_OF + originalEvent).isEqualByComparingTo(originalEvent.getTimestamp());
    }
}
Also used : Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event) DateTime(org.joda.time.DateTime)

Example 2 with Event

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event 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 3 with Event

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event in project open-smart-grid-platform by OSGP.

the class EventMessageDataContainerConverter method convert.

@Override
public FindEventsResponseData convert(final EventMessagesResponse source, final Type<? extends FindEventsResponseData> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    final org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.FindEventsResponseData response = new org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.FindEventsResponseData();
    for (final Event event : source.getEvents()) {
        final org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Event eventResponse = this.mapperFacade.map(event, org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.Event.class);
        response.getEvents().add(eventResponse);
    }
    return response;
}
Also used : FindEventsResponseData(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.FindEventsResponseData) Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event) FindEventsResponseData(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.FindEventsResponseData)

Example 4 with Event

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event in project open-smart-grid-platform by OSGP.

the class ManagementService method findEventsByCorrelationUid.

public List<Event> findEventsByCorrelationUid(final String organisationIdentification, final String correlationUid) throws OsgpException {
    log.info("findEventsByCorrelationUid called with organisation {}}", organisationIdentification);
    this.domainHelperService.findOrganisation(organisationIdentification);
    final ResponseData responseData = this.responseDataRepository.findByCorrelationUid(correlationUid);
    final List<Event> events = new ArrayList<>();
    final Serializable messageData = responseData.getMessageData();
    if (messageData instanceof EventMessagesResponse) {
        events.addAll(((EventMessagesResponse) messageData).getEvents());
        log.info("deleting ResponseData for correlation uid {}.", correlationUid);
        this.responseDataRepository.delete(responseData);
    } else {
        /**
         * If the returned data is not an EventMessageContainer but a String, there has been an
         * exception. The exception message has been put in the messageData.
         *
         * <p>As there is no way of knowing what the type of the exception was (because it is passed
         * as a String) it is thrown as a TechnicalException because the user is most probably not to
         * blame for the exception.
         */
        if (messageData instanceof String) {
            throw new TechnicalException(ComponentType.UNKNOWN, (String) messageData);
        }
        log.info("findEventsByCorrelationUid found other type of meter response data: {} for correlation UID: {}", messageData.getClass().getName(), correlationUid);
    }
    log.info("returning a list containing {} events", events.size());
    return events;
}
Also used : Serializable(java.io.Serializable) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) ArrayList(java.util.ArrayList) Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event) EventMessagesResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse)

Example 5 with Event

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event 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

Event (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event)9 DateTime (org.joda.time.DateTime)4 EventDetail (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail)4 ArrayList (java.util.ArrayList)2 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 Serializable (java.io.Serializable)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 DatatypeFactory (javax.xml.datatype.DatatypeFactory)1 Test (org.junit.jupiter.api.Test)1 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)1 EventLogCategory (org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.EventLogCategory)1 EventType (org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.EventType)1 FindEventsResponse (org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.FindEventsResponse)1 FindEventsResponseData (org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.FindEventsResponseData)1