Project

General

Profile

Download (4.98 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 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.taxon;
10

    
11
import javax.persistence.Entity;
12
import javax.persistence.FetchType;
13
import javax.persistence.ManyToOne;
14
import javax.validation.constraints.NotNull;
15
import javax.xml.bind.annotation.XmlAccessType;
16
import javax.xml.bind.annotation.XmlAccessorType;
17
import javax.xml.bind.annotation.XmlElement;
18
import javax.xml.bind.annotation.XmlIDREF;
19
import javax.xml.bind.annotation.XmlRootElement;
20
import javax.xml.bind.annotation.XmlSchemaType;
21
import javax.xml.bind.annotation.XmlType;
22

    
23
import org.apache.log4j.Logger;
24
import org.hibernate.annotations.Cascade;
25
import org.hibernate.annotations.CascadeType;
26
import org.hibernate.envers.Audited;
27
import org.springframework.security.core.GrantedAuthority;
28

    
29
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
30
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
31
import eu.etaxonomy.cdm.model.common.DefinedTerm;
32
import eu.etaxonomy.cdm.model.common.TermType;
33

    
34
/**
35
 * This class relates a TaxonNode (Taxon within it's given publication context)
36
 * to an agent (person or team) and defining a type for this relationship.
37
 * This is to indicate that an agent plays a certain role for this taxon
38
 * (e.g. author of the according subtree, last scrutiny, ...).
39
 * It is not meant to define rights and roles which are only handled via the
40
 * {@link GrantedAuthority granted authorities}.
41
 * @author a.mueller
42
 \* @since 29.05.2015
43
 */
44
@XmlAccessorType(XmlAccessType.FIELD)
45
@XmlType(name = "TaxonNodeAgentRelation", propOrder = {
46
        "taxonNode",
47
        "agent",
48
        "type",
49
    })
50
@XmlRootElement(name = "TaxonNodeAgentRelation")
51
@Entity
52
@Audited
53
public class TaxonNodeAgentRelation extends AnnotatableEntity {
54
    private static final long serialVersionUID = -1476342569350403356L;
55
    private static final Logger logger = Logger.getLogger(TaxonNodeAgentRelation.class);
56

    
57
    @XmlElement(name = "TaxonNode")
58
    @XmlIDREF
59
    @XmlSchemaType(name = "IDREF")
60
    @ManyToOne(fetch = FetchType.LAZY)
61
//    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})  //the
62
    @NotNull
63
    private TaxonNode taxonNode;
64

    
65
    @XmlElement(name = "Agent")
66
    @XmlIDREF
67
    @XmlSchemaType(name = "IDREF")
68
    @ManyToOne(fetch = FetchType.LAZY)
69
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
70
    @NotNull
71
    private TeamOrPersonBase<?> agent;
72

    
73
    @XmlElement(name = "Type")
74
    @XmlIDREF
75
    @XmlSchemaType(name = "IDREF")
76
    @ManyToOne(fetch = FetchType.EAGER)
77
    private DefinedTerm type;
78

    
79
    protected static TaxonNodeAgentRelation NewInstance(TaxonNode taxonNode, TeamOrPersonBase<?> agent, DefinedTerm type){
80
        TaxonNodeAgentRelation result = new TaxonNodeAgentRelation();
81
        result.taxonNode = taxonNode;
82
        result.agent = agent;
83
        result.setType(type);
84
        taxonNode.addAgentRelation(result);
85
        return result;
86
    }
87

    
88
    private TaxonNodeAgentRelation(){}
89

    
90
//********************* GETTER / SETTER **********************/
91

    
92
    public TaxonNode getTaxonNode() {
93
        return taxonNode;
94
    }
95
    protected void setTaxonNode(TaxonNode taxonNode) {
96
        this.taxonNode = taxonNode;
97
    }
98

    
99
    public TeamOrPersonBase<?> getAgent() {
100
        return agent;
101
    }
102
    public void setAgent(TeamOrPersonBase<?> agent) {
103
        this.agent = agent;
104
    }
105

    
106
    public DefinedTerm getType() {
107
        return type;
108
    }
109
    public void setType(DefinedTerm type) {
110
        if (type != null && type.getTermType() != TermType.TaxonNodeAgentRelationType){
111
            throw new IllegalArgumentException("Only TaxonNode Agent Relation Type terms are allowed as TaxonNodeAgentRelation.type");
112
        }
113
        this.type = type;
114
    }
115

    
116
//************************ to String **********************************/
117

    
118

    
119
    @Override
120
    public String toString() {
121
        return "TaxonNodeAgentRelation [taxonNode=" + taxonNode +
122
                ", agent=" + agent + ", type=" + type + "]";
123
    }
124

    
125

    
126
//************************** clone *******************************************/
127

    
128
    /**
129
     * Clones <i>this</i> taxon node agent relation. This is a shortcut that enables to create
130
     * a new instance that differs only slightly from <i>this</i> relation.
131
     *
132
     * @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
133
     * @see java.lang.Object#clone()
134
     */
135
    @Override
136
    public Object clone()  {
137
        try{
138
            TaxonNodeAgentRelation result = (TaxonNodeAgentRelation)super.clone();
139

    
140
            //no change to taxonNode, agent, type
141
            return result;
142
        }catch (CloneNotSupportedException e) {
143
            logger.warn("Object does not implement cloneable");
144
            e.printStackTrace();
145
            return null;
146
        }
147
    }
148

    
149
}
(14-14/21)