Add direct link to the job archive file (raw data)
[proteocache.git] / engine / compbio / engine / archive / ArchivedJob.java
1 package compbio.engine.archive;
2
3 import java.io.FileOutputStream;
4 import java.io.IOException;
5 import java.net.MalformedURLException;
6 import java.net.URL;
7 import java.nio.channels.Channels;
8 import java.nio.channels.ReadableByteChannel;
9 import java.nio.file.Paths;
10 import java.nio.file.Files;
11 import java.util.List;
12
13 import compbio.engine.ProteoCachePropertyHelperManager;
14 import compbio.util.PropertyHelper;
15
16 public class ArchivedJob {
17         String path;
18         String id;
19         String jobfilename;
20         int filesize;
21         List<String> files;
22         private static final PropertyHelper ph = ProteoCachePropertyHelperManager.getPropertyHelper();
23
24         public ArchivedJob(String id) {
25                 this.id = id;
26                 jobfilename = id + ".tar.gz";
27         }
28
29         public boolean copyArchiveFromWeb(String webpath) throws IOException, MalformedURLException {
30                 URL website = new URL(webpath);
31                 ReadableByteChannel rbc = Channels.newChannel(website.openStream());
32                 FileOutputStream fos = new FileOutputStream(path);
33                 fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
34                 fos.close();
35                 return true;
36         }
37
38         public String prepareJobArchiveToWeb() throws IOException {
39                 String resultpath = ph.getProperty("archive.web.dir");
40                 String thefile = ph.getProperty("archive.path") + '/' + jobfilename;
41                 String finalpath = ProteoCachePropertyHelperManager.getLocalPath() + resultpath + '/' + jobfilename;
42                 if (Files.isReadable(Paths.get(thefile))) {
43                         Files.copy(Paths.get(thefile), Paths.get(finalpath));
44                         return  resultpath + '/' + jobfilename;
45                 }
46                 return null;
47         }
48
49         public boolean copyArchiveLocaly(String localpath) throws IOException {
50                 Files.copy(Paths.get(localpath), Paths.get(path));
51                 return true;
52         }
53
54         public void setArchivePath(String path) {
55                 this.path = path;
56         }
57
58         public int getSize() {
59                 return filesize;
60         }
61
62         public List<String> unpack() {
63                 if (null != files) {
64
65                 }
66                 return files;
67         }
68 }