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.media;
|
11
|
|
12
|
import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
|
13
|
import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter;
|
14
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
15
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
16
|
import eu.etaxonomy.cdm.model.common.IMultiLanguageText;
|
17
|
import eu.etaxonomy.cdm.model.common.Language;
|
18
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
19
|
import eu.etaxonomy.cdm.model.common.MultilanguageText;
|
20
|
|
21
|
import org.apache.log4j.Logger;
|
22
|
import org.hibernate.annotations.Cascade;
|
23
|
import org.hibernate.annotations.CascadeType;
|
24
|
import org.hibernate.annotations.Type;
|
25
|
import org.hibernate.envers.Audited;
|
26
|
import org.hibernate.search.annotations.Indexed;
|
27
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
28
|
import org.joda.time.DateTime;
|
29
|
|
30
|
import java.util.*;
|
31
|
import javax.persistence.*;
|
32
|
import javax.xml.bind.annotation.XmlAccessType;
|
33
|
import javax.xml.bind.annotation.XmlAccessorType;
|
34
|
import javax.xml.bind.annotation.XmlElement;
|
35
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
36
|
import javax.xml.bind.annotation.XmlElements;
|
37
|
import javax.xml.bind.annotation.XmlIDREF;
|
38
|
import javax.xml.bind.annotation.XmlRootElement;
|
39
|
import javax.xml.bind.annotation.XmlSchemaType;
|
40
|
import javax.xml.bind.annotation.XmlType;
|
41
|
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
42
|
|
43
|
/**
|
44
|
* A {@link Media media} is any kind of media that represents a media object.
|
45
|
* This media object can have multiple {@link MediaRepresentation media representations} that differ in MIME-type
|
46
|
* and/or quality.
|
47
|
* E.g.
|
48
|
* (1) an image can have a tiff and a jpg media representation.
|
49
|
* (2) an formatted text can have a text/html or an application/pdf representation.
|
50
|
* @author m.doering
|
51
|
* @version 1.0
|
52
|
* @created 08-Nov-2007 13:06:34
|
53
|
*/
|
54
|
@XmlAccessorType(XmlAccessType.FIELD)
|
55
|
@XmlType(name = "Media", propOrder = {
|
56
|
"title",
|
57
|
"mediaCreated",
|
58
|
"description",
|
59
|
"representations",
|
60
|
"rights",
|
61
|
"artist"
|
62
|
})
|
63
|
@XmlRootElement(name = "Media")
|
64
|
@Entity
|
65
|
@Indexed
|
66
|
@Audited
|
67
|
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
|
68
|
public class Media extends AnnotatableEntity implements Cloneable {
|
69
|
private static final long serialVersionUID = -1927421567263473658L;
|
70
|
private static final Logger logger = Logger.getLogger(Media.class);
|
71
|
|
72
|
// TODO once hibernate annotations support custom collection type
|
73
|
// private MultilanguageText title = new MultilanguageText();
|
74
|
@XmlElement(name = "MediaTitle")
|
75
|
@XmlJavaTypeAdapter(MultilanguageTextAdapter.class)
|
76
|
@OneToMany(fetch = FetchType.LAZY)
|
77
|
@IndexedEmbedded
|
78
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE,CascadeType.DELETE})
|
79
|
private Map<Language,LanguageString> title = new HashMap<Language,LanguageString>();
|
80
|
|
81
|
//creation date of the media (not of the record)
|
82
|
@XmlElement(name = "MediaCreated", type= String.class)
|
83
|
@XmlJavaTypeAdapter(DateTimeAdapter.class)
|
84
|
@Type(type="dateTimeUserType")
|
85
|
@Basic(fetch = FetchType.LAZY)
|
86
|
private DateTime mediaCreated;
|
87
|
|
88
|
// TODO once hibernate annotations support custom collection type
|
89
|
// private MultilanguageText description = new MultilanguageText();
|
90
|
@XmlElement(name = "MediaDescription")
|
91
|
@XmlJavaTypeAdapter(MultilanguageTextAdapter.class)
|
92
|
@OneToMany(fetch = FetchType.LAZY)
|
93
|
@IndexedEmbedded
|
94
|
@JoinTable(name = "Media_Description")
|
95
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE,CascadeType.DELETE})
|
96
|
private Map<Language,LanguageString> description = new HashMap<Language,LanguageString>();
|
97
|
|
98
|
//A single medium such as a picture can have multiple representations in files.
|
99
|
//Common are multiple resolutions or file formats for images for example
|
100
|
@XmlElementWrapper(name = "MediaRepresentations")
|
101
|
@XmlElement(name = "MediaRepresentation")
|
102
|
@OneToMany(mappedBy="media",fetch = FetchType.LAZY)
|
103
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
|
104
|
private Set<MediaRepresentation> representations = new HashSet<MediaRepresentation>();
|
105
|
|
106
|
// FIXME should be OneToMany?
|
107
|
@XmlElementWrapper(name = "Rights")
|
108
|
@XmlElement(name = "Right")
|
109
|
@ManyToMany(fetch = FetchType.LAZY)
|
110
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
|
111
|
private Set<Rights> rights = new HashSet<Rights>();
|
112
|
|
113
|
@XmlElement(name = "Artist")
|
114
|
@XmlIDREF
|
115
|
@XmlSchemaType(name = "IDREF")
|
116
|
@ManyToOne(fetch = FetchType.LAZY)
|
117
|
@IndexedEmbedded
|
118
|
@Cascade(CascadeType.SAVE_UPDATE)
|
119
|
private AgentBase artist;
|
120
|
|
121
|
/**
|
122
|
* Factory method
|
123
|
* @return
|
124
|
*/
|
125
|
public static Media NewInstance(){
|
126
|
logger.debug("NewInstance");
|
127
|
return new Media();
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* Constructor
|
132
|
*/
|
133
|
protected Media() {
|
134
|
super();
|
135
|
}
|
136
|
|
137
|
public Set<MediaRepresentation> getRepresentations(){
|
138
|
return this.representations;
|
139
|
}
|
140
|
|
141
|
@SuppressWarnings("deprecation")
|
142
|
public void addRepresentation(MediaRepresentation representation){
|
143
|
if (representation != null){
|
144
|
this.getRepresentations().add(representation);
|
145
|
representation.setMedia(this);
|
146
|
}
|
147
|
}
|
148
|
|
149
|
@SuppressWarnings("deprecation")
|
150
|
public void removeRepresentation(MediaRepresentation representation){
|
151
|
this.getRepresentations().remove(representation);
|
152
|
if (representation != null){
|
153
|
representation.setMedia(null);
|
154
|
}
|
155
|
|
156
|
}
|
157
|
|
158
|
public AgentBase getArtist(){
|
159
|
return this.artist;
|
160
|
}
|
161
|
|
162
|
public void setArtist(AgentBase artist){
|
163
|
this.artist = artist;
|
164
|
}
|
165
|
|
166
|
public Set<Rights> getRights(){
|
167
|
return this.rights;
|
168
|
}
|
169
|
|
170
|
public void addRights(Rights rights){
|
171
|
this.rights.add(rights);
|
172
|
}
|
173
|
|
174
|
public void removeRights(Rights rights){
|
175
|
this.rights.remove(rights);
|
176
|
}
|
177
|
|
178
|
public Map<Language,LanguageString> getTitle(){
|
179
|
return this.title;
|
180
|
}
|
181
|
|
182
|
public void addTitle(LanguageString title){
|
183
|
this.title.put(title.getLanguage(), title);
|
184
|
}
|
185
|
|
186
|
public void removeTitle(Language language){
|
187
|
this.title.remove(language);
|
188
|
}
|
189
|
|
190
|
public DateTime getMediaCreated(){
|
191
|
return this.mediaCreated;
|
192
|
}
|
193
|
|
194
|
public void setMediaCreated(DateTime mediaCreated){
|
195
|
this.mediaCreated = mediaCreated;
|
196
|
}
|
197
|
|
198
|
public Map<Language,LanguageString> getDescription(){
|
199
|
return this.description;
|
200
|
}
|
201
|
|
202
|
public void addDescription(LanguageString description){
|
203
|
this.description.put(description.getLanguage(),description);
|
204
|
}
|
205
|
|
206
|
public void addDescription(String text, Language language){
|
207
|
this.description.put(language, LanguageString.NewInstance(text, language));
|
208
|
}
|
209
|
|
210
|
public void removeDescription(Language language){
|
211
|
this.description.remove(language);
|
212
|
}
|
213
|
|
214
|
//************************* CLONE **************************/
|
215
|
|
216
|
|
217
|
/* (non-Javadoc)
|
218
|
* @see java.lang.Object#clone()
|
219
|
*/
|
220
|
@Override
|
221
|
public Object clone() throws CloneNotSupportedException{
|
222
|
Media result = (Media)super.clone();
|
223
|
//description
|
224
|
result.description = new HashMap<Language, LanguageString>();
|
225
|
for (Language language: this.description.keySet()){
|
226
|
result.description.put(language, this.description.get(language));
|
227
|
}
|
228
|
//title
|
229
|
result.title = new HashMap<Language, LanguageString>();
|
230
|
for (Language language: this.title.keySet()){
|
231
|
result.title.put(language, this.title.get(language));
|
232
|
}
|
233
|
//media representations
|
234
|
result.representations = new HashSet<MediaRepresentation>();
|
235
|
for (MediaRepresentation mediaRepresentation: this.representations){
|
236
|
result.representations.add((MediaRepresentation)mediaRepresentation.clone());
|
237
|
}
|
238
|
//rights
|
239
|
result.rights = new HashSet<Rights>();
|
240
|
for (Rights rights: this.rights){
|
241
|
result.rights.add((Rights)rights);
|
242
|
}
|
243
|
//no changes to: artist
|
244
|
return result;
|
245
|
}
|
246
|
}
|