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.common.Annotation;
|
32
|
import eu.etaxonomy.cdm.model.media.Media;
|
33
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
34
|
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
|
35
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
36
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
37
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
38
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
39
|
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
|
40
|
import io.swagger.annotations.Api;
|
41
|
|
42
|
/**
|
43
|
* @author a.kohlbecker
|
44
|
* @since Jul 31, 2018
|
45
|
*
|
46
|
*/
|
47
|
@Controller
|
48
|
@Api(value = "typeDesignation")
|
49
|
@RequestMapping(value = {"/typedesignation/{uuid}"})
|
50
|
/* can not use BaseController since the getMethod needs to call service.loadTypeDesignatio() which is generically not possible */
|
51
|
public class TypeDesignationController extends AbstractController<TaxonName, INameService> {
|
52
|
|
53
|
|
54
|
private static final Logger logger = Logger.getLogger(TypeDesignationController.class);
|
55
|
|
56
|
/**
|
57
|
* {@inheritDoc}
|
58
|
*/
|
59
|
@Override
|
60
|
@Autowired
|
61
|
public void setService(INameService service) {
|
62
|
this.service = service;
|
63
|
}
|
64
|
|
65
|
@RequestMapping(value="media", method = RequestMethod.GET)
|
66
|
public Collection<MediaDTO> doGetMedia(
|
67
|
@PathVariable("uuid") UUID uuid,
|
68
|
HttpServletRequest request,
|
69
|
HttpServletResponse response) throws IOException {
|
70
|
|
71
|
|
72
|
logger.info("doGetMediaUris() - " + requestPathAndQuery(request));
|
73
|
ArrayList<MediaDTO> dtos = new ArrayList<>();
|
74
|
TypeDesignationBase<?> td = service.loadTypeDesignation(uuid, Arrays.asList("typeSpecimen.mediaSpecimen.representations.mediaRepresentationParts"));
|
75
|
if(td instanceof SpecimenTypeDesignation){
|
76
|
SpecimenTypeDesignation std = (SpecimenTypeDesignation)td;
|
77
|
DerivedUnit du = HibernateProxyHelper.deproxy(std.getTypeSpecimen(), DerivedUnit.class);
|
78
|
if(du != null && du instanceof MediaSpecimen) {
|
79
|
Media media = ((MediaSpecimen)du).getMediaSpecimen();
|
80
|
if(media != null){
|
81
|
for(MediaRepresentation mrp : media.getRepresentations()){
|
82
|
for(MediaRepresentationPart p : mrp.getParts()){
|
83
|
if(p.getUri() != null){
|
84
|
MediaDTO dto = new MediaDTO(media.getUuid());
|
85
|
dto.setUri(p.getUri().toString());
|
86
|
dtos.add(dto);
|
87
|
}
|
88
|
}
|
89
|
}
|
90
|
}
|
91
|
}
|
92
|
|
93
|
}
|
94
|
return dtos;
|
95
|
}
|
96
|
|
97
|
@RequestMapping(method = RequestMethod.GET)
|
98
|
public TypeDesignationBase<?> doGetMethod(
|
99
|
@PathVariable("uuid") UUID uuid,
|
100
|
HttpServletRequest request,
|
101
|
HttpServletResponse response) throws IOException {
|
102
|
|
103
|
String servletPath = request.getServletPath();
|
104
|
String propertyName = FilenameUtils.getBaseName(servletPath);
|
105
|
|
106
|
logger.info("doGet() - " + requestPathAndQuery(request));
|
107
|
|
108
|
TypeDesignationBase<?> dtb = service.loadTypeDesignation(uuid, Arrays.asList("$"));
|
109
|
if(dtb == null){
|
110
|
HttpStatusMessage.UUID_NOT_FOUND.send(response);
|
111
|
}
|
112
|
return dtb;
|
113
|
}
|
114
|
|
115
|
@RequestMapping(method = RequestMethod.GET, value="annotations")
|
116
|
public Collection<Annotation> doGetAnnotations(
|
117
|
@PathVariable("uuid") UUID uuid,
|
118
|
HttpServletRequest request,
|
119
|
HttpServletResponse response) throws IOException {
|
120
|
|
121
|
String servletPath = request.getServletPath();
|
122
|
String propertyName = FilenameUtils.getBaseName(servletPath);
|
123
|
|
124
|
logger.info("doGetAnnotations() - " + requestPathAndQuery(request));
|
125
|
|
126
|
TypeDesignationBase<?> dtb = service.loadTypeDesignation(uuid, Arrays.asList("$", "annotations"));
|
127
|
if(dtb == null){
|
128
|
HttpStatusMessage.UUID_NOT_FOUND.send(response);
|
129
|
}
|
130
|
return dtb.getAnnotations();
|
131
|
}
|
132
|
|
133
|
}
|