1
|
/**
|
2
|
* Copyright (C) 2009 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.media;
|
11
|
|
12
|
import java.util.HashSet;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import javax.persistence.FetchType;
|
16
|
import javax.persistence.ManyToMany;
|
17
|
import javax.persistence.MappedSuperclass;
|
18
|
import javax.xml.bind.annotation.XmlAccessType;
|
19
|
import javax.xml.bind.annotation.XmlAccessorType;
|
20
|
import javax.xml.bind.annotation.XmlElement;
|
21
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
22
|
import javax.xml.bind.annotation.XmlIDREF;
|
23
|
import javax.xml.bind.annotation.XmlSchemaType;
|
24
|
import javax.xml.bind.annotation.XmlType;
|
25
|
|
26
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
27
|
import org.hibernate.annotations.Cascade;
|
28
|
import org.hibernate.annotations.CascadeType;
|
29
|
import org.hibernate.envers.Audited;
|
30
|
|
31
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
32
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
33
|
import eu.etaxonomy.cdm.strategy.merge.Merge;
|
34
|
import eu.etaxonomy.cdm.strategy.merge.MergeMode;
|
35
|
|
36
|
@XmlAccessorType(XmlAccessType.FIELD)
|
37
|
@XmlType(name = "IdentifiableMediaEntity", propOrder = {
|
38
|
"media"
|
39
|
})
|
40
|
@MappedSuperclass
|
41
|
@Audited
|
42
|
public abstract class IdentifiableMediaEntity<S extends IIdentifiableEntityCacheStrategy<?>>
|
43
|
extends IdentifiableEntity<S>
|
44
|
implements IMediaEntity{
|
45
|
|
46
|
private static final long serialVersionUID = 4038647011021908313L;
|
47
|
@SuppressWarnings("unused")
|
48
|
private static final Logger logger = LogManager.getLogger(IdentifiableMediaEntity.class);
|
49
|
|
50
|
@XmlElementWrapper(name = "Media", nillable = true)
|
51
|
@XmlElement(name = "Medium")
|
52
|
@XmlIDREF
|
53
|
@XmlSchemaType(name = "IDREF")
|
54
|
@ManyToMany(fetch = FetchType.LAZY)
|
55
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
56
|
//TODO
|
57
|
@Merge(MergeMode.ADD_CLONE)
|
58
|
private Set<Media> media = new HashSet<>();
|
59
|
|
60
|
|
61
|
@Override
|
62
|
public Set<Media> getMedia() {
|
63
|
return media;
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
public void addMedia(Media media) {
|
68
|
this.media.add(media);
|
69
|
}
|
70
|
@Override
|
71
|
public void removeMedia(Media media) {
|
72
|
this.media.remove(media);
|
73
|
}
|
74
|
|
75
|
//******************** CLONE **********************************************/
|
76
|
|
77
|
@Override
|
78
|
public IdentifiableMediaEntity<S> clone() throws CloneNotSupportedException{
|
79
|
IdentifiableMediaEntity<S> result = (IdentifiableMediaEntity<S>)super.clone();
|
80
|
//Media
|
81
|
result.media = new HashSet<>();
|
82
|
for(Media media : this.media) {
|
83
|
result.addMedia(media);
|
84
|
}
|
85
|
//no changes to: -
|
86
|
return result;
|
87
|
}
|
88
|
|
89
|
}
|