PollQuestion.java 2.31 KB
package fi.insomnia.bortal.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "poll_question")
public class PollQuestion extends GenericEventChild {

    public PollQuestion() {
        super();
    }

    public PollQuestion(Poll p) {
        super(p.getId());
        this.poll = p;

    }

    /**
     * 
     */
    private static final long serialVersionUID = 821112669474215823L;

    @JoinColumns({
            @JoinColumn(name = "poll_id", referencedColumnName = "id", nullable = false),
            @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
    @ManyToOne
    private Poll poll;

    @OneToMany(mappedBy = "question", cascade = CascadeType.ALL)
    private List<PossibleAnswer> answers = new ArrayList<PossibleAnswer>();

    @Lob
    private String question;
    @Column(nullable = false)
    private Integer choices = 1;
    @Column(nullable = false)
    private Integer sort = 100;
    @Column(nullable = false)
    private Integer page = 1;

    public String getQuestion() {
        return question;
    }

    public boolean isFreeText() {
        return (answers.size() == 1 && answers.get(0).isText());
    }

    public void setQuestion(String question) {
        this.question = question;
    }

    public Integer getChoices() {
        return choices;
    }

    public void setChoices(Integer choices) {
        this.choices = choices;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Poll getPoll() {
        return poll;
    }

    public void setPoll(Poll poll) {
        this.poll = poll;
    }

    public List<PossibleAnswer> getAnswers() {
        return answers;
    }

    public void setAnswers(List<PossibleAnswer> answers) {
        this.answers = answers;
    }

}