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.remote.controller;
|
10
|
|
11
|
import java.io.IOException;
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Arrays;
|
14
|
import java.util.Collection;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import javax.servlet.http.HttpServletRequest;
|
18
|
import javax.servlet.http.HttpServletResponse;
|
19
|
|
20
|
import org.apache.commons.io.FilenameUtils;
|
21
|
import org.apache.log4j.Logger;
|
22
|
import org.springframework.beans.factory.annotation.Autowired;
|
23
|
import org.springframework.stereotype.Controller;
|
24
|
import org.springframework.web.bind.annotation.PathVariable;
|
25
|
import org.springframework.web.bind.annotation.RequestMapping;
|
26
|
import org.springframework.web.bind.annotation.RequestMethod;
|
27
|
|
28
|
import eu.etaxonomy.cdm.api.service.INameService;
|
29
|
import eu.etaxonomy.cdm.api.service.dto.MediaDTO;
|
30
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
31
|
import eu.etaxonomy.cdm.model.media.Media;
|
32
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
33
|
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
|
34
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
35
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
36
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
37
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
38
|
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
|
39
|
import io.swagger.annotations.Api;
|
40
|
|
41
|
/**
|
42
|
* @author a.kohlbecker
|
43
|
* @since Jul 31, 2018
|
44
|
*
|
45
|
*/
|
46
|
@Controller
|
47
|
@Api(value = "typeDesignation")
|
48
|
@RequestMapping(value = {"/typedesignation/{uuid}"})
|
49
|
public class TypeDesignationController extends AbstractController<TaxonName, INameService> {
|
50
|
|
51
|
|
52
|
private static final Logger logger = Logger.getLogger(TypeDesignationController.class);
|
53
|
|
54
|
/**
|
55
|
* {@inheritDoc}
|
56
|
*/
|
57
|
@Override
|
58
|
@Autowired
|
59
|
public void setService(INameService service) {
|
60
|
this.service = service;
|
61
|
}
|
62
|
|
63
|
@RequestMapping(value="media", method = RequestMethod.GET)
|
64
|
public Collection<MediaDTO> doGetMedia(
|
65
|
@PathVariable("uuid") UUID uuid,
|
66
|
HttpServletRequest request,
|
67
|
HttpServletResponse response) throws IOException {
|
68
|
|
69
|
|
70
|
logger.info("doGetMediaUris() - " + requestPathAndQuery(request));
|
71
|
ArrayList<MediaDTO> dtos = new ArrayList<>();
|
72
|
TypeDesignationBase<?> td = service.loadTypeDesignation(uuid, Arrays.asList("typeSpecimen.mediaSpecimen.representations.mediaRepresentationParts"));
|
73
|
if(td instanceof SpecimenTypeDesignation){
|
74
|
SpecimenTypeDesignation std = (SpecimenTypeDesignation)td;
|
75
|
DerivedUnit du = HibernateProxyHelper.deproxy(std.getTypeSpecimen(), DerivedUnit.class);
|
76
|
if(du != null && du instanceof MediaSpecimen) {
|
77
|
Media media = ((MediaSpecimen)du).getMediaSpecimen();
|
78
|
if(media != null){
|
79
|
for(MediaRepresentation mrp : media.getRepresentations()){
|
80
|
for(MediaRepresentationPart p : mrp.getParts()){
|
81
|
if(p.getUri() != null){
|
82
|
MediaDTO dto = new MediaDTO(media.getUuid());
|
83
|
dto.setUri(p.getUri().toString());
|
84
|
dtos.add(dto);
|
85
|
}
|
86
|
}
|
87
|
}
|
88
|
}
|
89
|
}
|
90
|
|
91
|
}
|
92
|
return dtos;
|
93
|
}
|
94
|
|
95
|
@RequestMapping(method = RequestMethod.GET)
|
96
|
public TypeDesignationBase<?> doGetMethod(
|
97
|
@PathVariable("uuid") UUID uuid,
|
98
|
HttpServletRequest request,
|
99
|
HttpServletResponse response) throws IOException {
|
100
|
|
101
|
String servletPath = request.getServletPath();
|
102
|
String propertyName = FilenameUtils.getBaseName(servletPath);
|
103
|
|
104
|
logger.info("doGet() - " + requestPathAndQuery(request));
|
105
|
|
106
|
TypeDesignationBase<?> dtb = service.loadTypeDesignation(uuid, Arrays.asList("$"));
|
107
|
if(dtb == null){
|
108
|
HttpStatusMessage.UUID_NOT_FOUND.send(response);
|
109
|
}
|
110
|
return dtb;
|
111
|
}
|
112
|
|
113
|
}
|