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());
}
}
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);
}
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;
}
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;
}
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);
}
Aggregations