2 * Copyright (C) 2007 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.
10 package eu
.etaxonomy
.cdm
.model
.common
;
13 import java
.util
.HashSet
;
16 import javax
.persistence
.Column
;
17 import javax
.persistence
.Entity
;
18 import javax
.persistence
.FetchType
;
19 import javax
.persistence
.Inheritance
;
20 import javax
.persistence
.InheritanceType
;
21 import javax
.persistence
.OneToMany
;
22 import javax
.validation
.constraints
.NotNull
;
23 import javax
.xml
.bind
.annotation
.XmlAccessType
;
24 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
25 import javax
.xml
.bind
.annotation
.XmlAttribute
;
26 import javax
.xml
.bind
.annotation
.XmlElement
;
27 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
28 import javax
.xml
.bind
.annotation
.XmlRootElement
;
29 import javax
.xml
.bind
.annotation
.XmlType
;
31 import org
.apache
.commons
.lang
.StringUtils
;
32 import org
.apache
.log4j
.Logger
;
33 import org
.hibernate
.annotations
.Cascade
;
34 import org
.hibernate
.annotations
.CascadeType
;
35 import org
.hibernate
.annotations
.Table
;
36 import org
.hibernate
.annotations
.Type
;
37 import org
.hibernate
.envers
.Audited
;
38 import org
.springframework
.util
.Assert
;
40 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
41 import eu
.etaxonomy
.cdm
.model
.media
.ExternalLink
;
42 import eu
.etaxonomy
.cdm
.strategy
.merge
.Merge
;
43 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeMode
;
46 * Abstract base class for classes implementing {@link eu.etaxonomy.cdm.model.common.IOriginalSource IOriginalSource}.
47 * @see eu.etaxonomy.cdm.model.common.IOriginalSource
50 * @since 08-Nov-2007 13:06:22
53 @XmlAccessorType(XmlAccessType
.FIELD
)
54 @XmlType(name
= "OriginalSource", propOrder
= {
60 @XmlRootElement(name
= "OriginalSource")
63 @Inheritance(strategy
=InheritanceType
.SINGLE_TABLE
)
64 @Table(appliesTo
="OriginalSourceBase")
65 public abstract class OriginalSourceBase
<T
extends ISourceable
>
66 extends ReferencedEntityBase
67 implements IOriginalSource
<T
>, IIntextReferenceTarget
,Cloneable
{
68 private static final long serialVersionUID
= -1972959999261181462L;
69 @SuppressWarnings("unused")
70 private static final Logger logger
= Logger
.getLogger(OriginalSourceBase
.class);
73 * The {@link OriginalSourceType type} of this source. According to PROV the type has to be thought as
74 * an activity that leads from the source entity to the current entity. It is not a property of the
77 @XmlAttribute(name
="type")
78 @Column(name
="sourceType")
80 @Type(type
= "eu.etaxonomy.cdm.hibernate.EnumUserType",
81 parameters
= {@org.hibernate
.annotations
.Parameter(name
="enumClass", value
="eu.etaxonomy.cdm.model.common.OriginalSourceType")}
84 private OriginalSourceType type
;
86 //The object's ID in the source, where the alternative string comes from
87 @XmlElement(name
= "IdInSource")
88 private String idInSource
;
90 @XmlElement(name
= "IdNamespace")
91 private String idNamespace
;
93 @XmlElementWrapper(name
= "Links", nillable
= true)
94 @XmlElement(name
= "Link")
95 @OneToMany(fetch
=FetchType
.LAZY
, orphanRemoval
=true)
96 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
, CascadeType
.DELETE
})
97 @Merge(MergeMode
.ADD_CLONE
)
98 private Set
<ExternalLink
> links
= new HashSet
<>();
100 //***************** CONSTRUCTOR ***********************/
102 //for hibernate use only
103 protected OriginalSourceBase() {
111 protected OriginalSourceBase(OriginalSourceType type
){
113 throw new IllegalArgumentException("OriginalSourceType must not be null");
118 //**************** GETTER / SETTER *******************************/
122 public String
getIdInSource(){
123 return this.idInSource
;
126 public void setIdInSource(String idInSource
){
127 this.idInSource
= idInSource
;
132 public String
getIdNamespace() {
136 public void setIdNamespace(String idNamespace
) {
137 this.idNamespace
= idNamespace
;
142 public OriginalSourceType
getType() {
146 public void setType(OriginalSourceType type
) {
147 Assert
.notNull(type
, "OriginalSourceType must not be null");
151 //********************** External Links **********************************************
153 public Set
<ExternalLink
> getLinks(){
156 public void addLink(ExternalLink link
){
161 public void removeLink(ExternalLink link
){
162 if(links
.contains(link
)) {
167 //********************** CLONE ************************************************/
170 public Object
clone() throws CloneNotSupportedException
{
171 OriginalSourceBase
<?
> result
= (OriginalSourceBase
<?
>)super.clone();
173 //no changes to: idInSource
178 //************************ toString ***************************************/
180 public String
toString(){
181 if (StringUtils
.isNotBlank(idInSource
) || StringUtils
.isNotBlank(idNamespace
) ){
182 return "OriginalSource:" + CdmUtils
.concat(":", idNamespace
, idInSource
);
184 return super.toString();
188 //*********************************** EQUALS *********************************************************/
194 public boolean equalsByShallowCompare(ReferencedEntityBase other
) {
196 if(!super.equalsByShallowCompare(other
)) {
199 OriginalSourceBase
<T
> theOther
= (OriginalSourceBase
<T
>)other
;
200 if(!StringUtils
.equals(this.getIdInSource(), theOther
.getIdInSource())
201 || !StringUtils
.equals(this.getIdNamespace(), theOther
.getIdNamespace())) {