package dynamo.services;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import dynamo.backlog.BackLogProcessor;
import dynamo.backlog.tasks.files.DeleteFileTask;
import dynamo.core.manager.DAOManager;
import dynamo.core.model.DownloadableFile;
import dynamo.core.model.DownloadableUtilsDAO;

@Path("file-list")
public class FileListService {
	
	private static final DownloadableUtilsDAO downloadableDAO = DAOManager.getInstance().getDAO( DownloadableUtilsDAO.class );
	
	@GET
	@Path("{id}")
	@Produces(MediaType.APPLICATION_JSON)
	public List<DownloadableFile> getFilesForId( @PathParam("id") long id ) {
		return downloadableDAO.getAllFiles(id);
	}

	@DELETE
	public void delete(@QueryParam("path") String pathStr) {
		java.nio.file.Path path = Paths.get( pathStr );
		BackLogProcessor.getInstance().schedule( new DeleteFileTask(path), false );
	}
	
	@GET
	@Path("/download")
	public Response downloadFile( @QueryParam("path") java.nio.file.Path path ) throws IOException {
		DownloadableFile file = downloadableDAO.getFile(path);

		String fileName = path.getFileName().toString();
		
		try (InputStream input = Files.newInputStream(path)) {
			return Response.ok(
					input, MediaType.APPLICATION_OCTET_STREAM)
					.header("Content-Length", file.getSize())
					.header("content-disposition","attachment; filename = " + fileName)
					.build();
		}
		
	}

}

@@ -1247,16 +1247,56 @@
 %22path%22) 
+String pathStr ) throws IOException %7B%0A%09%09
 java.nio
@@ -1311,38 +1311,39 @@
 th path 
-) throws IOException %7B
+= Paths.get( pathStr );
 %0A%09%09Downl

Fix param type