CompoEntry.java 3.59 KB
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fi.codecrew.moya.model;

import java.util.Calendar;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 
 */
@Entity
@Table(name = "compo_entries")
public class CompoEntry extends GenericEntity {
	private static final long serialVersionUID = 2L;

	@JoinColumn(name = "compo_id", referencedColumnName = "id", nullable = false)
	@ManyToOne(optional = false)
	private Compo compo;

	@Column(name = "entry_created", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Calendar created = Calendar.getInstance();

	@Column(name = "title", nullable = false)
	private String title = "";

	@Column(name = "author")
	private String author = "";

	@Lob
	@Column(name = "notes")
	private String notes = "";

	@Lob
	@Column(name = "screen_message")
	private String screenMessage = "";

	@Column(name = "sort")
	private Integer sort = 10;

	@Column(name = "final_position")
	private Integer finalPosition;

	@JoinColumn(name = "current_file_id", referencedColumnName = CompoEntryFile.ID_COLUMN)
	@OneToOne
	private CompoEntryFile currentFile;

	@OneToMany(mappedBy = "compoEntry")
	private List<Vote> votes;
	//
	// @PrivateOwned
	// @OneToMany(cascade = CascadeType.ALL, mappedBy = "entry", fetch =
	// FetchType.LAZY)
	// private List<CompoEntryFile> files;

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "entry")
	private List<CompoEntryParticipant> participants;

	@JoinColumn(name = "creator_eventuser_id", referencedColumnName = EventUser.ID_COLUMN, nullable = false)
	@ManyToOne
	private EventUser creator;

	public Integer getVotetotal()
	{
		int votetotal = 0;
		for (Vote v : getVotes()) {
			votetotal += v.getScore();
		}
		return votetotal;
	}

	public CompoEntry() {
		super();
	}

	public Calendar getCreated() {
		return created;
	}

	public void setCreated(Calendar entryCreated) {
		this.created = entryCreated;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public String getScreenMessage() {
		return screenMessage;
	}

	public void setScreenMessage(String screenMessage) {
		this.screenMessage = screenMessage;
	}

	public Integer getSort() {
		return sort;
	}

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

	public List<Vote> getVotes() {
		return votes;
	}

	public void setVotes(List<Vote> voteList) {
		this.votes = voteList;
	}

	public List<CompoEntryParticipant> getParticipants() {
		return participants;
	}

	public void setParticipants(
			List<CompoEntryParticipant> compoEntryParticipantList) {
		this.participants = compoEntryParticipantList;
	}

	public Compo getCompo() {
		return compo;
	}

	public void setCompo(Compo composId) {
		this.compo = composId;
	}

	public EventUser getCreator() {
		return creator;
	}

	public void setCreator(EventUser creator) {
		this.creator = creator;
	}

	public void setFinalPosition(Integer finalPosition) {
		this.finalPosition = finalPosition;
	}

	public Integer getFinalPosition() {
		return finalPosition;
	}

	public String getTitle() {
		return title;
	}

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

	public String getAuthor() {
		return author;
	}

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

}