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
.springframework
.beans
.factory
.annotation
.Autowired
;
33 import org
.springframework
.stereotype
.Controller
;
34 import org
.springframework
.web
.bind
.WebDataBinder
;
35 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
36 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
37 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
38 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
39 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
40 import org
.springframework
.web
.servlet
.ModelAndView
;
43 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
44 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
45 import eu
.etaxonomy
.cdm
.api
.service
.IMarkerService
;
46 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
47 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
48 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
49 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
50 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
51 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
52 import eu
.etaxonomy
.cdm
.api
.service
.config
.ITaxonServiceConfigurator
;
53 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonServiceConfiguratorImpl
;
54 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
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
.Marker
;
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
.TaxonDescription
;
63 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
64 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
65 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
66 import eu
.etaxonomy
.cdm
.model
.media
.MediaUtils
;
67 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
68 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
69 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
70 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
71 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
72 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
73 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
74 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
75 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
76 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
77 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.PagerParameters
;
78 import eu
.etaxonomy
.cdm
.remote
.editor
.CdmTypePropertyEditor
;
79 import eu
.etaxonomy
.cdm
.remote
.editor
.MatchModePropertyEditor
;
80 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaPropertyEditor
;
83 * The TaxonPortalController class is a Spring MVC Controller.
85 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
86 * The available {datasource-name}s are defined in a configuration file which
87 * is loaded by the {@link UpdatableRoutingDataSource}. If the
88 * UpdatableRoutingDataSource is not being used in the actual application
89 * context any arbitrary {datasource-name} may be used.
91 * Methods mapped at type level, inherited from super classes ({@link BaseController}):
93 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}</b>
95 * Get the {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
96 * The returned Taxon is initialized by
97 * the following strategy {@link #TAXON_INIT_STRATEGY}
100 * @author a.kohlbecker
105 @RequestMapping(value
= {"/portal/taxon/{uuid}"})
106 public class TaxonPortalController
extends BaseController
<TaxonBase
, ITaxonService
>
108 public static final Logger logger
= Logger
.getLogger(TaxonPortalController
.class);
111 private INameService nameService
;
114 private IDescriptionService descriptionService
;
117 private IOccurrenceService occurrenceService
;
120 private IClassificationService classificationService
;
123 private ITaxonService taxonService
;
126 private ITermService markerTypeService
;
129 private IMarkerService markerService
;
130 //private IService<MarkerType> markerTypeService;
133 private IFeatureTreeService featureTreeService
;
135 private static final List
<String
> TAXON_INIT_STRATEGY
= Arrays
.asList(new String
[]{
138 "relationsToThisName.fromTaxon.name",
141 "name.rank.representations",
142 "name.status.type.representations",
144 // taxon descriptions
145 "descriptions.elements.area.$",
146 "descriptions.elements.multilanguageText",
147 "descriptions.elements.media.representations.parts",
148 "descriptions.elements.media.title",
152 private static final List
<String
> TAXON_WITH_NODES_INIT_STRATEGY
= Arrays
.asList(new String
[]{
154 "taxonNodes.classification.$",
155 "taxonNodes.childNodes.$"
158 private static final List
<String
> SIMPLE_TAXON_INIT_STRATEGY
= Arrays
.asList(new String
[]{
161 "relationsToThisName.fromTaxon.name",
164 "name.rank.representations",
165 "name.status.type.representations",
166 "name.nomenclaturalReference"
169 private static final List
<String
> SYNONYMY_INIT_STRATEGY
= Arrays
.asList(new String
[]{
170 // initialize homotypical and heterotypical groups; needs synonyms
171 "synonymRelations.$",
172 "synonymRelations.synonym.$",
173 "synonymRelations.synonym.name.status.type.representation",
174 "synonymRelations.synonym.name.nomenclaturalReference.inReference",
175 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.$",
176 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.$",
177 "synonymRelations.synonym.name.combinationAuthorTeam.$",
179 "name.typeDesignations",
181 "name.homotypicalGroup.$",
182 "name.homotypicalGroup.typifiedNames.$",
183 "name.homotypicalGroup.typifiedNames.nomenclaturalReference.authorTeam",
185 "name.homotypicalGroup.typifiedNames.taxonBases.$"
188 private static final List
<String
> SYNONYMY_WITH_NODES_INIT_STRATEGY
= Arrays
.asList(new String
[]{
189 // initialize homotypical and heterotypical groups; needs synonyms
190 "synonymRelations.$",
191 "synonymRelations.synonym.$",
192 "synonymRelations.synonym.name.status.type.representation",
193 "synonymRelations.synonym.name.nomenclaturalReference.inReference",
194 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.$",
195 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.$",
196 "synonymRelations.synonym.name.combinationAuthorTeam.$",
198 "name.homotypicalGroup.$",
199 "name.homotypicalGroup.typifiedNames.$",
200 "name.homotypicalGroup.typifiedNames.nomenclaturalReference.authorTeam",
202 "name.homotypicalGroup.typifiedNames.taxonBases.$",
205 "taxonNodes.classification.$",
206 "taxonNodes.childNodes.$"
208 private static final List
<String
> SIMPLE_TAXON_WITH_NODES_INIT_STRATEGY
= Arrays
.asList(new String
[]{
211 "relationsToThisName.fromTaxon.name",
214 "name.rank.representations",
215 "name.status.type.representations",
216 "name.nomenclaturalReference",
219 "taxonNodes.classification.$",
220 "taxonNodes.childNodes.$"
224 private static final List
<String
> TAXONRELATIONSHIP_INIT_STRATEGY
= Arrays
.asList(new String
[]{
226 "type.inverseRepresentations",
233 private static final List
<String
> NAMERELATIONSHIP_INIT_STRATEGY
= Arrays
.asList(new String
[]{
235 "type.inverseRepresentations",
241 protected static final List
<String
> TAXONDESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
244 "elements.sources.citation.authorTeam",
245 "elements.sources.nameUsedInSource.originalNameString",
246 "elements.multilanguageText",
247 "elements.media.representations.parts",
248 "elements.media.title",
251 protected static final List
<String
> TAXONUSEDESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
256 "elements.sources.citation.authorTeam",
257 "elements.sources.nameUsedInSource.originalNameString",
258 /*//"elements.multilanguageText",
259 "elements.media.representations.parts",
260 "elements.media.title",*/
263 protected static final List
<String
> DESCRIPTION_ELEMENT_INIT_STRATEGY
= Arrays
.asList(new String
[]{
265 "sources.citation.authorTeam",
266 "sources.nameUsedInSource.originalNameString",
268 "media.representations.parts",
273 // private static final List<String> NAMEDESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
277 // "elements.multilanguageText",
278 // "elements.media.representations.parts",
279 // "elements.media.title",
282 protected static final List
<String
> TAXONDESCRIPTION_MEDIA_INIT_STRATEGY
= Arrays
.asList(new String
[]{
283 "elements.media.representations.parts",
284 "elements.media.title"
288 private static final List
<String
> TYPEDESIGNATION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
291 "citation.authorTeam.$",
295 protected static final List
<String
> TAXONNODE_WITHTAXON_INIT_STRATEGY
= Arrays
.asList(new String
[]{
299 protected static final List
<String
> TAXONNODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
300 "taxonNodes.classification"
305 private static final String featureTreeUuidPattern
= "^/taxon(?:(?:/)([^/?#&\\.]+))+.*";
307 public TaxonPortalController(){
309 setInitializationStrategy(TAXON_INIT_STRATEGY
);
313 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
317 public void setService(ITaxonService service
) {
318 this.service
= service
;
323 public void initBinder(WebDataBinder binder
) {
324 super.initBinder(binder
);
325 binder
.registerCustomEditor(NamedArea
.class, new NamedAreaPropertyEditor());
326 binder
.registerCustomEditor(MatchMode
.class, new MatchModePropertyEditor());
327 binder
.registerCustomEditor(Class
.class, new CdmTypePropertyEditor());
332 * @see eu.etaxonomy.cdm.remote.controller.BaseController#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
335 @RequestMapping(method = RequestMethod.GET)
336 public TaxonBase doGet(HttpServletRequest request, HttpServletResponse response)throws IOException {
337 logger.info("doGet()");
338 TaxonBase tb = getCdmBase(request, response, TAXON_INIT_STRATEGY, TaxonBase.class);
343 * Find Taxa, Synonyms, Common Names by name, either globally or in a specific geographic area.
345 * URI: <b>/{datasource-name}/portal/taxon/find</b>
348 * the string to query for. Since the wildcard character '*'
349 * internally always is appended to the query string, a search
350 * always compares the query string with the beginning of a name.
351 * - <i>required parameter</i>
353 * the {@link UUID} of a {@link Classification} to which the
354 * search is to be restricted. - <i>optional parameter</i>
356 * restrict the search to a set of geographic {@link NamedArea}s.
357 * The parameter currently takes a list of TDWG area labels.
358 * - <i>optional parameter</i>
360 * the number of the page to be returned, the first page has the
361 * pageNumber = 1 - <i>optional parameter</i>
363 * the maximum number of entities returned per page (can be -1
364 * to return all entities in a single page) - <i>optional parameter</i>
366 * weather to search for instances of {@link Taxon} - <i>optional parameter</i>
368 * weather to search for instances of {@link Synonym} - <i>optional parameter</i>
369 * @param doTaxaByCommonNames
370 * for instances of {@link Taxon} by a common name used - <i>optional parameter</i>
372 * valid values are "EXACT", "BEGINNING", "ANYWHERE", "END" (case sensitive !!!)
373 * @return a Pager on a list of {@link IdentifiableEntity}s initialized by
374 * the following strategy {@link #SIMPLE_TAXON_INIT_STRATEGY}
375 * @throws IOException
377 @RequestMapping(method
= RequestMethod
.GET
,
378 value
= {"/portal/taxon/find"}) //TODO map to path /*/portal/taxon/
379 public Pager
<IdentifiableEntity
> doFind(
380 @RequestParam(value
= "query", required
= false) String query
,
381 @RequestParam(value
= "tree", required
= false) UUID treeUuid
,
382 @RequestParam(value
= "area", required
= false) Set
<NamedArea
> areas
,
383 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
384 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
385 @RequestParam(value
= "doTaxa", required
= false) Boolean doTaxa
,
386 @RequestParam(value
= "doSynonyms", required
= false) Boolean doSynonyms
,
387 @RequestParam(value
= "doMisappliedNames", required
= false) Boolean doMisappliedNames
,
388 @RequestParam(value
= "doTaxaByCommonNames", required
= false) Boolean doTaxaByCommonNames
,
389 @RequestParam(value
= "matchMode", required
= false) MatchMode matchMode
,
390 HttpServletRequest request
,
391 HttpServletResponse response
395 logger
.info("doFind : " + request
.getRequestURI() + "?" + request
.getQueryString() );
397 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
398 pagerParams
.normalizeAndValidate(response
);
400 ITaxonServiceConfigurator config
= new TaxonServiceConfiguratorImpl();
401 config
.setPageNumber(pagerParams
.getPageIndex());
402 config
.setPageSize(pagerParams
.getPageSize());
403 config
.setTitleSearchString(query
);
404 config
.setDoTaxa(doTaxa
!= null ? doTaxa
: Boolean
.FALSE
);
405 config
.setDoSynonyms(doSynonyms
!= null ? doSynonyms
: Boolean
.FALSE
);
406 config
.setDoMisappliedNames(doMisappliedNames
!= null ? doMisappliedNames
: Boolean
.FALSE
);
407 config
.setDoTaxaByCommonNames(doTaxaByCommonNames
!= null ? doTaxaByCommonNames
: Boolean
.FALSE
);
408 config
.setMatchMode(matchMode
!= null ? matchMode
: MatchMode
.BEGINNING
);
409 config
.setTaxonPropertyPath(SIMPLE_TAXON_INIT_STRATEGY
);
410 config
.setNamedAreas(areas
);
411 if(treeUuid
!= null){
412 Classification classification
= classificationService
.find(treeUuid
);
413 config
.setClassification(classification
);
416 return (Pager
<IdentifiableEntity
>) service
.findTaxaAndNames(config
);
420 * Get the synonymy for a taxon identified by the <code>{taxon-uuid}</code>.
421 * The synonymy consists
422 * of two parts: The group of homotypic synonyms of the taxon and the
423 * heterotypic synonymy groups of the taxon. The synonymy is ordered
424 * historically by the type designations and by the publication date of the
425 * nomenclatural reference
428 * <b>/{datasource-name}/portal/taxon/{taxon-uuid}/synonymy</b>
433 * @return a Map with to entries which are mapped by the following keys:
434 * "homotypicSynonymsByHomotypicGroup", "heterotypicSynonymyGroups",
435 * containing lists of {@link Synonym}s which are initialized using the
436 * following initialization strategy: {@link #SYNONYMY_INIT_STRATEGY}
438 * @throws IOException
441 value
= {"synonymy"},
442 method
= RequestMethod
.GET
)
443 public ModelAndView
doGetSynonymy(@PathVariable("uuid") UUID uuid
,
444 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
447 logger
.info("doGetSynonymy() " + request
.getServletPath());
449 ModelAndView mv
= new ModelAndView();
450 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
451 Map
<String
, List
<?
>> synonymy
= new Hashtable
<String
, List
<?
>>();
452 synonymy
.put("homotypicSynonymsByHomotypicGroup", service
.getHomotypicSynonymsByHomotypicGroup(taxon
, SYNONYMY_INIT_STRATEGY
));
453 synonymy
.put("heterotypicSynonymyGroups", service
.getHeterotypicSynonymyGroups(taxon
, SYNONYMY_INIT_STRATEGY
));
454 mv
.addObject(synonymy
);
459 * Get the set of accepted {@link Taxon} entities for a given
460 * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
462 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/accepted</b>
466 * @return a Set of {@link Taxon} entities which are initialized
467 * using the following initialization strategy:
468 * {@link #SYNONYMY_INIT_STRATEGY}
469 * @throws IOException
471 @RequestMapping(value
= "accepted/{classification_uuid}", method
= RequestMethod
.GET
)
472 public Set
<TaxonBase
> getAccepted(
473 @PathVariable("uuid") UUID uuid
,
474 @PathVariable("classification_uuid") UUID classification_uuid
,
475 HttpServletRequest request
,
476 HttpServletResponse response
)
480 logger
.info("getAccepted() " + request
.getServletPath());
483 TaxonBase tb
= service
.load(uuid
, SYNONYMY_WITH_NODES_INIT_STRATEGY
);
485 response
.sendError(HttpServletResponse
.SC_NOT_FOUND
, "A taxon with the uuid " + uuid
+ " does not exist");
489 HashSet
<TaxonBase
> resultset
= new HashSet
<TaxonBase
>();
491 if (tb
instanceof Taxon
){
492 Taxon taxon
= (Taxon
) tb
;
493 Set
<TaxonNode
> nodes
= taxon
.getTaxonNodes();
494 for (TaxonNode taxonNode
: nodes
) {
495 if (taxonNode
.getClassification().compareTo(classification_uuid
) == 0){
496 resultset
.add((Taxon
) tb
);
499 if (resultset
.size() > 1){
500 //error!! A taxon is not allow to have more taxonnodes for a given classification
501 response
.sendError(HttpServletResponse
.SC_INTERNAL_SERVER_ERROR
,
502 "A taxon with the uuid " + uuid
+ " has more than one taxon node for the given classification" + classification_uuid
);
505 Synonym syn
= (Synonym
) tb
;
506 for(TaxonBase accepted
: syn
.getAcceptedTaxa()){
507 tb
= service
.load(accepted
.getUuid(), SIMPLE_TAXON_WITH_NODES_INIT_STRATEGY
);
508 if (tb
instanceof Taxon
){
509 Taxon taxon
= (Taxon
) tb
;
510 Set
<TaxonNode
> nodes
= taxon
.getTaxonNodes();
511 for (TaxonNode taxonNode
: nodes
) {
512 if (taxonNode
.getClassification().compareTo(classification_uuid
) == 0){
513 resultset
.add((Taxon
) tb
);
516 if (resultset
.size() > 1){
517 //error!! A taxon is not allow to have more taxonnodes for a given classification
518 response
.sendError(HttpServletResponse
.SC_INTERNAL_SERVER_ERROR
,
519 "A taxon with the uuid " + uuid
+ " has more than one taxon node for the given classification" + classification_uuid
);
522 //ERROR!! perhaps missapplied name????
523 //syn.getRelationType((Taxon)accepted);
529 if(tb instanceof Taxon){
530 //the taxon already is accepted
531 //FIXME take the current view into account once views are implemented!!!
532 resultset.add((Taxon)tb);
534 Synonym syn = (Synonym)tb;
535 for(TaxonBase accepted : syn.getAcceptedTaxa()){
536 accepted = service.load(accepted.getUuid(), SIMPLE_TAXON_INIT_STRATEGY);
537 resultset.add(accepted);
545 * Get the list of {@link TaxonRelationship}s for the given
546 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
548 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/taxonRelationships</b>
552 * @return a List of {@link TaxonRelationship} entities which are initialized
553 * using the following initialization strategy:
554 * {@link #TAXONRELATIONSHIP_INIT_STRATEGY}
555 * @throws IOException
558 value
= {"taxonRelationships"},
559 method
= RequestMethod
.GET
)
560 public List
<TaxonRelationship
> doGetTaxonRelations(@PathVariable("uuid") UUID uuid
,
561 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
563 logger
.info("doGetTaxonRelations()" + request
.getServletPath());
564 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
565 List
<TaxonRelationship
> toRelationships
= service
.listToTaxonRelationships(taxon
, null, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY
);
566 List
<TaxonRelationship
> fromRelationships
= service
.listFromTaxonRelationships(taxon
, null, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY
);
568 List
<TaxonRelationship
> allRelationships
= new ArrayList
<TaxonRelationship
>(toRelationships
.size() + fromRelationships
.size());
569 allRelationships
.addAll(toRelationships
);
570 allRelationships
.addAll(fromRelationships
);
572 return allRelationships
;
576 * Get the list of {@link NameRelationship}s of the Name associated with the
577 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
579 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameRelationships</b>
583 * @return a List of {@link NameRelationship} entities which are initialized
584 * using the following initialization strategy:
585 * {@link #NAMERELATIONSHIP_INIT_STRATEGY}
586 * @throws IOException
589 value
= {"toNameRelationships"},
590 method
= RequestMethod
.GET
)
591 public List
<NameRelationship
> doGetToNameRelations(@PathVariable("uuid") UUID uuid
,
592 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
593 logger
.info("doGetNameRelations()" + request
.getServletPath());
594 TaxonBase taxonBase
= getCdmBaseInstance(TaxonBase
.class, uuid
, response
, (List
<String
>)null);
595 List
<NameRelationship
> list
= nameService
.listNameRelationships(taxonBase
.getName(), Direction
.relatedTo
, null, null, 0, null, NAMERELATIONSHIP_INIT_STRATEGY
);
596 //List<NameRelationship> list = nameService.listToNameRelationships(taxonBase.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY);
601 * Get the list of {@link NameRelationship}s of the Name associated with the
602 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
604 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameRelationships</b>
608 * @return a List of {@link NameRelationship} entities which are initialized
609 * using the following initialization strategy:
610 * {@link #NAMERELATIONSHIP_INIT_STRATEGY}
611 * @throws IOException
614 value
= {"fromNameRelationships"},
615 method
= RequestMethod
.GET
)
616 public List
<NameRelationship
> doGetFromNameRelations(@PathVariable("uuid") UUID uuid
,
617 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
618 logger
.info("doGetNameFromNameRelations()" + request
.getServletPath());
620 TaxonBase taxonbase
= getCdmBaseInstance(TaxonBase
.class, uuid
, response
, SIMPLE_TAXON_INIT_STRATEGY
);
621 List
<NameRelationship
> list
= nameService
.listNameRelationships(taxonbase
.getName(), Direction
.relatedFrom
, null, null, 0, null, NAMERELATIONSHIP_INIT_STRATEGY
);
622 //List<NameRelationship> list = nameService.listFromNameRelationships(taxonbase.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY);
627 * Get the list of {@link TypeDesignationBase}s of the
628 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
630 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameTypeDesignations</b>
634 * @return a List of {@link TypeDesignationBase} entities which are initialized
635 * using the following initialization strategy:
636 * {@link #TYPEDESIGNATION_INIT_STRATEGY}
637 * @throws IOException
638 * @Deprecated use /name/{uuid}/typeDesignations & /derivedunitfacade/{uuid} instead
639 * also see http://dev.e-taxonomy.eu/trac/ticket/2280
643 value
= {"nameTypeDesignations"},
644 method
= RequestMethod
.GET
)
645 public List
<TypeDesignationBase
> doGetNameTypeDesignations(@PathVariable("uuid") UUID uuid
,
646 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
647 logger
.info("doGetNameTypeDesignations()" + request
.getServletPath());
648 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, SIMPLE_TAXON_INIT_STRATEGY
);
649 Pager
<TypeDesignationBase
> p
= nameService
.getTypeDesignations(taxon
.getName(), null, null, null, TYPEDESIGNATION_INIT_STRATEGY
);
650 return p
.getRecords();
653 @RequestMapping(value
= "taxonNodes", method
= RequestMethod
.GET
)
654 public Set
<TaxonNode
> doGetTaxonNodes(
655 @PathVariable("uuid") UUID uuid
,
656 HttpServletRequest request
,
657 HttpServletResponse response
) throws IOException
{
658 TaxonBase tb
= service
.load(uuid
, TAXONNODE_INIT_STRATEGY
);
659 if(tb
instanceof Taxon
){
660 return ((Taxon
)tb
).getTaxonNodes();
662 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
668 * Get the list of {@link TaxonDescription}s of the
669 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code>.
671 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/descriptions</b>
675 * @return a List of {@link TaxonDescription} entities which are initialized
676 * using the following initialization strategy:
677 * {@link #TAXONDESCRIPTION_INIT_STRATEGY}
678 * @throws IOException
681 value
= {"descriptions"},
682 method
= RequestMethod
.GET
)
683 public List
<TaxonDescription
> doGetDescriptions(
684 @PathVariable("uuid") UUID uuid
,
685 HttpServletRequest request
,
686 HttpServletResponse response
)throws IOException
{
688 logger
.info("doGetDescriptions()" + request
.getServletPath());
690 Set
<MarkerType
> markerTypes
= new HashSet
<MarkerType
>(markerTypeService
.listByTermClass(MarkerType
.class, null, null, null, null));
691 //MarkerType useMarkerType = (MarkerType) markerTypeService.find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f059"));
692 MarkerType useMarkerType
= (MarkerType
) markerTypeService
.find(UUID
.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));
694 markerTypes
.remove(useMarkerType
);
695 Taxon t
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
696 //List<TaxonDescription> descriptions = descriptionService.listTaxonDescriptions(t, null, null, markerTypes, null, null, TAXONUSEDESCRIPTION_INIT_STRATEGY);
697 Pager
<TaxonDescription
> p
= descriptionService
.getTaxonDescriptions(t
, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY
);
698 List
<TaxonDescription
> descriptions
= p
.getRecords();
699 Iterator
<TaxonDescription
> itr
= descriptions
.iterator();
700 //for(TaxonDescription taxonDesc: descriptions) {
701 while (itr
.hasNext()) {
702 TaxonDescription taxonDesc
= (TaxonDescription
) itr
.next();
703 Pager
<Marker
> pMarkers
= descriptionService
.getMarkers(taxonDesc
, null, null, null, null, null);
704 Pager
<Marker
> useMarkers
= markerService
.page(useMarkerType
, null, null, null, null);
705 List
<DefinedTermBase
> useMarkers2
= markerTypeService
.list(MarkerType
.class, null, null, null, null);
706 if(pMarkers
.getCount() != 0) {
707 List
<Marker
> testMarkers
= pMarkers
.getRecords();
708 List
<Marker
> testUseMarkers
= useMarkers
.getRecords();
709 for (Marker marker
: testMarkers
) {
710 for (Marker useMaker
: testUseMarkers
){
711 if(marker
.equals(useMaker
)) {
718 return p
.getRecords();
721 @RequestMapping(value
= "useDescriptions", method
= RequestMethod
.GET
)
722 public List
<TaxonDescription
> doGetUseDescriptions(
723 @PathVariable("uuid") UUID uuid
,
724 HttpServletRequest request
,
725 HttpServletResponse response
) throws IOException
{
726 logger
.info("doGetDescriptionElements() - " + request
.getServletPath());
728 //ModelAndView mv = new ModelAndView();
729 Taxon t
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
731 //MarkerType useMarkerType = (MarkerType) markerTypeService.find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f059"));
732 MarkerType useMarkerType
= (MarkerType
) markerTypeService
.find(UUID
.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));
734 //find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f059"));
735 Set
<MarkerType
> markerTypes
= new HashSet
<MarkerType
>();
736 markerTypes
.add(useMarkerType
);
737 List
<TaxonDescription
> descriptionElements
= descriptionService
.listTaxonDescriptions(t
, null, null, markerTypes
, null, null, TAXONUSEDESCRIPTION_INIT_STRATEGY
);
738 //getDescriptionElements(description, features, type, pageSize, pageNumber, propertyPaths) load(uuid);
740 /*if(!(description instanceof TaxonDescription)){
741 HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
742 // will terminate thread
745 //boolean hasStructuredData = service. hasStructuredData(description);
747 //mv.addObject(hasStructuredData);
749 return descriptionElements
;
752 @RequestMapping(value
= "descriptions/elementsByType/{classSimpleName}", method
= RequestMethod
.GET
)
753 public ModelAndView
doGetDescriptionElementsByType(
754 @PathVariable("uuid") UUID uuid
,
755 @PathVariable("classSimpleName") String classSimpleName
,
756 @RequestParam(value
= "count", required
= false, defaultValue
= "false") Boolean doCount
,
757 HttpServletRequest request
,
758 HttpServletResponse response
) throws IOException
{
759 logger
.info("doGetDescriptionElementsByType() - " + request
.getServletPath());
761 ModelAndView mv
= new ModelAndView();
763 List
<DescriptionElementBase
> allElements
= new ArrayList
<DescriptionElementBase
>();
764 List
<DescriptionElementBase
> elements
;
767 List
<String
> initStrategy
= doCount ?
null : DESCRIPTION_ELEMENT_INIT_STRATEGY
;
769 List
<TaxonDescription
> taxonDescriptions
= doGetDescriptions(uuid
, request
, response
);
772 type
= Class
.forName("eu.etaxonomy.cdm.model.description."
774 if (taxonDescriptions
!= null) {
775 for (TaxonDescription description
: taxonDescriptions
) {
776 elements
= descriptionService
.listDescriptionElements(description
, null, type
, null, 0, initStrategy
);
777 allElements
.addAll(elements
);
778 count
+= elements
.size();
782 } catch (ClassNotFoundException e
) {
783 HttpStatusMessage
.fromString(e
.getLocalizedMessage()).send(response
);
788 mv
.addObject(allElements
);
793 // @RequestMapping(value = "specimens", method = RequestMethod.GET)
794 // public ModelAndView doGetSpecimens(
795 // @PathVariable("uuid") UUID uuid,
796 // HttpServletRequest request,
797 // HttpServletResponse response) throws IOException, ClassNotFoundException {
798 // logger.info("doGetSpecimens() - " + request.getServletPath());
800 // ModelAndView mv = new ModelAndView();
802 // List<DerivedUnitFacade> derivedUnitFacadeList = new ArrayList<DerivedUnitFacade>();
804 // // find speciemens in the TaxonDescriptions
805 // List<TaxonDescription> taxonDescriptions = doGetDescriptions(uuid, request, response);
806 // if (taxonDescriptions != null) {
808 // for (TaxonDescription description : taxonDescriptions) {
809 // derivedUnitFacadeList.addAll( occurrenceService.listDerivedUnitFacades(description, null) );
812 // // TODO find speciemens in the NameDescriptions ??
814 // // TODO also find type specimens
816 // mv.addObject(derivedUnitFacadeList);
822 * Get the {@link Media} attached to the {@link Taxon} instance
823 * identified by the <code>{taxon-uuid}</code>.
825 * Usage /{datasource-name}/portal/taxon/{taxon-
826 * uuid}/media/{mime type
827 * list}/{size}[,[widthOrDuration}][,{height}]/
831 * <li><b>{mime type list}</b>: a comma separated list of mime types, in the
832 * order of preference. The forward slashes contained in the mime types must
833 * be replaced by a colon. Regular expressions can be used. Each media
834 * associated with this given taxon is being searched whereas the first
835 * matching mime type matching a representation always rules.</li>
836 * <li><b>{size},{widthOrDuration},{height}</b>: <i>not jet implemented</i>
837 * valid values are an integer or the asterisk '*' as a wildcard</li>
842 * @return a List of {@link Media} entities which are initialized
843 * using the following initialization strategy:
844 * {@link #TAXONDESCRIPTION_INIT_STRATEGY}
845 * @throws IOException
849 method
= RequestMethod
.GET
)
850 public List
<Media
> doGetMedia(
851 @PathVariable("uuid") UUID uuid
,
852 @RequestParam(value
= "type", required
= false) Class
<?
extends MediaRepresentationPart
> type
,
853 @RequestParam(value
= "mimeTypes", required
= false) String
[] mimeTypes
,
854 @RequestParam(value
= "widthOrDuration", required
= false) Integer widthOrDuration
,
855 @RequestParam(value
= "height", required
= false) Integer height
,
856 @RequestParam(value
= "size", required
= false) Integer size
,
857 HttpServletRequest request
, HttpServletResponse response
) throws IOException
{
859 logger
.info("doGetMedia()" + request
.getServletPath());
860 Taxon t
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
861 String path
= request
.getServletPath();
862 List
<Media
> returnMedia
= getMediaForTaxon(t
, type
, mimeTypes
, widthOrDuration
, height
, size
);
867 value
= {"subtree/media"},
868 method
= RequestMethod
.GET
)
869 public List
<Media
> doGetSubtreeMedia(
870 @PathVariable("uuid") UUID uuid
,
871 @RequestParam(value
= "type", required
= false) Class
<?
extends MediaRepresentationPart
> type
,
872 @RequestParam(value
= "mimeTypes", required
= false) String
[] mimeTypes
,
873 @RequestParam(value
= "widthOrDuration", required
= false) Integer widthOrDuration
,
874 @RequestParam(value
= "height", required
= false) Integer height
,
875 @RequestParam(value
= "size", required
= false) Integer size
,
876 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
877 logger
.info("doGetMedia()" + request
.getServletPath());
878 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, TAXON_WITH_NODES_INIT_STRATEGY
);
879 String requestPath
= request
.getServletPath();
880 List
<Media
> returnMedia
= getMediaForTaxon(taxon
, type
, mimeTypes
, widthOrDuration
, height
, size
);
882 //looking for all medias of genus
883 if (taxon
.getTaxonNodes().size()>0){
884 Set
<TaxonNode
> nodes
= taxon
.getTaxonNodes();
885 Iterator
<TaxonNode
> iterator
= nodes
.iterator();
887 node
= iterator
.next();
888 //Check if TaxonNode belongs to the current tree
890 node
= classificationService
.loadTaxonNode(node
, TAXONNODE_WITHTAXON_INIT_STRATEGY
);
891 Set
<TaxonNode
> children
= node
.getChildNodes();
893 for (TaxonNode child
: children
){
894 childTaxon
= child
.getTaxon();
895 childTaxon
= (Taxon
)taxonService
.load(childTaxon
.getUuid(), null);
896 returnMedia
.addAll(getMediaForTaxon(childTaxon
, type
, mimeTypes
, widthOrDuration
, height
, size
));
903 private List
<Media
> getMediaForTaxon(Taxon taxon
, Class
<?
extends MediaRepresentationPart
> type
, String
[] mimeTypes
,
904 Integer widthOrDuration
, Integer height
, Integer size
){
906 Pager
<TaxonDescription
> p
=
907 descriptionService
.getTaxonDescriptions(taxon
, null, null, null, null, TAXONDESCRIPTION_MEDIA_INIT_STRATEGY
);
909 // pars the media and quality parameters
912 // collect all media of the given taxon
913 boolean limitToGalleries
= false;
914 List
<Media
> taxonMedia
= new ArrayList
<Media
>();
915 List
<Media
> taxonGalleryMedia
= new ArrayList
<Media
>();
916 for(TaxonDescription desc
: p
.getRecords()){
918 if(desc
.isImageGallery()){
919 for(DescriptionElementBase element
: desc
.getElements()){
920 for(Media media
: element
.getMedia()){
921 taxonGalleryMedia
.add(media
);
924 } else if(!limitToGalleries
){
925 for(DescriptionElementBase element
: desc
.getElements()){
926 for(Media media
: element
.getMedia()){
927 taxonMedia
.add(media
);
934 taxonGalleryMedia
.addAll(taxonMedia
);
936 List
<Media
> returnMedia
= MediaUtils
.findPreferredMedia(taxonGalleryMedia
, type
,
937 mimeTypes
, null, widthOrDuration
, height
, size
);
943 // ---------------------- code snippet preserved for possible later use --------------------
945 // value = {"/*/portal/taxon/*/descriptions"},
946 // method = RequestMethod.GET)
947 // public List<TaxonDescription> doGetDescriptionsbyFeatureTree(HttpServletRequest request, HttpServletResponse response)throws IOException {
948 // TaxonBase tb = getCdmBase(request, response, null, Taxon.class);
949 // if(tb instanceof Taxon){
950 // //T O D O this is a quick and dirty implementation -> generalize
951 // UUID featureTreeUuid = readValueUuid(request, featureTreeUuidPattern);
953 // FeatureTree featureTree = descriptionService.getFeatureTreeByUuid(featureTreeUuid);
954 // Pager<TaxonDescription> p = descriptionService.getTaxonDescriptions((Taxon)tb, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY);
955 // List<TaxonDescription> descriptions = p.getRecords();
957 // if(!featureTree.isDescriptionSeparated()){
959 // TaxonDescription superDescription = TaxonDescription.NewInstance();
960 // //put all descriptionElements in superDescription and make it invisible
961 // for(TaxonDescription description: descriptions){
962 // for(DescriptionElementBase element: description.getElements()){
963 // superDescription.addElement(element);
966 // List<TaxonDescription> separatedDescriptions = new ArrayList<TaxonDescription>(descriptions.size());
967 // separatedDescriptions.add(superDescription);
968 // return separatedDescriptions;
970 // return descriptions;
973 // response.sendError(HttpServletResponse.SC_NOT_FOUND, "invalid type; Taxon expected but " + tb.getClass().getSimpleName() + " found.");