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.io.IOException;
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.Arrays;
|
15
|
import java.util.List;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import javax.servlet.http.HttpServletRequest;
|
19
|
import javax.servlet.http.HttpServletResponse;
|
20
|
|
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
|
import org.springframework.web.bind.annotation.RequestParam;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
30
|
import eu.etaxonomy.cdm.api.service.dto.FieldUnitDTO;
|
31
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
|
33
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
34
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
35
|
import io.swagger.annotations.Api;
|
36
|
|
37
|
/**
|
38
|
* TODO write controller documentation
|
39
|
*
|
40
|
* @author a.kohlbecker
|
41
|
* @since 24.03.2009
|
42
|
*/
|
43
|
@Controller
|
44
|
@Api("occurrence")
|
45
|
@RequestMapping(value = {"/occurrence/{uuid}"})
|
46
|
public class OccurrenceController extends AbstractIdentifiableController<SpecimenOrObservationBase, IOccurrenceService>{
|
47
|
|
48
|
private static final Logger logger = Logger.getLogger(OccurrenceController.class);
|
49
|
|
50
|
|
51
|
protected static final List<String> DEFAULT_INIT_STRATEGY = Arrays.asList(new String []{
|
52
|
"$",
|
53
|
"sequences.$",
|
54
|
});
|
55
|
|
56
|
public static final List<String> DERIVED_UNIT_INIT_STRATEGY = Arrays.asList(new String []{
|
57
|
"derivedFrom.derivatives",
|
58
|
"derivedFrom.originals",
|
59
|
"specimenTypeDesignations.*",
|
60
|
"specimenTypeDesignations.source.citation.*",
|
61
|
"specimenTypeDesignations.homotypicalGroup.*",
|
62
|
"specimenTypeDesignations.typifiedNames",
|
63
|
"collection.$"
|
64
|
});
|
65
|
|
66
|
private static final List<String> EXTENSIONS_INIT_STRATEGY = Arrays.asList(new String []{
|
67
|
"extensions.type",
|
68
|
});
|
69
|
|
70
|
|
71
|
|
72
|
/* (non-Javadoc)
|
73
|
* @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
|
74
|
*/
|
75
|
@Autowired
|
76
|
@Override
|
77
|
public void setService(IOccurrenceService service) {
|
78
|
this.service = service;
|
79
|
}
|
80
|
|
81
|
|
82
|
|
83
|
@Override
|
84
|
protected <CDM_BASE extends CdmBase> List<String> complementInitStrategy(Class<CDM_BASE> clazz,
|
85
|
List<String> pathProperties) {
|
86
|
|
87
|
if(pathProperties.stream().anyMatch(s -> s.startsWith("specimenTypeDesignations"))) {
|
88
|
List<String> complemented = new ArrayList<>(pathProperties);
|
89
|
complemented.add("specimenTypeDesignations.source.citation.*");
|
90
|
return complemented;
|
91
|
}
|
92
|
return pathProperties;
|
93
|
}
|
94
|
|
95
|
|
96
|
|
97
|
@RequestMapping(value = { "derivedFrom" }, method = RequestMethod.GET)
|
98
|
public DerivationEvent doGetDerivedFrom(
|
99
|
@PathVariable("uuid") UUID uuid, HttpServletRequest request,
|
100
|
HttpServletResponse response) throws IOException {
|
101
|
|
102
|
logger.info("doGetDerivedFrom()" + requestPathAndQuery(request));
|
103
|
|
104
|
SpecimenOrObservationBase<?> sob = getCdmBaseInstance(uuid, response, DERIVED_UNIT_INIT_STRATEGY);
|
105
|
sob = checkExistsAndAccess(sob, NO_UNPUBLISHED, response);
|
106
|
if(sob instanceof DerivedUnit){
|
107
|
DerivationEvent derivationEvent = ((DerivedUnit)sob).getDerivedFrom();
|
108
|
if (derivationEvent != null) {
|
109
|
return derivationEvent;
|
110
|
}
|
111
|
}
|
112
|
return null;
|
113
|
}
|
114
|
|
115
|
|
116
|
@RequestMapping(value = { "fieldUnitDTO" }, method = RequestMethod.GET)
|
117
|
public FieldUnitDTO doGetFieldUnitDTO(
|
118
|
@PathVariable("uuid") UUID uuid,
|
119
|
HttpServletRequest request,
|
120
|
HttpServletResponse response) throws IOException {
|
121
|
|
122
|
logger.info("doGetFieldUnitDTO()" + requestPathAndQuery(request));
|
123
|
|
124
|
SpecimenOrObservationBase sob = getCdmBaseInstance(uuid, response, DERIVED_UNIT_INIT_STRATEGY);
|
125
|
|
126
|
sob = checkExistsAndAccess(sob, NO_UNPUBLISHED, response);
|
127
|
|
128
|
FieldUnitDTO fieldUnitDto = null;
|
129
|
if(sob != null){
|
130
|
fieldUnitDto = service.loadFieldUnitDTO(uuid);
|
131
|
}
|
132
|
|
133
|
return fieldUnitDto;
|
134
|
}
|
135
|
|
136
|
@RequestMapping(value = { "fieldUnitDTOs" }, method = RequestMethod.GET)
|
137
|
public List<FieldUnitDTO> doListFieldUnitDTO(
|
138
|
@PathVariable("uuid") List<UUID> uuids,
|
139
|
HttpServletRequest request,
|
140
|
HttpServletResponse response) throws IOException {
|
141
|
|
142
|
logger.info("doListFieldUnitDTO()" + requestPathAndQuery(request));
|
143
|
List<FieldUnitDTO> dtos = new ArrayList<>(uuids.size());
|
144
|
for(UUID uuid : uuids){
|
145
|
dtos.add(service.loadFieldUnitDTO(uuid));
|
146
|
}
|
147
|
|
148
|
return dtos;
|
149
|
}
|
150
|
|
151
|
// @RequestMapping(value = { "specimenTypeDesignations" }, method = RequestMethod.GET)
|
152
|
// public List<SpecimenTypeDesignation> doGetTypeDesignations(
|
153
|
// @PathVariable("uuid") UUID uuid,
|
154
|
// HttpServletRequest request,
|
155
|
// HttpServletResponse response) throws IOException {
|
156
|
//
|
157
|
// logger.info("doGetSpecimenTypeDesignations()" + requestPathAndQuery(request));
|
158
|
//
|
159
|
// DerivedUnit sob = (DerivedUnit) getCdmBaseInstance(uuid, response, DERIVED_UNIT_INIT_STRATEGY);
|
160
|
//
|
161
|
// sob = checkExistsAndAccess(sob, NO_UNPUBLISHED, response);
|
162
|
//
|
163
|
// FieldUnitDTO fieldUnitDto = null;
|
164
|
// if(sob instanceof DerivedUnit){
|
165
|
//
|
166
|
// fieldUnitDto = service.findFieldUnitDTO(new PreservedSpecimenDTO(sob) , new ArrayList<FieldUnitDTO>(), new HashMap<UUID, DerivateDTO>());
|
167
|
//
|
168
|
// }
|
169
|
//
|
170
|
// return fieldUnitDto;
|
171
|
// }
|
172
|
|
173
|
/**
|
174
|
*
|
175
|
* @param uuid
|
176
|
* @param request
|
177
|
* @param response
|
178
|
* @return
|
179
|
* @throws IOException
|
180
|
*/
|
181
|
@RequestMapping(value = { "extensions" }, method = RequestMethod.GET)
|
182
|
public Object doGetExtensions(
|
183
|
@PathVariable("uuid") UUID uuid, HttpServletRequest request,
|
184
|
// doPage request parameters
|
185
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
186
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
187
|
// doList request parameters
|
188
|
@RequestParam(value = "start", required = false) Integer start,
|
189
|
@RequestParam(value = "limit", required = false) Integer limit,
|
190
|
HttpServletResponse response) throws IOException {
|
191
|
|
192
|
logger.info("doGetExtensions()" + requestPathAndQuery(request));
|
193
|
SpecimenOrObservationBase<?> sob = getCdmBaseInstance(uuid, response, EXTENSIONS_INIT_STRATEGY);
|
194
|
sob = checkExistsAndAccess(sob, NO_UNPUBLISHED, response);
|
195
|
|
196
|
return pageFromCollection(sob.getExtensions(), pageNumber, pageSize, start, limit, response) ;
|
197
|
}
|
198
|
}
|