// Path: axon-eventstore/lib/src/main/java/de/qyotta/axonframework/eventstore/utils/EsEventStoreUtils.java
// @UtilityClass
// @SuppressWarnings("nls")
// public final class EsEventStoreUtils {
//    private static final Type METADATA_TYPE = new TypeToken<Map<String, ?>>() {
//       //
//    }.getType();
// 
//    public static final String getStreamName(final String type, final Object identifier, final String prefix) {
//       return prefix + "-" + type.toLowerCase() + "-" + identifier.toString();
//    }
// 
//    @SuppressWarnings({ "rawtypes", "unchecked" })
//    public static DomainEventMessage domainEventMessageOf(final EventResponse eventResponse) {
//       try {
//          final Gson gson = createGson();
//          final Class<?> payloadType = Class.forName(eventResponse.getContent()
//                .getEventType());
//          final Object payload = gson.fromJson(eventResponse.getContent()
//                .getData(), payloadType);
// 
//          final Map<String, ?> metaData = gson.fromJson(eventResponse.getContent()
//                .getMetadata(), METADATA_TYPE);
// 
//          final Map<String, ?> eventMetadata = (Map<String, ?>) metaData.get(Constants.EVENT_METADATA_KEY);
//          return new GenericDomainEventMessage(eventResponse.getTitle(), new DateTime(eventResponse.getUpdated(), DateTimeZone.UTC), metaData.get(Constants.AGGREGATE_ID_KEY), eventResponse.getContent()
//                .getEventNumber(), payload, new MetaData(eventMetadata));
//       } catch (final ClassNotFoundException e) {
//          throw new RuntimeException(e);
//       }
// 
//    }
// 
//    private static Gson createGson() {
//       //// final RuntimeTypeAdapterFactory<Entity> typeFactory = RuntimeTypeAdapterFactory.of(Entity.class, "type")
//       //// .registerSubtype(UserEntity.class);
//       // final Gson gson = new GsonBuilder().registerTypeAdapterFactory(typeFactory)
//       // .create();
//       // return gson;
//       return new Gson();
//    }
// 
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/EventStream.java
// public interface EventStream {
// 
//    boolean hasNext();
// 
//    EventResponse next();
// 
//    EventResponse peek();
// 
//    void setAfterTimestamp(final Date timestamp);
// 
//    void setAfterTitle(final String eventId);
// 
//    /**
//     * Attempts to load the next event in the stream from the current point. If the next event was already loaded this method does nothing. This method is only useful after hasNext returned false.
//     * After this method has been called use hasNext to check whether a new event arrived.
//     */
//    void loadNext();
// 
// }


import org.axonframework.domain.DomainEventMessage;
import org.axonframework.domain.DomainEventStream;
import de.qyotta.axonframework.eventstore.utils.EsEventStoreUtils;
import de.qyotta.eventstore.EventStream;
package de.qyotta.axonframework.eventstore;



@SuppressWarnings({ "rawtypes" })
public class EsEventStreamBackedDomainEventStream implements DomainEventStream {

// Path: axon-eventstore/lib/src/main/java/de/qyotta/axonframework/eventstore/utils/EsEventStoreUtils.java
// @UtilityClass
// @SuppressWarnings("nls")
// public final class EsEventStoreUtils {
//    private static final Type METADATA_TYPE = new TypeToken<Map<String, ?>>() {
//       //
//    }.getType();
// 
//    public static final String getStreamName(final String type, final Object identifier, final String prefix) {
//       return prefix + "-" + type.toLowerCase() + "-" + identifier.toString();
//    }
// 
//    @SuppressWarnings({ "rawtypes", "unchecked" })
//    public static DomainEventMessage domainEventMessageOf(final EventResponse eventResponse) {
//       try {
//          final Gson gson = createGson();
//          final Class<?> payloadType = Class.forName(eventResponse.getContent()
//                .getEventType());
//          final Object payload = gson.fromJson(eventResponse.getContent()
//                .getData(), payloadType);
// 
//          final Map<String, ?> metaData = gson.fromJson(eventResponse.getContent()
//                .getMetadata(), METADATA_TYPE);
// 
//          final Map<String, ?> eventMetadata = (Map<String, ?>) metaData.get(Constants.EVENT_METADATA_KEY);
//          return new GenericDomainEventMessage(eventResponse.getTitle(), new DateTime(eventResponse.getUpdated(), DateTimeZone.UTC), metaData.get(Constants.AGGREGATE_ID_KEY), eventResponse.getContent()
//                .getEventNumber(), payload, new MetaData(eventMetadata));
//       } catch (final ClassNotFoundException e) {
//          throw new RuntimeException(e);
//       }
// 
//    }
// 
//    private static Gson createGson() {
//       //// final RuntimeTypeAdapterFactory<Entity> typeFactory = RuntimeTypeAdapterFactory.of(Entity.class, "type")
//       //// .registerSubtype(UserEntity.class);
//       // final Gson gson = new GsonBuilder().registerTypeAdapterFactory(typeFactory)
//       // .create();
//       // return gson;
//       return new Gson();
//    }
// 
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/EventStream.java
// public interface EventStream {
// 
//    boolean hasNext();
// 
//    EventResponse next();
// 
//    EventResponse peek();
// 
//    void setAfterTimestamp(final Date timestamp);
// 
//    void setAfterTitle(final String eventId);
// 
//    /**
//     * Attempts to load the next event in the stream from the current point. If the next event was already loaded this method does nothing. This method is only useful after hasNext returned false.
//     * After this method has been called use hasNext to check whether a new event arrived.
//     */
//    void loadNext();
// 
// }


// Path: axon-eventstore/lib/src/main/java/de/qyotta/axonframework/eventstore/EsEventStreamBackedDomainEventStream.java
import org.axonframework.domain.DomainEventMessage;
import org.axonframework.domain.DomainEventStream;
import de.qyotta.axonframework.eventstore.utils.EsEventStoreUtils;
import de.qyotta.eventstore.EventStream;

package de.qyotta.axonframework.eventstore;



@SuppressWarnings({ "rawtypes" })
public class EsEventStreamBackedDomainEventStream implements DomainEventStream {

   private final EventStream eventStream;