ref #9811 adding classification uuids to TaxonRelationshipsDTO
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / dto / MediaDTO.java
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 /**
39 * Creates a list of DTOs from the Media entity.
40 * For each MediaRepresentationPart a single MediaDTO is being created.
41 * TODO this needs to be changed so that it is possible to filter the representations by preferences,
42 * see {@link MediaUtils#findBestMatchingRepresentation(Media, Class, Integer, Integer, Integer, String[], eu.etaxonomy.cdm.model.media.MediaUtils.MissingValueStrategy)}
43 */
44 public static List<MediaDTO> fromEntity(Media entity) {
45 List<MediaDTO> dtos = new ArrayList<>();
46 entity.getAllTitles(); // initialize all titles!!!
47 for (MediaRepresentation rep :entity.getRepresentations()){
48 for(MediaRepresentationPart p : rep.getParts()){
49 if(p.getUri() != null){
50 MediaDTO dto = new MediaDTO(entity.getUuid());
51 dto.setUri(p.getUri().toString());
52 dtos.add(dto);
53 }
54 }
55 }
56 return dtos;
57 }
58
59 /**
60 * @param type
61 * @param uuid
62 */
63 public MediaDTO(UUID uuid) {
64 super(Media.class, uuid);
65 }
66
67 public String getUri() {
68 return uri;
69 }
70 public void setUri(String uri) {
71 this.uri = uri;
72 }
73
74 public String getTitle_l10n() {
75 return title_L10n;
76 }
77 public void setTitle_l10n(String title_l10n) {
78 this.title_L10n = title_l10n;
79 }
80
81 public String getMimeType() {
82 return mimeType;
83 }
84 public void setMimeType(String mimeType) {
85 this.mimeType = mimeType;
86 }
87
88 public Integer getSize() {
89 return size;
90 }
91 public void setSize(Integer size) {
92 this.size = size;
93 }
94
95 }