Revision 6df5928c
Added by Andreas Müller over 1 year ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/media/MediaRepresentationPart.java | ||
---|---|---|
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 java.util.HashSet; |
|
13 |
import java.util.Set; |
|
14 |
|
|
15 |
import javax.persistence.Entity; |
|
16 |
import javax.persistence.FetchType; |
|
17 |
import javax.persistence.JoinColumn; |
|
18 |
import javax.persistence.ManyToOne; |
|
19 |
import javax.persistence.OneToMany; |
|
20 |
import javax.xml.bind.annotation.XmlAccessType; |
|
21 |
import javax.xml.bind.annotation.XmlAccessorType; |
|
22 |
import javax.xml.bind.annotation.XmlElement; |
|
23 |
import javax.xml.bind.annotation.XmlElementWrapper; |
|
24 |
import javax.xml.bind.annotation.XmlIDREF; |
|
25 |
import javax.xml.bind.annotation.XmlSchemaType; |
|
26 |
import javax.xml.bind.annotation.XmlType; |
|
27 |
|
|
28 |
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger; |
|
29 |
import org.hibernate.annotations.Cascade; |
|
30 |
import org.hibernate.annotations.CascadeType; |
|
31 |
import org.hibernate.annotations.Type; |
|
32 |
import org.hibernate.envers.Audited; |
|
33 |
import org.hibernate.search.annotations.FieldBridge; |
|
34 |
|
|
35 |
import eu.etaxonomy.cdm.common.URI; |
|
36 |
import eu.etaxonomy.cdm.hibernate.search.UriBridge; |
|
37 |
import eu.etaxonomy.cdm.model.common.VersionableEntity; |
|
38 |
|
|
39 |
/** |
|
40 |
* A media representation part is a resource that can be referenced by an URI. |
|
41 |
* It represents a part of or the entire media. <br> |
|
42 |
* E.g. a jpg file or a website |
|
43 |
* |
|
44 |
* @author a.mueller |
|
45 |
* @since 09.06.2008 |
|
46 |
*/ |
|
47 |
@XmlAccessorType(XmlAccessType.FIELD) |
|
48 |
@XmlType(name = "MediaRepresentationPart", propOrder = { |
|
49 |
"uri", |
|
50 |
"size", |
|
51 |
"mediaRepresentation", |
|
52 |
"mediaMetaData" |
|
53 |
}) |
|
54 |
@Entity |
|
55 |
@Audited |
|
56 |
public class MediaRepresentationPart extends VersionableEntity { |
|
57 |
private static final long serialVersionUID = -1674422508643785796L; |
|
58 |
@SuppressWarnings("unused") |
|
59 |
private static final Logger logger = LogManager.getLogger(MediaRepresentationPart.class); |
|
60 |
|
|
61 |
// where the media file is stored |
|
62 |
@XmlElement(name = "URI") |
|
63 |
@FieldBridge(impl = UriBridge.class) |
|
64 |
@Type(type="uriUserType") |
|
65 |
private URI uri; |
|
66 |
|
|
67 |
// in bytes |
|
68 |
@XmlElement(name = "Size") |
|
69 |
private Integer size; |
|
70 |
|
|
71 |
// the MediaRepresentation of this MediaRepresentationPart |
|
72 |
@XmlElement(name = "MediaRepresentation") |
|
73 |
@XmlIDREF |
|
74 |
@XmlSchemaType(name = "IDREF") |
|
75 |
@ManyToOne(fetch = FetchType.LAZY) |
|
76 |
@JoinColumn(name = "representation_id", nullable = false, updatable = false, insertable = false) |
|
77 |
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE}) |
|
78 |
private MediaRepresentation mediaRepresentation; |
|
79 |
|
|
80 |
@XmlElementWrapper(name = "MediaMetaDatas") |
|
81 |
@XmlElement(name = "MediaMetaData") |
|
82 |
@OneToMany (mappedBy="mediaRepresentation", fetch= FetchType.LAZY, orphanRemoval=true) |
|
83 |
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE, CascadeType.REFRESH}) |
|
84 |
private Set<MediaMetaData> mediaMetaData = new HashSet<>(); |
|
85 |
|
|
86 |
|
|
87 |
// *************** FACTORY METHOD *********************************/ |
|
88 |
|
|
89 |
public static MediaRepresentationPart NewInstance(URI uri, Integer size) { |
|
90 |
MediaRepresentationPart result = new MediaRepresentationPart(uri, size); |
|
91 |
return result; |
|
92 |
} |
|
93 |
|
|
94 |
protected MediaRepresentationPart() { |
|
95 |
super(); |
|
96 |
} |
|
97 |
|
|
98 |
protected MediaRepresentationPart(URI uri, Integer size) { |
|
99 |
this(); |
|
100 |
this.setUri(uri); |
|
101 |
this.setSize(size); |
|
102 |
} |
|
103 |
|
|
104 |
//*************** GETTER / SETTER *************************************/ |
|
105 |
|
|
106 |
public MediaRepresentation getMediaRepresentation() { |
|
107 |
return this.mediaRepresentation; |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* @deprecated for internal (bidirectional) use only |
|
112 |
*/ |
|
113 |
@Deprecated |
|
114 |
protected void setMediaRepresentation(MediaRepresentation mediaRepresentation) { |
|
115 |
this.mediaRepresentation = mediaRepresentation; |
|
116 |
} |
|
117 |
|
|
118 |
//uri |
|
119 |
public URI getUri() { |
|
120 |
return this.uri; |
|
121 |
} |
|
122 |
|
|
123 |
public void setUri(URI uri) { |
|
124 |
this.uri = uri; |
|
125 |
} |
|
126 |
|
|
127 |
//size |
|
128 |
public Integer getSize() { |
|
129 |
return this.size; |
|
130 |
} |
|
131 |
public void setSize(Integer size) { |
|
132 |
this.size = size; |
|
133 |
} |
|
134 |
|
|
135 |
//metadata |
|
136 |
|
|
137 |
|
|
138 |
public void addMediaMetaData(MediaMetaData metaData){ |
|
139 |
this.mediaMetaData.add(metaData); |
|
140 |
if(metaData.getMediaRepresentation() != this){ |
|
141 |
metaData.setMediaRepresentation(this); |
|
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
public Set<MediaMetaData> getMediaMetaData() { |
|
146 |
return mediaMetaData; |
|
147 |
} |
|
148 |
|
|
149 |
// public void setMediaMetaData(Set<MediaMetaData> mediaMetaData) { |
|
150 |
// this.mediaMetaData = mediaMetaData; |
|
151 |
// } |
|
152 |
|
|
153 |
public void removeMediaMetaData(MediaMetaData metaData){ |
|
154 |
this.mediaMetaData.remove(metaData); |
|
155 |
if(metaData.getMediaRepresentation() == this){ |
|
156 |
metaData.setMediaRepresentation(null); |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
//************************* CLONE **************************/ |
|
161 |
|
|
162 |
@Override |
|
163 |
public MediaRepresentationPart clone() throws CloneNotSupportedException{ |
|
164 |
MediaRepresentationPart result = (MediaRepresentationPart)super.clone(); |
|
165 |
|
|
166 |
//media representation |
|
167 |
result.setMediaRepresentation(null); |
|
168 |
|
|
169 |
for (MediaMetaData metaData : this.getMediaMetaData()) { |
|
170 |
result.addMediaMetaData(metaData.clone()); |
|
171 |
} |
|
172 |
|
|
173 |
//no changes to: size, uri |
|
174 |
return result; |
|
175 |
} |
|
176 |
} |
|
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 |
package eu.etaxonomy.cdm.model.media; |
|
10 |
|
|
11 |
import java.util.HashSet; |
|
12 |
import java.util.Set; |
|
13 |
|
|
14 |
import javax.persistence.Entity; |
|
15 |
import javax.persistence.FetchType; |
|
16 |
import javax.persistence.JoinColumn; |
|
17 |
import javax.persistence.ManyToOne; |
|
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.XmlIDREF; |
|
24 |
import javax.xml.bind.annotation.XmlSchemaType; |
|
25 |
import javax.xml.bind.annotation.XmlType; |
|
26 |
|
|
27 |
import org.apache.logging.log4j.LogManager; |
|
28 |
import org.apache.logging.log4j.Logger; |
|
29 |
import org.hibernate.annotations.Cascade; |
|
30 |
import org.hibernate.annotations.CascadeType; |
|
31 |
import org.hibernate.annotations.Type; |
|
32 |
import org.hibernate.envers.Audited; |
|
33 |
import org.hibernate.search.annotations.FieldBridge; |
|
34 |
|
|
35 |
import eu.etaxonomy.cdm.common.URI; |
|
36 |
import eu.etaxonomy.cdm.hibernate.search.UriBridge; |
|
37 |
import eu.etaxonomy.cdm.model.common.VersionableEntity; |
|
38 |
|
|
39 |
/** |
|
40 |
* A media representation part is a resource that can be referenced by an URI. |
|
41 |
* It represents a part of or the entire media. <br> |
|
42 |
* E.g. a jpg file or a website |
|
43 |
* |
|
44 |
* @author a.mueller |
|
45 |
* @since 09.06.2008 |
|
46 |
*/ |
|
47 |
@XmlAccessorType(XmlAccessType.FIELD) |
|
48 |
@XmlType(name = "MediaRepresentationPart", propOrder = { |
|
49 |
"uri", |
|
50 |
"size", |
|
51 |
"mediaRepresentation", |
|
52 |
"mediaMetaData" |
|
53 |
}) |
|
54 |
@Entity |
|
55 |
@Audited |
|
56 |
public class MediaRepresentationPart extends VersionableEntity { |
|
57 |
private static final long serialVersionUID = -1674422508643785796L; |
|
58 |
@SuppressWarnings("unused") |
|
59 |
private static final Logger logger = LogManager.getLogger(MediaRepresentationPart.class); |
|
60 |
|
|
61 |
// where the media file is stored |
|
62 |
@XmlElement(name = "URI") |
|
63 |
@FieldBridge(impl = UriBridge.class) |
|
64 |
@Type(type="uriUserType") |
|
65 |
private URI uri; |
|
66 |
|
|
67 |
// in bytes |
|
68 |
@XmlElement(name = "Size") |
|
69 |
private Integer size; |
|
70 |
|
|
71 |
// the MediaRepresentation of this MediaRepresentationPart |
|
72 |
@XmlElement(name = "MediaRepresentation") |
|
73 |
@XmlIDREF |
|
74 |
@XmlSchemaType(name = "IDREF") |
|
75 |
@ManyToOne(fetch = FetchType.LAZY) |
|
76 |
@JoinColumn(name = "representation_id", nullable = false, updatable = false, insertable = false) |
|
77 |
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE}) |
|
78 |
private MediaRepresentation mediaRepresentation; |
|
79 |
|
|
80 |
@XmlElementWrapper(name = "MediaMetaDatas") |
|
81 |
@XmlElement(name = "MediaMetaData") |
|
82 |
@OneToMany (mappedBy="mediaRepresentation", fetch= FetchType.LAZY, orphanRemoval=true) |
|
83 |
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE, CascadeType.REFRESH}) |
|
84 |
private Set<MediaMetaData> mediaMetaData = new HashSet<>(); |
|
85 |
|
|
86 |
|
|
87 |
// *************** FACTORY METHOD *********************************/ |
|
88 |
|
|
89 |
public static MediaRepresentationPart NewInstance(URI uri, Integer size) { |
|
90 |
MediaRepresentationPart result = new MediaRepresentationPart(uri, size); |
|
91 |
return result; |
|
92 |
} |
|
93 |
|
|
94 |
protected MediaRepresentationPart() { |
|
95 |
super(); |
|
96 |
} |
|
97 |
|
|
98 |
protected MediaRepresentationPart(URI uri, Integer size) { |
|
99 |
this(); |
|
100 |
this.setUri(uri); |
|
101 |
this.setSize(size); |
|
102 |
} |
|
103 |
|
|
104 |
//*************** GETTER / SETTER *************************************/ |
|
105 |
|
|
106 |
public MediaRepresentation getMediaRepresentation() { |
|
107 |
return this.mediaRepresentation; |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* @deprecated for internal (bidirectional) use only |
|
112 |
*/ |
|
113 |
@Deprecated |
|
114 |
protected void setMediaRepresentation(MediaRepresentation mediaRepresentation) { |
|
115 |
this.mediaRepresentation = mediaRepresentation; |
|
116 |
} |
|
117 |
|
|
118 |
//uri |
|
119 |
public URI getUri() { |
|
120 |
return this.uri; |
|
121 |
} |
|
122 |
|
|
123 |
public void setUri(URI uri) { |
|
124 |
this.uri = uri; |
|
125 |
} |
|
126 |
|
|
127 |
//size |
|
128 |
public Integer getSize() { |
|
129 |
return this.size; |
|
130 |
} |
|
131 |
public void setSize(Integer size) { |
|
132 |
this.size = size; |
|
133 |
} |
|
134 |
|
|
135 |
//metadata |
|
136 |
|
|
137 |
|
|
138 |
public void addMediaMetaData(MediaMetaData metaData){ |
|
139 |
this.mediaMetaData.add(metaData); |
|
140 |
if(metaData.getMediaRepresentation() != this){ |
|
141 |
metaData.setMediaRepresentation(this); |
|
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
public Set<MediaMetaData> getMediaMetaData() { |
|
146 |
return mediaMetaData; |
|
147 |
} |
|
148 |
|
|
149 |
// public void setMediaMetaData(Set<MediaMetaData> mediaMetaData) { |
|
150 |
// this.mediaMetaData = mediaMetaData; |
|
151 |
// } |
|
152 |
|
|
153 |
public void removeMediaMetaData(MediaMetaData metaData){ |
|
154 |
this.mediaMetaData.remove(metaData); |
|
155 |
if(metaData.getMediaRepresentation() == this){ |
|
156 |
metaData.setMediaRepresentation(null); |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
//************************* CLONE **************************/ |
|
161 |
|
|
162 |
@Override |
|
163 |
public MediaRepresentationPart clone() throws CloneNotSupportedException{ |
|
164 |
MediaRepresentationPart result = (MediaRepresentationPart)super.clone(); |
|
165 |
|
|
166 |
//media representation |
|
167 |
result.setMediaRepresentation(null); |
|
168 |
|
|
169 |
for (MediaMetaData metaData : this.getMediaMetaData()) { |
|
170 |
result.addMediaMetaData(metaData.clone()); |
|
171 |
} |
|
172 |
|
|
173 |
//no changes to: size, uri |
|
174 |
return result; |
|
175 |
} |
|
176 |
} |
Also available in: Unified diff
cleanup