1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.fileupload.api.job;
23
24 import org.opencastproject.mediapackage.MediaPackage;
25 import org.opencastproject.mediapackage.MediaPackageElementFlavor;
26
27 import java.util.UUID;
28
29 import javax.xml.bind.annotation.XmlAccessType;
30 import javax.xml.bind.annotation.XmlAccessorType;
31 import javax.xml.bind.annotation.XmlAttribute;
32 import javax.xml.bind.annotation.XmlElement;
33 import javax.xml.bind.annotation.XmlEnum;
34 import javax.xml.bind.annotation.XmlEnumValue;
35 import javax.xml.bind.annotation.XmlRootElement;
36 import javax.xml.bind.annotation.XmlType;
37
38
39
40
41
42 @XmlType(name = "uploadjob", namespace = "http://fileupload.opencastproject.org")
43 @XmlRootElement(name = "uploadjob", namespace = "http://fileupload.opencastproject.org")
44 @XmlAccessorType(XmlAccessType.NONE)
45 public class FileUploadJob {
46
47 @XmlEnum
48 public enum JobState {
49 @XmlEnumValue("READY") READY,
50 @XmlEnumValue("INPROGRESS") INPROGRESS,
51 @XmlEnumValue("FINALIZING") FINALIZING,
52 @XmlEnumValue("COMPLETE") COMPLETE
53 }
54
55 @XmlAttribute()
56 private String id;
57 @XmlAttribute()
58 private JobState state = JobState.READY;
59 private long modified;
60 @XmlElement(name = "payload")
61 private Payload payload;
62 @XmlElement(name = "chunksize")
63 private int chunksize = -1;
64 @XmlElement(name = "chunks-total")
65 private long chunksTotal = 1;
66 @XmlElement(name = "current-chunk")
67 private Chunk currentChunk = new Chunk();
68
69 public FileUploadJob() {
70 this.id = UUID.randomUUID().toString();
71 this.modified = System.currentTimeMillis();
72 this.payload = new Payload("unknown", -1, null, null);
73 }
74
75 public FileUploadJob(
76 String filename,
77 long filesize,
78 int chunksize,
79 MediaPackage mp,
80 MediaPackageElementFlavor flavor
81 ) {
82 this.id = UUID.randomUUID().toString();
83 this.modified = System.currentTimeMillis();
84 this.chunksize = chunksize;
85 if (chunksize == -1) {
86 chunksTotal = 1;
87 } else {
88 chunksTotal = filesize / chunksize;
89 if (filesize % chunksize != 0) {
90 chunksTotal++;
91 }
92 }
93 this.payload = new Payload(filename, filesize, mp, flavor);
94 }
95
96 public String getId() {
97 return id;
98 }
99
100 public synchronized JobState getState() {
101 return this.state;
102 }
103
104 public synchronized void setState(JobState state) {
105 setLastModified(System.currentTimeMillis());
106 this.state = state;
107 }
108
109 public void setLastModified(long time) {
110 this.modified = time;
111 }
112
113 public long lastModified() {
114 return this.modified;
115 }
116
117 public Payload getPayload() {
118 return this.payload;
119 }
120
121 public int getChunksize() {
122 return chunksize;
123 }
124
125 public long getChunksTotal() {
126 return chunksTotal;
127 }
128
129 public Chunk getCurrentChunk() {
130 return currentChunk;
131 }
132
133 public void setCurrentChunk(Chunk currentChunk) {
134 setLastModified(System.currentTimeMillis());
135 this.currentChunk = currentChunk;
136 }
137
138 @Override
139 public String toString() {
140 StringBuilder sb = new StringBuilder().append("FileUploadJob(id=").append(this.id).append(", filename=")
141 .append(this.payload.getFilename()).append(")");
142 return sb.toString();
143 }
144 }