]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/model/logo/BusinessLogo.java
Updated copyright year
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / model / logo / BusinessLogo.java
1 /*
2  * Copyright (C) 2016 - 2020 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jcontactsbusiness.model.logo;
18
19 import java.util.Date;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.OneToOne;
30 import javax.persistence.Table;
31 import javax.persistence.Temporal;
32 import javax.persistence.TemporalType;
33 import javax.persistence.Transient;
34 import org.mxchange.jcoreutils.Comparables;
35 import org.mxchange.jusercore.model.user.LoginUser;
36 import org.mxchange.jusercore.model.user.User;
37
38 /**
39  * A POJO for company logos
40  * <p>
41  * @author Roland Häder<roland@mxchange.org>
42  */
43 @Entity (name = "company_logos")
44 @Table (name = "company_logos")
45 @SuppressWarnings ("PersistenceUnitPresent")
46 public class BusinessLogo implements Logo {
47
48         /**
49          * Serial number
50          */
51         @Transient
52         private static final long serialVersionUID = 475_871_875_718_751_285L;
53
54         /**
55          * Timestamp when this entry has been created
56          */
57         @Basic (optional = false)
58         @Temporal (TemporalType.TIMESTAMP)
59         @Column (name = "logo_entry_created", nullable = false, updatable = false)
60         private Date logoCreated;
61
62         /**
63          * Local file name of the logo (relative to /resources/logos/)
64          */
65         @Basic (optional = false)
66         @Column (name = "logo_file_name", nullable = false, unique = true, updatable = false)
67         private String logoFileName;
68
69         /**
70          * Id number
71          */
72         @Id
73         @GeneratedValue (strategy = GenerationType.IDENTITY)
74         @Column (name = "logo_id", nullable = false, updatable = false)
75         private Long logoId;
76
77         /**
78          * Logo uploader user instance
79          */
80         @JoinColumn (name = "logo_uploader_id", nullable = false, updatable = false)
81         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
82         private User logoUploader;
83
84         @Override
85         public int compareTo (final Logo logo) {
86                 // Check parameter on null-reference and equality to this
87                 if (null == logo) {
88                         // Should not happen
89                         throw new NullPointerException("logo is null"); //NOI18N
90                 } else if (logo.equals(this)) {
91                         // Same object
92                         return 0;
93                 }
94
95                 // Init comparisons
96                 final int[] comparators = {
97                         // First file name ...
98                         this.getLogoFileName().compareToIgnoreCase(logo.getLogoFileName()),
99                         // ... then uploader instance
100                         this.getLogoUploader().compareTo(logo.getLogoUploader())
101                 };
102
103                 // Check all values
104                 final int comparison = Comparables.checkAll(comparators);
105
106                 // Return value
107                 return comparison;
108         }
109
110         @Override
111         public boolean equals (final Object object) {
112                 if (null == object) {
113                         return false;
114                 } else if (this.getClass() != object.getClass()) {
115                         return false;
116                 }
117
118                 final Logo other = (Logo) object;
119
120                 if (!Objects.equals(this.getLogoId(), other.getLogoId())) {
121                         return false;
122                 } else if (!Objects.equals(this.getLogoUploader(), other.getLogoUploader())) {
123                         return false;
124                 } else if (!Objects.equals(this.getLogoFileName(), other.getLogoFileName())) {
125                         return false;
126                 }
127
128                 return true;
129         }
130
131         @Override
132         @SuppressWarnings ("ReturnOfDateField")
133         public Date getLogoCreated () {
134                 return this.logoCreated;
135         }
136
137         @Override
138         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
139         public void setLogoCreated (final Date logoCreated) {
140                 this.logoCreated = logoCreated;
141         }
142
143         @Override
144         public String getLogoFileName () {
145                 return this.logoFileName;
146         }
147
148         @Override
149         public void setLogoFileName (final String logoFileName) {
150                 this.logoFileName = logoFileName;
151         }
152
153         @Override
154         public Long getLogoId () {
155                 return this.logoId;
156         }
157
158         @Override
159         public void setLogoId (final Long logoId) {
160                 this.logoId = logoId;
161         }
162
163         @Override
164         public User getLogoUploader () {
165                 return this.logoUploader;
166         }
167
168         @Override
169         public void setLogoUploader (final User logoUploader) {
170                 this.logoUploader = logoUploader;
171         }
172
173         @Override
174         public int hashCode () {
175                 int hash = 3;
176
177                 hash = 53 * hash + Objects.hashCode(this.getLogoId());
178                 hash = 53 * hash + Objects.hashCode(this.getLogoFileName());
179                 hash = 53 * hash + Objects.hashCode(this.getLogoUploader());
180
181                 return hash;
182         }
183
184 }