|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.proteomecommons.tranche.util; |
|
17 |
| |
|
18 |
| import java.util.ArrayList; |
|
19 |
| import org.proteomecommons.tranche.Signature; |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| public class MetaData { |
|
27 |
| |
|
28 |
| public static final int VERSION_ONE_BIT = (int) Math.pow(2, 0); |
|
29 |
| public static final int PROJECT_FILE_BIT = (int) Math.pow(2, 1); |
|
30 |
| public static final int STICKY_DATA_BIT = (int) Math.pow(2, 2); |
|
31 |
| public static final int STICKY_META_DATA_BIT = (int) Math.pow(2, 3); |
|
32 |
| public static final int GZIP_COMPRESSED_BIT = (int) Math.pow(2, 4); |
|
33 |
| public static final int LIMITED_LIFE_BIT = (int) Math.pow(2, 5); |
|
34 |
| public static final int MIME_TYPE_BIT = (int) Math.pow(2, 6); |
|
35 |
| |
|
36 |
| private String version = "1"; |
|
37 |
| |
|
38 |
| private long timestamp = System.currentTimeMillis(); |
|
39 |
| |
|
40 |
| private long expiration = 0; |
|
41 |
| |
|
42 |
| private String name = ""; |
|
43 |
| |
|
44 |
| private ArrayList<BigHash> parts = new ArrayList(); |
|
45 |
| |
|
46 |
| private ArrayList<FileEncoding> encodings = new ArrayList(); |
|
47 |
| |
|
48 |
| private ArrayList<MetaDataAnnotation> annotations = new ArrayList(); |
|
49 |
| |
|
50 |
| private ArrayList<Signature> signatures = new ArrayList(); |
|
51 |
| |
|
52 |
| private int flags = VERSION_ONE_BIT | GZIP_COMPRESSED_BIT; |
|
53 |
| |
|
54 |
| private String mimeType = null; |
|
55 |
| |
|
56 |
34639
| public boolean hasMimeType() {
|
|
57 |
34639
| return (MIME_TYPE_BIT & flags) != 0;
|
|
58 |
| } |
|
59 |
| |
|
60 |
17
| public boolean isStickyData() {
|
|
61 |
17
| return (STICKY_DATA_BIT & flags) != 0;
|
|
62 |
| } |
|
63 |
| |
|
64 |
19
| public boolean isStickyMetaData() {
|
|
65 |
19
| return (STICKY_META_DATA_BIT & flags) != 0;
|
|
66 |
| } |
|
67 |
| |
|
68 |
22996
| public boolean isProjectFile() {
|
|
69 |
| |
|
70 |
22996
| if (getName() != null && getName().contains(ProjectFile.DEFAULT_PROJECT_FILE_NAME)) {
|
|
71 |
155
| return true;
|
|
72 |
| } |
|
73 |
| |
|
74 |
22841
| return (PROJECT_FILE_BIT & flags) != 0;
|
|
75 |
| } |
|
76 |
| |
|
77 |
34641
| public boolean isLimitedLife() {
|
|
78 |
34641
| return (LIMITED_LIFE_BIT & flags) != 0;
|
|
79 |
| } |
|
80 |
| |
|
81 |
34639
| public boolean isGZIPCompressed() {
|
|
82 |
34639
| return (GZIP_COMPRESSED_BIT & flags) != 0;
|
|
83 |
| } |
|
84 |
| |
|
85 |
23532
| public boolean isVersionOne() {
|
|
86 |
23532
| return (VERSION_ONE_BIT & flags) != 0;
|
|
87 |
| } |
|
88 |
| |
|
89 |
18
| public boolean isDeleted() {
|
|
90 |
18
| synchronized (annotations) {
|
|
91 |
18
| for (MetaDataAnnotation mda : annotations) {
|
|
92 |
43
| if (mda.getName().equals(MetaDataAnnotation.PROP_DELETED)) {
|
|
93 |
3
| return true;
|
|
94 |
| } |
|
95 |
| } |
|
96 |
| } |
|
97 |
15
| return false;
|
|
98 |
| } |
|
99 |
| |
|
100 |
2
| public void setDeleted(boolean isDeleted) {
|
|
101 |
2
| if (isDeleted && !isDeleted()) {
|
|
102 |
1
| synchronized (annotations) {
|
|
103 |
1
| annotations.add(new MetaDataAnnotation(MetaDataAnnotation.PROP_DELETED, String.valueOf(System.currentTimeMillis())));
|
|
104 |
| } |
|
105 |
1
| } else if (!isDeleted && isDeleted()) {
|
|
106 |
1
| synchronized (annotations) {
|
|
107 |
1
| MetaDataAnnotation deletedAnnotation = null;
|
|
108 |
1
| for (MetaDataAnnotation mda : annotations) {
|
|
109 |
1
| if (mda.getName().equals(MetaDataAnnotation.PROP_DELETED)) {
|
|
110 |
1
| deletedAnnotation = mda;
|
|
111 |
| } |
|
112 |
| } |
|
113 |
1
| if (deletedAnnotation != null) {
|
|
114 |
1
| annotations.remove(deletedAnnotation);
|
|
115 |
| } |
|
116 |
| } |
|
117 |
| } |
|
118 |
| } |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
34
| public boolean isEncrypted() {
|
|
124 |
| |
|
125 |
34
| synchronized (encodings) {
|
|
126 |
| |
|
127 |
34
| for (FileEncoding fe : encodings) {
|
|
128 |
| |
|
129 |
| |
|
130 |
72
| if (fe.getName().equals(FileEncoding.AES)) {
|
|
131 |
5
| return true;
|
|
132 |
| } |
|
133 |
| } |
|
134 |
| } |
|
135 |
29
| return false;
|
|
136 |
| } |
|
137 |
| |
|
138 |
0
| public void setPublicPassphrase(String passphrase) throws Exception {
|
|
139 |
0
| FileEncoding AESFileEncoding = null;
|
|
140 |
| |
|
141 |
| |
|
142 |
0
| synchronized (encodings) {
|
|
143 |
| |
|
144 |
0
| for (FileEncoding fe : encodings) {
|
|
145 |
| |
|
146 |
0
| if (fe.getName().equals(FileEncoding.AES)) {
|
|
147 |
0
| AESFileEncoding = fe;
|
|
148 |
0
| break;
|
|
149 |
| } |
|
150 |
| } |
|
151 |
| } |
|
152 |
| |
|
153 |
| |
|
154 |
0
| if (AESFileEncoding == null) {
|
|
155 |
0
| throw new RuntimeException("The data is not encrypted.");
|
|
156 |
| } |
|
157 |
| |
|
158 |
| |
|
159 |
0
| if (passphrase == null || passphrase.equals("")) {
|
|
160 |
0
| AESFileEncoding.getProperties().remove(FileEncoding.PROP_PASSPHRASE);
|
|
161 |
| } else { |
|
162 |
0
| AESFileEncoding.setProperty(FileEncoding.PROP_PASSPHRASE, passphrase);
|
|
163 |
0
| addAnnotation(new MetaDataAnnotation(MetaDataAnnotation.PROP_PUBLISHED_TIMESTAMP, String.valueOf(System.currentTimeMillis())));
|
|
164 |
| } |
|
165 |
| } |
|
166 |
| |
|
167 |
1
| public String getPublicPassphrase() throws Exception {
|
|
168 |
1
| FileEncoding AESFileEncoding = null;
|
|
169 |
| |
|
170 |
| |
|
171 |
1
| synchronized (encodings) {
|
|
172 |
| |
|
173 |
1
| for (FileEncoding fe : encodings) {
|
|
174 |
| |
|
175 |
2
| if (fe.getName().equals(FileEncoding.AES)) {
|
|
176 |
1
| AESFileEncoding = fe;
|
|
177 |
1
| break;
|
|
178 |
| } |
|
179 |
| } |
|
180 |
| } |
|
181 |
| |
|
182 |
| |
|
183 |
1
| if (AESFileEncoding == null) {
|
|
184 |
0
| throw new RuntimeException("The data is not encrypted.");
|
|
185 |
| } |
|
186 |
| |
|
187 |
| |
|
188 |
1
| if (AESFileEncoding.getProperty(FileEncoding.PROP_PASSPHRASE) == null) {
|
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
1
| return null;
|
|
194 |
| } |
|
195 |
| |
|
196 |
0
| return AESFileEncoding.getProperty(FileEncoding.PROP_PASSPHRASE);
|
|
197 |
| } |
|
198 |
| |
|
199 |
12548
| public ArrayList<BigHash> getParts() {
|
|
200 |
12548
| return parts;
|
|
201 |
| } |
|
202 |
| |
|
203 |
23521
| public void setParts(ArrayList<BigHash> parts) {
|
|
204 |
23521
| this.parts = parts;
|
|
205 |
| } |
|
206 |
| |
|
207 |
13026
| public ArrayList<FileEncoding> getEncodings() {
|
|
208 |
13026
| return encodings;
|
|
209 |
| } |
|
210 |
| |
|
211 |
23521
| public void setEncodings(ArrayList<FileEncoding> encodings) {
|
|
212 |
23521
| this.encodings = encodings;
|
|
213 |
| } |
|
214 |
| |
|
215 |
16
| public String getVersion() {
|
|
216 |
16
| return version;
|
|
217 |
| } |
|
218 |
| |
|
219 |
23521
| public void setVersion(String version) {
|
|
220 |
23521
| this.version = version;
|
|
221 |
| } |
|
222 |
| |
|
223 |
11122
| public ArrayList<MetaDataAnnotation> getAnnotations() {
|
|
224 |
11122
| return annotations;
|
|
225 |
| } |
|
226 |
| |
|
227 |
2
| public void addAnnotation(MetaDataAnnotation mda) {
|
|
228 |
2
| this.annotations.add(mda);
|
|
229 |
| } |
|
230 |
| |
|
231 |
23521
| public void setAnnotations(ArrayList<MetaDataAnnotation> annotations) {
|
|
232 |
23521
| this.annotations = annotations;
|
|
233 |
| } |
|
234 |
| |
|
235 |
11996
| public ArrayList<Signature> getSignatures() {
|
|
236 |
11996
| return signatures;
|
|
237 |
| } |
|
238 |
| |
|
239 |
23521
| public void setSignatures(ArrayList<Signature> sigs) {
|
|
240 |
23521
| this.signatures = sigs;
|
|
241 |
| } |
|
242 |
| |
|
243 |
57533
| public String getName() {
|
|
244 |
57533
| return name;
|
|
245 |
| } |
|
246 |
| |
|
247 |
34620
| public void setName(String name) {
|
|
248 |
34620
| this.name = name;
|
|
249 |
| } |
|
250 |
| |
|
251 |
11115
| public long getTimestamp() {
|
|
252 |
11115
| return timestamp;
|
|
253 |
| } |
|
254 |
| |
|
255 |
33935
| public void setTimestamp(long timestamp) {
|
|
256 |
33935
| this.timestamp = timestamp;
|
|
257 |
| } |
|
258 |
| |
|
259 |
1
| public long getExpiration() {
|
|
260 |
1
| return expiration;
|
|
261 |
| } |
|
262 |
| |
|
263 |
2
| public void setExpiration(long expiration) {
|
|
264 |
2
| this.expiration = expiration;
|
|
265 |
2
| if (expiration != 0) {
|
|
266 |
1
| setFlags(getFlags() | MetaData.LIMITED_LIFE_BIT);
|
|
267 |
| } else { |
|
268 |
| |
|
269 |
1
| setFlags(getFlags() & (VERSION_ONE_BIT | PROJECT_FILE_BIT | STICKY_DATA_BIT | STICKY_META_DATA_BIT | GZIP_COMPRESSED_BIT | MetaData.MIME_TYPE_BIT));
|
|
270 |
| } |
|
271 |
| } |
|
272 |
| |
|
273 |
53526
| public int getFlags() {
|
|
274 |
53526
| return flags;
|
|
275 |
| } |
|
276 |
| |
|
277 |
54833
| public void setFlags(int flags) {
|
|
278 |
54833
| this.flags = flags;
|
|
279 |
| } |
|
280 |
| |
|
281 |
10429
| public String getMimeType() {
|
|
282 |
10429
| return mimeType;
|
|
283 |
| } |
|
284 |
| |
|
285 |
31236
| public void setMimeType(String mimeType) {
|
|
286 |
31236
| this.mimeType = mimeType;
|
|
287 |
| |
|
288 |
31236
| if (mimeType != null) {
|
|
289 |
31236
| setFlags(getFlags() | MetaData.MIME_TYPE_BIT);
|
|
290 |
| } else { |
|
291 |
| |
|
292 |
0
| setFlags(getFlags() & (VERSION_ONE_BIT | PROJECT_FILE_BIT | STICKY_DATA_BIT | STICKY_META_DATA_BIT | GZIP_COMPRESSED_BIT | LIMITED_LIFE_BIT));
|
|
293 |
| } |
|
294 |
| } |
|
295 |
| } |