fix bugs and adapt tests for original source type
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / OriginalSourceBase.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.cdm.model.common;
11
12
13 import javax.persistence.Column;
14 import javax.persistence.Entity;
15 import javax.persistence.Inheritance;
16 import javax.persistence.InheritanceType;
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
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.log4j.Logger;
27 import org.hibernate.annotations.Table;
28 import org.hibernate.envers.Audited;
29 import org.springframework.util.Assert;
30
31 import eu.etaxonomy.cdm.common.CdmUtils;
32
33 /**
34 * Abstract base class for classes implementing {@link eu.etaxonomy.cdm.model.common.IOriginalSource IOriginalSource}.
35 * @see eu.etaxonomy.cdm.model.common.IOriginalSource
36 *
37 * @author m.doering
38 * @version 1.0
39 * @created 08-Nov-2007 13:06:22
40 */
41
42 @XmlAccessorType(XmlAccessType.FIELD)
43 @XmlType(name = "OriginalSource", propOrder = {
44 "type",
45 "idInSource",
46 "idNamespace"
47 })
48 @XmlRootElement(name = "OriginalSource")
49 @Entity
50 @Audited
51 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
52 @Table(appliesTo="OriginalSourceBase")
53 public abstract class OriginalSourceBase<T extends ISourceable> extends ReferencedEntityBase implements IOriginalSource<T>, Cloneable {
54 private static final long serialVersionUID = -1972959999261181462L;
55 @SuppressWarnings("unused")
56 private static final Logger logger = Logger.getLogger(OriginalSourceBase.class);
57
58
59
60 /**
61 * The {@link OriginalSourceType type} of this source. According to PROV the type has to be thought as
62 * an activity that leads from the source entity to the current entity. It is not a property of the
63 * source itself.
64 */
65 @XmlAttribute(name ="type")
66 @Column(name="sourceType")
67 @NotNull
68 private OriginalSourceType type;
69
70 //The object's ID in the source, where the alternative string comes from
71 @XmlElement(name = "IdInSource")
72 private String idInSource;
73
74 @XmlElement(name = "IdNamespace")
75 private String idNamespace;
76
77 //***************** CONSTRUCTOR ***********************/
78
79 //for hibernate use only
80 protected OriginalSourceBase() {
81
82 }
83
84 /**
85 * Constructor
86 * @param type2
87 */
88 protected OriginalSourceBase(OriginalSourceType type){
89 Assert.notNull(type, "OriginalSourceType must not be null");
90 this.type = type;
91 }
92
93 //**************** GETTER / SETTER *******************************/
94
95
96 /* (non-Javadoc)
97 * @see eu.etaxonomy.cdm.model.common.IOriginalSource#getIdInSource()
98 */
99 public String getIdInSource(){
100 return this.idInSource;
101 }
102 /* (non-Javadoc)
103 * @see eu.etaxonomy.cdm.model.common.IOriginalSource#setIdInSource(java.lang.String)
104 */
105 public void setIdInSource(String idInSource){
106 this.idInSource = idInSource;
107 }
108
109
110 /* (non-Javadoc)
111 * @see eu.etaxonomy.cdm.model.common.IOriginalSource#getIdNamespace()
112 */
113 public String getIdNamespace() {
114 return idNamespace;
115 }
116
117 /* (non-Javadoc)
118 * @see eu.etaxonomy.cdm.model.common.IOriginalSource#setIdNamespace(java.lang.String)
119 */
120 public void setIdNamespace(String idNamespace) {
121 this.idNamespace = idNamespace;
122 }
123
124
125 public OriginalSourceType getType() {
126 return type;
127 }
128
129 public void setType(OriginalSourceType type) {
130 Assert.notNull(type, "OriginalSourceType must not be null");
131 this.type = type;
132 }
133
134
135 //********************** CLONE ************************************************/
136
137 /* (non-Javadoc)
138 * @see java.lang.Object#clone()
139 */
140 @Override
141 public Object clone() throws CloneNotSupportedException{
142 OriginalSourceBase<?> result = (OriginalSourceBase<?>)super.clone();
143
144 //no changes to: idInSource, sourcedObj
145 return result;
146 }
147
148
149 //************************ toString ***************************************/
150 @Override
151 public String toString(){
152 if (StringUtils.isNotBlank(idInSource) || StringUtils.isNotBlank(idNamespace) ){
153 return "OriginalSource:" + CdmUtils.concat(":", idNamespace, idInSource);
154 }else{
155 return super.toString();
156 }
157 }
158
159 }