ref #9771 add handling for externally managed
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / ExternallyManaged.java
1 /**
2 * Copyright (C) 2019 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.cdm.model.common;
10
11 import java.io.Serializable;
12
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;
25
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;
32
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;
37
38 /**
39 * Embedabble class to embed attributes to use externally managed data
40 * @author a.mueller
41 * @since 12.08.2019
42 */
43 @XmlAccessorType(XmlAccessType.FIELD)
44 @XmlType(name = "ExternallyManaged", propOrder = {
45 "lastRetrieved",
46 "externalId",
47 "externalLink",
48 "authorityType",
49 "importMethod"
50 })
51 @XmlRootElement(name = "ExternallyManaged")
52 @Embeddable
53 public class ExternallyManaged implements Cloneable, Serializable, ICheckEmpty{
54
55 private static final long serialVersionUID = -2254347420863435872L;
56
57
58 //attributes for externally managed
59
60 // @XmlElement (name = "LastRetrieved", type= String.class)
61 @XmlJavaTypeAdapter(DateTimeAdapter.class)
62 @Type(type="dateTimeUserType")
63 //TODO needed??
64 @Basic(fetch = FetchType.LAZY)
65 @Column(name="lastRetrieved")
66 private DateTime lastRetrieved;
67
68 @XmlElement(name ="ExternalId" )
69 // @Field
70 // @Match(MatchMode.EQUAL) //TODO check if this is correct
71 @NullOrNotEmpty
72 @Column(name="externalId", length=255)
73 private String externalId;
74
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;
82
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")}
87 )
88 @NotNull
89 private AuthorityType authorityType;
90
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")}
95 )
96 @NotNull
97 private ExternallyManagedImport importMethod;
98
99 //************************* **********************/
100
101 @Override
102 public boolean checkEmpty() {
103 return authorityType == null && StringUtils.isBlank(externalId)
104 && externalLink == null && importMethod == null && lastRetrieved == null;
105 }
106
107 // ************************ GETTER /SETTER ***********************/
108
109 public DateTime getLastRetrieved() {
110 return lastRetrieved;
111 }
112 public void setLastRetrieved(DateTime lastRetrieved) {
113 this.lastRetrieved = lastRetrieved;
114 }
115
116 public String getExternalId() {
117 return externalId;
118 }
119 public void setExternalId(String externalId) {
120 this.externalId = externalId;
121 }
122
123 public URI getExternalLink() {
124 return externalLink;
125 }
126 public void setExternalLink(URI externalLink) {
127 this.externalLink = externalLink;
128 }
129
130 public AuthorityType getAuthorityType() {
131 return authorityType;
132 }
133 public void setAuthorityType(AuthorityType authorityType) {
134 this.authorityType = authorityType;
135 }
136
137 public ExternallyManagedImport getImportMethod() {
138 return importMethod;
139 }
140 public void setImportMethod(ExternallyManagedImport importMethod) {
141 this.importMethod = importMethod;
142 }
143
144 // ********************** CLONE ***********************************/
145
146 @Override
147 protected Object clone() throws CloneNotSupportedException {
148 ExternallyManaged result = (ExternallyManaged)super.clone();
149
150 return result;
151 }
152
153 }