2 * Copyright (C) 2019 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.model
.common
;
11 import java
.io
.Serializable
;
13 import javax
.persistence
.Basic
;
14 import javax
.persistence
.Column
;
15 import javax
.persistence
.Embeddable
;
16 import javax
.persistence
.FetchType
;
17 import javax
.validation
.constraints
.NotNull
;
18 import javax
.xml
.bind
.annotation
.XmlAccessType
;
19 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
20 import javax
.xml
.bind
.annotation
.XmlAttribute
;
21 import javax
.xml
.bind
.annotation
.XmlElement
;
22 import javax
.xml
.bind
.annotation
.XmlRootElement
;
23 import javax
.xml
.bind
.annotation
.XmlType
;
24 import javax
.xml
.bind
.annotation
.adapters
.XmlJavaTypeAdapter
;
26 import org
.apache
.commons
.lang3
.StringUtils
;
27 import org
.hibernate
.annotations
.Type
;
28 import org
.hibernate
.search
.annotations
.Analyze
;
29 import org
.hibernate
.search
.annotations
.Field
;
30 import org
.hibernate
.search
.annotations
.FieldBridge
;
31 import org
.joda
.time
.DateTime
;
33 import eu
.etaxonomy
.cdm
.common
.URI
;
34 import eu
.etaxonomy
.cdm
.hibernate
.search
.UriBridge
;
35 import eu
.etaxonomy
.cdm
.jaxb
.DateTimeAdapter
;
36 import eu
.etaxonomy
.cdm
.validation
.annotation
.NullOrNotEmpty
;
39 * Embedabble class to embed attributes to use externally managed data
43 @XmlAccessorType(XmlAccessType
.FIELD
)
44 @XmlType(name
= "ExternallyManaged", propOrder
= {
51 @XmlRootElement(name
= "ExternallyManaged")
53 public class ExternallyManaged
implements Cloneable
, Serializable
, ICheckEmpty
{
55 private static final long serialVersionUID
= -2254347420863435872L;
58 //attributes for externally managed
60 // @XmlElement (name = "LastRetrieved", type= String.class)
61 @XmlJavaTypeAdapter(DateTimeAdapter
.class)
62 @Type(type
="dateTimeUserType")
64 @Basic(fetch
= FetchType
.LAZY
)
65 @Column(name
="lastRetrieved")
66 private DateTime lastRetrieved
;
68 @XmlElement(name
="ExternalId" )
70 // @Match(MatchMode.EQUAL) //TODO check if this is correct
72 @Column(name
="externalId", length
=255)
73 private String externalId
;
75 //Actionable link e.g. to a webservice
76 @XmlElement(name
= "ExternalLink")
77 @Field(analyze
= Analyze
.NO
)
78 @FieldBridge(impl
= UriBridge
.class)
79 @Type(type
="uriUserType")
80 @Column(name
="externalLink")
81 private URI externalLink
;
83 @XmlAttribute(name
="authority")
84 @Column(name
="authorityType", length
=10)
85 @Type(type
= "eu.etaxonomy.cdm.hibernate.EnumUserType",
86 parameters
= {@org.hibernate
.annotations
.Parameter(name
= "enumClass", value
= "eu.etaxonomy.cdm.model.common.AuthorityType")}
89 private AuthorityType authorityType
;
91 @XmlAttribute(name
="importMethod")
92 @Column(name
="importMethod", length
=30)
93 @Type(type
= "eu.etaxonomy.cdm.hibernate.EnumUserType",
94 parameters
= {@org.hibernate
.annotations
.Parameter(name
= "enumClass", value
= "eu.etaxonomy.cdm.model.common.ExternallyManagedImport")}
97 private ExternallyManagedImport importMethod
;
99 //************************* **********************/
102 public boolean checkEmpty() {
103 return authorityType
== null && StringUtils
.isBlank(externalId
)
104 && externalLink
== null && importMethod
== null && lastRetrieved
== null;
107 // ************************ GETTER /SETTER ***********************/
109 public DateTime
getLastRetrieved() {
110 return lastRetrieved
;
112 public void setLastRetrieved(DateTime lastRetrieved
) {
113 this.lastRetrieved
= lastRetrieved
;
116 public String
getExternalId() {
119 public void setExternalId(String externalId
) {
120 this.externalId
= externalId
;
123 public URI
getExternalLink() {
126 public void setExternalLink(URI externalLink
) {
127 this.externalLink
= externalLink
;
130 public AuthorityType
getAuthorityType() {
131 return authorityType
;
133 public void setAuthorityType(AuthorityType authorityType
) {
134 this.authorityType
= authorityType
;
137 public ExternallyManagedImport
getImportMethod() {
140 public void setImportMethod(ExternallyManagedImport importMethod
) {
141 this.importMethod
= importMethod
;
144 // ********************** CLONE ***********************************/
147 protected Object
clone() throws CloneNotSupportedException
{
148 ExternallyManaged result
= (ExternallyManaged
)super.clone();