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 java
.io
.IOException
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Arrays
;
16 import java
.util
.HashSet
;
17 import java
.util
.Hashtable
;
18 import java
.util
.Iterator
;
19 import java
.util
.List
;
22 import java
.util
.UUID
;
24 import javax
.servlet
.http
.HttpServletRequest
;
25 import javax
.servlet
.http
.HttpServletResponse
;
27 import org
.apache
.commons
.lang
.ObjectUtils
;
28 import org
.apache
.log4j
.Logger
;
29 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
30 import org
.springframework
.stereotype
.Controller
;
31 import org
.springframework
.web
.bind
.WebDataBinder
;
32 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
33 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
34 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
35 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
36 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
37 import org
.springframework
.web
.servlet
.ModelAndView
;
39 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
40 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
41 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
42 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
43 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonTreeService
;
44 import eu
.etaxonomy
.cdm
.api
.service
.config
.ITaxonServiceConfigurator
;
45 import eu
.etaxonomy
.cdm
.api
.service
.config
.impl
.TaxonServiceConfiguratorImpl
;
46 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
47 import eu
.etaxonomy
.cdm
.database
.UpdatableRoutingDataSource
;
48 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
49 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
50 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
51 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
52 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
53 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
54 import eu
.etaxonomy
.cdm
.model
.media
.MediaUtils
;
55 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
56 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
57 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
58 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
59 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
60 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
61 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
62 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
63 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
64 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonomicTree
;
65 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
66 import eu
.etaxonomy
.cdm
.remote
.editor
.MatchModePropertyEditor
;
67 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaPropertyEditor
;
68 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDPropertyEditor
;
71 * The TaxonPortalController class is a Spring MVC Controller.
73 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
74 * The available {datasource-name}s are defined in a configuration file which
75 * is loaded by the {@link UpdatableRoutingDataSource}. If the
76 * UpdatableRoutingDataSource is not being used in the actual application
77 * context any arbitrary {datasource-name} may be used.
79 * Methods mapped at type level, inherited from super classes ({@link BaseController}):
81 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}</b>
83 * Get the {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
84 * The returned Taxon is initialized by
85 * the following strategy {@link #TAXON_INIT_STRATEGY}
88 * @author a.kohlbecker
93 @RequestMapping(value
= {"/portal/taxon/{uuid}"})
94 public class TaxonPortalController
extends BaseController
<TaxonBase
, ITaxonService
>
96 public static final Logger logger
= Logger
.getLogger(TaxonPortalController
.class);
99 private INameService nameService
;
102 private IDescriptionService descriptionService
;
105 private ITaxonTreeService taxonTreeService
;
108 private ITaxonService taxonService
;
110 private static final List
<String
> TAXON_INIT_STRATEGY
= Arrays
.asList(new String
[]{
113 "relationsToThisName.fromTaxon.name",
116 "name.rank.representations",
117 "name.status.type.representations",
119 // taxon descriptions
120 "descriptions.elements.area.$",
121 "descriptions.elements.multilanguageText",
122 "descriptions.elements.media.representations.parts",
123 "descriptions.elements.media.title",
127 private static final List
<String
> TAXON_WITH_NODES_INIT_STRATEGY
= Arrays
.asList(new String
[]{
129 "taxonNodes.taxonomicTree.$",
130 "taxonNodes.childNodes.$"
133 private static final List
<String
> SIMPLE_TAXON_INIT_STRATEGY
= Arrays
.asList(new String
[]{
136 "relationsToThisName.fromTaxon.name",
139 "name.rank.representations",
140 "name.status.type.representations",
141 "name.nomenclaturalReference"
144 private static final List
<String
> SYNONYMY_INIT_STRATEGY
= Arrays
.asList(new String
[]{
145 // initialize homotypical and heterotypical groups; needs synonyms
146 "synonymRelations.$",
147 "synonymRelations.synonym.$",
148 "synonymRelations.synonym.name.status.type.representation",
149 "synonymRelations.synonym.name.nomenclaturalReference.inReference",
150 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.$",
151 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.$",
152 "synonymRelations.synonym.name.combinationAuthorTeam.$",
154 "name.homotypicalGroup.$",
155 "name.homotypicalGroup.typifiedNames.$",
157 "name.homotypicalGroup.typifiedNames.taxonBases.$"
160 private static final List
<String
> TAXONRELATIONSHIP_INIT_STRATEGY
= Arrays
.asList(new String
[]{
162 "type.inverseRepresentations",
167 private static final List
<String
> NAMERELATIONSHIP_INIT_STRATEGY
= Arrays
.asList(new String
[]{
169 "type.inverseRepresentations",
175 protected static final List
<String
> TAXONDESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
178 "elements.sources.citation.",
179 "elements.sources.nameUsedInSource.originalNameString",
180 "elements.multilanguageText",
181 "elements.media.representations.parts",
182 "elements.media.title",
186 private static final List
<String
> NAMEDESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
190 "elements.multilanguageText",
191 "elements.media.representations.parts",
192 "elements.media.title",
195 protected static final List
<String
> TAXONDESCRIPTION_MEDIA_INIT_STRATEGY
= Arrays
.asList(new String
[]{
196 "elements.media.representations.parts",
197 "elements.media.title"
201 private static final List
<String
> TYPEDESIGNATION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
208 protected static final List
<String
> TAXONNODE_WITHTAXON_INIT_STRATEGY
= Arrays
.asList(new String
[]{
212 protected static final List
<String
> TAXONNODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
213 "taxonNodes.taxonomicTree"
218 private static final String featureTreeUuidPattern
= "^/taxon(?:(?:/)([^/?#&\\.]+))+.*";
220 public TaxonPortalController(){
222 setInitializationStrategy(TAXON_INIT_STRATEGY
);
226 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
230 public void setService(ITaxonService service
) {
231 this.service
= service
;
235 public void initBinder(WebDataBinder binder
) {
236 binder
.registerCustomEditor(UUID
.class, new UUIDPropertyEditor());
237 binder
.registerCustomEditor(NamedArea
.class, new NamedAreaPropertyEditor());
238 binder
.registerCustomEditor(MatchMode
.class, new MatchModePropertyEditor());
243 * @see eu.etaxonomy.cdm.remote.controller.BaseController#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
246 @RequestMapping(method = RequestMethod.GET)
247 public TaxonBase doGet(HttpServletRequest request, HttpServletResponse response)throws IOException {
248 logger.info("doGet()");
249 TaxonBase tb = getCdmBase(request, response, TAXON_INIT_STRATEGY, TaxonBase.class);
254 * Find Taxa, Synonyms, Common Names by name, either globally or in a specific geographic area.
256 * URI: <b>/{datasource-name}/portal/taxon/find</b>
259 * the string to query for. Since the wildcard character '*'
260 * internally always is appended to the query string, a search
261 * always compares the query string with the beginning of a name.
262 * - <i>required parameter</i>
264 * the {@link UUID} of a {@link TaxonomicTree} to which the
265 * search is to be restricted. - <i>optional parameter</i>
267 * restrict the search to a set of geographic {@link NamedArea}s.
268 * The parameter currently takes a list of TDWG area labels.
269 * - <i>optional parameter</i>
271 * the number of the page to be returned, the first page has the
272 * pageNumber = 1 - <i>optional parameter</i>
274 * the maximum number of entities returned per page (can be -1
275 * to return all entities in a single page) - <i>optional parameter</i>
277 * weather to search for instances of {@link Taxon} - <i>optional parameter</i>
279 * weather to search for instances of {@link Synonym} - <i>optional parameter</i>
280 * @param doTaxaByCommonNames
281 * for instances of {@link Taxon} by a common name used - <i>optional parameter</i>
283 * valid values are "EXACT", "BEGINNING", "ANYWHERE", "END" (case sensitive !!!)
284 * @return a Pager on a list of {@link IdentifiableEntity}s initialized by
285 * the following strategy {@link #SIMPLE_TAXON_INIT_STRATEGY}
286 * @throws IOException
288 @RequestMapping(method
= RequestMethod
.GET
,
289 value
= {"/portal/taxon/find"}) //TODO map to path /*/portal/taxon/
290 public Pager
<IdentifiableEntity
> doFind(
291 @RequestParam(value
= "query", required
= false) String query
,
292 @RequestParam(value
= "tree", required
= false) UUID treeUuid
,
293 @RequestParam(value
= "area", required
= false) Set
<NamedArea
> areas
,
294 @RequestParam(value
= "page", required
= false) Integer page
,
295 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
296 @RequestParam(value
= "doTaxa", required
= false) Boolean doTaxa
,
297 @RequestParam(value
= "doSynonyms", required
= false) Boolean doSynonyms
,
298 @RequestParam(value
= "doTaxaByCommonNames", required
= false) Boolean doTaxaByCommonNames
,
299 @RequestParam(value
= "matchMode", required
= false) MatchMode matchMode
303 logger
.info("doFind( " +
304 "query=\"" + ObjectUtils
.toString(query
) + "\", treeUuid=" + ObjectUtils
.toString(treeUuid
) +
305 ", area=" + ObjectUtils
.toString(areas
) +
306 ", pageSize=" + ObjectUtils
.toString(pageSize
) + ", page=" + ObjectUtils
.toString(page
) +
307 ", doTaxa=" + ObjectUtils
.toString(doTaxa
) + ", doSynonyms=" + ObjectUtils
.toString(doSynonyms
)
308 +", doTaxaByCommonNames=" + ObjectUtils
.toString(doTaxaByCommonNames
) +")" );
310 if(page
== null){ page
= BaseListController
.DEFAULT_PAGE_NUMBER
;}
311 if(pageSize
== null){ pageSize
= BaseListController
.DEFAULT_PAGESIZE
;}
316 ITaxonServiceConfigurator config
= new TaxonServiceConfiguratorImpl();
317 config
.setPageNumber(page
);
318 config
.setPageSize(pageSize
);
319 config
.setSearchString(query
);
320 config
.setDoTaxa(doTaxa
!= null ? doTaxa
: Boolean
.FALSE
);
321 config
.setDoSynonyms(doSynonyms
!= null ? doSynonyms
: Boolean
.FALSE
);
322 config
.setDoTaxaByCommonNames(doTaxaByCommonNames
!= null ? doTaxaByCommonNames
: Boolean
.FALSE
);
323 config
.setMatchMode(matchMode
!= null ? matchMode
: MatchMode
.BEGINNING
);
324 config
.setTaxonPropertyPath(SIMPLE_TAXON_INIT_STRATEGY
);
325 config
.setNamedAreas(areas
);
326 if(treeUuid
!= null){
327 TaxonomicTree taxonomicTree
= taxonTreeService
.find(treeUuid
);
328 config
.setTaxonomicTree(taxonomicTree
);
331 return (Pager
<IdentifiableEntity
>) service
.findTaxaAndNames(config
);
335 * Get the synonymy for a taxon identified by the <code>{taxon-uuid}</code>.
336 * The synonymy consists
337 * of two parts: The group of homotypic synonyms of the taxon and the
338 * heterotypic synonymy groups of the taxon. The synonymy is ordered
339 * historically by the type designations and by the publication date of the
340 * nomenclatural reference
343 * <b>/{datasource-name}/portal/taxon/{taxon-uuid}/synonymy</b>
348 * @return a Map with to entries which are mapped by the following keys:
349 * "homotypicSynonymsByHomotypicGroup", "heterotypicSynonymyGroups",
350 * containing lists of {@link Synonym}s which are initialized using the
351 * following initialization strategy: {@link #SYNONYMY_INIT_STRATEGY}
353 * @throws IOException
356 value
= {"synonymy"},
357 method
= RequestMethod
.GET
)
358 public ModelAndView
doGetSynonymy(@PathVariable("uuid") UUID uuid
,
359 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
361 logger
.info("doGetSynonymy() " + request
.getServletPath());
362 ModelAndView mv
= new ModelAndView();
363 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
364 Map
<String
, List
<?
>> synonymy
= new Hashtable
<String
, List
<?
>>();
365 synonymy
.put("homotypicSynonymsByHomotypicGroup", service
.getHomotypicSynonymsByHomotypicGroup(taxon
, SYNONYMY_INIT_STRATEGY
));
366 synonymy
.put("heterotypicSynonymyGroups", service
.getHeterotypicSynonymyGroups(taxon
, SYNONYMY_INIT_STRATEGY
));
367 mv
.addObject(synonymy
);
372 * Get the set of accepted {@link Taxon} entities for a given
373 * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
375 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/accepted</b>
379 * @return a Set of {@link Taxon} entities which are initialized
380 * using the following initialization strategy:
381 * {@link #SYNONYMY_INIT_STRATEGY}
382 * @throws IOException
384 @RequestMapping(value
= "accepted", method
= RequestMethod
.GET
)
385 public Set
<TaxonBase
> getAccepted(@PathVariable("uuid") UUID uuid
,
386 HttpServletRequest request
, HttpServletResponse response
) throws IOException
{
388 logger
.info("getAccepted() " + request
.getServletPath());
390 TaxonBase tb
= service
.load(uuid
, SYNONYMY_INIT_STRATEGY
);
392 response
.sendError(HttpServletResponse
.SC_NOT_FOUND
, "A taxon with the uuid " + uuid
+ " does not exist");
395 HashSet
<TaxonBase
> resultset
= new HashSet
<TaxonBase
>();
396 if(tb
instanceof Taxon
){
397 //the taxon already is accepted
398 //FIXME take the current view into account once views are implemented!!!
399 resultset
.add((Taxon
)tb
);
401 Synonym syn
= (Synonym
)tb
;
402 for(TaxonBase accepted
: syn
.getAcceptedTaxa()){
403 accepted
= service
.load(accepted
.getUuid(), SIMPLE_TAXON_INIT_STRATEGY
);
404 resultset
.add(accepted
);
411 * Get the list of {@link TaxonRelationship}s for the given
412 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
414 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/taxonRelationships</b>
418 * @return a List of {@link TaxonRelationship} entities which are initialized
419 * using the following initialization strategy:
420 * {@link #TAXONRELATIONSHIP_INIT_STRATEGY}
421 * @throws IOException
424 value
= {"taxonRelationships"},
425 method
= RequestMethod
.GET
)
426 public List
<TaxonRelationship
> doGetTaxonRelations(@PathVariable("uuid") UUID uuid
,
427 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
429 logger
.info("doGetTaxonRelations()" + request
.getServletPath());
430 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
431 List
<TaxonRelationship
> relations
= new ArrayList
<TaxonRelationship
>();
432 List
<TaxonRelationship
> results
= service
.listToTaxonRelationships(taxon
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR(), null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY
);
433 relations
.addAll(results
);
434 results
= service
.listToTaxonRelationships(taxon
, TaxonRelationshipType
.INVALID_DESIGNATION_FOR(), null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY
);
435 relations
.addAll(results
);
441 * Get the list of {@link NameRelationship}s of the Name associated with the
442 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
444 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameRelationships</b>
448 * @return a List of {@link NameRelationship} entities which are initialized
449 * using the following initialization strategy:
450 * {@link #NAMERELATIONSHIP_INIT_STRATEGY}
451 * @throws IOException
454 value
= {"toNameRelationships"},
455 method
= RequestMethod
.GET
)
456 public List
<NameRelationship
> doGetToNameRelations(@PathVariable("uuid") UUID uuid
,
457 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
458 logger
.info("doGetNameRelations()" + request
.getServletPath());
459 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
460 List
<NameRelationship
> list
= nameService
.listToNameRelationships(taxon
.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY
);
465 * Get the list of {@link NameRelationship}s of the Name associated with the
466 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
468 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameRelationships</b>
472 * @return a List of {@link NameRelationship} entities which are initialized
473 * using the following initialization strategy:
474 * {@link #NAMERELATIONSHIP_INIT_STRATEGY}
475 * @throws IOException
478 value
= {"fromNameRelationships"},
479 method
= RequestMethod
.GET
)
480 public List
<NameRelationship
> doGetFromNameRelations(@PathVariable("uuid") UUID uuid
,
481 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
482 logger
.info("doGetNameFromNameRelations()" + request
.getServletPath());
484 TaxonBase taxonbase
= getCdmBaseInstance(TaxonBase
.class, uuid
, response
, SIMPLE_TAXON_INIT_STRATEGY
);
485 List
<NameRelationship
> list
= nameService
.listFromNameRelationships(taxonbase
.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY
);
490 * Get the list of {@link TypeDesignationBase}s of the
491 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
493 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameTypeDesignations</b>
497 * @return a List of {@link TypeDesignationBase} entities which are initialized
498 * using the following initialization strategy:
499 * {@link #TYPEDESIGNATION_INIT_STRATEGY}
500 * @throws IOException
501 * @Deprecated use /name/{uuid}/typeDesignations & /derivedunitfacade/{uuid} instead
505 value
= {"nameTypeDesignations"},
506 method
= RequestMethod
.GET
)
507 public List
<TypeDesignationBase
> doGetNameTypeDesignations(@PathVariable("uuid") UUID uuid
,
508 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
509 logger
.info("doGetNameTypeDesignations()" + request
.getServletPath());
510 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, SIMPLE_TAXON_INIT_STRATEGY
);
511 Pager
<TypeDesignationBase
> p
= nameService
.getTypeDesignations(taxon
.getName(), null, null, null, TYPEDESIGNATION_INIT_STRATEGY
);
512 return p
.getRecords();
515 @RequestMapping(value
= "taxonNodes", method
= RequestMethod
.GET
)
516 public Set
<TaxonNode
> doGetTaxonNodes(
517 @PathVariable("uuid") UUID uuid
,
518 HttpServletRequest request
,
519 HttpServletResponse response
) throws IOException
{
520 TaxonBase tb
= service
.load(uuid
, TAXONNODE_INIT_STRATEGY
);
521 if(tb
instanceof Taxon
){
522 return ((Taxon
)tb
).getTaxonNodes();
524 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
530 * Get the list of {@link TaxonDescription}s of the
531 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code>.
533 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/descriptions</b>
537 * @return a List of {@link TaxonDescription} entities which are initialized
538 * using the following initialization strategy:
539 * {@link #TAXONDESCRIPTION_INIT_STRATEGY}
540 * @throws IOException
543 value
= {"descriptions"},
544 method
= RequestMethod
.GET
)
545 public List
<TaxonDescription
> doGetDescriptions(@PathVariable("uuid") UUID uuid
,
546 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
547 logger
.info("doGetDescriptions()" + request
.getServletPath());
548 Taxon t
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
549 Pager
<TaxonDescription
> p
= descriptionService
.getTaxonDescriptions(t
, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY
);
550 return p
.getRecords();
554 * Get the {@link Media} attached to the {@link Taxon} instance
555 * identified by the <code>{taxon-uuid}</code>.
557 * Usage /{datasource-name}/portal/taxon/{taxon-
558 * uuid}/media/{mime type
559 * list}/{size}[,[widthOrDuration}][,{height}]/
563 * <li><b>{mime type list}</b>: a comma separated list of mime types, in the
564 * order of preference. The forward slashes contained in the mime types must
565 * be replaced by a colon. Regular expressions can be used. Each media
566 * associated with this given taxon is being searched whereas the first
567 * matching mime type matching a representation always rules.</li>
568 * <li><b>{size},{widthOrDuration},{height}</b>: <i>not jet implemented</i>
569 * valid values are an integer or the asterisk '*' as a wildcard</li>
574 * @return a List of {@link Media} entities which are initialized
575 * using the following initialization strategy:
576 * {@link #TAXONDESCRIPTION_INIT_STRATEGY}
577 * @throws IOException
580 value
= {"media/*/*"},
581 method
= RequestMethod
.GET
)
582 public List
<Media
> doGetMedia(@PathVariable("uuid") UUID uuid
,
583 HttpServletRequest request
, HttpServletResponse response
) throws IOException
{
584 logger
.info("doGetMedia()" + request
.getServletPath());
585 Taxon t
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
586 String path
= request
.getServletPath();
587 List
<Media
> returnMedia
= getMediaForTaxon(t
, path
, 5);
592 value
= {"subtree/media/*/*"},
593 method
= RequestMethod
.GET
)
594 public List
<Media
> doGetSubtreeMedia(@PathVariable("uuid") UUID uuid
,
595 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
596 logger
.info("doGetMedia()" + request
.getServletPath());
597 Taxon t
= getCdmBaseInstance(Taxon
.class, uuid
, response
, TAXON_WITH_NODES_INIT_STRATEGY
);
598 String path
= request
.getServletPath();
599 List
<Media
> returnMedia
= getMediaForTaxon(t
, path
, 6);
601 //looking for all medias of genus
602 if (t
.getTaxonNodes().size()>0){
603 Set
<TaxonNode
> nodes
= t
.getTaxonNodes();
604 Iterator
<TaxonNode
> iterator
= nodes
.iterator();
606 node
= iterator
.next();
607 //überprüfen, ob der TaxonNode zum aktuellen Baum gehört.
609 node
= taxonTreeService
.loadTaxonNode(node
, TAXONNODE_WITHTAXON_INIT_STRATEGY
);
610 Set
<TaxonNode
> children
= node
.getChildNodes();
612 for (TaxonNode child
: children
){
613 childTaxon
= child
.getTaxon();
614 childTaxon
= (Taxon
)taxonService
.load(childTaxon
.getUuid(), null);
615 returnMedia
.addAll(getMediaForTaxon(childTaxon
, path
, 6));
622 private List
<Media
> getMediaForTaxon(Taxon taxon
, String path
, int mimeTypeTokenPosition
){
624 Pager
<TaxonDescription
> p
=
625 descriptionService
.getTaxonDescriptions(taxon
, null, null, null, null, TAXONDESCRIPTION_MEDIA_INIT_STRATEGY
);
627 // pars the media and quality parameters
630 // collect all media of the given taxon
631 boolean limitToGalleries
= false;
632 List
<Media
> taxonMedia
= new ArrayList
<Media
>();
633 for(TaxonDescription desc
: p
.getRecords()){
634 if(!limitToGalleries
|| desc
.isImageGallery()){
635 for(DescriptionElementBase element
: desc
.getElements()){
636 for(Media media
: element
.getMedia()){
637 taxonMedia
.add(media
);
643 String
[] pathTokens
= path
.split("/");
645 String
[] mimeTypes
= pathTokens
[mimeTypeTokenPosition
].split(",");
646 String
[] sizeTokens
= pathTokens
[mimeTypeTokenPosition
+ 1].split(",");
647 Integer widthOrDuration
= null;
648 Integer height
= null;
651 List
<Media
> returnMedia
= MediaUtils
.findPreferredMedia(taxonMedia
, mimeTypes
,
652 sizeTokens
, widthOrDuration
, height
, size
);
658 // ---------------------- code snippet preserved for possible later use --------------------
660 // value = {"/*/portal/taxon/*/descriptions"},
661 // method = RequestMethod.GET)
662 // public List<TaxonDescription> doGetDescriptionsbyFeatureTree(HttpServletRequest request, HttpServletResponse response)throws IOException {
663 // TaxonBase tb = getCdmBase(request, response, null, Taxon.class);
664 // if(tb instanceof Taxon){
665 // //T O D O this is a quick and dirty implementation -> generalize
666 // UUID featureTreeUuid = readValueUuid(request, featureTreeUuidPattern);
668 // FeatureTree featureTree = descriptionService.getFeatureTreeByUuid(featureTreeUuid);
669 // Pager<TaxonDescription> p = descriptionService.getTaxonDescriptions((Taxon)tb, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY);
670 // List<TaxonDescription> descriptions = p.getRecords();
672 // if(!featureTree.isDescriptionSeparated()){
674 // TaxonDescription superDescription = TaxonDescription.NewInstance();
675 // //put all descriptionElements in superDescription and make it invisible
676 // for(TaxonDescription description: descriptions){
677 // for(DescriptionElementBase element: description.getElements()){
678 // superDescription.addElement(element);
681 // List<TaxonDescription> separatedDescriptions = new ArrayList<TaxonDescription>(descriptions.size());
682 // separatedDescriptions.add(superDescription);
683 // return separatedDescriptions;
685 // return descriptions;
688 // response.sendError(HttpServletResponse.SC_NOT_FOUND, "invalid type; Taxon expected but " + tb.getClass().getSimpleName() + " found.");