1
2
3
4 package de.tivsource.page.common.css;
5
6 import java.io.File;
7 import java.util.Date;
8 import java.util.SortedSet;
9 import java.util.UUID;
10
11 import javax.persistence.CascadeType;
12 import javax.persistence.Column;
13 import javax.persistence.Entity;
14 import javax.persistence.FetchType;
15 import javax.persistence.Id;
16 import javax.persistence.JoinColumn;
17 import javax.persistence.JoinTable;
18 import javax.persistence.ManyToMany;
19 import javax.persistence.Table;
20 import javax.persistence.Temporal;
21 import javax.persistence.Transient;
22 import javax.persistence.Version;
23
24 import org.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
26 import org.hibernate.annotations.SortNatural;
27 import org.hibernate.envers.Audited;
28 import org.hibernate.search.annotations.DocumentId;
29
30 import de.tivsource.page.common.file.FileActions;
31
32
33
34
35
36 @Audited
37 @Entity
38 @Table(name = "CSSFile")
39 public class CSSFile implements Comparable<CSSFile> {
40
41
42
43
44 private static final Logger logger = LogManager.getLogger(CSSFile.class);
45
46
47
48
49
50 @Id
51 @DocumentId
52 @Column(name = "uuid", unique = true, length = 42)
53 private String uuid;
54
55 private String name;
56
57 private String description;
58
59 private Integer priority;
60
61 private String path;
62
63
64
65
66
67 @Transient
68 private File uploadFile;
69
70
71
72
73 @ManyToMany(targetEntity = CSSGroup.class, cascade = { CascadeType.PERSIST }, fetch = FetchType.EAGER)
74 @JoinTable(
75 name = "CSSFile_CSSGroup",
76 joinColumns = @JoinColumn(name = "cssFile_uuid"),
77 inverseJoinColumns = @JoinColumn(name = "cssGroup_uuid")
78 )
79 @SortNatural
80 private SortedSet<CSSGroup> groups;
81
82 @Temporal(javax.persistence.TemporalType.TIMESTAMP)
83 private Date created;
84
85 @Temporal(javax.persistence.TemporalType.TIMESTAMP)
86 private Date modified;
87
88 private String modifiedBy;
89
90 private String modifiedAddress;
91
92
93
94
95 @Version
96 private Integer version;
97
98
99
100
101 public String getUuid() {
102 return uuid;
103 }
104
105
106
107
108
109 public void setUuid(String uuid) {
110 this.uuid = uuid;
111 }
112
113
114
115
116 public String getName() {
117 return name;
118 }
119
120
121
122
123
124 public void setName(String name) {
125 this.name = name;
126 }
127
128
129
130
131 public String getDescription() {
132 return description;
133 }
134
135
136
137
138
139 public void setDescription(String description) {
140 this.description = description;
141 }
142
143
144
145
146 public Integer getPriority() {
147 return priority;
148 }
149
150
151
152
153
154 public void setPriority(Integer priority) {
155 this.priority = priority;
156 }
157
158
159
160
161 public String getPath() {
162 return path;
163 }
164
165
166
167
168
169 public void setPath(String path) {
170 this.path = path;
171 }
172
173
174
175
176 public File getUploadFile() {
177 return uploadFile;
178 }
179
180
181
182
183
184 public void setUploadFile(File uploadFile) {
185 this.uploadFile = uploadFile;
186 }
187
188
189
190
191 public SortedSet<CSSGroup> getGroups() {
192 return groups;
193 }
194
195
196
197
198
199 public void setGroups(SortedSet<CSSGroup> groups) {
200 this.groups = groups;
201 }
202
203
204
205
206 public Date getCreated() {
207 return created;
208 }
209
210
211
212
213
214 public void setCreated(Date created) {
215 this.created = created;
216 }
217
218
219
220
221 public Date getModified() {
222 return modified;
223 }
224
225
226
227
228
229 public void setModified(Date modified) {
230 this.modified = modified;
231 }
232
233
234
235
236 public String getModifiedBy() {
237 return modifiedBy;
238 }
239
240
241
242
243
244 public void setModifiedBy(String modifiedBy) {
245 this.modifiedBy = modifiedBy;
246 }
247
248
249
250
251 public String getModifiedAddress() {
252 return modifiedAddress;
253 }
254
255
256
257
258
259 public void setModifiedAddress(String modifiedAddress) {
260 this.modifiedAddress = modifiedAddress;
261 }
262
263
264
265
266 public Integer getVersion() {
267 return version;
268 }
269
270
271
272
273
274 public void setVersion(Integer version) {
275 this.version = version;
276 }
277
278 public void generate() {
279 String filePath = "/srv/tiv-page/cssfile/";
280
281 String cssSaveName = UUID.randomUUID().toString();
282 try {
283
284 File fileToCreate = new File(filePath, cssSaveName + ".css");
285 logger.debug("Absoluter Pfad der neuen CSS-Datei : "
286 + fileToCreate.getAbsolutePath());
287
288
289 if (!fileToCreate.exists()) {
290 FileActions.savePictureFile(this.getUploadFile(), fileToCreate);
291 }
292 }
293 catch (Exception e) {
294 logger.error(e.getMessage());
295 }
296 setPath(filePath + cssSaveName + ".css");
297 }
298
299 @Override
300 public int compareTo(CSSFile o) {
301 if (o.priority < this.priority) {
302 return 1;
303 } else if (o.priority > this.priority) {
304 return -1;
305 } else {
306 return o.uuid.compareTo(this.uuid);
307 }
308 }
309
310 }