Project

General

Profile

Download (2.89 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.api.service.dto;
10

    
11
import java.util.ArrayList;
12
import java.util.List;
13
import java.util.UUID;
14

    
15
import eu.etaxonomy.cdm.model.media.Media;
16
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
17
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
18
import eu.etaxonomy.cdm.model.media.MediaUtils;
19
import eu.etaxonomy.cdm.ref.TypedEntityReference;
20

    
21
/**
22
 * @author a.kohlbecker
23
 * @since Aug 3, 2018
24
 *
25
 */
26
public class MediaDTO extends TypedEntityReference<Media> {
27

    
28
    private static final long serialVersionUID = 1981292478312137355L;
29

    
30
    private String uri;
31

    
32
    private String title_L10n;
33

    
34
    private String mimeType;
35

    
36
    private Integer size;
37

    
38
    private List<SourceDTO> sources = new ArrayList<>();
39

    
40
    /**
41
     * Creates a list of DTOs from the Media entity.
42
     * For each MediaRepresentationPart a single MediaDTO is being created.
43
     * TODO this needs to be changed so that it is possible to filter the representations by preferences,
44
     * see {@link MediaUtils#findBestMatchingRepresentation(Media, Class, Integer, Integer, Integer, String[], eu.etaxonomy.cdm.model.media.MediaUtils.MissingValueStrategy)}
45
     */
46
    public static List<MediaDTO> fromEntity(Media entity) {
47
        List<MediaDTO> dtos = new ArrayList<>();
48
        entity.getAllTitles(); // initialize all titles!!!
49
        MediaDTO dto = new MediaDTO(entity.getUuid());
50
        for (MediaRepresentation rep :entity.getRepresentations()){
51
            for(MediaRepresentationPart p : rep.getParts()){
52
                if(p.getUri() != null){
53
                    dto.setUri(p.getUri().toString());
54
                    break;
55
                }
56
            }
57
        }
58
        entity.getSources().stream().forEach(s -> dto.getSources().add(SourceDTO.fromIdentifiableSource(s)));
59
        if(dto.getUri() != null || !dto.getSources().isEmpty()) {
60
            dtos.add(dto);
61
        }
62
        return dtos;
63
    }
64

    
65
    /**
66
     * @param type
67
     * @param uuid
68
     */
69
    public MediaDTO(UUID uuid) {
70
        super(Media.class, uuid);
71
    }
72

    
73
    public String getUri() {
74
        return uri;
75
    }
76
    public void setUri(String uri) {
77
        this.uri = uri;
78
    }
79

    
80
    public String getTitle_l10n() {
81
        return title_L10n;
82
    }
83
    public void setTitle_l10n(String title_l10n) {
84
        this.title_L10n = title_l10n;
85
    }
86

    
87
    public String getMimeType() {
88
        return mimeType;
89
    }
90
    public void setMimeType(String mimeType) {
91
        this.mimeType = mimeType;
92
    }
93

    
94
    public Integer getSize() {
95
        return size;
96
    }
97
    public void setSize(Integer size) {
98
        this.size = size;
99
    }
100

    
101
    public List<SourceDTO> getSources() {
102
        return sources;
103
    }
104

    
105

    
106
}
(26-26/47)