package com.cloudbees.breizhcamp.domain;

import com.google.common.base.Objects;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;

import javax.annotation.Nullable;
import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * @author: <a hef="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
 */
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE)
public class Talk {

    @Id
    @GeneratedValue
    private long id;

    @JsonProperty("title")
    private String title;

    @Column(name = "abstract")
    @JsonProperty("abstract")
    private String abstract_;

    @Nullable
    @JsonProperty("start")
    private Date start;

    @JsonProperty("duree")
    private int duree;

    @JsonProperty("room")
    public String getRoomName() {
        if (room != null) {
            return room.getName();
        }
        return null;
    }

    @ManyToOne
    private Room room;

    @Enumerated(EnumType.ORDINAL)
    @Column(columnDefinition = "NUMBER")
    @JsonProperty("theme")
    private Theme theme;

    @ManyToMany(mappedBy = "talks", fetch = FetchType.EAGER)
    private final Set<Speaker> speakers = new HashSet<Speaker>();

    public long getId() {
        return id;
    }

    @JsonProperty("speakers")
    public Set<Long> getSpeakersId() {
        Set<Long> speakersId = new HashSet<Long>();
        for (Speaker speaker : speakers) {
            speakersId.add(speaker.getId());
        }
        return speakersId;
    }

    public Set<Speaker> getSpeakers() {
        return speakers;
    }

    public String getAbstract() {
        return abstract_;
    }

    public void setAbstract(String abstract_) {
        this.abstract_ = abstract_;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Date getStart() {
        return start;
    }

    public void setStart(Date start) {
        this.start = start;
    }

    public Room getRoom() {
        return room;
    }

    public void setRoom(Room room) {
        this.room = room;
    }

    public Theme getTheme() {
        return theme;
    }

    public void setTheme(Theme theme) {
        this.theme = theme;
    }

    public int getDuree() {
        return duree;
    }

    public void setDuree(int duree) {
        this.duree = duree;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null) {
            return false;
        }
        if (o instanceof Talk) {
            Talk other = (Talk) o;
            return Objects.equal(other.id, id);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return Objects.toStringHelper(this).add("id", id).add("title", title).add("theme", theme).add("room", room).add("start", start).add("duree", duree).toString();
    }

}

@@ -772,24 +772,39 @@
 = %22abstract%22
+, length = 4000
 )%0A    @JsonP

Passage de la colonne abstract à 4000. (modification de la taille déjà fait en base).