package models;

import javax.persistence.*;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = "messages")
public class Message {
    @Id
    @GeneratedValue
    @Column(name = "message_id", nullable = false)
    private long id;

    @ManyToOne(fetch = FetchType.LAZY)
    private Message parent;

    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<Message> comments = new ArrayList<>();

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    private Person author;

    @Temporal(TemporalType.TIMESTAMP)
    @Column
    @Past
    private Date timestamp;

    @Column(length = 10000)
    private String body;

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name = "tags",
            joinColumns = {@JoinColumn(name = "message_id")},
            inverseJoinColumns = {@JoinColumn(name = "person_id")}
    )
    private List<Person> tags = new ArrayList<>();

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name = "upvotes",
            joinColumns = {@JoinColumn(name = "message_id")},
            inverseJoinColumns = {@JoinColumn(name = "person_id")}
    )
    private List<Person> upvotes = new ArrayList<>();

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name = "message_attachments",
            joinColumns = {@JoinColumn(name = "message_id")},
            inverseJoinColumns = {@JoinColumn(name = "person_id")}
    )
    private List<Person> messageAttachment = new ArrayList<>();

    public long getId() {
        return id;
    }

    public Message getParent() {
        return parent;
    }

    public void setParent(Message parent) {
        this.parent = parent;
    }

    public List<Message> getComments() {
        return comments;
    }

    public Person getAuthor() {
        return author;
    }

    public void setAuthor(Person author) {
        this.author = author;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public List<Person> getTags() {
        return tags;
    }
}

@@ -10,16 +10,87 @@
 odels;%0A%0A
+import modules.preloader.DatabasePreloader;%0Aimport utils.SimpleQuery;%0A%0A
 import j
@@ -166,37 +166,44 @@
 java
-x.validation.constraints.Size
+.sql.Time;%0Aimport java.sql.Timestamp
 ;%0Aim
@@ -273,16 +273,188 @@
 il.List;
+%0Aimport java.util.Random;%0A%0Aimport static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;%0Aimport static org.apache.commons.lang3.text.WordUtils.capitalizeFully;
 %0A%0A@Entit
@@ -2664,11 +2664,1388 @@
 s;%0A    %7D
+%0A%0A    static %7B%0A        DatabasePreloader.addTest((em -%3E %7B%0A            for (int i = 0; i %3C 100; i++) %7B%0A                Message message = new Message();%0A                List%3CPerson%3E people = (new SimpleQuery(em, Person.class)).getResultList();%0A                int random = new Random().nextInt(people.size());%0A                Person author = people.get(random);%0A                message.setAuthor(author);%0A                message.setParent(message);%0A                Timestamp timestamp = new Timestamp(System.currentTimeMillis());%0A                long offset = Timestamp.valueOf(%222012-01-01 00:00:00%22).getTime();%0A                long end = timestamp.getTime();%0A                long diff = end - offset + 1;%0A                Timestamp rand = new Timestamp(offset + (long)(Math.random() * diff));%0A                message.setTimestamp(rand);%0A                int blanks = new Random().nextInt(10) + 1;%0A                StringBuilder body = new StringBuilder();%0A                for(int j = 0; j %3C= blanks; j++)%7B%0A                    Random randomLength = new Random();%0A                    int length = randomLength.nextInt(15) + 1;%0A                    body.append(capitalizeFully(randomAlphabetic(length)));%0A                    body.append(%22 %22);%0A                %7D%0A                message.setBody(body.toString());%0A                em.persist(message);%0A            %7D%0A        %7D), 50);%0A%0A    %7D
 %0A%7D%0A

Add generator in Message module