1
2
3
4
5
6
7 package org.tailormap.api.persistence;
8
9 import jakarta.persistence.Basic;
10 import jakarta.persistence.Entity;
11 import jakarta.persistence.EntityListeners;
12 import jakarta.persistence.FetchType;
13 import jakarta.persistence.GeneratedValue;
14 import jakarta.persistence.GenerationType;
15 import jakarta.persistence.Id;
16 import jakarta.persistence.PrePersist;
17 import jakarta.persistence.PreUpdate;
18 import jakarta.validation.constraints.NotNull;
19 import java.time.OffsetDateTime;
20 import java.time.ZoneId;
21 import java.util.UUID;
22 import org.apache.commons.codec.digest.DigestUtils;
23 import org.tailormap.api.persistence.listener.EntityEventPublisher;
24
25 @Entity
26 @EntityListeners(EntityEventPublisher.class)
27 public class Upload {
28 public static final String CATEGORY_APP_LOGO = "app-logo";
29 public static final String CATEGORY_LEGEND = "legend";
30 public static final String CATEGORY_PORTAL_IMAGE = "portal-image";
31 public static final String CATEGORY_DRAWING_STYLE = "drawing-style";
32 public static final String CATEGORY_DRAWING_STYLE_IMAGE = "drawing-style-image";
33 public static final String CATEGORY_SSO_IMAGE = "sso-image";
34
35 @Id
36 @GeneratedValue(strategy = GenerationType.UUID)
37 private UUID id;
38
39 private String category;
40
41 private String filename;
42
43 private String mimeType;
44
45 private Integer imageWidth;
46
47 private Integer imageHeight;
48
49 private Boolean hiDpiImage;
50
51 @NotNull private OffsetDateTime lastModified = OffsetDateTime.now(ZoneId.systemDefault());
52
53 @Basic(fetch = FetchType.LAZY)
54 private byte[] content;
55
56 private String hash;
57
58
59 public int getContentLength() {
60 return getContent() == null ? 0 : content.length;
61 }
62
63 public UUID getId() {
64 return id;
65 }
66
67 public Upload setId(UUID id) {
68 this.id = id;
69 return this;
70 }
71
72 public String getCategory() {
73 return category;
74 }
75
76 public Upload setCategory(String category) {
77 this.category = category;
78 return this;
79 }
80
81 public String getFilename() {
82 return filename;
83 }
84
85 public Upload setFilename(String filename) {
86 this.filename = filename;
87 return this;
88 }
89
90 public String getMimeType() {
91 return mimeType;
92 }
93
94 public Upload setMimeType(String mimeType) {
95 this.mimeType = mimeType;
96 return this;
97 }
98
99 public Integer getImageWidth() {
100 return imageWidth;
101 }
102
103 public Upload setImageWidth(Integer imageWidth) {
104 this.imageWidth = imageWidth;
105 return this;
106 }
107
108 public Integer getImageHeight() {
109 return imageHeight;
110 }
111
112 public Upload setImageHeight(Integer imageHeight) {
113 this.imageHeight = imageHeight;
114 return this;
115 }
116
117 public Boolean getHiDpiImage() {
118 return hiDpiImage;
119 }
120
121 public Upload setHiDpiImage(Boolean hiDpiImage) {
122 this.hiDpiImage = hiDpiImage;
123 return this;
124 }
125
126 public OffsetDateTime getLastModified() {
127 return lastModified;
128 }
129
130 public Upload setLastModified(OffsetDateTime lastModified) {
131 this.lastModified = lastModified;
132 return this;
133 }
134
135 public byte[] getContent() {
136 return content;
137 }
138
139 public Upload setContent(byte[] content) {
140 this.content = content;
141 return this;
142 }
143
144 public String getHash() {
145 return hash;
146 }
147
148 public Upload setHash(String hash) {
149 this.hash = hash;
150 return this;
151 }
152
153
154 @PrePersist
155 @PreUpdate
156 public void computeHash() {
157 if (content != null) {
158 this.hash = DigestUtils.sha1Hex(content);
159 } else {
160 this.hash = null;
161 }
162 }
163 }