-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFile.java
More file actions
161 lines (147 loc) · 4.16 KB
/
File.java
File metadata and controls
161 lines (147 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package File;
import java.io.InputStream;
import java.util.Date;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.bson.codecs.pojo.annotations.BsonIgnore;
import org.bson.codecs.pojo.annotations.BsonProperty;
import org.bson.types.ObjectId;
import org.json.JSONObject;
@Slf4j
public class File {
@Getter @Setter private ObjectId id; // id of file in collection (metadata)
@Getter @Setter private ObjectId fileId; // id of file in bucket (actual file bytes)
@Getter @Setter @BsonIgnore private InputStream fileStream;
@Getter @Setter private String filename;
@Getter @Setter private FileType fileType;
@Getter @Setter private Date uploadedAt;
@Getter @Setter private String username;
@Getter @Setter private String organizationName;
@Getter
@Setter
@BsonProperty(value = "annotated")
private boolean isAnnotated;
@Getter @Setter private IdCategoryType idCategory;
@Getter @Setter private String contentType;
public File() {}
public File(
ObjectId id,
String filename,
FileType fileType,
Date uploadedAt,
String username,
String organizationName,
String contentType) {
this.id = id;
this.filename = filename;
this.fileType = fileType;
this.uploadedAt = uploadedAt;
this.username = username;
this.organizationName = organizationName;
this.contentType = contentType;
}
public File(
String username,
Date uploadedAt,
InputStream fileStream,
FileType fileType,
IdCategoryType idCategory,
String fileName,
String organizationName,
boolean isAnnotated,
String contentType) {
this.id = new ObjectId();
this.username = username;
this.uploadedAt = uploadedAt;
this.fileStream = fileStream;
this.fileType = fileType;
this.idCategory = idCategory;
this.filename = fileName;
this.organizationName = organizationName;
this.isAnnotated = isAnnotated;
this.contentType = contentType;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
File file = (File) o;
return isAnnotated == file.isAnnotated
&& id.equals(file.id)
&& fileId.equals(file.fileId)
&& filename.equals(file.filename)
&& fileType == file.fileType
&& idCategory == file.idCategory
&& uploadedAt.equals(file.uploadedAt)
&& username.equals(file.username)
&& organizationName.equals(file.organizationName)
&& contentType.equals(file.contentType);
}
@Override
public int hashCode() {
return Objects.hash(
id,
fileId,
filename,
fileType,
idCategory,
uploadedAt,
username,
organizationName,
isAnnotated,
contentType);
}
@Override
public String toString() {
return "File{"
+ "id="
+ id.toString()
+ ", fileId="
+ fileId.toString()
+ ", filename='"
+ filename
+ '\''
+ ", fileType="
+ fileType
+ ", idCategory="
+ idCategory
+ ", uploadedAt="
+ uploadedAt
+ ", username='"
+ username
+ '\''
+ ", organizationName='"
+ organizationName
+ '\''
+ ", isAnnotated="
+ isAnnotated
+ ", contentType='"
+ contentType
+ '\''
+ '}';
}
public JSONObject toJsonView() {
JSONObject fileMetadata =
new JSONObject()
.put("uploader", this.username)
.put("organizationName", this.organizationName)
.put("id", this.getId().toString())
.put("uploadDate", this.uploadedAt)
.put("idCategory", this.idCategory)
.put("filename", this.filename)
.put("annotated", this.isAnnotated);
return fileMetadata;
}
/*
Metadata fields from database:
filetype (str/enum) DONE
upload_date (date) DONE
uploader (str) DONE
organization_name (str) DONE
annotated (bool) DONE
hash of file and metadata for integrity checks
https://developers.google.com/tink?authuser=2
*/
}