Project

General

Profile

Download (6.41 KB) Statistics
| Branch: | Tag: | Revision:
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
import java.util.HashSet;
13
import java.util.Set;
14
import java.util.UUID;
15

    
16
import javax.persistence.FetchType;
17
import javax.persistence.MappedSuperclass;
18
import javax.persistence.OneToMany;
19
import javax.xml.bind.annotation.XmlAccessType;
20
import javax.xml.bind.annotation.XmlAccessorType;
21
import javax.xml.bind.annotation.XmlElement;
22
import javax.xml.bind.annotation.XmlElementWrapper;
23
import javax.xml.bind.annotation.XmlType;
24

    
25
import org.apache.log4j.Logger;
26
import org.hibernate.annotations.Cascade;
27
import org.hibernate.annotations.CascadeType;
28
import org.hibernate.envers.Audited;
29

    
30
import eu.etaxonomy.cdm.strategy.merge.Merge;
31
import eu.etaxonomy.cdm.strategy.merge.MergeMode;
32

    
33
/**
34
 * Abstract superclass implementing human annotations and machine markers to be assigned to CDM objects.
35
 * @author m.doering
36
 * @version 1.0
37
 * @created 08-Nov-2007 13:06:10
38
 */
39
@XmlAccessorType(XmlAccessType.FIELD)
40
@XmlType(name = "AnnotatableEntity", propOrder = {
41
    "markers",
42
    "annotations"
43
})
44
@Audited
45
@MappedSuperclass
46
public abstract class AnnotatableEntity extends VersionableEntity implements IAnnotatableEntity {
47
	private static final long serialVersionUID = 9151211842542443102L;
48
	@SuppressWarnings("unused")
49
	private static final Logger logger = Logger.getLogger(AnnotatableEntity.class);
50

    
51
	@XmlElementWrapper(name = "Markers", nillable = true)
52
	@XmlElement(name = "Marker")
53
	@OneToMany(fetch=FetchType.LAZY, orphanRemoval=true)
54
	@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
55
	@Merge(MergeMode.ADD_CLONE)
56
	protected Set<Marker> markers = new HashSet<Marker>();
57

    
58
	@XmlElementWrapper(name = "Annotations", nillable = true)
59
	@XmlElement(name = "Annotation")
60
    @OneToMany(fetch=FetchType.LAZY, orphanRemoval=true)
61
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
62
	@Merge(MergeMode.ADD_CLONE)
63
	protected Set<Annotation> annotations = new HashSet<Annotation>();
64

    
65
	protected AnnotatableEntity() {
66
		super();
67
	}
68

    
69
//*************** MARKER **********************************************
70

    
71

    
72
	@Override
73
    public Set<Marker> getMarkers(){
74
		return this.markers;
75
	}
76

    
77
	@Override
78
    public void addMarker(Marker marker){
79
		if (marker != null){
80
			getMarkers().add(marker);
81
		}
82
	}
83
	@Override
84
    public void removeMarker(Marker marker){
85
		if(getMarkers().contains(marker)) {
86
			getMarkers().remove(marker);
87
		}
88
	}
89

    
90
	@Override
91
    public boolean hasMarker(MarkerType type, boolean value){
92
		return hasMarker(type.getUuid(), value);
93
	}
94

    
95
	@Override
96
    public boolean hasMarker(UUID uuidMarkerType, boolean value){
97
		for (Marker marker: getMarkers()){
98
			if (marker.getMarkerType().getUuid().equals(uuidMarkerType)){
99
				if (marker.getFlag() == value){
100
					return true;
101
				}
102
			}
103
		}
104
		return false;
105
	}
106

    
107
//*************** ANNOTATIONS **********************************************
108

    
109
	@Override
110
    public Set<Annotation> getAnnotations(){
111
		return this.annotations;
112
	}
113
	@Override
114
    public void addAnnotation(Annotation annotation){
115
		if (annotation != null){
116
			getAnnotations().add(annotation);
117
		}
118
	}
119

    
120
	@Override
121
    public void removeAnnotation(Annotation annotation){
122
		if(getAnnotations().contains(annotation)) {
123
			getAnnotations().remove(annotation);
124
		}
125
	}
126

    
127
//********************** CLONE *****************************************/
128

    
129

    
130
	@Override
131
	public Object clone() throws CloneNotSupportedException{
132
		AnnotatableEntity result = (AnnotatableEntity)super.clone();
133

    
134
		//Annotations
135
		result.annotations = new HashSet<Annotation>();
136
		for (Annotation annotation : getAnnotations()){
137
			Annotation newAnnotation = (Annotation)annotation.clone();
138
			result.addAnnotation(newAnnotation);
139
		}
140

    
141
		//Markers
142
		result.markers = new HashSet<Marker>();
143
		for (Marker marker : getMarkers()){
144
			Marker newMarker = (Marker)marker.clone();
145
			result.addMarker(newMarker);
146
		}
147

    
148
		//no changes to: -
149
		return result;
150
	}
151
}
(1-1/72)