-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathPhoto.java
More file actions
218 lines (181 loc) · 5.67 KB
/
Photo.java
File metadata and controls
218 lines (181 loc) · 5.67 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package com.photoalbum.model;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.UUID;
/**
* Represents an uploaded photo with metadata for display and management
*/
@Entity
@Table(name = "photos", indexes = {
@Index(name = "idx_photos_uploaded_at", columnList = "uploaded_at", unique = false)
})
public class Photo {
/**
* Unique identifier for the photo using UUID
*/
@Id
@Column(name = "id", length = 36)
private String id;
/**
* Original filename as uploaded by user
*/
@NotBlank
@Size(max = 255)
@Column(name = "original_file_name", nullable = false, length = 255)
private String originalFileName;
/**
* Binary photo data stored directly in PostgreSQL database
* Migrated from Oracle to PostgreSQL according to java check item 1: Convert all table and column names from uppercase to lowercase in JPA annotations.
*/
@Lob
@Column(name = "photo_data", nullable = true)
private byte[] photoData;
/**
* GUID-based filename with extension (for compatibility)
*/
@NotBlank
@Size(max = 255)
@Column(name = "stored_file_name", nullable = false, length = 255)
private String storedFileName;
/**
* Relative path from static resources (for compatibility - not used for DB storage)
*/
@Size(max = 500)
@Column(name = "file_path", length = 500)
private String filePath;
/**
* File size in bytes
* Migrated from Oracle to PostgreSQL according to java check item 1: Convert all table and column names from uppercase to lowercase in JPA annotations.
*/
@NotNull
@Positive
@Column(name = "file_size", nullable = false)
private Long fileSize;
/**
* MIME type (e.g., image/jpeg, image/png)
*/
@NotBlank
@Size(max = 50)
@Column(name = "mime_type", nullable = false, length = 50)
private String mimeType;
/**
* Timestamp of upload
* Migrated from Oracle to PostgreSQL according to java check item 1: Convert all table and column names from uppercase to lowercase in JPA annotations.
*/
@NotNull
@Column(name = "uploaded_at", nullable = false)
private LocalDateTime uploadedAt;
/**
* Image width in pixels (populated after upload)
*/
@Column(name = "width")
private Integer width;
/**
* Image height in pixels (populated after upload)
*/
@Column(name = "height")
private Integer height;
// Default constructor
public Photo() {
this.id = UUID.randomUUID().toString();
this.uploadedAt = LocalDateTime.now();
}
// Constructor with required fields
public Photo(String originalFileName, byte[] photoData, String storedFileName, String filePath, Long fileSize, String mimeType) {
this();
this.originalFileName = originalFileName;
this.photoData = photoData;
this.storedFileName = storedFileName;
this.filePath = filePath;
this.fileSize = fileSize;
this.mimeType = mimeType;
}
// Constructor with required fields (file system compatibility)
public Photo(String originalFileName, String storedFileName, String filePath, Long fileSize, String mimeType) {
this();
this.originalFileName = originalFileName;
this.storedFileName = storedFileName;
this.filePath = filePath;
this.fileSize = fileSize;
this.mimeType = mimeType;
}
// Getters and Setters
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getOriginalFileName() {
return originalFileName;
}
public void setOriginalFileName(String originalFileName) {
this.originalFileName = originalFileName;
}
public byte[] getPhotoData() {
return photoData;
}
public void setPhotoData(byte[] photoData) {
this.photoData = photoData;
}
public String getStoredFileName() {
return storedFileName;
}
public void setStoredFileName(String storedFileName) {
this.storedFileName = storedFileName;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public Long getFileSize() {
return fileSize;
}
public void setFileSize(Long fileSize) {
this.fileSize = fileSize;
}
public String getMimeType() {
return mimeType;
}
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
public LocalDateTime getUploadedAt() {
return uploadedAt;
}
public void setUploadedAt(LocalDateTime uploadedAt) {
this.uploadedAt = uploadedAt;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
@Override
public String toString() {
return "Photo{" +
"id=" + id +
", originalFileName='" + originalFileName + '\'' +
", storedFileName='" + storedFileName + '\'' +
", filePath='" + filePath + '\'' +
", fileSize=" + fileSize +
", mimeType='" + mimeType + '\'' +
", uploadedAt=" + uploadedAt +
", width=" + width +
", height=" + height +
'}';
}
}