1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.remote.controller;
|
12
|
|
13
|
import io.swagger.annotations.Api;
|
14
|
|
15
|
import java.io.IOException;
|
16
|
import java.util.Arrays;
|
17
|
import java.util.List;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import javax.servlet.http.HttpServletRequest;
|
21
|
import javax.servlet.http.HttpServletResponse;
|
22
|
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
24
|
import org.springframework.stereotype.Controller;
|
25
|
import org.springframework.web.bind.annotation.PathVariable;
|
26
|
import org.springframework.web.bind.annotation.RequestMapping;
|
27
|
import org.springframework.web.bind.annotation.RequestMethod;
|
28
|
import org.springframework.web.bind.annotation.RequestParam;
|
29
|
import org.springframework.web.servlet.ModelAndView;
|
30
|
|
31
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
32
|
import eu.etaxonomy.cdm.api.service.dto.DerivateDTO;
|
33
|
import eu.etaxonomy.cdm.api.service.dto.PreservedSpecimenDTO;
|
34
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
|
35
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
36
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
37
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
38
|
|
39
|
/**
|
40
|
* TODO write controller documentation
|
41
|
*
|
42
|
* @author a.kohlbecker
|
43
|
* @date 24.03.2009
|
44
|
*/
|
45
|
@Controller
|
46
|
@Api("portal_occurrence")
|
47
|
@RequestMapping(value = {"/portal/occurrence/{uuid}"})
|
48
|
public class OccurrencePortalController extends BaseController<SpecimenOrObservationBase, IOccurrenceService>
|
49
|
{
|
50
|
|
51
|
private static final List<String> DEFAULT_INIT_STRATEGY = Arrays.asList(new String []{
|
52
|
"$",
|
53
|
"determinations.*",
|
54
|
"sources.$",
|
55
|
"derivedFrom.type",
|
56
|
"derivedFrom.originals.*",
|
57
|
"derivedFrom.originals.determinations.taxon",
|
58
|
"derivedFrom.originals.gatheringEvent.exactLocation.$",
|
59
|
"derivedFrom.gatheringEvent.exactLocation.$",
|
60
|
"specimenTypeDesignations.*",
|
61
|
"specimenTypeDesignations.citation.*",
|
62
|
"specimenTypeDesignations.homotypicalGroup.*",
|
63
|
"sequences.$",
|
64
|
"sequences.annotations",
|
65
|
"markers.markerType",
|
66
|
"gatheringEvent.$",
|
67
|
"gatheringEvent.exactLocation.referenceSystem", // TODO implement auto initializer?
|
68
|
"descriptions"
|
69
|
});
|
70
|
|
71
|
|
72
|
/**
|
73
|
*
|
74
|
*/
|
75
|
public OccurrencePortalController() {
|
76
|
super();
|
77
|
setInitializationStrategy(DEFAULT_INIT_STRATEGY);
|
78
|
}
|
79
|
|
80
|
/* (non-Javadoc)
|
81
|
* @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
|
82
|
*/
|
83
|
@Autowired
|
84
|
@Override
|
85
|
public void setService(IOccurrenceService service) {
|
86
|
this.service = service;
|
87
|
}
|
88
|
|
89
|
@RequestMapping(value = { "derivedFrom" }, method = RequestMethod.GET)
|
90
|
public ModelAndView doGetDerivedFrom(
|
91
|
@PathVariable("uuid") UUID uuid,
|
92
|
HttpServletRequest request,
|
93
|
HttpServletResponse response) throws IOException {
|
94
|
|
95
|
logger.info("doGetDerivedFrom() " + request.getRequestURI());
|
96
|
|
97
|
ModelAndView mv = new ModelAndView();
|
98
|
|
99
|
SpecimenOrObservationBase sob = getCdmBaseInstance(uuid, response, getInitializationStrategy());
|
100
|
if(sob instanceof DerivedUnit){
|
101
|
DerivationEvent derivationEvent = ((DerivedUnit)sob).getDerivedFrom();
|
102
|
mv.addObject(derivationEvent);
|
103
|
}
|
104
|
return mv;
|
105
|
}
|
106
|
|
107
|
@RequestMapping(value = { "derivateHierarchy" }, method = RequestMethod.GET)
|
108
|
public ModelAndView doGetDerivateHierarchy(
|
109
|
@PathVariable("uuid") UUID uuid,
|
110
|
@RequestParam(value = "taxonUuid", required = true) UUID taxonUuid,
|
111
|
HttpServletRequest request,
|
112
|
HttpServletResponse response) throws IOException {
|
113
|
|
114
|
logger.info("doGetDerivateHierarchy() " + request.getRequestURI());
|
115
|
|
116
|
ModelAndView mv = new ModelAndView();
|
117
|
|
118
|
SpecimenOrObservationBase sob = service.load(uuid);
|
119
|
if(sob instanceof FieldUnit){
|
120
|
FieldUnit fieldUnit = (FieldUnit)sob;
|
121
|
if(fieldUnit.isPublish()){
|
122
|
final DerivateDTO fieldUnitDTO = service.assembleFieldUnitDTO(fieldUnit, taxonUuid);
|
123
|
if(fieldUnitDTO!=null){
|
124
|
mv.addObject(fieldUnitDTO);
|
125
|
}
|
126
|
}
|
127
|
}
|
128
|
return mv;
|
129
|
}
|
130
|
|
131
|
@RequestMapping(value = { "specimenDerivates" }, method = RequestMethod.GET)
|
132
|
public ModelAndView doGetSpecimenDerivates(
|
133
|
@PathVariable("uuid") UUID uuid,
|
134
|
HttpServletRequest request,
|
135
|
HttpServletResponse response) throws IOException {
|
136
|
|
137
|
logger.info("doGetSpecimenDerivates() " + request.getRequestURI());
|
138
|
|
139
|
ModelAndView mv = new ModelAndView();
|
140
|
|
141
|
SpecimenOrObservationBase sob = service.load(uuid);
|
142
|
if(sob instanceof DerivedUnit){
|
143
|
DerivedUnit derivedUnit = (DerivedUnit) sob;
|
144
|
if(derivedUnit.isPublish()){
|
145
|
PreservedSpecimenDTO specimenDTO = service.assemblePreservedSpecimenDTO(derivedUnit);
|
146
|
if(specimenDTO!=null){
|
147
|
mv.addObject(specimenDTO);
|
148
|
}
|
149
|
}
|
150
|
}
|
151
|
return mv;
|
152
|
}
|
153
|
|
154
|
|
155
|
|
156
|
}
|