Compo.java 5.3 KB
/*
 * Copyright Codecrew Ry
 * 
 * All rights reserved.
 * 
 * This license applies to any software containing a notice placed by the 
 * copyright holder. Such software is herein referred to as the Software. 
 * This license covers modification, distribution and use of the Software. 
 * 
 * Any distribution and use in source and binary forms, with or without 
 * modification is not permitted without explicit written permission from the 
 * copyright owner. 
 * 
 * A non-exclusive royalty-free right is granted to the copyright owner of the 
 * Software to use, modify and distribute all modifications to the Software in 
 * future versions of the Software. 
 * 
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fi.codecrew.moya.model;

import java.util.Date;
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.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Competition to be held at the event.
 */
@Entity
@Table(name = "compos")
public class Compo extends GenericEntity {
	private static final long serialVersionUID = 2L;

	/**
	 * Name of the competition.
	 */
	@Column(name = "compo_name", nullable = false)
	private String name;

	public static final String EVENT_ID_COLUMN = "event_id";

	@ManyToOne()
	@JoinColumn(name = EVENT_ID_COLUMN, nullable = false)
	private LanEvent event;

	/**
	 * Start time of the competition Submitting entries should be disabled after
	 * this time.
	 */
	@Column(name = "compo_start")
	@Temporal(TemporalType.TIMESTAMP)
	private Date startTime;

	@Column(name = "compo_end")
	@Temporal(TemporalType.TIMESTAMP)
	private Date endTime;

	/**
	 * When the voting should start
	 * 
	 * @see {@link #holdVoting}
	 */
	@Column(name = "vote_start")
	@Temporal(TemporalType.TIMESTAMP)
	private Date voteStart;

	@Column(name = "vote_end")
	@Temporal(TemporalType.TIMESTAMP)
	private Date voteEnd;

	@Column(name = "submit_start")
	@Temporal(TemporalType.TIMESTAMP)
	private Date submitStart;

	@Column(name = "submit_end")
	@Temporal(TemporalType.TIMESTAMP)
	private Date submitEnd;

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

	@Column(name = "max_participant_count")
	private int maxParticipantCount;

	/**
	 * If ( for some unimaginable reason ) compo is delayed hold voting can be
	 * used to postpone the start of the voting from the time specified in
	 * {@link #voteStart}
	 */
	@Column(name = "hold_voting", nullable = false)
	private boolean holdVoting = false;

	@Column(name = "hidden", nullable = false)
	private boolean hidden = false;

	public boolean isHidden() {
		return hidden;
	}

	public void setHidden(boolean hidden) {
		this.hidden = hidden;
	}

	/**
	 * Entries submitted to participate this compo.
	 */
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "compo")
	@OrderBy("sort")
	private List<CompoEntry> compoEntries;

	public Compo(String compoName, boolean holdVoting) {
		this();

		this.name = compoName;
		this.holdVoting = holdVoting;
	}

	public boolean isSubmit()
	{
		Date now = new Date();
		return now.after(getSubmitStart()) && now.before(getSubmitEnd());
	}

	public boolean isVote()
	{
		Date now = new Date();
		return !getHoldVoting() &&
				now.after(getVoteStart()) &&
				now.before(getVoteEnd());
	}

	public Compo() {
		super();
	}

	public String getName() {
		return name;
	}

	public void setName(String compoName) {
		this.name = compoName;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date compoStart) {
		this.startTime = compoStart;
	}

	public Date getVoteStart() {
		return voteStart;
	}

	public void setVoteStart(Date voteStart) {
		this.voteStart = voteStart;
	}

	public Date getVoteEnd() {
		return voteEnd;
	}

	public void setVoteEnd(Date voteEnd) {
		this.voteEnd = voteEnd;
	}

	public Date getSubmitStart() {
		return submitStart;
	}

	public void setSubmitStart(Date submitStart) {
		this.submitStart = submitStart;
	}

	public Date getSubmitEnd() {
		return submitEnd;
	}

	public void setSubmitEnd(Date submitEnd) {
		this.submitEnd = submitEnd;
	}

	public boolean getHoldVoting() {
		return holdVoting;
	}

	public void setHoldVoting(boolean holdVoting) {
		this.holdVoting = holdVoting;
	}

	public List<CompoEntry> getCompoEntries() {
		return compoEntries;
	}

	public void setCompoEntries(List<CompoEntry> compoEntryList) {
		this.compoEntries = compoEntryList;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

	/**
	 * @return the maxParticipantCount
	 */
	public int getMaxParticipantCount() {
		return maxParticipantCount;
	}

	/**
	 * @param maxParticipantCount
	 *            the maxParticipantCount to set
	 */
	public void setMaxParticipantCount(int maxParticipantCount) {
		this.maxParticipantCount = maxParticipantCount;
	}

	public LanEvent getEvent() {
		return event;
	}

	public void setEvent(LanEvent event) {
		this.event = event;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

}