package ca.corefacility.bioinformatics.irida.ria.web.files;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException;
import ca.corefacility.bioinformatics.irida.model.project.ReferenceFile;
import ca.corefacility.bioinformatics.irida.service.ReferenceFileService;

/**
 * Controller for all {@link ReferenceFile} related views
 *
 * @author Josh Adam <josh.adam@phac-aspc.gc.ca>
 */
@Controller
@RequestMapping("/referenceFiles")
public class ReferenceFileController {
	private ReferenceFileService referenceFileService;

	@Autowired
	public ReferenceFileController(ReferenceFileService referenceFileService) {
		this.referenceFileService = referenceFileService;
	}

	@RequestMapping(value = "/download/{fileId}")
	public void downloadReferenceFile(@PathVariable Long fileId,
			HttpServletResponse response) throws IOException {
		ReferenceFile file = referenceFileService.read(fileId);
		if (file != null) {
			Path path = file.getFile();
			response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getLabel() + "\"");
			Files.copy(path, response.getOutputStream());
			response.flushBuffer();
		} else {
			throw new EntityNotFoundException(
					"Cannot find reference file with id [" + fileId + "]");
		}
	}
}


@@ -428,88 +428,8 @@
 g;%0A%0A
-import ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException;%0A
 impo
@@ -1199,31 +1199,8 @@
 d);%0A
-%09%09if (file != null) %7B%0A%09
 %09%09Pa
@@ -1223,25 +1223,24 @@
 etFile();%0A%09%09
-%09
 response.set
@@ -1324,17 +1324,16 @@
 %5C%22%22);%0A%09%09
-%09
 Files.co
@@ -1372,17 +1372,16 @@
 m());%0A%09%09
-%09
 response
@@ -1400,122 +1400,8 @@
 ();%0A
-%09%09%7D else %7B%0A%09%09%09throw new EntityNotFoundException(%0A%09%09%09%09%09%22Cannot find reference file with id %5B%22 + fileId + %22%5D%22);%0A%09%09%7D%0A
 %09%7D%0A%7D

Remove throwing EntityNotFoundException