Project

General

Profile

Download (47 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id: TaxonController.java 5473 2009-03-25 13:42:07Z a.kohlbecker $
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 java.io.IOException;
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.EnumSet;
17
import java.util.HashSet;
18
import java.util.Hashtable;
19
import java.util.Iterator;
20
import java.util.List;
21
import java.util.Map;
22
import java.util.Set;
23
import java.util.UUID;
24

    
25
import javax.servlet.http.HttpServletRequest;
26
import javax.servlet.http.HttpServletResponse;
27

    
28
import org.apache.commons.lang.BooleanUtils;
29
import org.apache.log4j.Logger;
30
import org.apache.lucene.queryParser.ParseException;
31
import org.springframework.beans.factory.annotation.Autowired;
32
import org.springframework.stereotype.Controller;
33
import org.springframework.web.bind.WebDataBinder;
34
import org.springframework.web.bind.annotation.InitBinder;
35
import org.springframework.web.bind.annotation.PathVariable;
36
import org.springframework.web.bind.annotation.RequestMapping;
37
import org.springframework.web.bind.annotation.RequestMethod;
38
import org.springframework.web.bind.annotation.RequestParam;
39
import org.springframework.web.servlet.ModelAndView;
40

    
41
import eu.etaxonomy.cdm.api.service.IClassificationService;
42
import eu.etaxonomy.cdm.api.service.IDescriptionService;
43
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
44
import eu.etaxonomy.cdm.api.service.INameService;
45
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
46
import eu.etaxonomy.cdm.api.service.ITaxonService;
47
import eu.etaxonomy.cdm.api.service.ITermService;
48
import eu.etaxonomy.cdm.api.service.TaxaAndNamesSearchMode;
49
import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
50
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
51
import eu.etaxonomy.cdm.api.service.pager.Pager;
52
import eu.etaxonomy.cdm.api.service.search.LuceneMultiSearchException;
53
import eu.etaxonomy.cdm.api.service.search.SearchResult;
54
import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;
55
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
56
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
57
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
58
import eu.etaxonomy.cdm.model.common.Language;
59
import eu.etaxonomy.cdm.model.common.MarkerType;
60
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
61
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
62
import eu.etaxonomy.cdm.model.description.Feature;
63
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
64
import eu.etaxonomy.cdm.model.description.TaxonDescription;
65
import eu.etaxonomy.cdm.model.location.NamedArea;
66
import eu.etaxonomy.cdm.model.media.Media;
67
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
68
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
69
import eu.etaxonomy.cdm.model.media.MediaUtils;
70
import eu.etaxonomy.cdm.model.name.NameRelationship;
71
import eu.etaxonomy.cdm.model.taxon.Classification;
72
import eu.etaxonomy.cdm.model.taxon.Synonym;
73
import eu.etaxonomy.cdm.model.taxon.Taxon;
74
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
75
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
76
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
77
import eu.etaxonomy.cdm.persistence.query.MatchMode;
78
import eu.etaxonomy.cdm.persistence.query.OrderHint;
79
import eu.etaxonomy.cdm.remote.controller.util.ControllerUtils;
80
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
81
import eu.etaxonomy.cdm.remote.editor.CdmTypePropertyEditor;
82
import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
83
import eu.etaxonomy.cdm.remote.editor.MatchModePropertyEditor;
84
import eu.etaxonomy.cdm.remote.editor.NamedAreaPropertyEditor;
85
import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
86
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
87
import eu.etaxonomy.cdm.remote.editor.UuidList;
88

    
89
/**
90
 * The TaxonPortalController class is a Spring MVC Controller.
91
 * <p>
92
 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
93
 * The available {datasource-name}s are defined in a configuration file which
94
 * is loaded by the {@link UpdatableRoutingDataSource}. If the
95
 * UpdatableRoutingDataSource is not being used in the actual application
96
 * context any arbitrary {datasource-name} may be used.
97
 * <p>
98
 * Methods mapped at type level, inherited from super classes ({@link BaseController}):
99
 * <blockquote>
100
 * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;taxon&#x002F;{taxon-uuid}</b>
101
 *
102
 * Get the {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
103
 * The returned Taxon is initialized by
104
 * the following strategy {@link #TAXON_INIT_STRATEGY}
105
 * </blockquote>
106
 *
107
 * @author a.kohlbecker
108
 * @date 20.07.2009
109
 *
110
 */
111
@Controller
112
@RequestMapping(value = {"/portal/taxon/{uuid}"})
113
public class TaxonPortalController extends TaxonController
114
{
115

    
116
    public static final Logger logger = Logger.getLogger(TaxonPortalController.class);
117

    
118
    @Autowired
119
    private INameService nameService;
120

    
121
    @Autowired
122
    private IDescriptionService descriptionService;
123

    
124
    @Autowired
125
    private IOccurrenceService occurrenceService;
126

    
127
    @Autowired
128
    private IClassificationService classificationService;
129

    
130
    @Autowired
131
    private ITaxonService taxonService;
132

    
133
    @Autowired
134
    private ITermService termService;
135

    
136
    @Autowired
137
    private IFeatureTreeService featureTreeService;
138

    
139
    private static final List<String> TAXON_INIT_STRATEGY = Arrays.asList(new String []{
140
            "$",
141
            "sources",
142
            // taxon relations
143
//            "relationsToThisName.fromTaxon.name",
144
            // the name
145
            "name.$",
146
            "name.nomenclaturalReference.authorTeam",
147
            "name.nomenclaturalReference.inReference",
148
            "name.rank.representations",
149
            "name.status.type.representations",
150

    
151
//            "descriptions" // TODO remove
152

    
153
            });
154

    
155
    private static final List<String> TAXON_WITH_NODES_INIT_STRATEGY = Arrays.asList(new String []{
156
            "taxonNodes.$",
157
            "taxonNodes.classification.$",
158
            "taxonNodes.childNodes.$"
159
            });
160

    
161
    private static final List<String> SIMPLE_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
162
            "$",
163
            // the name
164
            "name.$",
165
            "name.rank.representations",
166
            "name.status.type.representations",
167
            "name.nomenclaturalReference.authorTeam",
168
            "name.nomenclaturalReference.inReference",
169
            "taxonNodes.classification",
170
            });
171

    
172
    private static final List<String> SYNONYMY_INIT_STRATEGY = Arrays.asList(new String []{
173
            // initialize homotypical and heterotypical groups; needs synonyms
174
            "synonymRelations.$",
175
            "synonymRelations.synonym.$",
176
            "synonymRelations.synonym.name.status.type.representation",
177
            "synonymRelations.synonym.name.nomenclaturalReference.authorTeam",
178
            "synonymRelations.synonym.name.nomenclaturalReference.inReference",
179
            "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.$",
180
            "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.$",
181
            "synonymRelations.synonym.name.combinationAuthorTeam.$",
182

    
183
            "name.typeDesignations",
184

    
185
            "name.homotypicalGroup.$",
186
            "name.homotypicalGroup.typifiedNames.$",
187
            "name.homotypicalGroup.typifiedNames.nomenclaturalReference.authorTeam",
188
            "name.homotypicalGroup.typifiedNames.nomenclaturalReference.inReference",
189
            "name.homotypicalGroup.typifiedNames.taxonBases.$"
190
    });
191

    
192
    private static final List<String> SYNONYMY_WITH_NODES_INIT_STRATEGY = Arrays.asList(new String []{
193
            // initialize homotypical and heterotypical groups; needs synonyms
194
            "synonymRelations.$",
195
            "synonymRelations.synonym.$",
196
            "synonymRelations.synonym.name.status.type.representation",
197
            "synonymRelations.synonym.name.nomenclaturalReference.authorTeam",
198
            "synonymRelations.synonym.name.nomenclaturalReference.inReference",
199
            "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.$",
200
            "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.$",
201
            "synonymRelations.synonym.name.combinationAuthorTeam.$",
202

    
203
            "name.homotypicalGroup.$",
204
            "name.homotypicalGroup.typifiedNames.$",
205
            "name.homotypicalGroup.typifiedNames.nomenclaturalReference.authorTeam",
206
            "name.homotypicalGroup.typifiedNames.nomenclaturalReference.inReference",
207

    
208
            "name.homotypicalGroup.typifiedNames.taxonBases.$",
209

    
210
            "taxonNodes.$",
211
            "taxonNodes.classification.$",
212
            "taxonNodes.childNodes.$"
213
    });
214
    private static final List<String> SIMPLE_TAXON_WITH_NODES_INIT_STRATEGY = Arrays.asList(new String []{
215
            "*",
216
            // taxon relations
217
            "relationsToThisName.fromTaxon.name",
218
            // the name
219
            "name.$",
220
            "name.rank.representations",
221
            "name.status.type.representations",
222
            "name.nomenclaturalReference.authorTeam",
223
            "name.nomenclaturalReference.inReference",
224

    
225
            "taxonNodes.$",
226
            "taxonNodes.classification.$",
227
            "taxonNodes.childNodes.$"
228
            });
229

    
230

    
231
    private static final List<String> TAXONRELATIONSHIP_INIT_STRATEGY = Arrays.asList(new String []{
232
            "$",
233
            "type.inverseRepresentations",
234
            "fromTaxon.sec",
235
            "fromTaxon.name",
236
            "toTaxon.sec",
237
            "toTaxon.name"
238
    });
239

    
240
    private static final List<String> NAMERELATIONSHIP_INIT_STRATEGY = Arrays.asList(new String []{
241
            "$",
242
            "type.inverseRepresentations",
243
            "toName.$",
244
            "toName.nomenclaturalReference.authorTeam",
245
            "toName.nomenclaturalReference.inReference",
246
            "fromName.$",
247
            "fromName.nomenclaturalReference.authorTeam",
248
            "fromName.nomenclaturalReference.inReference",
249

    
250
    });
251

    
252

    
253
    protected static final List<String> TAXONDESCRIPTION_INIT_STRATEGY = Arrays.asList(new String [] {
254
            "$",
255
            "elements.$",
256
            "elements.stateData.$",
257
            "elements.sources.citation.authorTeam",
258
            "elements.sources.nameUsedInSource",
259
            "elements.multilanguageText",
260
            "elements.media",
261
            "elements.modifyingText",
262
            "elements.modifiers",
263
            "elements.kindOfUnit",
264
            "name.$",
265
            "name.rank.representations",
266
            "name.status.type.representations",
267
            "sources.$",
268
    });
269

    
270
    protected static final List<String> DESCRIPTION_ELEMENT_INIT_STRATEGY = Arrays.asList(new String []{
271
            "$",
272
            "sources.citation.authorTeam",
273
            "sources.nameUsedInSource",
274
            "multilanguageText",
275
            "media",
276
    });
277

    
278

    
279
//	private static final List<String> NAMEDESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
280
//			"uuid",
281
//			"feature",
282
//			"elements.$",
283
//			"elements.multilanguageText",
284
//			"elements.media",
285
//	});
286

    
287
    protected static final List<String> TAXONDESCRIPTION_MEDIA_INIT_STRATEGY = Arrays.asList(new String []{
288
            "elements.media"
289

    
290
    });
291

    
292
    private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{
293
            "typeSpecimen.$",
294
            "citation.authorTeam.$",
295
            "typeName",
296
            "typeStatus"
297
    });
298

    
299
    protected static final List<String> TAXONNODE_WITHTAXON_INIT_STRATEGY = Arrays.asList(new String []{
300
            "childNodes.taxon",
301
    });
302

    
303
    protected static final List<String> TAXONNODE_INIT_STRATEGY = Arrays.asList(new String []{
304
            "taxonNodes.classification"
305
    });
306

    
307

    
308

    
309
    private static final String featureTreeUuidPattern = "^/taxon(?:(?:/)([^/?#&\\.]+))+.*";
310

    
311
    public TaxonPortalController(){
312
        super();
313
        setInitializationStrategy(TAXON_INIT_STRATEGY);
314
    }
315

    
316
    /* (non-Javadoc)
317
     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
318
     */
319
    @Autowired
320
    @Override
321
    public void setService(ITaxonService service) {
322
        this.service = service;
323
    }
324

    
325
    @InitBinder
326
    @Override
327
    public void initBinder(WebDataBinder binder) {
328
        super.initBinder(binder);
329
        binder.registerCustomEditor(NamedArea.class, new NamedAreaPropertyEditor());
330
        binder.registerCustomEditor(MatchMode.class, new MatchModePropertyEditor());
331
        binder.registerCustomEditor(Class.class, new CdmTypePropertyEditor());
332
        binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
333
        binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<NamedArea>(termService));
334

    
335
    }
336

    
337

    
338
    /* (non-Javadoc)
339
     * @see eu.etaxonomy.cdm.remote.controller.BaseController#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
340

    
341
    @Override
342
    @RequestMapping(method = RequestMethod.GET)
343
    public TaxonBase doGet(HttpServletRequest request, HttpServletResponse response)throws IOException {
344
        logger.info("doGet()");
345
        TaxonBase tb = getCdmBase(request, response, TAXON_INIT_STRATEGY, TaxonBase.class);
346
        return tb;
347
    }
348
     */
349

    
350
    @RequestMapping(method = RequestMethod.GET,
351
            value = {"/portal/taxon/find"}) //TODO map to path /*/portal/taxon/
352
    public Pager<IdentifiableEntity> doFind(
353
            @RequestParam(value = "query", required = false) String query,
354
            @RequestParam(value = "tree", required = false) UUID treeUuid,
355
            @RequestParam(value = "area", required = false) Set<NamedArea> areas,
356
            @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
357
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
358
            @RequestParam(value = "doTaxa", required = false) Boolean doTaxa,
359
            @RequestParam(value = "doSynonyms", required = false) Boolean doSynonyms,
360
            @RequestParam(value = "doMisappliedNames", required = false) Boolean doMisappliedNames,
361
            @RequestParam(value = "doTaxaByCommonNames", required = false) Boolean doTaxaByCommonNames,
362
            @RequestParam(value = "matchMode", required = false) MatchMode matchMode,
363
            HttpServletRequest request,
364
            HttpServletResponse response
365
            )
366
             throws IOException {
367

    
368
        logger.info("doFind : " + request.getRequestURI() + "?" + request.getQueryString() );
369

    
370
        PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
371
        pagerParams.normalizeAndValidate(response);
372

    
373
        IFindTaxaAndNamesConfigurator config = new FindTaxaAndNamesConfiguratorImpl();
374
        config.setPageNumber(pagerParams.getPageIndex());
375
        config.setPageSize(pagerParams.getPageSize());
376
        config.setTitleSearchString(query);
377
        config.setDoTaxa(doTaxa!= null ? doTaxa : Boolean.FALSE );
378
        config.setDoSynonyms(doSynonyms != null ? doSynonyms : Boolean.FALSE );
379
        config.setDoMisappliedNames(doMisappliedNames != null ? doMisappliedNames : Boolean.FALSE);
380
        config.setDoTaxaByCommonNames(doTaxaByCommonNames != null ? doTaxaByCommonNames : Boolean.FALSE );
381
        config.setMatchMode(matchMode != null ? matchMode : MatchMode.BEGINNING);
382
        config.setTaxonPropertyPath(SIMPLE_TAXON_INIT_STRATEGY);
383
        config.setNamedAreas(areas);
384
        if(treeUuid != null){
385
            Classification classification = classificationService.find(treeUuid);
386
            config.setClassification(classification);
387
        }
388

    
389
        return service.findTaxaAndNames(config);
390
    }
391

    
392
    /**
393
     * <b>NOTE and TODO</b>: this method is a direct copy of the same method in {@link TaxonListController},
394
     * refactorting needed to avoid method dublication
395
     * <p>
396
     * Find Taxa, Synonyms, Common Names by name, either globally or in a specific geographic area.
397
     * <p>
398
     * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;taxon&#x002F;find</b>
399
     *
400
     * @param query
401
     *            the string to query for. Since the wildcard character '*'
402
     *            internally always is appended to the query string, a search
403
     *            always compares the query string with the beginning of a name.
404
     *            - <i>required parameter</i>
405
     * @param treeUuid
406
     *            the {@link UUID} of a {@link Classification} to which the
407
     *            search is to be restricted. - <i>optional parameter</i>
408
     * @param areas
409
     *            restrict the search to a set of geographic {@link NamedArea}s.
410
     *            The parameter value must be a list of comma separated NamedArea uuids
411
     *            - <i>optional parameter</i>
412
     * @param pageNumber
413
     *            the number of the page to be returned, the first page has the
414
     *            pageNumber = 1 - <i>optional parameter</i>
415
     * @param pageSize
416
     *            the maximum number of entities returned per page (can be -1
417
     *            to return all entities in a single page) - <i>optional parameter</i>
418
     * @param doTaxa
419
     *            weather to search for instances of {@link Taxon} - <i>optional parameter</i>
420
     * @param doSynonyms
421
     *            weather to search for instances of {@link Synonym} - <i>optional parameter</i>
422
     * @param doTaxaByCommonNames
423
     *            for instances of {@link Taxon} by a common name used - <i>optional parameter</i>
424
     * @return a Pager on a list of {@link IdentifiableEntity}s initialized by
425
     *         the following strategy {@link #SIMPLE_TAXON_INIT_STRATEGY}
426
     * @throws IOException
427
     * @throws LuceneMultiSearchException
428
     * @throws ParseException
429
     */
430
    @RequestMapping(method = RequestMethod.GET, value={"/portal/taxon/search"})
431
    public Pager<SearchResult<TaxonBase>> doSearch(
432
            @RequestParam(value = "query", required = true) String query,
433
            @RequestParam(value = "tree", required = false) UUID treeUuid,
434
            @RequestParam(value = "area", required = false) DefinedTermBaseList<NamedArea> areaList,
435
            @RequestParam(value = "status", required = false) Set<PresenceAbsenceTermBase<?>> status,
436
            @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
437
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
438
            @RequestParam(value = "doTaxa", required = false) Boolean doTaxa,
439
            @RequestParam(value = "doSynonyms", required = false) Boolean doSynonyms,
440
            @RequestParam(value = "doMisappliedNames", required = false) Boolean doMisappliedNames,
441
            @RequestParam(value = "doTaxaByCommonNames", required = false) Boolean doTaxaByCommonNames,
442
            HttpServletRequest request,
443
            HttpServletResponse response
444
            )
445
             throws IOException, ParseException, LuceneMultiSearchException {
446

    
447

    
448
        logger.info("search : " + requestPathAndQuery(request) );
449

    
450
        Set<NamedArea> areaSet = null;
451
        if(areaList != null){
452
            areaSet = new HashSet<NamedArea>(areaList.size());
453
            areaSet.addAll(areaList);
454
            TaxonListController.includeAllSubAreas(areaSet, termService);
455
        }
456

    
457
        PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
458
        pagerParams.normalizeAndValidate(response);
459

    
460
        // TODO change type of do* parameters  to TaxaAndNamesSearchMode
461
        EnumSet<TaxaAndNamesSearchMode> searchModes = EnumSet.noneOf(TaxaAndNamesSearchMode.class);
462
        if(BooleanUtils.toBoolean(doTaxa)) {
463
            searchModes.add(TaxaAndNamesSearchMode.doTaxa);
464
        }
465
        if(BooleanUtils.toBoolean(doSynonyms)) {
466
            searchModes.add(TaxaAndNamesSearchMode.doSynonyms);
467
        }
468
        if(BooleanUtils.toBoolean(doMisappliedNames)) {
469
            searchModes.add(TaxaAndNamesSearchMode.doMisappliedNames);
470
        }
471
        if(BooleanUtils.toBoolean(doTaxaByCommonNames)) {
472
            searchModes.add(TaxaAndNamesSearchMode.doTaxaByCommonNames);
473
        }
474

    
475
        Classification classification = null;
476
        if(treeUuid != null){
477
            classification = classificationService.find(treeUuid);
478
        }
479

    
480
        return service.findTaxaAndNamesByFullText(searchModes, query,
481
                classification, areaSet, status, null,
482
                false, pagerParams.getPageSize(), pagerParams.getPageIndex(),
483
                OrderHint.NOMENCLATURAL_SORT_ORDER, SIMPLE_TAXON_INIT_STRATEGY);
484
    }
485

    
486
    /**
487
     * @param clazz
488
     * @param queryString
489
     * @param treeUuid
490
     * @param languages
491
     * @param features one or more feature uuids
492
     * @param pageNumber
493
     * @param pageSize
494
     * @param request
495
     * @param response
496
     * @return
497
     * @throws IOException
498
     * @throws ParseException
499
     */
500
    @SuppressWarnings("rawtypes")
501
    @RequestMapping(method = RequestMethod.GET, value={"/portal/taxon/findByDescriptionElementFullText"})
502
    public Pager<SearchResult<TaxonBase>> dofindByDescriptionElementFullText(
503
            @RequestParam(value = "clazz", required = false) Class clazz,
504
            @RequestParam(value = "query", required = true) String queryString,
505
            @RequestParam(value = "tree", required = false) UUID treeUuid,
506
            @RequestParam(value = "features", required = false) UuidList featureUuids,
507
            @RequestParam(value = "languages", required = false) List<Language> languages,
508
            @RequestParam(value = "hl", required = false) Boolean highlighting,
509
            @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
510
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
511
            HttpServletRequest request,
512
            HttpServletResponse response
513
            )
514
             throws IOException, ParseException {
515

    
516
         logger.info("findByDescriptionElementFullText : " + requestPathAndQuery(request) );
517

    
518
         PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
519
         pagerParams.normalizeAndValidate(response);
520

    
521
         if(highlighting == null){
522
             highlighting = false;
523
         }
524

    
525
         Classification classification = null;
526
        if(treeUuid != null){
527
            classification = classificationService.find(treeUuid);
528
        }
529

    
530
        List<Feature> features = null;
531
        if(featureUuids != null){
532
            features = new ArrayList<Feature>(featureUuids.size());
533
            for(UUID uuid : featureUuids){
534
                features.add((Feature) termService.find(uuid));
535
            }
536
        }
537

    
538
        Pager<SearchResult<TaxonBase>> pager = service.findByDescriptionElementFullText(
539
                clazz, queryString, classification, features, languages, highlighting,
540
                pagerParams.getPageSize(), pagerParams.getPageIndex(),
541
                ((List<OrderHint>)null), SIMPLE_TAXON_INIT_STRATEGY);
542
        return pager;
543
    }
544

    
545
    /**
546
     * Get the synonymy for a taxon identified by the <code>{taxon-uuid}</code>.
547
     * The synonymy consists
548
     * of two parts: The group of homotypic synonyms of the taxon and the
549
     * heterotypic synonymy groups of the taxon. The synonymy is ordered
550
     * historically by the type designations and by the publication date of the
551
     * nomenclatural reference
552
     * <p>
553
     * URI:
554
     * <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;taxon&#x002F;{taxon-uuid}&#x002F;synonymy</b>
555
     *
556
     *
557
     * @param request
558
     * @param response
559
     * @return a Map with to entries which are mapped by the following keys:
560
     *         "homotypicSynonymsByHomotypicGroup", "heterotypicSynonymyGroups",
561
     *         containing lists of {@link Synonym}s which are initialized using the
562
     *         following initialization strategy: {@link #SYNONYMY_INIT_STRATEGY}
563
     *
564
     * @throws IOException
565
     */
566
    @RequestMapping(
567
            value = {"synonymy"},
568
            method = RequestMethod.GET)
569
    public ModelAndView doGetSynonymy(@PathVariable("uuid") UUID uuid,
570
            HttpServletRequest request, HttpServletResponse response)throws IOException {
571

    
572
        if(request != null){
573
            logger.info("doGetSynonymy() " + requestPathAndQuery(request));
574
        }
575
        ModelAndView mv = new ModelAndView();
576
        Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
577
        Map<String, List<?>> synonymy = new Hashtable<String, List<?>>();
578

    
579
        //new
580
        List<List<Synonym>> synonymyGroups = service.getSynonymsByHomotypicGroup(taxon, SYNONYMY_INIT_STRATEGY);
581
        synonymy.put("homotypicSynonymsByHomotypicGroup", synonymyGroups.get(0));
582
        synonymyGroups.remove(0);
583
        synonymy.put("heterotypicSynonymyGroups", synonymyGroups);
584

    
585
        //old
586
//        synonymy.put("homotypicSynonymsByHomotypicGroup", service.getHomotypicSynonymsByHomotypicGroup(taxon, SYNONYMY_INIT_STRATEGY));
587
//        synonymy.put("heterotypicSynonymyGroups", service.getHeterotypicSynonymyGroups(taxon, SYNONYMY_INIT_STRATEGY));
588

    
589

    
590
        mv.addObject(synonymy);
591
        return mv;
592
    }
593

    
594

    
595
    /**
596
     * Get the list of {@link TaxonRelationship}s for the given
597
     * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
598
     * <p>
599
     * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;taxon&#x002F;{taxon-uuid}&#x002F;taxonRelationships</b>
600
     *
601
     * @param request
602
     * @param response
603
     * @return a List of {@link TaxonRelationship} entities which are initialized
604
     *         using the following initialization strategy:
605
     *         {@link #TAXONRELATIONSHIP_INIT_STRATEGY}
606
     * @throws IOException
607
     */
608
    @RequestMapping(
609
            value = {"taxonRelationships"},
610
            method = RequestMethod.GET)
611
    public List<TaxonRelationship> doGetTaxonRelations(@PathVariable("uuid") UUID uuid,
612
            HttpServletRequest request, HttpServletResponse response)throws IOException {
613

    
614
        logger.info("doGetTaxonRelations()" + requestPathAndQuery(request));
615
        Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
616
        List<TaxonRelationship> toRelationships = service.listToTaxonRelationships(taxon, null, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);
617
        List<TaxonRelationship> fromRelationships = service.listFromTaxonRelationships(taxon, null, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);
618

    
619
        List<TaxonRelationship> allRelationships = new ArrayList<TaxonRelationship>(toRelationships.size() + fromRelationships.size());
620
        allRelationships.addAll(toRelationships);
621
        allRelationships.addAll(fromRelationships);
622

    
623
        return allRelationships;
624
    }
625

    
626
    /**
627
     * Get the list of {@link NameRelationship}s of the Name associated with the
628
     * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
629
     * <p>
630
     * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;taxon&#x002F;{taxon-uuid}&#x002F;nameRelationships</b>
631
     *
632
     * @param request
633
     * @param response
634
     * @return a List of {@link NameRelationship} entities which are initialized
635
     *         using the following initialization strategy:
636
     *         {@link #NAMERELATIONSHIP_INIT_STRATEGY}
637
     * @throws IOException
638
     */
639
    @RequestMapping(
640
            value = {"toNameRelationships"},
641
            method = RequestMethod.GET)
642
    public List<NameRelationship> doGetToNameRelations(@PathVariable("uuid") UUID uuid,
643
            HttpServletRequest request, HttpServletResponse response)throws IOException {
644
        logger.info("doGetNameRelations()" + request.getRequestURI());
645
        TaxonBase taxonBase = getCdmBaseInstance(TaxonBase.class, uuid, response, (List<String>)null);
646
        List<NameRelationship> list = nameService.listNameRelationships(taxonBase.getName(), Direction.relatedTo, null, null, 0, null, NAMERELATIONSHIP_INIT_STRATEGY);
647
        //List<NameRelationship> list = nameService.listToNameRelationships(taxonBase.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY);
648
        return list;
649
    }
650

    
651
    /**
652
     * Get the list of {@link NameRelationship}s of the Name associated with the
653
     * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
654
     * <p>
655
     * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;taxon&#x002F;{taxon-uuid}&#x002F;nameRelationships</b>
656
     *
657
     * @param request
658
     * @param response
659
     * @return a List of {@link NameRelationship} entities which are initialized
660
     *         using the following initialization strategy:
661
     *         {@link #NAMERELATIONSHIP_INIT_STRATEGY}
662
     * @throws IOException
663
     */
664
    @RequestMapping(
665
            value = {"fromNameRelationships"},
666
            method = RequestMethod.GET)
667
    public List<NameRelationship> doGetFromNameRelations(@PathVariable("uuid") UUID uuid,
668
            HttpServletRequest request, HttpServletResponse response)throws IOException {
669
        logger.info("doGetNameFromNameRelations()" + requestPathAndQuery(request));
670

    
671
        TaxonBase taxonbase = getCdmBaseInstance(TaxonBase.class, uuid, response, SIMPLE_TAXON_INIT_STRATEGY);
672
        List<NameRelationship> list = nameService.listNameRelationships(taxonbase.getName(), Direction.relatedFrom, null, null, 0, null, NAMERELATIONSHIP_INIT_STRATEGY);
673
        //List<NameRelationship> list = nameService.listFromNameRelationships(taxonbase.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY);
674
        return list;
675
    }
676

    
677
    @Override
678
    @RequestMapping(value = "taxonNodes", method = RequestMethod.GET)
679
    public Set<TaxonNode>  doGetTaxonNodes(
680
            @PathVariable("uuid") UUID uuid,
681
            HttpServletRequest request,
682
            HttpServletResponse response) throws IOException {
683
        logger.info("doGetTaxonNodes" + requestPathAndQuery(request));
684
        TaxonBase taxon = service.load(uuid, TAXONNODE_INIT_STRATEGY);
685
        if(taxon instanceof Taxon){
686
            return ((Taxon)taxon).getTaxonNodes();
687
        } else {
688
            HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
689
            return null;
690
        }
691
    }
692

    
693
    /**
694
     * Get the list of {@link TaxonDescription}s of the
695
     * {@link Taxon} instance identified by the <code>{taxon-uuid}</code>.
696
     * <p>
697
     * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;taxon&#x002F;{taxon-uuid}&#x002F;descriptions</b>
698
     *
699
     * @param request
700
     * @param response
701
     * @return a List of {@link TaxonDescription} entities which are initialized
702
     *         using the following initialization strategy:
703
     *         {@link #TAXONDESCRIPTION_INIT_STRATEGY}
704
     * @throws IOException
705
     */
706
    @RequestMapping(
707
            value = {"descriptions"},
708
            method = RequestMethod.GET)
709
    public List<TaxonDescription> doGetDescriptions(
710
            @PathVariable("uuid") UUID uuid,
711
            @RequestParam(value = "markerTypes", required = false) UuidList markerTypeUUIDs,
712
            HttpServletRequest request,
713
            HttpServletResponse response)throws IOException {
714
        if(request != null){
715
            logger.info("doGetDescriptions()" + requestPathAndQuery(request));
716
        }
717
        List<DefinedTermBase> markerTypeTerms = null;
718
        Set<UUID> sMarkerTypeUUIDs = null;
719

    
720
        if(markerTypeUUIDs != null && !markerTypeUUIDs.isEmpty()){
721
            sMarkerTypeUUIDs = new HashSet<UUID>(markerTypeUUIDs);
722
            markerTypeTerms = termService.find(sMarkerTypeUUIDs);
723
        } else if(markerTypeUUIDs != null && markerTypeUUIDs.isEmpty()){
724
            markerTypeTerms = new ArrayList<DefinedTermBase>();
725
        }
726
        Set<MarkerType> markerTypes = new HashSet<MarkerType>();
727
        List<TaxonDescription> descriptions = new ArrayList<TaxonDescription>();
728
        if (markerTypeTerms != null) {
729
            for (DefinedTermBase markerTypeTerm : markerTypeTerms) {
730
                markerTypes.add((MarkerType)markerTypeTerm);
731
            }
732
        }
733
        Taxon t = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
734
        if (markerTypeTerms == null) {
735

    
736
            Pager<TaxonDescription> p = descriptionService.pageTaxonDescriptions(t, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY);
737
            descriptions = p.getRecords();
738
        }
739

    
740
        else if (markerTypeTerms != null && markerTypeTerms.isEmpty()) {
741
            descriptions = descriptionService.listTaxonDescriptions(t, null, null, markerTypes, null, null, TAXONDESCRIPTION_INIT_STRATEGY);
742

    
743
        }
744
        else {
745
            descriptions = descriptionService.listTaxonDescriptions(t, null, null, markerTypes, null, null, TAXONDESCRIPTION_INIT_STRATEGY);
746
            /*for (TaxonDescription description: descriptions) {
747
                for (IdentifiableSource source :description.getSources()) {
748
                    if (source.getOriginalNameString() != null) {
749
                        description.
750
                    }
751

    
752
                }
753

    
754

    
755
            }*/
756
        }
757
        return descriptions;
758
    }
759

    
760
    @RequestMapping(value = "useDescriptions", method = RequestMethod.GET)
761
    public List<TaxonDescription> doGetUseDescriptions(
762
            @PathVariable("uuid") UUID uuid,
763
            HttpServletRequest request,
764
            HttpServletResponse response) throws IOException {
765
        logger.info("doGetDescriptionElements() - " + requestPathAndQuery(request));
766

    
767
        //ModelAndView mv = new ModelAndView();
768
        Taxon t = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
769

    
770
       //MarkerType useMarkerType = (MarkerType) markerTypeService.find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f059"));
771
        MarkerType useMarkerType = (MarkerType) termService.find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));
772

    
773
       //find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f059"));
774
       Set<MarkerType> markerTypes =  new HashSet<MarkerType>();
775
       markerTypes.add(useMarkerType);
776
       List<TaxonDescription> descriptionElements = descriptionService.listTaxonDescriptions(t, null, null, markerTypes, null, null, TAXONDESCRIPTION_INIT_STRATEGY);
777
        //getDescriptionElements(description, features, type, pageSize, pageNumber, propertyPaths)  load(uuid);
778

    
779
        /*if(!(description instanceof TaxonDescription)){
780
            HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
781
            // will terminate thread
782
        }*/
783

    
784
        //boolean hasStructuredData = service.        hasStructuredData(description);
785

    
786
        //mv.addObject(hasStructuredData);
787

    
788
        return descriptionElements;
789
    }
790

    
791
    @RequestMapping(value = "descriptions/elementsByType/{classSimpleName}", method = RequestMethod.GET)
792
    public ModelAndView doGetDescriptionElementsByType(
793
            @PathVariable("uuid") UUID uuid,
794
            @PathVariable("classSimpleName") String classSimpleName,
795
            @RequestParam(value = "markerTypes", required = false) UuidList markerTypeUUIDs,
796
            @RequestParam(value = "count", required = false, defaultValue = "false") Boolean doCount,
797
            HttpServletRequest request,
798
            HttpServletResponse response) throws IOException {
799
        logger.info("doGetDescriptionElementsByType() - " + requestPathAndQuery(request));
800

    
801
        ModelAndView mv = new ModelAndView();
802

    
803
        List<DescriptionElementBase> allElements = new ArrayList<DescriptionElementBase>();
804
        List<DescriptionElementBase> elements;
805
        int count = 0;
806

    
807
        List<String> initStrategy = doCount ? null : DESCRIPTION_ELEMENT_INIT_STRATEGY;
808

    
809
        List<TaxonDescription> taxonDescriptions = doGetDescriptions(uuid, markerTypeUUIDs, request, response);
810
        try {
811
            Class type;
812
            type = Class.forName("eu.etaxonomy.cdm.model.description."
813
                    + classSimpleName);
814
            if (taxonDescriptions != null) {
815
                for (TaxonDescription description : taxonDescriptions) {
816
                    elements = descriptionService.listDescriptionElements(description, null, type, null, 0, initStrategy);
817
                    allElements.addAll(elements);
818
                    count += elements.size();
819
                }
820

    
821
            }
822
        } catch (ClassNotFoundException e) {
823
            HttpStatusMessage.fromString(e.getLocalizedMessage()).send(response);
824
        }
825
        if(doCount){
826
            mv.addObject(count);
827
        } else {
828
            mv.addObject(allElements);
829
        }
830
        return mv;
831
    }
832

    
833
//	@RequestMapping(value = "specimens", method = RequestMethod.GET)
834
//	public ModelAndView doGetSpecimens(
835
//			@PathVariable("uuid") UUID uuid,
836
//			HttpServletRequest request,
837
//			HttpServletResponse response) throws IOException, ClassNotFoundException {
838
//		logger.info("doGetSpecimens() - " + request.getRequestURI());
839
//
840
//		ModelAndView mv = new ModelAndView();
841
//
842
//		List<DerivedUnitFacade> derivedUnitFacadeList = new ArrayList<DerivedUnitFacade>();
843
//
844
//		// find speciemens in the TaxonDescriptions
845
//		List<TaxonDescription> taxonDescriptions = doGetDescriptions(uuid, request, response);
846
//		if (taxonDescriptions != null) {
847
//
848
//			for (TaxonDescription description : taxonDescriptions) {
849
//				derivedUnitFacadeList.addAll( occurrenceService.listDerivedUnitFacades(description, null) );
850
//			}
851
//		}
852
//		// TODO find speciemens in the NameDescriptions ??
853
//
854
//		// TODO also find type specimens
855
//
856
//		mv.addObject(derivedUnitFacadeList);
857
//
858
//		return mv;
859
//	}
860

    
861
    /**
862
     * Get the {@link Media} attached to the {@link Taxon} instance
863
     * identified by the <code>{taxon-uuid}</code>.
864
     *
865
     * Usage &#x002F;{datasource-name}&#x002F;portal&#x002F;taxon&#x002F;{taxon-
866
     * uuid}&#x002F;media&#x002F;{mime type
867
     * list}&#x002F;{size}[,[widthOrDuration}][,{height}]&#x002F;
868
     *
869
     * Whereas
870
     * <ul>
871
     * <li><b>{mime type list}</b>: a comma separated list of mime types, in the
872
     * order of preference. The forward slashes contained in the mime types must
873
     * be replaced by a colon. Regular expressions can be used. Each media
874
     * associated with this given taxon is being searched whereas the first
875
     * matching mime type matching a representation always rules.</li>
876
     * <li><b>{size},{widthOrDuration},{height}</b>: <i>not jet implemented</i>
877
     * valid values are an integer or the asterisk '*' as a wildcard</li>
878
     * </ul>
879
     *
880
     * @param request
881
     * @param response
882
     * @return a List of {@link Media} entities which are initialized
883
     *         using the following initialization strategy:
884
     *         {@link #TAXONDESCRIPTION_INIT_STRATEGY}
885
     * @throws IOException
886
     */
887
    @RequestMapping(
888
        value = {"media"},
889
        method = RequestMethod.GET)
890
    public List<Media> doGetMedia(
891
            @PathVariable("uuid") UUID uuid,
892
            @RequestParam(value = "type", required = false) Class<? extends MediaRepresentationPart> type,
893
            @RequestParam(value = "mimeTypes", required = false) String[] mimeTypes,
894
            @RequestParam(value = "relationships", required = false) UuidList relationshipUuids,
895
            @RequestParam(value = "relationshipsInvers", required = false) UuidList relationshipInversUuids,
896
            @RequestParam(value = "includeTaxonDescriptions", required = true) Boolean  includeTaxonDescriptions,
897
            @RequestParam(value = "includeOccurrences", required = true) Boolean  includeOccurrences,
898
            @RequestParam(value = "includeTaxonNameDescriptions", required = true) Boolean  includeTaxonNameDescriptions,
899
            @RequestParam(value = "widthOrDuration", required = false) Integer  widthOrDuration,
900
            @RequestParam(value = "height", required = false) Integer height,
901
            @RequestParam(value = "size", required = false) Integer size,
902
            HttpServletRequest request, HttpServletResponse response) throws IOException {
903

    
904
        logger.info("doGetMedia() " + requestPathAndQuery(request));
905

    
906
        Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
907

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

    
910
        List<Media> returnMedia = getMediaForTaxon(taxon, includeRelationships,
911
                includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions,
912
                type, mimeTypes, widthOrDuration, height, size);
913
        return returnMedia;
914
    }
915

    
916
    @RequestMapping(
917
            value = {"subtree/media"},
918
            method = RequestMethod.GET)
919
        public List<Media> doGetSubtreeMedia(
920
                @PathVariable("uuid") UUID uuid,
921
                @RequestParam(value = "type", required = false) Class<? extends MediaRepresentationPart> type,
922
                @RequestParam(value = "mimeTypes", required = false) String[] mimeTypes,
923
                @RequestParam(value = "relationships", required = false) UuidList relationshipUuids,
924
                @RequestParam(value = "relationshipsInvers", required = false) UuidList relationshipInversUuids,
925
                @RequestParam(value = "includeTaxonDescriptions", required = true) Boolean  includeTaxonDescriptions,
926
                @RequestParam(value = "includeOccurrences", required = true) Boolean  includeOccurrences,
927
                @RequestParam(value = "includeTaxonNameDescriptions", required = true) Boolean  includeTaxonNameDescriptions,
928
                @RequestParam(value = "widthOrDuration", required = false) Integer  widthOrDuration,
929
                @RequestParam(value = "height", required = false) Integer height,
930
                @RequestParam(value = "size", required = false) Integer size,
931
                HttpServletRequest request, HttpServletResponse response)throws IOException {
932

    
933
        logger.info("doGetSubtreeMedia() " + requestPathAndQuery(request));
934

    
935
        Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, TAXON_WITH_NODES_INIT_STRATEGY);
936

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

    
939
        List<Media> returnMedia = getMediaForTaxon(taxon, includeRelationships,
940
                includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions,
941
                type, mimeTypes, widthOrDuration, height, size);
942
        TaxonNode node;
943
        //looking for all medias of genus
944
        if (taxon.getTaxonNodes().size()>0){
945
            Set<TaxonNode> nodes = taxon.getTaxonNodes();
946
            Iterator<TaxonNode> iterator = nodes.iterator();
947
            //TaxonNode holen
948
            node = iterator.next();
949
            //Check if TaxonNode belongs to the current tree
950

    
951
            node = classificationService.loadTaxonNode(node, TAXONNODE_WITHTAXON_INIT_STRATEGY);
952
            List<TaxonNode> children = node.getChildNodes();
953
            Taxon childTaxon;
954
            for (TaxonNode child : children){
955
                childTaxon = child.getTaxon();
956
                childTaxon = (Taxon)taxonService.load(childTaxon.getUuid(), null);
957
                returnMedia.addAll(getMediaForTaxon(childTaxon, includeRelationships,
958
                        includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions,
959
                        type, mimeTypes, widthOrDuration, height, size));
960
            }
961
        }
962
        return returnMedia;
963
    }
964

    
965
    /**
966
     *
967
     * @param taxon
968
     * @param includeRelationships
969
     * @param type
970
     * @param mimeTypes
971
     * @param widthOrDuration
972
     * @param height
973
     * @param size
974
     * @return
975
     */
976
    private List<Media> getMediaForTaxon(Taxon taxon, Set<TaxonRelationshipEdge> includeRelationships,
977
            Boolean includeTaxonDescriptions, Boolean includeOccurrences, Boolean includeTaxonNameDescriptions,
978
            Class<? extends MediaRepresentationPart> type, String[] mimeTypes, Integer widthOrDuration,
979
            Integer height, Integer size) {
980

    
981
        // list the media
982
        logger.trace("getMediaForTaxon() - list the media");
983
        List<Media> taxonGalleryMedia = service.listMedia(taxon, includeRelationships,
984
                false, includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions,
985
                TAXONDESCRIPTION_MEDIA_INIT_STRATEGY);
986

    
987
        // filter by preferred size and type
988

    
989
        logger.trace("getMediaForTaxon() - filter the media");
990
        Map<Media, MediaRepresentation> mediaRepresentationMap = MediaUtils.findPreferredMedia(
991
                taxonGalleryMedia, type, mimeTypes, null, widthOrDuration, height, size);
992

    
993
        List<Media> filteredMedia = new ArrayList<Media>(mediaRepresentationMap.size());
994
        for (Media media : mediaRepresentationMap.keySet()) {
995
            media.getRepresentations().clear();
996
            media.addRepresentation(mediaRepresentationMap.get(media));
997
            filteredMedia.add(media);
998
        }
999

    
1000
        logger.trace("getMediaForTaxon() - END ");
1001

    
1002
        return filteredMedia;
1003
    }
1004

    
1005
// ---------------------- code snippet preserved for possible later use --------------------
1006
//	@RequestMapping(
1007
//			value = {"/*/portal/taxon/*/descriptions"},
1008
//			method = RequestMethod.GET)
1009
//	public List<TaxonDescription> doGetDescriptionsbyFeatureTree(HttpServletRequest request, HttpServletResponse response)throws IOException {
1010
//		TaxonBase tb = getCdmBase(request, response, null, Taxon.class);
1011
//		if(tb instanceof Taxon){
1012
//			//T O D O this is a quick and dirty implementation -> generalize
1013
//			UUID featureTreeUuid = readValueUuid(request, featureTreeUuidPattern);
1014
//
1015
//			FeatureTree featureTree = descriptionService.getFeatureTreeByUuid(featureTreeUuid);
1016
//			Pager<TaxonDescription> p = descriptionService.getTaxonDescriptions((Taxon)tb, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY);
1017
//			List<TaxonDescription> descriptions = p.getRecords();
1018
//
1019
//			if(!featureTree.isDescriptionSeparated()){
1020
//
1021
//				TaxonDescription superDescription = TaxonDescription.NewInstance();
1022
//				//put all descriptionElements in superDescription and make it invisible
1023
//				for(TaxonDescription description: descriptions){
1024
//					for(DescriptionElementBase element: description.getElements()){
1025
//						superDescription.addElement(element);
1026
//					}
1027
//				}
1028
//				List<TaxonDescription> separatedDescriptions = new ArrayList<TaxonDescription>(descriptions.size());
1029
//				separatedDescriptions.add(superDescription);
1030
//				return separatedDescriptions;
1031
//			}else{
1032
//				return descriptions;
1033
//			}
1034
//		} else {
1035
//			response.sendError(HttpServletResponse.SC_NOT_FOUND, "invalid type; Taxon expected but " + tb.getClass().getSimpleName() + " found.");
1036
//			return null;
1037
//		}
1038
//	}
1039

    
1040
}
(52-52/56)