1 // $Id: TaxonController.java 5473 2009-03-25 13:42:07Z a.kohlbecker $
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.remote
.controller
;
13 import static java
.net
.HttpURLConnection
.HTTP_BAD_REQUEST
;
15 import java
.io
.IOException
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Arrays
;
18 import java
.util
.HashSet
;
19 import java
.util
.Hashtable
;
20 import java
.util
.Iterator
;
21 import java
.util
.List
;
24 import java
.util
.UUID
;
26 import javax
.servlet
.http
.HttpServletRequest
;
27 import javax
.servlet
.http
.HttpServletResponse
;
29 import org
.apache
.commons
.lang
.ObjectUtils
;
30 import org
.apache
.http
.HttpRequest
;
31 import org
.apache
.log4j
.Logger
;
32 import org
.apache
.lucene
.queryParser
.ParseException
;
33 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
34 import org
.springframework
.stereotype
.Controller
;
35 import org
.springframework
.web
.bind
.WebDataBinder
;
36 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
37 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
38 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
39 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
40 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
41 import org
.springframework
.web
.servlet
.ModelAndView
;
44 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
45 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
46 import eu
.etaxonomy
.cdm
.api
.service
.IMarkerService
;
47 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
48 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
49 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
50 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
51 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
52 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
53 import eu
.etaxonomy
.cdm
.api
.service
.config
.IFindTaxaAndNamesConfigurator
;
54 import eu
.etaxonomy
.cdm
.api
.service
.config
.FindTaxaAndNamesConfiguratorImpl
;
55 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
56 import eu
.etaxonomy
.cdm
.api
.service
.search
.SearchResult
;
57 import eu
.etaxonomy
.cdm
.database
.UpdatableRoutingDataSource
;
58 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
59 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
60 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
61 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
62 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
63 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
64 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
.Direction
;
65 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
66 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
67 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
68 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
69 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
70 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
71 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
72 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
73 import eu
.etaxonomy
.cdm
.model
.media
.MediaUtils
;
74 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
75 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
76 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
77 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
78 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
79 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
80 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
81 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
82 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
83 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
84 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
85 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.PagerParameters
;
86 import eu
.etaxonomy
.cdm
.remote
.editor
.CdmTypePropertyEditor
;
87 import eu
.etaxonomy
.cdm
.remote
.editor
.MatchModePropertyEditor
;
88 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaPropertyEditor
;
89 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
90 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
93 * The TaxonPortalController class is a Spring MVC Controller.
95 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
96 * The available {datasource-name}s are defined in a configuration file which
97 * is loaded by the {@link UpdatableRoutingDataSource}. If the
98 * UpdatableRoutingDataSource is not being used in the actual application
99 * context any arbitrary {datasource-name} may be used.
101 * Methods mapped at type level, inherited from super classes ({@link BaseController}):
103 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}</b>
105 * Get the {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
106 * The returned Taxon is initialized by
107 * the following strategy {@link #TAXON_INIT_STRATEGY}
110 * @author a.kohlbecker
115 @RequestMapping(value
= {"/portal/taxon/{uuid}"})
116 public class TaxonPortalController
extends BaseController
<TaxonBase
, ITaxonService
>
118 public static final Logger logger
= Logger
.getLogger(TaxonPortalController
.class);
121 private INameService nameService
;
124 private IDescriptionService descriptionService
;
127 private IOccurrenceService occurrenceService
;
130 private IClassificationService classificationService
;
133 private ITaxonService taxonService
;
136 private ITermService termService
;
139 private IFeatureTreeService featureTreeService
;
141 private static final List
<String
> TAXON_INIT_STRATEGY
= Arrays
.asList(new String
[]{
144 "relationsToThisName.fromTaxon.name",
147 "name.rank.representations",
148 "name.status.type.representations",
150 // taxon descriptions
151 "descriptions.elements.area.$",
152 "descriptions.elements.multilanguageText",
153 "descriptions.elements.media",
157 private static final List
<String
> TAXON_WITH_NODES_INIT_STRATEGY
= Arrays
.asList(new String
[]{
159 "taxonNodes.classification.$",
160 "taxonNodes.childNodes.$"
163 private static final List
<String
> SIMPLE_TAXON_INIT_STRATEGY
= Arrays
.asList(new String
[]{
166 "relationsToThisName.fromTaxon.name",
169 "name.rank.representations",
170 "name.status.type.representations",
171 "name.nomenclaturalReference"
174 private static final List
<String
> SYNONYMY_INIT_STRATEGY
= Arrays
.asList(new String
[]{
175 // initialize homotypical and heterotypical groups; needs synonyms
176 "synonymRelations.$",
177 "synonymRelations.synonym.$",
178 "synonymRelations.synonym.name.status.type.representation",
179 "synonymRelations.synonym.name.nomenclaturalReference.inReference",
180 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.$",
181 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.$",
182 "synonymRelations.synonym.name.combinationAuthorTeam.$",
184 "name.typeDesignations",
186 "name.homotypicalGroup.$",
187 "name.homotypicalGroup.typifiedNames.$",
188 "name.homotypicalGroup.typifiedNames.nomenclaturalReference.authorTeam",
190 "name.homotypicalGroup.typifiedNames.taxonBases.$"
193 private static final List
<String
> SYNONYMY_WITH_NODES_INIT_STRATEGY
= Arrays
.asList(new String
[]{
194 // initialize homotypical and heterotypical groups; needs synonyms
195 "synonymRelations.$",
196 "synonymRelations.synonym.$",
197 "synonymRelations.synonym.name.status.type.representation",
198 "synonymRelations.synonym.name.nomenclaturalReference.inReference",
199 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.$",
200 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.$",
201 "synonymRelations.synonym.name.combinationAuthorTeam.$",
203 "name.homotypicalGroup.$",
204 "name.homotypicalGroup.typifiedNames.$",
205 "name.homotypicalGroup.typifiedNames.nomenclaturalReference.authorTeam",
207 "name.homotypicalGroup.typifiedNames.taxonBases.$",
210 "taxonNodes.classification.$",
211 "taxonNodes.childNodes.$"
213 private static final List
<String
> SIMPLE_TAXON_WITH_NODES_INIT_STRATEGY
= Arrays
.asList(new String
[]{
216 "relationsToThisName.fromTaxon.name",
219 "name.rank.representations",
220 "name.status.type.representations",
221 "name.nomenclaturalReference",
224 "taxonNodes.classification.$",
225 "taxonNodes.childNodes.$"
229 private static final List
<String
> TAXONRELATIONSHIP_INIT_STRATEGY
= Arrays
.asList(new String
[]{
231 "type.inverseRepresentations",
238 private static final List
<String
> NAMERELATIONSHIP_INIT_STRATEGY
= Arrays
.asList(new String
[]{
240 "type.inverseRepresentations",
246 protected static final List
<String
> TAXONDESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
249 "elements.sources.citation.authorTeam",
250 "elements.sources.nameUsedInSource.originalNameString",
251 "elements.multilanguageText",
255 protected static final List
<String
> TAXONUSEDESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
258 "name.rank.representations",
259 "name.status.type.representations",
263 "elements.sources.citation.authorTeam",
264 "elements.sources.nameUsedInSource.originalNameString",
265 "elements.multilanguageText",
269 protected static final List
<String
> DESCRIPTION_ELEMENT_INIT_STRATEGY
= Arrays
.asList(new String
[]{
271 "sources.citation.authorTeam",
272 "sources.nameUsedInSource.originalNameString",
278 // private static final List<String> NAMEDESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
282 // "elements.multilanguageText",
286 protected static final List
<String
> TAXONDESCRIPTION_MEDIA_INIT_STRATEGY
= Arrays
.asList(new String
[]{
291 private static final List
<String
> TYPEDESIGNATION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
293 "citation.authorTeam.$",
298 protected static final List
<String
> TAXONNODE_WITHTAXON_INIT_STRATEGY
= Arrays
.asList(new String
[]{
302 protected static final List
<String
> TAXONNODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
303 "taxonNodes.classification"
308 private static final String featureTreeUuidPattern
= "^/taxon(?:(?:/)([^/?#&\\.]+))+.*";
310 public TaxonPortalController(){
312 setInitializationStrategy(TAXON_INIT_STRATEGY
);
316 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
320 public void setService(ITaxonService service
) {
321 this.service
= service
;
326 public void initBinder(WebDataBinder binder
) {
327 super.initBinder(binder
);
328 binder
.registerCustomEditor(NamedArea
.class, new NamedAreaPropertyEditor());
329 binder
.registerCustomEditor(MatchMode
.class, new MatchModePropertyEditor());
330 binder
.registerCustomEditor(Class
.class, new CdmTypePropertyEditor());
331 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
337 * @see eu.etaxonomy.cdm.remote.controller.BaseController#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
340 @RequestMapping(method = RequestMethod.GET)
341 public TaxonBase doGet(HttpServletRequest request, HttpServletResponse response)throws IOException {
342 logger.info("doGet()");
343 TaxonBase tb = getCdmBase(request, response, TAXON_INIT_STRATEGY, TaxonBase.class);
348 * Find Taxa, Synonyms, Common Names by name, either globally or in a specific geographic area.
350 * URI: <b>/{datasource-name}/portal/taxon/find</b>
353 * the string to query for. Since the wildcard character '*'
354 * internally always is appended to the query string, a search
355 * always compares the query string with the beginning of a name.
356 * - <i>required parameter</i>
358 * the {@link UUID} of a {@link Classification} to which the
359 * search is to be restricted. - <i>optional parameter</i>
361 * restrict the search to a set of geographic {@link NamedArea}s.
362 * The parameter currently takes a list of TDWG area labels.
363 * - <i>optional parameter</i>
365 * the number of the page to be returned, the first page has the
366 * pageNumber = 1 - <i>optional parameter</i>
368 * the maximum number of entities returned per page (can be -1
369 * to return all entities in a single page) - <i>optional parameter</i>
371 * weather to search for instances of {@link Taxon} - <i>optional parameter</i>
373 * weather to search for instances of {@link Synonym} - <i>optional parameter</i>
374 * @param doTaxaByCommonNames
375 * for instances of {@link Taxon} by a common name used - <i>optional parameter</i>
377 * valid values are "EXACT", "BEGINNING", "ANYWHERE", "END" (case sensitive !!!)
378 * @return a Pager on a list of {@link IdentifiableEntity}s initialized by
379 * the following strategy {@link #SIMPLE_TAXON_INIT_STRATEGY}
380 * @throws IOException
382 @RequestMapping(method
= RequestMethod
.GET
,
383 value
= {"/portal/taxon/find"}) //TODO map to path /*/portal/taxon/
384 public Pager
<IdentifiableEntity
> doFind(
385 @RequestParam(value
= "query", required
= false) String query
,
386 @RequestParam(value
= "tree", required
= false) UUID treeUuid
,
387 @RequestParam(value
= "area", required
= false) Set
<NamedArea
> areas
,
388 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
389 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
390 @RequestParam(value
= "doTaxa", required
= false) Boolean doTaxa
,
391 @RequestParam(value
= "doSynonyms", required
= false) Boolean doSynonyms
,
392 @RequestParam(value
= "doMisappliedNames", required
= false) Boolean doMisappliedNames
,
393 @RequestParam(value
= "doTaxaByCommonNames", required
= false) Boolean doTaxaByCommonNames
,
394 @RequestParam(value
= "matchMode", required
= false) MatchMode matchMode
,
395 HttpServletRequest request
,
396 HttpServletResponse response
400 logger
.info("doFind : " + request
.getRequestURI() + "?" + request
.getQueryString() );
402 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
403 pagerParams
.normalizeAndValidate(response
);
405 IFindTaxaAndNamesConfigurator config
= new FindTaxaAndNamesConfiguratorImpl();
406 config
.setPageNumber(pagerParams
.getPageIndex());
407 config
.setPageSize(pagerParams
.getPageSize());
408 config
.setTitleSearchString(query
);
409 config
.setDoTaxa(doTaxa
!= null ? doTaxa
: Boolean
.FALSE
);
410 config
.setDoSynonyms(doSynonyms
!= null ? doSynonyms
: Boolean
.FALSE
);
411 config
.setDoMisappliedNames(doMisappliedNames
!= null ? doMisappliedNames
: Boolean
.FALSE
);
412 config
.setDoTaxaByCommonNames(doTaxaByCommonNames
!= null ? doTaxaByCommonNames
: Boolean
.FALSE
);
413 config
.setMatchMode(matchMode
!= null ? matchMode
: MatchMode
.BEGINNING
);
414 config
.setTaxonPropertyPath(SIMPLE_TAXON_INIT_STRATEGY
);
415 config
.setNamedAreas(areas
);
416 if(treeUuid
!= null){
417 Classification classification
= classificationService
.find(treeUuid
);
418 config
.setClassification(classification
);
421 return (Pager
<IdentifiableEntity
>) service
.findTaxaAndNames(config
);
429 * @param features one or more feature uuids
435 * @throws IOException
436 * @throws ParseException
438 @RequestMapping(method
= RequestMethod
.GET
, value
={"/portal/taxon/findByDescriptionElementFullText"})
439 public Pager
<SearchResult
<TaxonBase
>> dofindByDescriptionElementFullText(
440 @RequestParam(value
= "clazz", required
= false) Class clazz
,
441 @RequestParam(value
= "query", required
= true) String queryString
,
442 @RequestParam(value
= "tree", required
= false) UUID treeUuid
,
443 @RequestParam(value
= "features", required
= false) UuidList featureUuids
,
444 @RequestParam(value
= "languages", required
= false) List
<Language
> languages
,
445 @RequestParam(value
= "hl", required
= false) Boolean highlighting
,
446 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
447 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
448 HttpServletRequest request
,
449 HttpServletResponse response
451 throws IOException
, ParseException
{
453 logger
.info("findByDescriptionElementFullText : " + request
.getRequestURI() + "?" + request
.getQueryString() );
455 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
456 pagerParams
.normalizeAndValidate(response
);
458 if(highlighting
== null){
459 highlighting
= false;
462 Classification classification
= null;
463 if(treeUuid
!= null){
464 classification
= classificationService
.find(treeUuid
);
467 List
<Feature
> features
= null;
468 if(featureUuids
!= null){
469 features
= new ArrayList
<Feature
>(featureUuids
.size());
470 for(UUID uuid
: featureUuids
){
471 features
.add((Feature
) termService
.find(uuid
));
475 Pager
<SearchResult
<TaxonBase
>> pager
= service
.findByDescriptionElementFullText(clazz
, queryString
, classification
, features
, languages
, highlighting
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(), ((List
<OrderHint
>)null), SIMPLE_TAXON_INIT_STRATEGY
);
480 * Get the synonymy for a taxon identified by the <code>{taxon-uuid}</code>.
481 * The synonymy consists
482 * of two parts: The group of homotypic synonyms of the taxon and the
483 * heterotypic synonymy groups of the taxon. The synonymy is ordered
484 * historically by the type designations and by the publication date of the
485 * nomenclatural reference
488 * <b>/{datasource-name}/portal/taxon/{taxon-uuid}/synonymy</b>
493 * @return a Map with to entries which are mapped by the following keys:
494 * "homotypicSynonymsByHomotypicGroup", "heterotypicSynonymyGroups",
495 * containing lists of {@link Synonym}s which are initialized using the
496 * following initialization strategy: {@link #SYNONYMY_INIT_STRATEGY}
498 * @throws IOException
501 value
= {"synonymy"},
502 method
= RequestMethod
.GET
)
503 public ModelAndView
doGetSynonymy(@PathVariable("uuid") UUID uuid
,
504 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
507 logger
.info("doGetSynonymy() " + request
.getServletPath());
509 ModelAndView mv
= new ModelAndView();
510 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
511 Map
<String
, List
<?
>> synonymy
= new Hashtable
<String
, List
<?
>>();
512 synonymy
.put("homotypicSynonymsByHomotypicGroup", service
.getHomotypicSynonymsByHomotypicGroup(taxon
, SYNONYMY_INIT_STRATEGY
));
513 synonymy
.put("heterotypicSynonymyGroups", service
.getHeterotypicSynonymyGroups(taxon
, SYNONYMY_INIT_STRATEGY
));
514 mv
.addObject(synonymy
);
519 * Get the set of accepted {@link Taxon} entities for a given
520 * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
522 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/accepted</b>
526 * @return a Set of {@link Taxon} entities which are initialized
527 * using the following initialization strategy:
528 * {@link #SYNONYMY_INIT_STRATEGY}
529 * @throws IOException
531 @RequestMapping(value
= "accepted/{classification_uuid}", method
= RequestMethod
.GET
)
532 public Set
<TaxonBase
> getAccepted(
533 @PathVariable("uuid") UUID uuid
,
534 @PathVariable("classification_uuid") UUID classification_uuid
,
535 HttpServletRequest request
,
536 HttpServletResponse response
)
540 logger
.info("getAccepted() " + request
.getServletPath());
543 TaxonBase tb
= service
.load(uuid
, SYNONYMY_WITH_NODES_INIT_STRATEGY
);
545 response
.sendError(HttpServletResponse
.SC_NOT_FOUND
, "A taxon with the uuid " + uuid
+ " does not exist");
549 HashSet
<TaxonBase
> resultset
= new HashSet
<TaxonBase
>();
551 if (tb
instanceof Taxon
){
552 Taxon taxon
= (Taxon
) tb
;
553 Set
<TaxonNode
> nodes
= taxon
.getTaxonNodes();
554 for (TaxonNode taxonNode
: nodes
) {
555 if (taxonNode
.getClassification().compareTo(classification_uuid
) == 0){
556 resultset
.add((Taxon
) tb
);
559 if (resultset
.size() > 1){
560 //error!! A taxon is not allow to have more taxonnodes for a given classification
561 response
.sendError(HttpServletResponse
.SC_INTERNAL_SERVER_ERROR
,
562 "A taxon with the uuid " + uuid
+ " has more than one taxon node for the given classification" + classification_uuid
);
565 Synonym syn
= (Synonym
) tb
;
566 for(TaxonBase accepted
: syn
.getAcceptedTaxa()){
567 tb
= service
.load(accepted
.getUuid(), SIMPLE_TAXON_WITH_NODES_INIT_STRATEGY
);
568 if (tb
instanceof Taxon
){
569 Taxon taxon
= (Taxon
) tb
;
570 Set
<TaxonNode
> nodes
= taxon
.getTaxonNodes();
571 for (TaxonNode taxonNode
: nodes
) {
572 if (taxonNode
.getClassification().compareTo(classification_uuid
) == 0){
573 resultset
.add((Taxon
) tb
);
576 if (resultset
.size() > 1){
577 //error!! A taxon is not allow to have more taxonnodes for a given classification
578 response
.sendError(HttpServletResponse
.SC_INTERNAL_SERVER_ERROR
,
579 "A taxon with the uuid " + uuid
+ " has more than one taxon node for the given classification" + classification_uuid
);
582 //ERROR!! perhaps missapplied name????
583 //syn.getRelationType((Taxon)accepted);
589 if(tb instanceof Taxon){
590 //the taxon already is accepted
591 //FIXME take the current view into account once views are implemented!!!
592 resultset.add((Taxon)tb);
594 Synonym syn = (Synonym)tb;
595 for(TaxonBase accepted : syn.getAcceptedTaxa()){
596 accepted = service.load(accepted.getUuid(), SIMPLE_TAXON_INIT_STRATEGY);
597 resultset.add(accepted);
605 * Get the list of {@link TaxonRelationship}s for the given
606 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
608 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/taxonRelationships</b>
612 * @return a List of {@link TaxonRelationship} entities which are initialized
613 * using the following initialization strategy:
614 * {@link #TAXONRELATIONSHIP_INIT_STRATEGY}
615 * @throws IOException
618 value
= {"taxonRelationships"},
619 method
= RequestMethod
.GET
)
620 public List
<TaxonRelationship
> doGetTaxonRelations(@PathVariable("uuid") UUID uuid
,
621 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
623 logger
.info("doGetTaxonRelations()" + request
.getServletPath());
624 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
625 List
<TaxonRelationship
> toRelationships
= service
.listToTaxonRelationships(taxon
, null, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY
);
626 List
<TaxonRelationship
> fromRelationships
= service
.listFromTaxonRelationships(taxon
, null, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY
);
628 List
<TaxonRelationship
> allRelationships
= new ArrayList
<TaxonRelationship
>(toRelationships
.size() + fromRelationships
.size());
629 allRelationships
.addAll(toRelationships
);
630 allRelationships
.addAll(fromRelationships
);
632 return allRelationships
;
636 * Get the list of {@link NameRelationship}s of the Name associated with the
637 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
639 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameRelationships</b>
643 * @return a List of {@link NameRelationship} entities which are initialized
644 * using the following initialization strategy:
645 * {@link #NAMERELATIONSHIP_INIT_STRATEGY}
646 * @throws IOException
649 value
= {"toNameRelationships"},
650 method
= RequestMethod
.GET
)
651 public List
<NameRelationship
> doGetToNameRelations(@PathVariable("uuid") UUID uuid
,
652 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
653 logger
.info("doGetNameRelations()" + request
.getServletPath());
654 TaxonBase taxonBase
= getCdmBaseInstance(TaxonBase
.class, uuid
, response
, (List
<String
>)null);
655 List
<NameRelationship
> list
= nameService
.listNameRelationships(taxonBase
.getName(), Direction
.relatedTo
, null, null, 0, null, NAMERELATIONSHIP_INIT_STRATEGY
);
656 //List<NameRelationship> list = nameService.listToNameRelationships(taxonBase.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY);
661 * Get the list of {@link NameRelationship}s of the Name associated with the
662 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
664 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameRelationships</b>
668 * @return a List of {@link NameRelationship} entities which are initialized
669 * using the following initialization strategy:
670 * {@link #NAMERELATIONSHIP_INIT_STRATEGY}
671 * @throws IOException
674 value
= {"fromNameRelationships"},
675 method
= RequestMethod
.GET
)
676 public List
<NameRelationship
> doGetFromNameRelations(@PathVariable("uuid") UUID uuid
,
677 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
678 logger
.info("doGetNameFromNameRelations()" + request
.getServletPath());
680 TaxonBase taxonbase
= getCdmBaseInstance(TaxonBase
.class, uuid
, response
, SIMPLE_TAXON_INIT_STRATEGY
);
681 List
<NameRelationship
> list
= nameService
.listNameRelationships(taxonbase
.getName(), Direction
.relatedFrom
, null, null, 0, null, NAMERELATIONSHIP_INIT_STRATEGY
);
682 //List<NameRelationship> list = nameService.listFromNameRelationships(taxonbase.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY);
687 * Get the list of {@link TypeDesignationBase}s of the
688 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
690 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameTypeDesignations</b>
694 * @return a List of {@link TypeDesignationBase} entities which are initialized
695 * using the following initialization strategy:
696 * {@link #TYPEDESIGNATION_INIT_STRATEGY}
697 * @throws IOException
698 * @Deprecated use /name/{uuid}/typeDesignations & /derivedunitfacade/{uuid} instead
699 * also see http://dev.e-taxonomy.eu/trac/ticket/2280
703 value
= {"nameTypeDesignations"},
704 method
= RequestMethod
.GET
)
705 public List
<TypeDesignationBase
> doGetNameTypeDesignations(@PathVariable("uuid") UUID uuid
,
706 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
707 logger
.info("doGetNameTypeDesignations()" + request
.getServletPath());
708 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, SIMPLE_TAXON_INIT_STRATEGY
);
709 Pager
<TypeDesignationBase
> p
= nameService
.getTypeDesignations(taxon
.getName(), null, null, null, TYPEDESIGNATION_INIT_STRATEGY
);
710 return p
.getRecords();
713 @RequestMapping(value
= "taxonNodes", method
= RequestMethod
.GET
)
714 public Set
<TaxonNode
> doGetTaxonNodes(
715 @PathVariable("uuid") UUID uuid
,
716 HttpServletRequest request
,
717 HttpServletResponse response
) throws IOException
{
718 TaxonBase tb
= service
.load(uuid
, TAXONNODE_INIT_STRATEGY
);
719 if(tb
instanceof Taxon
){
720 return ((Taxon
)tb
).getTaxonNodes();
722 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
728 * Get the list of {@link TaxonDescription}s of the
729 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code>.
731 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/descriptions</b>
735 * @return a List of {@link TaxonDescription} entities which are initialized
736 * using the following initialization strategy:
737 * {@link #TAXONDESCRIPTION_INIT_STRATEGY}
738 * @throws IOException
741 value
= {"descriptions"},
742 method
= RequestMethod
.GET
)
743 public List
<TaxonDescription
> doGetDescriptions(
744 @PathVariable("uuid") UUID uuid
,
745 @RequestParam(value
= "markerTypes", required
= false) UuidList markerTypeUUIDs
,
746 HttpServletRequest request
,
747 HttpServletResponse response
)throws IOException
{
749 logger
.info("doGetDescriptions()" + request
.getServletPath());
751 List
<DefinedTermBase
> markerTypeTerms
= null;
752 Set
<UUID
> sMarkerTypeUUIDs
= null;
754 if(markerTypeUUIDs
!= null && !markerTypeUUIDs
.isEmpty()){
755 sMarkerTypeUUIDs
= new HashSet
<UUID
>(markerTypeUUIDs
);
756 markerTypeTerms
= termService
.find(sMarkerTypeUUIDs
);
757 } else if(markerTypeUUIDs
!= null && markerTypeUUIDs
.isEmpty()){
758 markerTypeTerms
= new ArrayList
<DefinedTermBase
>();
760 Set
<MarkerType
> markerTypes
= new HashSet
<MarkerType
>();
761 List
<TaxonDescription
> descriptions
= new ArrayList
<TaxonDescription
>();
762 if (markerTypeTerms
!= null) {
763 for (DefinedTermBase markerTypeTerm
: markerTypeTerms
) {
764 markerTypes
.add((MarkerType
)markerTypeTerm
);
767 Taxon t
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
768 if (markerTypeTerms
== null) {
770 Pager
<TaxonDescription
> p
= descriptionService
.getTaxonDescriptions(t
, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY
);
771 descriptions
= p
.getRecords();
774 else if (markerTypeTerms
!= null && markerTypeTerms
.isEmpty()) {
775 descriptions
= descriptionService
.listTaxonDescriptions(t
, null, null, markerTypes
, null, null, TAXONUSEDESCRIPTION_INIT_STRATEGY
);
779 descriptions
= descriptionService
.listTaxonDescriptions(t
, null, null, markerTypes
, null, null, TAXONUSEDESCRIPTION_INIT_STRATEGY
);
780 /*for (TaxonDescription description: descriptions) {
781 for (IdentifiableSource source :description.getSources()) {
782 if (source.getOriginalNameString() != null) {
794 @RequestMapping(value
= "useDescriptions", method
= RequestMethod
.GET
)
795 public List
<TaxonDescription
> doGetUseDescriptions(
796 @PathVariable("uuid") UUID uuid
,
797 HttpServletRequest request
,
798 HttpServletResponse response
) throws IOException
{
799 logger
.info("doGetDescriptionElements() - " + request
.getServletPath());
801 //ModelAndView mv = new ModelAndView();
802 Taxon t
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
804 //MarkerType useMarkerType = (MarkerType) markerTypeService.find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f059"));
805 MarkerType useMarkerType
= (MarkerType
) termService
.find(UUID
.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));
807 //find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f059"));
808 Set
<MarkerType
> markerTypes
= new HashSet
<MarkerType
>();
809 markerTypes
.add(useMarkerType
);
810 List
<TaxonDescription
> descriptionElements
= descriptionService
.listTaxonDescriptions(t
, null, null, markerTypes
, null, null, TAXONUSEDESCRIPTION_INIT_STRATEGY
);
811 //getDescriptionElements(description, features, type, pageSize, pageNumber, propertyPaths) load(uuid);
813 /*if(!(description instanceof TaxonDescription)){
814 HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
815 // will terminate thread
818 //boolean hasStructuredData = service. hasStructuredData(description);
820 //mv.addObject(hasStructuredData);
822 return descriptionElements
;
825 @RequestMapping(value
= "descriptions/elementsByType/{classSimpleName}", method
= RequestMethod
.GET
)
826 public ModelAndView
doGetDescriptionElementsByType(
827 @PathVariable("uuid") UUID uuid
,
828 @PathVariable("classSimpleName") String classSimpleName
,
829 @RequestParam(value
= "markerTypes", required
= false) UuidList markerTypeUUIDs
,
830 @RequestParam(value
= "count", required
= false, defaultValue
= "false") Boolean doCount
,
831 HttpServletRequest request
,
832 HttpServletResponse response
) throws IOException
{
833 logger
.info("doGetDescriptionElementsByType() - " + request
.getServletPath());
835 ModelAndView mv
= new ModelAndView();
837 List
<DescriptionElementBase
> allElements
= new ArrayList
<DescriptionElementBase
>();
838 List
<DescriptionElementBase
> elements
;
841 List
<String
> initStrategy
= doCount ?
null : DESCRIPTION_ELEMENT_INIT_STRATEGY
;
843 List
<TaxonDescription
> taxonDescriptions
= doGetDescriptions(uuid
, markerTypeUUIDs
, request
, response
);
846 type
= Class
.forName("eu.etaxonomy.cdm.model.description."
848 if (taxonDescriptions
!= null) {
849 for (TaxonDescription description
: taxonDescriptions
) {
850 elements
= descriptionService
.listDescriptionElements(description
, null, type
, null, 0, initStrategy
);
851 allElements
.addAll(elements
);
852 count
+= elements
.size();
856 } catch (ClassNotFoundException e
) {
857 HttpStatusMessage
.fromString(e
.getLocalizedMessage()).send(response
);
862 mv
.addObject(allElements
);
867 // @RequestMapping(value = "specimens", method = RequestMethod.GET)
868 // public ModelAndView doGetSpecimens(
869 // @PathVariable("uuid") UUID uuid,
870 // HttpServletRequest request,
871 // HttpServletResponse response) throws IOException, ClassNotFoundException {
872 // logger.info("doGetSpecimens() - " + request.getServletPath());
874 // ModelAndView mv = new ModelAndView();
876 // List<DerivedUnitFacade> derivedUnitFacadeList = new ArrayList<DerivedUnitFacade>();
878 // // find speciemens in the TaxonDescriptions
879 // List<TaxonDescription> taxonDescriptions = doGetDescriptions(uuid, request, response);
880 // if (taxonDescriptions != null) {
882 // for (TaxonDescription description : taxonDescriptions) {
883 // derivedUnitFacadeList.addAll( occurrenceService.listDerivedUnitFacades(description, null) );
886 // // TODO find speciemens in the NameDescriptions ??
888 // // TODO also find type specimens
890 // mv.addObject(derivedUnitFacadeList);
896 * Get the {@link Media} attached to the {@link Taxon} instance
897 * identified by the <code>{taxon-uuid}</code>.
899 * Usage /{datasource-name}/portal/taxon/{taxon-
900 * uuid}/media/{mime type
901 * list}/{size}[,[widthOrDuration}][,{height}]/
905 * <li><b>{mime type list}</b>: a comma separated list of mime types, in the
906 * order of preference. The forward slashes contained in the mime types must
907 * be replaced by a colon. Regular expressions can be used. Each media
908 * associated with this given taxon is being searched whereas the first
909 * matching mime type matching a representation always rules.</li>
910 * <li><b>{size},{widthOrDuration},{height}</b>: <i>not jet implemented</i>
911 * valid values are an integer or the asterisk '*' as a wildcard</li>
916 * @return a List of {@link Media} entities which are initialized
917 * using the following initialization strategy:
918 * {@link #TAXONDESCRIPTION_INIT_STRATEGY}
919 * @throws IOException
923 method
= RequestMethod
.GET
)
924 public List
<Media
> doGetMedia(
925 @PathVariable("uuid") UUID uuid
,
926 @RequestParam(value
= "type", required
= false) Class
<?
extends MediaRepresentationPart
> type
,
927 @RequestParam(value
= "mimeTypes", required
= false) String
[] mimeTypes
,
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
{
933 logger
.info("doGetMedia()" + request
.getServletPath());
934 Taxon t
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
935 String path
= request
.getServletPath();
936 List
<Media
> returnMedia
= getMediaForTaxon(t
, type
, mimeTypes
, widthOrDuration
, height
, size
);
941 value
= {"subtree/media"},
942 method
= RequestMethod
.GET
)
943 public List
<Media
> doGetSubtreeMedia(
944 @PathVariable("uuid") UUID uuid
,
945 @RequestParam(value
= "type", required
= false) Class
<?
extends MediaRepresentationPart
> type
,
946 @RequestParam(value
= "mimeTypes", required
= false) String
[] mimeTypes
,
947 @RequestParam(value
= "widthOrDuration", required
= false) Integer widthOrDuration
,
948 @RequestParam(value
= "height", required
= false) Integer height
,
949 @RequestParam(value
= "size", required
= false) Integer size
,
950 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
951 logger
.info("doGetMedia()" + request
.getServletPath());
952 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, TAXON_WITH_NODES_INIT_STRATEGY
);
953 String requestPath
= request
.getServletPath();
954 List
<Media
> returnMedia
= getMediaForTaxon(taxon
, type
, mimeTypes
, widthOrDuration
, height
, size
);
956 //looking for all medias of genus
957 if (taxon
.getTaxonNodes().size()>0){
958 Set
<TaxonNode
> nodes
= taxon
.getTaxonNodes();
959 Iterator
<TaxonNode
> iterator
= nodes
.iterator();
961 node
= iterator
.next();
962 //Check if TaxonNode belongs to the current tree
964 node
= classificationService
.loadTaxonNode(node
, TAXONNODE_WITHTAXON_INIT_STRATEGY
);
965 Set
<TaxonNode
> children
= node
.getChildNodes();
967 for (TaxonNode child
: children
){
968 childTaxon
= child
.getTaxon();
969 childTaxon
= (Taxon
)taxonService
.load(childTaxon
.getUuid(), null);
970 returnMedia
.addAll(getMediaForTaxon(childTaxon
, type
, mimeTypes
, widthOrDuration
, height
, size
));
977 private List
<Media
> getMediaForTaxon(Taxon taxon
, Class
<?
extends MediaRepresentationPart
> type
, String
[] mimeTypes
,
978 Integer widthOrDuration
, Integer height
, Integer size
){
980 List
<Media
> taxonGalleryMedia
= service
.listTaxonDescriptionMedia(taxon
, false, TAXONDESCRIPTION_MEDIA_INIT_STRATEGY
);
982 Map
<Media
, MediaRepresentation
> mediaRepresentationMap
= MediaUtils
.findPreferredMedia(taxonGalleryMedia
, type
,
983 mimeTypes
, null, widthOrDuration
, height
, size
);
985 List
<Media
> filteredMedia
= new ArrayList
<Media
>(mediaRepresentationMap
.size());
986 for(Media media
: mediaRepresentationMap
.keySet()){
987 media
.getRepresentations().clear();
988 media
.addRepresentation(mediaRepresentationMap
.get(media
));
989 filteredMedia
.add(media
);
992 return filteredMedia
;
996 // ---------------------- code snippet preserved for possible later use --------------------
998 // value = {"/*/portal/taxon/*/descriptions"},
999 // method = RequestMethod.GET)
1000 // public List<TaxonDescription> doGetDescriptionsbyFeatureTree(HttpServletRequest request, HttpServletResponse response)throws IOException {
1001 // TaxonBase tb = getCdmBase(request, response, null, Taxon.class);
1002 // if(tb instanceof Taxon){
1003 // //T O D O this is a quick and dirty implementation -> generalize
1004 // UUID featureTreeUuid = readValueUuid(request, featureTreeUuidPattern);
1006 // FeatureTree featureTree = descriptionService.getFeatureTreeByUuid(featureTreeUuid);
1007 // Pager<TaxonDescription> p = descriptionService.getTaxonDescriptions((Taxon)tb, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY);
1008 // List<TaxonDescription> descriptions = p.getRecords();
1010 // if(!featureTree.isDescriptionSeparated()){
1012 // TaxonDescription superDescription = TaxonDescription.NewInstance();
1013 // //put all descriptionElements in superDescription and make it invisible
1014 // for(TaxonDescription description: descriptions){
1015 // for(DescriptionElementBase element: description.getElements()){
1016 // superDescription.addElement(element);
1019 // List<TaxonDescription> separatedDescriptions = new ArrayList<TaxonDescription>(descriptions.size());
1020 // separatedDescriptions.add(superDescription);
1021 // return separatedDescriptions;
1023 // return descriptions;
1026 // response.sendError(HttpServletResponse.SC_NOT_FOUND, "invalid type; Taxon expected but " + tb.getClass().getSimpleName() + " found.");