View Javadoc
1   /*
2    * Copyright (C) 2024 B3Partners B.V.
3    *
4    * SPDX-License-Identifier: MIT
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.validation.constraints.NotNull;
17  import java.time.OffsetDateTime;
18  import java.time.ZoneId;
19  import java.util.UUID;
20  import org.tailormap.api.persistence.listener.EntityEventPublisher;
21  
22  @Entity
23  @EntityListeners(EntityEventPublisher.class)
24  public class Upload {
25    public static final String CATEGORY_APP_LOGO = "app-logo";
26    public static final String CATEGORY_LEGEND = "legend";
27  
28    @Id
29    @GeneratedValue(strategy = GenerationType.UUID)
30    private UUID id;
31  
32    private String category;
33  
34    private String filename;
35  
36    private String mimeType;
37  
38    private Integer imageWidth;
39  
40    private Integer imageHeight;
41  
42    private Boolean hiDpiImage;
43  
44    @NotNull private OffsetDateTime lastModified = OffsetDateTime.now(ZoneId.systemDefault());
45  
46    @Basic(fetch = FetchType.LAZY)
47    private byte[] content;
48  
49    public int getContentLength() {
50      return getContent() == null ? 0 : content.length;
51    }
52  
53    public UUID getId() {
54      return id;
55    }
56  
57    public Upload setId(UUID id) {
58      this.id = id;
59      return this;
60    }
61  
62    public String getCategory() {
63      return category;
64    }
65  
66    public Upload setCategory(String category) {
67      this.category = category;
68      return this;
69    }
70  
71    public String getFilename() {
72      return filename;
73    }
74  
75    public Upload setFilename(String filename) {
76      this.filename = filename;
77      return this;
78    }
79  
80    public String getMimeType() {
81      return mimeType;
82    }
83  
84    public Upload setMimeType(String mimeType) {
85      this.mimeType = mimeType;
86      return this;
87    }
88  
89    public Integer getImageWidth() {
90      return imageWidth;
91    }
92  
93    public Upload setImageWidth(Integer imageWidth) {
94      this.imageWidth = imageWidth;
95      return this;
96    }
97  
98    public Integer getImageHeight() {
99      return imageHeight;
100   }
101 
102   public Upload setImageHeight(Integer imageHeight) {
103     this.imageHeight = imageHeight;
104     return this;
105   }
106 
107   public Boolean getHiDpiImage() {
108     return hiDpiImage;
109   }
110 
111   public Upload setHiDpiImage(Boolean hiDpiImage) {
112     this.hiDpiImage = hiDpiImage;
113     return this;
114   }
115 
116   public OffsetDateTime getLastModified() {
117     return lastModified;
118   }
119 
120   public Upload setLastModified(OffsetDateTime lastModified) {
121     this.lastModified = lastModified;
122     return this;
123   }
124 
125   public byte[] getContent() {
126     return content;
127   }
128 
129   public Upload setContent(byte[] content) {
130     this.content = content;
131     return this;
132   }
133 }