1 |
2b296096
|
Andreas M��ller
|
// $Id$
|
2 |
|
|
/**
|
3 |
|
|
* Copyright (C) 2015 EDIT
|
4 |
|
|
* European Distributed Institute of Taxonomy
|
5 |
|
|
* http://www.e-taxonomy.eu
|
6 |
|
|
*
|
7 |
|
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8 |
|
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9 |
|
|
*/
|
10 |
|
|
package eu.etaxonomy.cdm.model.taxon;
|
11 |
|
|
|
12 |
|
|
import javax.persistence.Entity;
|
13 |
|
|
import javax.persistence.FetchType;
|
14 |
|
|
import javax.persistence.ManyToOne;
|
15 |
63228380
|
Andreas M��ller
|
import javax.validation.constraints.NotNull;
|
16 |
2b296096
|
Andreas M��ller
|
import javax.xml.bind.annotation.XmlAccessType;
|
17 |
|
|
import javax.xml.bind.annotation.XmlAccessorType;
|
18 |
|
|
import javax.xml.bind.annotation.XmlElement;
|
19 |
|
|
import javax.xml.bind.annotation.XmlIDREF;
|
20 |
|
|
import javax.xml.bind.annotation.XmlRootElement;
|
21 |
|
|
import javax.xml.bind.annotation.XmlSchemaType;
|
22 |
|
|
import javax.xml.bind.annotation.XmlType;
|
23 |
|
|
|
24 |
|
|
import org.apache.log4j.Logger;
|
25 |
|
|
import org.hibernate.annotations.Cascade;
|
26 |
|
|
import org.hibernate.annotations.CascadeType;
|
27 |
|
|
import org.hibernate.envers.Audited;
|
28 |
|
|
import org.springframework.security.core.GrantedAuthority;
|
29 |
|
|
|
30 |
|
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
31 |
|
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
32 |
|
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
33 |
63228380
|
Andreas M��ller
|
import eu.etaxonomy.cdm.model.common.TermType;
|
34 |
2b296096
|
Andreas M��ller
|
|
35 |
|
|
/**
|
36 |
|
|
* This class relates a TaxonNode (Taxon within it's given publication context)
|
37 |
|
|
* to an agent (person or team) and defining a type for this relationship.
|
38 |
|
|
* This is to indicate that an agent plays a certain role for this taxon
|
39 |
|
|
* (e.g. author of the according subtree, last scrutiny, ...).
|
40 |
|
|
* It is not meant to define rights and roles which are only handled via the
|
41 |
|
|
* {@link GrantedAuthority granted authorities}.
|
42 |
|
|
* @author a.mueller
|
43 |
|
|
* @date 29.05.2015
|
44 |
|
|
*/
|
45 |
|
|
@XmlAccessorType(XmlAccessType.FIELD)
|
46 |
|
|
@XmlType(name = "TaxonNodeAgentRelation", propOrder = {
|
47 |
|
|
"taxonNode",
|
48 |
|
|
"agent",
|
49 |
|
|
"type",
|
50 |
|
|
})
|
51 |
|
|
@XmlRootElement(name = "TaxonNodeAgentRelation")
|
52 |
|
|
@Entity
|
53 |
|
|
@Audited
|
54 |
|
|
public class TaxonNodeAgentRelation extends AnnotatableEntity {
|
55 |
|
|
private static final long serialVersionUID = -1476342569350403356L;
|
56 |
|
|
private static final Logger logger = Logger.getLogger(TaxonNodeAgentRelation.class);
|
57 |
|
|
|
58 |
|
|
@XmlElement(name = "TaxonNode")
|
59 |
|
|
@XmlIDREF
|
60 |
|
|
@XmlSchemaType(name = "IDREF")
|
61 |
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
62 |
|
|
// @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE}) //the
|
63 |
63228380
|
Andreas M��ller
|
@NotNull
|
64 |
2b296096
|
Andreas M��ller
|
private TaxonNode taxonNode;
|
65 |
|
|
|
66 |
|
|
@XmlElement(name = "Agent")
|
67 |
|
|
@XmlIDREF
|
68 |
|
|
@XmlSchemaType(name = "IDREF")
|
69 |
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
70 |
|
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
|
71 |
63228380
|
Andreas M��ller
|
@NotNull
|
72 |
2b296096
|
Andreas M��ller
|
private TeamOrPersonBase<?> agent;
|
73 |
|
|
|
74 |
|
|
@XmlElement(name = "Type")
|
75 |
|
|
@XmlIDREF
|
76 |
|
|
@XmlSchemaType(name = "IDREF")
|
77 |
|
|
@ManyToOne(fetch = FetchType.EAGER)
|
78 |
|
|
private DefinedTerm type;
|
79 |
|
|
|
80 |
63228380
|
Andreas M��ller
|
protected static TaxonNodeAgentRelation NewInstance(TaxonNode taxonNode, TeamOrPersonBase<?> agent, DefinedTerm type){
|
81 |
|
|
TaxonNodeAgentRelation result = new TaxonNodeAgentRelation();
|
82 |
|
|
result.taxonNode = taxonNode;
|
83 |
|
|
result.agent = agent;
|
84 |
|
|
result.setType(type);
|
85 |
1cf17f11
|
Andreas M��ller
|
taxonNode.addAgentRelation(result);
|
86 |
63228380
|
Andreas M��ller
|
return result;
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
private TaxonNodeAgentRelation(){}
|
90 |
2b296096
|
Andreas M��ller
|
|
91 |
|
|
//********************* GETTER / SETTER **********************/
|
92 |
|
|
|
93 |
|
|
public TaxonNode getTaxonNode() {
|
94 |
|
|
return taxonNode;
|
95 |
|
|
}
|
96 |
63228380
|
Andreas M��ller
|
protected void setTaxonNode(TaxonNode taxonNode) {
|
97 |
2b296096
|
Andreas M��ller
|
this.taxonNode = taxonNode;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
public TeamOrPersonBase<?> getAgent() {
|
101 |
|
|
return agent;
|
102 |
|
|
}
|
103 |
|
|
public void setAgent(TeamOrPersonBase<?> agent) {
|
104 |
|
|
this.agent = agent;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
public DefinedTerm getType() {
|
108 |
|
|
return type;
|
109 |
|
|
}
|
110 |
|
|
public void setType(DefinedTerm type) {
|
111 |
1cf17f11
|
Andreas M��ller
|
if (type != null && type.getTermType() != TermType.TaxonNodeAgentRelationType){
|
112 |
63228380
|
Andreas M��ller
|
throw new IllegalArgumentException("Only TaxonNode Agent Relation Type terms are allowed as TaxonNodeAgentRelation.type");
|
113 |
|
|
}
|
114 |
2b296096
|
Andreas M��ller
|
this.type = type;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
63228380
|
Andreas M��ller
|
//************************ to String **********************************/
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
@Override
|
121 |
|
|
public String toString() {
|
122 |
|
|
return "TaxonNodeAgentRelation [taxonNode=" + taxonNode +
|
123 |
|
|
", agent=" + agent + ", type=" + type + "]";
|
124 |
|
|
}
|
125 |
|
|
|
126 |
2b296096
|
Andreas M��ller
|
|
127 |
|
|
//************************** clone *******************************************/
|
128 |
|
|
|
129 |
|
|
/**
|
130 |
|
|
* Clones <i>this</i> taxon node agent relation. This is a shortcut that enables to create
|
131 |
|
|
* a new instance that differs only slightly from <i>this</i> relation.
|
132 |
|
|
*
|
133 |
|
|
* @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
|
134 |
|
|
* @see java.lang.Object#clone()
|
135 |
|
|
*/
|
136 |
|
|
@Override
|
137 |
|
|
public Object clone() {
|
138 |
|
|
try{
|
139 |
|
|
TaxonNodeAgentRelation result = (TaxonNodeAgentRelation)super.clone();
|
140 |
|
|
|
141 |
|
|
//no change to taxonNode, agent, type
|
142 |
|
|
return result;
|
143 |
|
|
}catch (CloneNotSupportedException e) {
|
144 |
|
|
logger.warn("Object does not implement cloneable");
|
145 |
|
|
e.printStackTrace();
|
146 |
|
|
return null;
|
147 |
|
|
}
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
}
|