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.remote.dto.assembler;
|
10
|
|
11
|
import java.util.Enumeration;
|
12
|
import java.util.HashSet;
|
13
|
import java.util.Locale;
|
14
|
import java.util.Set;
|
15
|
|
16
|
import org.springframework.stereotype.Component;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.media.AudioFile;
|
19
|
import eu.etaxonomy.cdm.model.media.ImageFile;
|
20
|
import eu.etaxonomy.cdm.model.media.Media;
|
21
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
22
|
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
|
23
|
import eu.etaxonomy.cdm.model.media.MovieFile;
|
24
|
import eu.etaxonomy.cdm.remote.dto.MediaRepresentationSTO;
|
25
|
import eu.etaxonomy.cdm.remote.dto.MediaTO;
|
26
|
import eu.etaxonomy.cdm.remote.dto.MediaSTO;
|
27
|
|
28
|
@Component
|
29
|
public class MediaAssembler extends AssemblerBase<MediaSTO, MediaTO, Media> {
|
30
|
|
31
|
@Override
|
32
|
MediaSTO getSTO(Media media, Enumeration<Locale> locales) {
|
33
|
MediaSTO mediaSTO = null;
|
34
|
if (media !=null){
|
35
|
mediaSTO = new MediaSTO();
|
36
|
setVersionableEntity(media, mediaSTO);
|
37
|
//TODO: pick right language!
|
38
|
mediaSTO.setTitle(media.getTitle().toString());
|
39
|
mediaSTO.setRepresentations(getMediaRepresentationSTOs(media.getRepresentations()));
|
40
|
}
|
41
|
return mediaSTO;
|
42
|
}
|
43
|
|
44
|
@Override
|
45
|
MediaTO getTO(Media media, Enumeration<Locale> locales) {
|
46
|
MediaTO mediaTO = null;
|
47
|
if (media !=null){
|
48
|
mediaTO = new MediaTO();
|
49
|
setVersionableEntity(media, mediaTO);
|
50
|
//TODO: pick right language!
|
51
|
mediaTO.setTitle(media.getTitle().toString());
|
52
|
//TODO: pick right language!
|
53
|
mediaTO.setDescription(media.getDescription().toString());
|
54
|
mediaTO.setRepresentations(getMediaRepresentationSTOs(media.getRepresentations()));
|
55
|
}
|
56
|
|
57
|
return mediaTO;
|
58
|
}
|
59
|
|
60
|
public Set<MediaRepresentationSTO> getMediaRepresentationSTOs(Set<MediaRepresentation> representations){
|
61
|
Set<MediaRepresentationSTO> representationSTOs = new HashSet<MediaRepresentationSTO>(representations.size());
|
62
|
|
63
|
for (MediaRepresentation mediaRepr : representations){
|
64
|
MediaRepresentationSTO reprSTO = new MediaRepresentationSTO();
|
65
|
reprSTO.setMimeType(mediaRepr.getMimeType());
|
66
|
reprSTO.setSuffix(mediaRepr.getSuffix());
|
67
|
reprSTO.setUuid(mediaRepr.getUuid().toString());
|
68
|
Integer width = null;
|
69
|
Integer height = null;
|
70
|
Integer duration = null;
|
71
|
for(MediaRepresentationPart part : mediaRepr.getParts()){
|
72
|
|
73
|
if(part instanceof AudioFile){
|
74
|
AudioFile audio = (AudioFile)part;
|
75
|
duration = audio.getDuration();
|
76
|
} else if(part instanceof MovieFile){
|
77
|
MovieFile movie = (MovieFile)part;
|
78
|
duration = movie.getDuration();
|
79
|
height = movie.getHeight();
|
80
|
width = movie.getWidth();
|
81
|
} else if(part instanceof ImageFile){
|
82
|
ImageFile image = (MovieFile)part;
|
83
|
height = image.getHeight();
|
84
|
width = image.getWidth();
|
85
|
}
|
86
|
reprSTO.addRepresenationPart(part.getUuid().toString(), part.getUri().toString(), height, width, duration);
|
87
|
}
|
88
|
}
|
89
|
return representationSTOs;
|
90
|
}
|
91
|
}
|