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

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

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile;
import ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission;

/**
 * Defines a genome assembly from an IRIDA-based analysis.
 */
@Entity
@Table(name = "genome_assembly_analysis")
@EntityListeners(AuditingEntityListener.class)
public class GenomeAssemblyFromAnalysis extends GenomeAssembly {

	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.DETACH)
	@JoinColumn(name = "analysis_submission_id", nullable = false)
	private AnalysisSubmission assembly;

	@SuppressWarnings("unused")
	private GenomeAssemblyFromAnalysis() {
		super();
	}

	public GenomeAssemblyFromAnalysis(AnalysisSubmission assembly) {
		super(new Date());
		this.assembly = assembly;
	}

	public AnalysisSubmission getAnalysisSubmission() {
		return assembly;
	}

	public void setAnalysisSubmission(AnalysisSubmission assembly) {
		this.assembly = assembly;
	}

	public AnalysisOutputFile getAssemblyOutput() {
		return assembly.getAnalysis().getAnalysisOutputFile("contigs-with-repeats");
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getLabel() {
		return getAssemblyOutput().getLabel();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Path getFile() {
		return getAssemblyOutput().getFile();
	}
}

@@ -436,16 +436,94 @@
 tener;%0A%0A
+import ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis;%0A
 import c
@@ -693,16 +693,64 @@
 ssion;%0A%0A
+import com.google.common.collect.ImmutableSet;%0A%0A
 /**%0A * D
@@ -1522,133 +1522,815 @@
 %7D%0A%0A%09
-public AnalysisOutputFile getAssemblyOutput() %7B%0A%09%09return assembly.getAnalysis().getAnalysisOutputFile(%22contigs-with-repeats%22)
+/**%0A%09 * Get genome assembly %7B@link AnalysisOutputFile%7D.%0A%09 * @return %7B@link AnalysisOutputFile%7D for a genome assembly %7B@link AnalysisSubmission%7D%0A%09 */%0A%09public AnalysisOutputFile getAssemblyOutput() %7B%0A%09%09// Probably need a better way of telling what's the assembly than a hardcoded set of output%0A%09%09// file key names. Annotate the workflow output? Wouldn't the GBK file be considered an%0A%09%09// assembly albeit an annotated one?%0A%09%09final ImmutableSet%3CString%3E ASSEMBLY_OUTPUT_KEYS = ImmutableSet.of(%22contigs.fasta%22, %22contigs-with-repeats%22);%0A%09%09final Analysis analysis = assembly.getAnalysis();%0A%09%09for (String assemblyOutputKey : ASSEMBLY_OUTPUT_KEYS) %7B%0A%09%09%09final AnalysisOutputFile outputFile = analysis.getAnalysisOutputFile(assemblyOutputKey);%0A%09%09%09if (outputFile != null) %7B%0A%09%09%09%09return outputFile;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return null
 ;%0A%09%7D

Fix getting assembly for a sample AnalysisOutputFile key changed from 'contigs-with-repeats' to 'contigs.fasta' in AssemblyAnnotation v0.5