Project

General

Profile

Download (7.03 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2009 EDIT European Distributed Institute of Taxonomy
3
 * http://www.e-taxonomy.eu
4
 *
5
 * The contents of this file are subject to the Mozilla Public License Version
6
 * 1.1 See LICENSE.TXT at the top of this package for the full license terms.
7
 */
8

    
9
package eu.etaxonomy.cdm.remote.controller;
10

    
11
import java.io.IOException;
12
import java.util.List;
13
import java.util.Set;
14
import java.util.UUID;
15

    
16
import javax.servlet.http.HttpServletRequest;
17
import javax.servlet.http.HttpServletResponse;
18

    
19
import org.apache.lucene.queryparser.classic.ParseException;
20
import org.hibernate.search.spatial.impl.Rectangle;
21
import org.springframework.beans.factory.annotation.Autowired;
22
import org.springframework.stereotype.Controller;
23
import org.springframework.web.bind.WebDataBinder;
24
import org.springframework.web.bind.annotation.InitBinder;
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.ITaxonService;
31
import eu.etaxonomy.cdm.api.service.ITermService;
32
import eu.etaxonomy.cdm.api.service.pager.Pager;
33
import eu.etaxonomy.cdm.api.service.search.LuceneParseException;
34
import eu.etaxonomy.cdm.api.service.search.SearchResult;
35
import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;
36
import eu.etaxonomy.cdm.model.common.Language;
37
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
38
import eu.etaxonomy.cdm.model.taxon.Taxon;
39
import eu.etaxonomy.cdm.persistence.query.OrderHint;
40
import eu.etaxonomy.cdm.remote.controller.util.ControllerUtils;
41
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
42
import eu.etaxonomy.cdm.remote.editor.RectanglePropertyEditor;
43
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
44
import eu.etaxonomy.cdm.remote.editor.UuidList;
45
import io.swagger.annotations.Api;
46

    
47
/**
48
 * TODO write controller documentation
49
 *
50
 * @author a.kohlbecker
51
 * @since 24.03.2009
52
 */
53
@Controller
54
@Api("occurrence")
55
@RequestMapping(value = {"/occurrence"})
56
public class OccurrenceListController extends AbstractIdentifiableListController<SpecimenOrObservationBase, IOccurrenceService> {
57

    
58

    
59
    @Autowired
60
    private ITaxonService taxonService;
61

    
62
    @Autowired
63
    private ITermService termService;
64

    
65
    /* (non-Javadoc)
66
     * @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)
67
     */
68
    @Override
69
    @Autowired
70
    public void setService(IOccurrenceService service) {
71
        this.service = service;
72
    }
73

    
74
    @InitBinder
75
    @Override
76
    public void initBinder(WebDataBinder binder) {
77
        super.initBinder(binder);
78
        binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
79
        binder.registerCustomEditor(Rectangle.class, new RectanglePropertyEditor());
80
    }
81

    
82
    /**
83
     * @param taxonUuid
84
     * @param relationshipUuids a comma separated list of uuids e.g. CongruentTo;  "60974c98-64ab-4574-bb5c-c110f6db634d"
85
     * @param relationshipInversUuids a comma separated list of uuids
86
     * @param maxDepth null for unlimited
87
     * @param pageNumber
88
     * @param pageSize
89
     * @param request
90
     * @param response
91
     * @return
92
     * @throws IOException
93
     */
94
    @RequestMapping(
95
            value = {"byAssociatedTaxon"},
96
            method = RequestMethod.GET)
97
    public Pager<SpecimenOrObservationBase> doListByAssociatedTaxon(
98
                @RequestParam(value = "taxonUuid", required = true) UUID taxonUuid,
99
                @RequestParam(value = "relationships", required = false) UuidList relationshipUuids,
100
                @RequestParam(value = "relationshipsInvers", required = false) UuidList relationshipInversUuids,
101
                @RequestParam(value = "maxDepth", required = false) Integer maxDepth,
102
                @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
103
                @RequestParam(value = "pageSize", required = false) Integer pageSize,
104
                HttpServletRequest request,
105
                HttpServletResponse response) throws IOException {
106

    
107
        logger.info("doListByAssociatedTaxon()" + request.getRequestURI() + "?" + request.getQueryString());
108

    
109
        Set<TaxonRelationshipEdge> includeRelationships = ControllerUtils.loadIncludeRelationships(relationshipUuids, relationshipInversUuids, termService);
110

    
111
        Taxon associatedTaxon = (Taxon) taxonService.find(taxonUuid);
112
        PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
113
        pagerParams.normalizeAndValidate(response);
114

    
115
        List<OrderHint> orderHints = null;
116

    
117
        return service.pageByAssociatedTaxon(null, includeRelationships, associatedTaxon,
118
                maxDepth, pagerParams.getPageSize(), pagerParams.getPageIndex(),
119
                orderHints, getInitializationStrategy());
120

    
121
    }
122

    
123
    /**
124
     *
125
     * @param clazz
126
     * @param queryString
127
     * @param boundingBox
128
     *            as
129
     *            minx(minlongitute),miny(minlatitute),maxx(maxlongitute),max(
130
     *            maxlatitute), e.g. 13.112,52.374,13.681,52.641 for the Berlin
131
     *            area
132
     * @param languages
133
     * @param highlighting
134
     * @param pageNumber
135
     * @param pageSize
136
     * @param request
137
     * @param response
138
     * @return
139
     * @throws IOException
140
     * @throws ParseException
141
     */
142
    @RequestMapping(method = RequestMethod.GET, value={"findByFullText"})
143
    public Pager<SearchResult<SpecimenOrObservationBase>> dofindByFullText(
144
            @RequestParam(value = "clazz", required = false) Class<? extends SpecimenOrObservationBase<?>> clazz,
145
            @RequestParam(value = "query", required = false) String queryString,
146
            @RequestParam(value = "bbox", required = false) Rectangle boundingBox,
147
            @RequestParam(value = "languages", required = false) List<Language> languages,
148
            @RequestParam(value = "hl", required = false) Boolean highlighting,
149
            @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
150
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
151
            HttpServletRequest request,
152
            HttpServletResponse response
153
            )
154
             throws IOException, LuceneParseException {
155

    
156
         logger.info("findByFullText : " + request.getRequestURI() + "?" + request.getQueryString() );
157

    
158
         PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
159
         pagerParams.normalizeAndValidate(response);
160

    
161
         if(highlighting == null){
162
             highlighting = false;
163
         }
164

    
165
         if(queryString == null && boundingBox == null) {
166
             HttpStatusMessage.create("Either query or bbox must be given", 400).send(response);
167
             return null;
168
         }
169

    
170
        Pager<SearchResult<SpecimenOrObservationBase>> pager = service.findByFullText(clazz, queryString, boundingBox, languages,
171
                highlighting, pagerParams.getPageSize(), pagerParams.getPageIndex(), ((List<OrderHint>)null),
172
                initializationStrategy);
173
        return pager;
174
    }
175

    
176
}
(42-42/67)