package ca.corefacility.bioinformatics.irida.model.project;

import java.nio.file.Path;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.hibernate.envers.Audited;

import ca.corefacility.bioinformatics.irida.model.VersionedFileFields;

/**
 * A reference file to be associated with a {@link Project}.
 * 
 * @author Franklin Bristow <franklin.bristow@phac-aspc.gc.ca>
 *
 */
@Entity
@Table(name = "reference_file")
@Audited
public class ReferenceFile implements VersionedFileFields<Long> {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Column(name = "filePath", unique = true)
	@NotNull(message = "{reference.file.file.notnull}")
	private Path file;

	@NotNull
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false)
	private final Date createdDate;

	@Temporal(TemporalType.TIMESTAMP)
	private Date modifiedDate;

	@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE, mappedBy = "referenceFile")
	private ProjectReferenceFileJoin project;

	private Long fileRevisionNumber; // the filesystem file revision number

	public ReferenceFile() {
		this.createdDate = new Date();
		this.fileRevisionNumber = 0L;
	}

	public ReferenceFile(Path file) {
		this();
		this.file = file;
	}

	@Override
	public String getLabel() {
		return file.getFileName().toString();
	}

	@Override
	public Long getId() {
		return this.id;
	}

	@Override
	public Date getModifiedDate() {
		return this.modifiedDate;
	}

	@Override
	public void setModifiedDate(Date modifiedDate) {
		this.modifiedDate = modifiedDate;
	}

	@Override
	public Date getTimestamp() {
		return this.createdDate;
	}

	public Path getFile() {
		return file;
	}

	public void setFile(Path file) {
		this.file = file;
	}

	@Override
	public Date getCreatedDate() {
		return this.createdDate;
	}
	public void incrementFileRevisionNumber() {
		this.fileRevisionNumber++;
	}

	public Long getFileRevisionNumber() {
		return fileRevisionNumber;
	}
}

@@ -103,16 +103,42 @@
 il.Date;
+%0Aimport java.util.Objects;
 %0A%0Aimport
@@ -1503,16 +1503,271 @@
 n number
+%0A%09%0A%09public int hashCode() %7B%0A%09%09return file.hashCode();%0A%09%7D%0A%09%0A%09public boolean equals(Object o) %7B%0A%09%09if (o == this) %7B%0A%09%09%09return true;%0A%09%09%7D else if (o instanceof ReferenceFile) %7B%0A%09%09%09return Objects.equals(file, ((ReferenceFile) o).file);%0A%09%09%7D%0A%09%09%0A%09%09return false;%0A%09%7D
 %0A%0A%09publi

Add hashCode and equals for ReferenceFile.