// Path: src/main/java/org/nextrtc/examples/videochat_with_rest/domain/Conversation.java
// @Entity
// @Table(name = "Conversations")
// public class Conversation {
// 
//     @Id
//     @GeneratedValue(strategy = GenerationType.AUTO)
//     @Column(name = "conversation_id")
//     private int id;
// 
//     @Column(name = "conversation_name")
//     private String conversationName;
// 
//     @Column(name = "created")
//     private Date created;
// 
//     @Column(name = "destroyed")
//     private Date destroyed;
// 
//     @OneToMany(mappedBy = "conversation", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
//     private Set<Connection> connections;
// 
//     @Deprecated
//     Conversation() {
//     }
// 
//     public Conversation(String conversationName) {
//         this.conversationName = conversationName;
//         created = now().toDate();
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("(%s)[%s - %s]", conversationName, created, destroyed);
//     }
// 
//     public void destroy() {
//         destroyed = now().toDate();
//         connections.stream()
//                 .filter(Connection::isClosed)
//                 .forEach(Connection::close);
//     }
// 
//     public void join(Member member) {
//         connections.add(new Connection(this, member));
//     }
// 
//     public boolean equals(Object o) {
//         if (o == this) return true;
//         if (!(o instanceof Conversation)) return false;
//         final Conversation other = (Conversation) o;
//         return other.id == id;
//     }
// 
//     public int hashCode() {
//         return id;
//     }
// 
//     public Set<Connection> getConnections() {
//         return connections;
//     }
// }
// 
// Path: src/main/java/org/nextrtc/examples/videochat_with_rest/domain/handler/common/ConversationHandler.java
// public abstract class ConversationHandler implements NextRTCHandler {
// 
//     @Override
//     public final void handleEvent(NextRTCEvent event) {
//         event.conversation().ifPresent(conversation -> handleEvent(conversation, event));
//     }
// 
//     protected abstract void handleEvent(NextRTCConversation conversation, NextRTCEvent event);
// }
// 
// Path: src/main/java/org/nextrtc/examples/videochat_with_rest/repo/ConversationRepository.java
// @Repository
// @Transactional
// public interface ConversationRepository extends JpaRepository<Conversation, Integer> {
// 
//     @Query("select c from Conversation c where c.destroyed is null and c.conversationName = :conversationName")
//     Conversation getByConversationName(@Param("conversationName") String conversationName);
// }


import org.apache.log4j.Logger;
import org.nextrtc.examples.videochat_with_rest.domain.Conversation;
import org.nextrtc.examples.videochat_with_rest.domain.handler.common.ConversationHandler;
import org.nextrtc.examples.videochat_with_rest.repo.ConversationRepository;
import org.nextrtc.signalingserver.api.annotation.NextRTCEventListener;
import org.nextrtc.signalingserver.api.dto.NextRTCConversation;
import org.nextrtc.signalingserver.api.dto.NextRTCEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import static org.nextrtc.signalingserver.api.NextRTCEvents.CONVERSATION_CREATED;
package org.nextrtc.examples.videochat_with_rest.domain.handler;



@Component
@NextRTCEventListener(CONVERSATION_CREATED)
public class ConversationCreatedHandler extends ConversationHandler {

    private static final Logger log = Logger.getLogger(ConversationCreatedHandler.class);
    @Autowired
    private ConversationRepository repo;

    @Override
    protected void handleEvent(NextRTCConversation rtcConversation, NextRTCEvent event) {
// Path: src/main/java/org/nextrtc/examples/videochat_with_rest/domain/Conversation.java
// @Entity
// @Table(name = "Conversations")
// public class Conversation {
// 
//     @Id
//     @GeneratedValue(strategy = GenerationType.AUTO)
//     @Column(name = "conversation_id")
//     private int id;
// 
//     @Column(name = "conversation_name")
//     private String conversationName;
// 
//     @Column(name = "created")
//     private Date created;
// 
//     @Column(name = "destroyed")
//     private Date destroyed;
// 
//     @OneToMany(mappedBy = "conversation", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
//     private Set<Connection> connections;
// 
//     @Deprecated
//     Conversation() {
//     }
// 
//     public Conversation(String conversationName) {
//         this.conversationName = conversationName;
//         created = now().toDate();
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("(%s)[%s - %s]", conversationName, created, destroyed);
//     }
// 
//     public void destroy() {
//         destroyed = now().toDate();
//         connections.stream()
//                 .filter(Connection::isClosed)
//                 .forEach(Connection::close);
//     }
// 
//     public void join(Member member) {
//         connections.add(new Connection(this, member));
//     }
// 
//     public boolean equals(Object o) {
//         if (o == this) return true;
//         if (!(o instanceof Conversation)) return false;
//         final Conversation other = (Conversation) o;
//         return other.id == id;
//     }
// 
//     public int hashCode() {
//         return id;
//     }
// 
//     public Set<Connection> getConnections() {
//         return connections;
//     }
// }
// 
// Path: src/main/java/org/nextrtc/examples/videochat_with_rest/domain/handler/common/ConversationHandler.java
// public abstract class ConversationHandler implements NextRTCHandler {
// 
//     @Override
//     public final void handleEvent(NextRTCEvent event) {
//         event.conversation().ifPresent(conversation -> handleEvent(conversation, event));
//     }
// 
//     protected abstract void handleEvent(NextRTCConversation conversation, NextRTCEvent event);
// }
// 
// Path: src/main/java/org/nextrtc/examples/videochat_with_rest/repo/ConversationRepository.java
// @Repository
// @Transactional
// public interface ConversationRepository extends JpaRepository<Conversation, Integer> {
// 
//     @Query("select c from Conversation c where c.destroyed is null and c.conversationName = :conversationName")
//     Conversation getByConversationName(@Param("conversationName") String conversationName);
// }


// Path: src/main/java/org/nextrtc/examples/videochat_with_rest/domain/handler/ConversationCreatedHandler.java
import org.apache.log4j.Logger;
import org.nextrtc.examples.videochat_with_rest.domain.Conversation;
import org.nextrtc.examples.videochat_with_rest.domain.handler.common.ConversationHandler;
import org.nextrtc.examples.videochat_with_rest.repo.ConversationRepository;
import org.nextrtc.signalingserver.api.annotation.NextRTCEventListener;
import org.nextrtc.signalingserver.api.dto.NextRTCConversation;
import org.nextrtc.signalingserver.api.dto.NextRTCEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import static org.nextrtc.signalingserver.api.NextRTCEvents.CONVERSATION_CREATED;

package org.nextrtc.examples.videochat_with_rest.domain.handler;



@Component
@NextRTCEventListener(CONVERSATION_CREATED)
public class ConversationCreatedHandler extends ConversationHandler {

    private static final Logger log = Logger.getLogger(ConversationCreatedHandler.class);
    @Autowired
    private ConversationRepository repo;

    @Override
    protected void handleEvent(NextRTCConversation rtcConversation, NextRTCEvent event) {
        Conversation conversation = repo.getByConversationName(rtcConversation.getId());