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
|
|
10
|
package eu.etaxonomy.cdm.remote.controller;
|
11
|
|
12
|
import java.util.Arrays;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import javax.servlet.http.HttpServletRequest;
|
17
|
import javax.servlet.http.HttpServletResponse;
|
18
|
|
19
|
import org.jboss.logging.Logger;
|
20
|
import org.springframework.beans.factory.annotation.Autowired;
|
21
|
import org.springframework.stereotype.Controller;
|
22
|
import org.springframework.web.bind.annotation.PathVariable;
|
23
|
import org.springframework.web.bind.annotation.RequestMapping;
|
24
|
import org.springframework.web.bind.annotation.RequestMethod;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
27
|
import eu.etaxonomy.cdm.api.service.dto.SpecimenOrObservationBaseDTO;
|
28
|
import eu.etaxonomy.cdm.model.media.Media;
|
29
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
30
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
31
|
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
|
32
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
33
|
import io.swagger.annotations.Api;
|
34
|
|
35
|
/**
|
36
|
* TODO write controller documentation
|
37
|
*
|
38
|
* @author a.kohlbecker
|
39
|
* @since 24.03.2009
|
40
|
*/
|
41
|
@Controller
|
42
|
@Api("portal_occurrence")
|
43
|
@RequestMapping(value = {"/portal/occurrence/{uuid}"})
|
44
|
public class OccurrencePortalController extends OccurrenceController
|
45
|
{
|
46
|
|
47
|
private static Logger logger = Logger.getLogger(OccurrencePortalController.class);
|
48
|
|
49
|
private static final List<String> DEFAULT_INIT_STRATEGY = Arrays.asList(new String []{
|
50
|
"$",
|
51
|
"determinations.*",
|
52
|
"sources.$",
|
53
|
"derivedFrom.type",
|
54
|
"derivedFrom.originals.*",
|
55
|
"derivedFrom.originals.determinations.taxon",
|
56
|
"derivedFrom.originals.gatheringEvent.exactLocation.$",
|
57
|
"derivedFrom.gatheringEvent.exactLocation.$",
|
58
|
"derivationEvents.derivatives.$",
|
59
|
"specimenTypeDesignations.*",
|
60
|
"specimenTypeDesignations.citation.*",
|
61
|
"specimenTypeDesignations.homotypicalGroup.*",
|
62
|
"specimenTypeDesignations.typifiedNames",
|
63
|
"sequences.$",
|
64
|
"sequences.annotations",
|
65
|
"markers.markerType",
|
66
|
"gatheringEvent.$",
|
67
|
"gatheringEvent.exactLocation.referenceSystem", // TODO implement auto initializer?
|
68
|
"gatheringEvent.collectingAreas",
|
69
|
"annotations",
|
70
|
"descriptions",
|
71
|
"collection.institute.$"
|
72
|
});
|
73
|
|
74
|
/**
|
75
|
*
|
76
|
*/
|
77
|
public OccurrencePortalController() {
|
78
|
super();
|
79
|
setInitializationStrategy(DEFAULT_INIT_STRATEGY);
|
80
|
}
|
81
|
|
82
|
@Autowired
|
83
|
@Override
|
84
|
public void setService(IOccurrenceService service) {
|
85
|
this.service = service;
|
86
|
}
|
87
|
|
88
|
@RequestMapping(value = { "asDTO" }, method = RequestMethod.GET)
|
89
|
public SpecimenOrObservationBaseDTO doGetAsDTO(
|
90
|
@PathVariable("uuid") UUID uuid,
|
91
|
HttpServletRequest request,
|
92
|
HttpServletResponse response) {
|
93
|
|
94
|
logger.info("doGetAsDTO() " + requestPathAndQuery(request));
|
95
|
|
96
|
SpecimenOrObservationBase<?> sob = service.load(uuid);
|
97
|
if(sob.isPublish()) {
|
98
|
if(sob instanceof FieldUnit){
|
99
|
return service.assembleFieldUnitDTO((FieldUnit)sob);
|
100
|
} else {
|
101
|
return service.assembleDerivedUnitDTO((DerivedUnit)sob);
|
102
|
}
|
103
|
}
|
104
|
// FIXME proper http code
|
105
|
return null;
|
106
|
}
|
107
|
|
108
|
@RequestMapping(value = { "mediaSpecimen" }, method = RequestMethod.GET)
|
109
|
public Media doGetMediaSpecimen(
|
110
|
@PathVariable("uuid") UUID uuid,
|
111
|
HttpServletRequest request,
|
112
|
@SuppressWarnings("unused") HttpServletResponse response) {
|
113
|
|
114
|
logger.info("doGetMediaSpecimen() " + requestPathAndQuery(request));
|
115
|
|
116
|
|
117
|
SpecimenOrObservationBase<?> sob = service.load(uuid, Arrays.asList("mediaSpecimen.sources.citation", "mediaSpecimen.representations.parts"));
|
118
|
if(sob instanceof MediaSpecimen){
|
119
|
MediaSpecimen mediaSpecimen = (MediaSpecimen) sob;
|
120
|
if(mediaSpecimen.isPublish()){
|
121
|
return mediaSpecimen.getMediaSpecimen();
|
122
|
}
|
123
|
}
|
124
|
return null;
|
125
|
}
|
126
|
|
127
|
// @RequestMapping(value = { "specimenDerivatesAndOriginals" }, method = RequestMethod.GET)
|
128
|
// public ModelAndView doGetSpecimenDerivatesAndOriginals(
|
129
|
// @RequestParam(value = "relationships", required = false) UuidList relationshipUuids,
|
130
|
// @RequestParam(value = "relationshipsInvers", required = false) UuidList relationshipInversUuids,
|
131
|
// @PathVariable("uuid") UUID uuid,
|
132
|
// HttpServletRequest request,
|
133
|
// HttpServletResponse response) throws IOException {
|
134
|
//
|
135
|
// logger.info("doGetSpecimenDerivates() " + request.getRequestURI());
|
136
|
//
|
137
|
// ModelAndView mv = new ModelAndView();
|
138
|
// Set<TaxonRelationshipEdge> includeRelationships = ControllerUtils.loadIncludeRelationships(relationshipUuids, relationshipInversUuids, termService);
|
139
|
// List<FieldUnitDTO> fieldUnitDTOs = service.findFieldUnitDTOByAssociatedTaxon(includeRelationships, uuid);
|
140
|
// if(fieldUnitDTOs!=null){
|
141
|
// mv.addObject(fieldUnitDTOs);
|
142
|
// }
|
143
|
//
|
144
|
// return mv;
|
145
|
// }
|
146
|
|
147
|
}
|