1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT 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
|
7
|
* 1.1 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 io.swagger.annotations.Api;
|
13
|
|
14
|
import java.io.IOException;
|
15
|
import java.util.List;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import javax.servlet.http.HttpServletRequest;
|
20
|
import javax.servlet.http.HttpServletResponse;
|
21
|
|
22
|
import org.apache.lucene.queryparser.classic.ParseException;
|
23
|
import org.hibernate.search.spatial.impl.Rectangle;
|
24
|
import org.springframework.beans.factory.annotation.Autowired;
|
25
|
import org.springframework.stereotype.Controller;
|
26
|
import org.springframework.web.bind.WebDataBinder;
|
27
|
import org.springframework.web.bind.annotation.InitBinder;
|
28
|
import org.springframework.web.bind.annotation.RequestMapping;
|
29
|
import org.springframework.web.bind.annotation.RequestMethod;
|
30
|
import org.springframework.web.bind.annotation.RequestParam;
|
31
|
|
32
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
33
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
34
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
35
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
36
|
import eu.etaxonomy.cdm.api.service.search.SearchResult;
|
37
|
import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;
|
38
|
import eu.etaxonomy.cdm.model.common.Language;
|
39
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
40
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
41
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
42
|
import eu.etaxonomy.cdm.remote.controller.util.ControllerUtils;
|
43
|
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
|
44
|
import eu.etaxonomy.cdm.remote.editor.RectanglePropertyEditor;
|
45
|
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
|
46
|
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
47
|
|
48
|
/**
|
49
|
* TODO write controller documentation
|
50
|
*
|
51
|
* @author a.kohlbecker
|
52
|
* @date 24.03.2009
|
53
|
*/
|
54
|
@Controller
|
55
|
@Api("occurrence")
|
56
|
@RequestMapping(value = {"/occurrence"})
|
57
|
public class OccurrenceListController extends IdentifiableListController<SpecimenOrObservationBase, IOccurrenceService> {
|
58
|
|
59
|
|
60
|
@Autowired
|
61
|
private ITaxonService taxonService;
|
62
|
|
63
|
@Autowired
|
64
|
private ITermService termService;
|
65
|
|
66
|
/* (non-Javadoc)
|
67
|
* @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)
|
68
|
*/
|
69
|
@Override
|
70
|
@Autowired
|
71
|
public void setService(IOccurrenceService service) {
|
72
|
this.service = service;
|
73
|
}
|
74
|
|
75
|
@InitBinder
|
76
|
@Override
|
77
|
public void initBinder(WebDataBinder binder) {
|
78
|
super.initBinder(binder);
|
79
|
binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
|
80
|
binder.registerCustomEditor(Rectangle.class, new RectanglePropertyEditor());
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* @param taxonUuid
|
85
|
* @param relationshipUuids a comma separated list of uuids e.g. CongruentTo; "60974c98-64ab-4574-bb5c-c110f6db634d"
|
86
|
* @param relationshipInversUuids a comma separated list of uuids
|
87
|
* @param maxDepth null for unlimited
|
88
|
* @param pageNumber
|
89
|
* @param pageSize
|
90
|
* @param request
|
91
|
* @param response
|
92
|
* @return
|
93
|
* @throws IOException
|
94
|
*/
|
95
|
@RequestMapping(
|
96
|
value = {"byAssociatedTaxon"},
|
97
|
method = RequestMethod.GET)
|
98
|
public Pager<SpecimenOrObservationBase> doListByAssociatedTaxon(
|
99
|
@RequestParam(value = "taxonUuid", required = true) UUID taxonUuid,
|
100
|
@RequestParam(value = "relationships", required = false) UuidList relationshipUuids,
|
101
|
@RequestParam(value = "relationshipsInvers", required = false) UuidList relationshipInversUuids,
|
102
|
@RequestParam(value = "maxDepth", required = false) Integer maxDepth,
|
103
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
104
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
105
|
HttpServletRequest request,
|
106
|
HttpServletResponse response) throws IOException {
|
107
|
|
108
|
logger.info("doListByAssociatedTaxon()" + request.getRequestURI() + "?" + request.getQueryString());
|
109
|
|
110
|
Set<TaxonRelationshipEdge> includeRelationships = ControllerUtils.loadIncludeRelationships(relationshipUuids, relationshipInversUuids, termService);
|
111
|
|
112
|
Taxon associatedTaxon = (Taxon) taxonService.find(taxonUuid);
|
113
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
|
114
|
pagerParams.normalizeAndValidate(response);
|
115
|
|
116
|
List<OrderHint> orderHints = null;
|
117
|
|
118
|
return service.pageByAssociatedTaxon(null, includeRelationships, associatedTaxon,
|
119
|
maxDepth, pagerParams.getPageSize(), pagerParams.getPageIndex(),
|
120
|
orderHints, getInitializationStrategy());
|
121
|
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
*
|
126
|
* @param clazz
|
127
|
* @param queryString
|
128
|
* @param boundingBox
|
129
|
* as
|
130
|
* minx(minlongitute),miny(minlatitute),maxx(maxlongitute),max(
|
131
|
* maxlatitute), e.g. 13.112,52.374,13.681,52.641 for the Berlin
|
132
|
* area
|
133
|
* @param languages
|
134
|
* @param highlighting
|
135
|
* @param pageNumber
|
136
|
* @param pageSize
|
137
|
* @param request
|
138
|
* @param response
|
139
|
* @return
|
140
|
* @throws IOException
|
141
|
* @throws ParseException
|
142
|
*/
|
143
|
@RequestMapping(method = RequestMethod.GET, value={"findByFullText"})
|
144
|
public Pager<SearchResult<SpecimenOrObservationBase>> dofindByFullText(
|
145
|
@RequestParam(value = "clazz", required = false) Class<? extends SpecimenOrObservationBase<?>> clazz,
|
146
|
@RequestParam(value = "query", required = false) String queryString,
|
147
|
@RequestParam(value = "bbox", required = false) Rectangle boundingBox,
|
148
|
@RequestParam(value = "languages", required = false) List<Language> languages,
|
149
|
@RequestParam(value = "hl", required = false) Boolean highlighting,
|
150
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
151
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
152
|
HttpServletRequest request,
|
153
|
HttpServletResponse response
|
154
|
)
|
155
|
throws IOException, ParseException {
|
156
|
|
157
|
logger.info("findByFullText : " + request.getRequestURI() + "?" + request.getQueryString() );
|
158
|
|
159
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
|
160
|
pagerParams.normalizeAndValidate(response);
|
161
|
|
162
|
if(highlighting == null){
|
163
|
highlighting = false;
|
164
|
}
|
165
|
|
166
|
if(queryString == null && boundingBox == null) {
|
167
|
HttpStatusMessage.create("Either query or bbox must be given", 400).send(response);
|
168
|
return null;
|
169
|
}
|
170
|
|
171
|
Pager<SearchResult<SpecimenOrObservationBase>> pager = service.findByFullText(clazz, queryString, boundingBox, languages,
|
172
|
highlighting, pagerParams.getPageSize(), pagerParams.getPageIndex(), ((List<OrderHint>)null),
|
173
|
initializationStrategy);
|
174
|
return pager;
|
175
|
}
|
176
|
|
177
|
}
|