View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.adopter.registration.dto;
23  
24  import org.opencastproject.security.api.Organization;
25  import org.opencastproject.util.EqualsUtil;
26  
27  import java.util.Date;
28  import java.util.Objects;
29  
30  import javax.persistence.Access;
31  import javax.persistence.AccessType;
32  import javax.persistence.Column;
33  import javax.persistence.Entity;
34  import javax.persistence.Id;
35  import javax.persistence.NamedQueries;
36  import javax.persistence.NamedQuery;
37  import javax.persistence.Table;
38  import javax.persistence.Temporal;
39  import javax.persistence.TemporalType;
40  
41  /**
42   * JPA-annotated registration form object.
43   */
44  @Entity
45  @Access(AccessType.FIELD)
46  @Table(name = "oc_adopter_registration")
47  @NamedQueries({
48          @NamedQuery(name = "Adopter.findAll", query = "SELECT f FROM Adopter f"),
49          @NamedQuery(name = "Adopter.deleteAll", query = "DELETE FROM Adopter f")
50  })
51  public class Adopter {
52  
53    public enum TERMSOFUSEVERSION {
54      PRE_2022, APRIL_2022
55    };
56  
57    public static final TERMSOFUSEVERSION getLatestTermsOfUse() {
58      return TERMSOFUSEVERSION.APRIL_2022;
59    }
60  
61  
62    //================================================================================
63    // Properties
64    //================================================================================
65  
66    @Id
67    @Column(name = "adopter_key", length = 64)
68    private String adopterKey;
69  
70    @Column(name = "statistic_key")
71    private String statisticKey;
72  
73    @Column(name = "organisation")
74    private String organisationName;
75  
76    @Column(name = "department")
77    private String departmentName;
78  
79    @Column(name = "first_name")
80    private String firstName;
81  
82    @Column(name = "last_name")
83    private String lastName;
84  
85    @Column(name = "email")
86    private String email;
87  
88    @Column(name = "country")
89    private String country;
90  
91    @Column(name = "postal_code")
92    private String postalCode;
93  
94    @Column(name = "city")
95    private String city;
96  
97    @Column(name = "street")
98    private String street;
99  
100   @Column(name = "street_no")
101   private String streetNo;
102 
103   @Column(name = "contact_me")
104   private boolean contactMe;
105 
106   @Column(name = "system_type")
107   private String systemType;
108 
109   @Column(name = "allows_statistics")
110   private boolean allowsStatistics;
111 
112   @Column(name = "allows_error_reports")
113   private boolean allowsErrorReports;
114 
115   @Column(name = "created", nullable = false)
116   @Temporal(TemporalType.TIMESTAMP)
117   private Date dateCreated;
118 
119   @Column(name = "last_modified", nullable = false)
120   @Temporal(TemporalType.TIMESTAMP)
121   private Date dateModified;
122 
123   @Column(name = "agreed_to_policy")
124   private boolean agreedToPolicy;
125 
126   @Column(name = "registered")
127   private boolean registered;
128 
129   // The default here is the original terms of use.
130   // Note that this object doesn't get instanciated unless you've agreed to the terms *at some point*
131   // so assuming a default of PRE_2022 is reasonable.  Either no agreement -> no db object at all, or
132   // agreement -> PRE_2022 default
133   @Column(name = "terms_version_agreed")
134   private TERMSOFUSEVERSION termsVersionAgreed = TERMSOFUSEVERSION.PRE_2022;
135 
136   // If this is true, then the next stats send pass should delete the registration, then delete this object.
137   @Column(name = "delete_me")
138   private boolean deleteMe = false;
139 
140 
141   //================================================================================
142   // Constructor and Methods
143   //================================================================================
144 
145   /** No-arg constructor needed by JPA. */
146   public Adopter() {
147 
148   }
149 
150   public Adopter(String organisationName, String departmentName, String firstName, String lastName, String email,
151           String country, String postalCode, String city, String street, String streetNo, boolean contactMe,
152           String systemType, boolean allowsStatistics, boolean allowsErrorReports, boolean agreedToPolicy,
153           boolean registered) {
154     this.organisationName = organisationName;
155     this.departmentName = departmentName;
156     this.firstName = firstName;
157     this.lastName = lastName;
158     this.email = email;
159     this.country = country;
160     this.postalCode = postalCode;
161     this.city = city;
162     this.street = street;
163     this.streetNo = streetNo;
164     this.contactMe = contactMe;
165     this.systemType = systemType;
166     this.allowsStatistics = allowsStatistics;
167     this.allowsErrorReports = allowsErrorReports;
168     this.agreedToPolicy = agreedToPolicy;
169     if (this.agreedToPolicy) {
170       this.termsVersionAgreed = getLatestTermsOfUse();
171     }
172     this.registered = registered;
173   }
174 
175   public void merge(Adopter a) {
176     this.organisationName = a.organisationName;
177     this.departmentName = a.departmentName;
178     this.firstName = a.firstName;
179     this.lastName = a.lastName;
180     this.email = a.email;
181     this.country = a.country;
182     this.postalCode = a.postalCode;
183     this.city = a.city;
184     this.street = a.street;
185     this.streetNo = a.streetNo;
186     this.contactMe = a.contactMe;
187     this.systemType = a.systemType;
188     this.allowsStatistics = a.allowsStatistics;
189     this.allowsErrorReports = a.allowsErrorReports;
190     this.agreedToPolicy = a.agreedToPolicy;
191     this.termsVersionAgreed = a.termsVersionAgreed;
192     if (!this.registered) {
193       // overwrite this field only when an adopter isn't registered yet
194       // once an adopter is registered, he stays registered
195       this.registered = a.registered;
196     }
197     this.dateModified = new Date();
198     this.deleteMe = a.deleteMe;
199   }
200 
201   @Override
202   public boolean equals(Object obj) {
203     if (!(obj instanceof Organization)) {
204       return false;
205     }
206     return ((Adopter) obj).adopterKey.equals(adopterKey);
207   }
208 
209   @Override
210   public int hashCode() {
211     return EqualsUtil.hash(adopterKey);
212   }
213 
214   @Override
215   public String toString() {
216     return adopterKey;
217   }
218 
219 
220   //================================================================================
221   // Getter and Setter
222   //================================================================================
223 
224   public String getAdopterKey() {
225     return adopterKey;
226   }
227 
228   public void setAdopterKey(String adopterKey) {
229     this.adopterKey = adopterKey;
230   }
231 
232   public String getStatisticKey() {
233     return statisticKey;
234   }
235 
236   public void setStatisticKey(String statisticKey) {
237     this.statisticKey = statisticKey;
238   }
239 
240   public String getOrganisationName() {
241     return organisationName;
242   }
243 
244   public void setOrganisationName(String organisationName) {
245     this.organisationName = organisationName;
246   }
247 
248   public String getDepartmentName() {
249     return departmentName;
250   }
251 
252   public void setDepartmentName(String departmentName) {
253     this.departmentName = departmentName;
254   }
255 
256   public String getFirstName() {
257     return firstName;
258   }
259 
260   public void setFirstName(String firstName) {
261     this.firstName = firstName;
262   }
263 
264   public String getLastName() {
265     return lastName;
266   }
267 
268   public void setLastName(String lastName) {
269     this.lastName = lastName;
270   }
271 
272   public String getEmail() {
273     return email;
274   }
275 
276   public void setEmail(String email) {
277     this.email = email;
278   }
279 
280   public String getCountry() {
281     return country;
282   }
283 
284   public void setCountry(String country) {
285     this.country = country;
286   }
287 
288   public String getPostalCode() {
289     return postalCode;
290   }
291 
292   public void setPostalCode(String postalCode) {
293     this.postalCode = postalCode;
294   }
295 
296   public String getCity() {
297     return city;
298   }
299 
300   public void setCity(String city) {
301     this.city = city;
302   }
303 
304   public String getStreet() {
305     return street;
306   }
307 
308   public void setStreet(String street) {
309     this.street = street;
310   }
311 
312   public String getStreetNo() {
313     return streetNo;
314   }
315 
316   public void setStreetNo(String streetNo) {
317     this.streetNo = streetNo;
318   }
319 
320   public boolean allowsContacting() {
321     return contactMe;
322   }
323 
324   public void setContactMe(boolean contactMe) {
325     this.contactMe = contactMe;
326   }
327 
328   public String systemType() {
329     return systemType;
330   }
331 
332   public void setSystemType(String systemType) {
333     this.systemType = systemType;
334   }
335 
336   public boolean allowsStatistics() {
337     return allowsStatistics;
338   }
339 
340   public void setAllowsStatistics(boolean allowsStatistics) {
341     this.allowsStatistics = allowsStatistics;
342   }
343 
344   public boolean allowsErrorReports() {
345     return allowsErrorReports;
346   }
347 
348   public void setAllowsErrorReports(boolean allowsErrorReports) {
349     this.allowsErrorReports = allowsErrorReports;
350   }
351 
352   public Date getDateCreated() {
353     return dateCreated;
354   }
355 
356   public void setDateCreated(Date dateCreated) {
357     this.dateCreated = dateCreated;
358   }
359 
360   public Date getDateModified() {
361     return dateModified;
362   }
363 
364   public void setDateModified(Date dateModified) {
365     this.dateModified = dateModified;
366   }
367 
368   public boolean agreedToPolicy() {
369     return agreedToPolicy;
370   }
371 
372   public void setAgreedToPolicy(boolean agreedToPolicy) {
373     this.agreedToPolicy = agreedToPolicy;
374   }
375 
376   public boolean isRegistered() {
377     return registered;
378   }
379 
380   public void setRegistered(boolean registered) {
381     this.registered = registered;
382   }
383 
384   public TERMSOFUSEVERSION getTermsVersionAgreed() {
385     return Objects.requireNonNullElse(termsVersionAgreed, TERMSOFUSEVERSION.PRE_2022);
386   }
387 
388   public void delete() {
389     this.deleteMe = true;
390     this.organisationName = null;
391     this.departmentName = null;
392     this.firstName = null;
393     this.lastName = null;
394     this.email = null;
395     this.country = null;
396     this.postalCode = null;
397     this.city = null;
398     this.street = null;
399     this.streetNo = null;
400     this.contactMe = false;
401     this.systemType = null;
402     this.allowsStatistics = false;
403     this.allowsErrorReports = false;
404     this.dateModified = new Date();
405     this.agreedToPolicy = false;
406   }
407 
408   public boolean shouldDelete() {
409     return this.deleteMe;
410   }
411 }