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
{
362 logger
.info("doGetSynonymy() " + request
.getServletPath());
364 ModelAndView mv
= new ModelAndView();
365 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
366 Map
<String
, List
<?
>> synonymy
= new Hashtable
<String
, List
<?
>>();
367 synonymy
.put("homotypicSynonymsByHomotypicGroup", service
.getHomotypicSynonymsByHomotypicGroup(taxon
, SYNONYMY_INIT_STRATEGY
));
368 synonymy
.put("heterotypicSynonymyGroups", service
.getHeterotypicSynonymyGroups(taxon
, SYNONYMY_INIT_STRATEGY
));
369 mv
.addObject(synonymy
);
374 * Get the set of accepted {@link Taxon} entities for a given
375 * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
377 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/accepted</b>
381 * @return a Set of {@link Taxon} entities which are initialized
382 * using the following initialization strategy:
383 * {@link #SYNONYMY_INIT_STRATEGY}
384 * @throws IOException
386 @RequestMapping(value
= "accepted", method
= RequestMethod
.GET
)
387 public Set
<TaxonBase
> getAccepted(@PathVariable("uuid") UUID uuid
,
388 HttpServletRequest request
, HttpServletResponse response
) throws IOException
{
391 logger
.info("getAccepted() " + request
.getServletPath());
394 TaxonBase tb
= service
.load(uuid
, SYNONYMY_INIT_STRATEGY
);
396 response
.sendError(HttpServletResponse
.SC_NOT_FOUND
, "A taxon with the uuid " + uuid
+ " does not exist");
399 HashSet
<TaxonBase
> resultset
= new HashSet
<TaxonBase
>();
400 if(tb
instanceof Taxon
){
401 //the taxon already is accepted
402 //FIXME take the current view into account once views are implemented!!!
403 resultset
.add((Taxon
)tb
);
405 Synonym syn
= (Synonym
)tb
;
406 for(TaxonBase accepted
: syn
.getAcceptedTaxa()){
407 accepted
= service
.load(accepted
.getUuid(), SIMPLE_TAXON_INIT_STRATEGY
);
408 resultset
.add(accepted
);
415 * Get the list of {@link TaxonRelationship}s for the given
416 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
418 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/taxonRelationships</b>
422 * @return a List of {@link TaxonRelationship} entities which are initialized
423 * using the following initialization strategy:
424 * {@link #TAXONRELATIONSHIP_INIT_STRATEGY}
425 * @throws IOException
428 value
= {"taxonRelationships"},
429 method
= RequestMethod
.GET
)
430 public List
<TaxonRelationship
> doGetTaxonRelations(@PathVariable("uuid") UUID uuid
,
431 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
433 logger
.info("doGetTaxonRelations()" + request
.getServletPath());
434 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
435 List
<TaxonRelationship
> relations
= new ArrayList
<TaxonRelationship
>();
436 List
<TaxonRelationship
> results
= service
.listToTaxonRelationships(taxon
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR(), null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY
);
437 relations
.addAll(results
);
438 results
= service
.listToTaxonRelationships(taxon
, TaxonRelationshipType
.INVALID_DESIGNATION_FOR(), null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY
);
439 relations
.addAll(results
);
445 * Get the list of {@link NameRelationship}s of the Name associated with the
446 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
448 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameRelationships</b>
452 * @return a List of {@link NameRelationship} entities which are initialized
453 * using the following initialization strategy:
454 * {@link #NAMERELATIONSHIP_INIT_STRATEGY}
455 * @throws IOException
458 value
= {"toNameRelationships"},
459 method
= RequestMethod
.GET
)
460 public List
<NameRelationship
> doGetToNameRelations(@PathVariable("uuid") UUID uuid
,
461 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
462 logger
.info("doGetNameRelations()" + request
.getServletPath());
463 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
464 List
<NameRelationship
> list
= nameService
.listToNameRelationships(taxon
.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY
);
469 * Get the list of {@link NameRelationship}s of the Name associated with the
470 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
472 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameRelationships</b>
476 * @return a List of {@link NameRelationship} entities which are initialized
477 * using the following initialization strategy:
478 * {@link #NAMERELATIONSHIP_INIT_STRATEGY}
479 * @throws IOException
482 value
= {"fromNameRelationships"},
483 method
= RequestMethod
.GET
)
484 public List
<NameRelationship
> doGetFromNameRelations(@PathVariable("uuid") UUID uuid
,
485 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
486 logger
.info("doGetNameFromNameRelations()" + request
.getServletPath());
488 TaxonBase taxonbase
= getCdmBaseInstance(TaxonBase
.class, uuid
, response
, SIMPLE_TAXON_INIT_STRATEGY
);
489 List
<NameRelationship
> list
= nameService
.listFromNameRelationships(taxonbase
.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY
);
494 * Get the list of {@link TypeDesignationBase}s of the
495 * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
497 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameTypeDesignations</b>
501 * @return a List of {@link TypeDesignationBase} entities which are initialized
502 * using the following initialization strategy:
503 * {@link #TYPEDESIGNATION_INIT_STRATEGY}
504 * @throws IOException
505 * @Deprecated use /name/{uuid}/typeDesignations & /derivedunitfacade/{uuid} instead
509 value
= {"nameTypeDesignations"},
510 method
= RequestMethod
.GET
)
511 public List
<TypeDesignationBase
> doGetNameTypeDesignations(@PathVariable("uuid") UUID uuid
,
512 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
513 logger
.info("doGetNameTypeDesignations()" + request
.getServletPath());
514 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, SIMPLE_TAXON_INIT_STRATEGY
);
515 Pager
<TypeDesignationBase
> p
= nameService
.getTypeDesignations(taxon
.getName(), null, null, null, TYPEDESIGNATION_INIT_STRATEGY
);
516 return p
.getRecords();
519 @RequestMapping(value
= "taxonNodes", method
= RequestMethod
.GET
)
520 public Set
<TaxonNode
> doGetTaxonNodes(
521 @PathVariable("uuid") UUID uuid
,
522 HttpServletRequest request
,
523 HttpServletResponse response
) throws IOException
{
524 TaxonBase tb
= service
.load(uuid
, TAXONNODE_INIT_STRATEGY
);
525 if(tb
instanceof Taxon
){
526 return ((Taxon
)tb
).getTaxonNodes();
528 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
534 * Get the list of {@link TaxonDescription}s of the
535 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code>.
537 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/descriptions</b>
541 * @return a List of {@link TaxonDescription} entities which are initialized
542 * using the following initialization strategy:
543 * {@link #TAXONDESCRIPTION_INIT_STRATEGY}
544 * @throws IOException
547 value
= {"descriptions"},
548 method
= RequestMethod
.GET
)
549 public List
<TaxonDescription
> doGetDescriptions(@PathVariable("uuid") UUID uuid
,
550 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
552 logger
.info("doGetDescriptions()" + request
.getServletPath());
554 Taxon t
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
555 Pager
<TaxonDescription
> p
= descriptionService
.getTaxonDescriptions(t
, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY
);
556 return p
.getRecords();
560 * Get the {@link Media} attached to the {@link Taxon} instance
561 * identified by the <code>{taxon-uuid}</code>.
563 * Usage /{datasource-name}/portal/taxon/{taxon-
564 * uuid}/media/{mime type
565 * list}/{size}[,[widthOrDuration}][,{height}]/
569 * <li><b>{mime type list}</b>: a comma separated list of mime types, in the
570 * order of preference. The forward slashes contained in the mime types must
571 * be replaced by a colon. Regular expressions can be used. Each media
572 * associated with this given taxon is being searched whereas the first
573 * matching mime type matching a representation always rules.</li>
574 * <li><b>{size},{widthOrDuration},{height}</b>: <i>not jet implemented</i>
575 * valid values are an integer or the asterisk '*' as a wildcard</li>
580 * @return a List of {@link Media} entities which are initialized
581 * using the following initialization strategy:
582 * {@link #TAXONDESCRIPTION_INIT_STRATEGY}
583 * @throws IOException
586 value
= {"media/*/*"},
587 method
= RequestMethod
.GET
)
588 public List
<Media
> doGetMedia(@PathVariable("uuid") UUID uuid
,
589 HttpServletRequest request
, HttpServletResponse response
) throws IOException
{
590 logger
.info("doGetMedia()" + request
.getServletPath());
591 Taxon t
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
592 String path
= request
.getServletPath();
593 List
<Media
> returnMedia
= getMediaForTaxon(t
, path
, 5);
598 value
= {"subtree/media/*/*"},
599 method
= RequestMethod
.GET
)
600 public List
<Media
> doGetSubtreeMedia(@PathVariable("uuid") UUID uuid
,
601 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
602 logger
.info("doGetMedia()" + request
.getServletPath());
603 Taxon t
= getCdmBaseInstance(Taxon
.class, uuid
, response
, TAXON_WITH_NODES_INIT_STRATEGY
);
604 String path
= request
.getServletPath();
605 List
<Media
> returnMedia
= getMediaForTaxon(t
, path
, 6);
607 //looking for all medias of genus
608 if (t
.getTaxonNodes().size()>0){
609 Set
<TaxonNode
> nodes
= t
.getTaxonNodes();
610 Iterator
<TaxonNode
> iterator
= nodes
.iterator();
612 node
= iterator
.next();
613 //überprüfen, ob der TaxonNode zum aktuellen Baum gehört.
615 node
= taxonTreeService
.loadTaxonNode(node
, TAXONNODE_WITHTAXON_INIT_STRATEGY
);
616 Set
<TaxonNode
> children
= node
.getChildNodes();
618 for (TaxonNode child
: children
){
619 childTaxon
= child
.getTaxon();
620 childTaxon
= (Taxon
)taxonService
.load(childTaxon
.getUuid(), null);
621 returnMedia
.addAll(getMediaForTaxon(childTaxon
, path
, 6));
628 private List
<Media
> getMediaForTaxon(Taxon taxon
, String path
, int mimeTypeTokenPosition
){
630 Pager
<TaxonDescription
> p
=
631 descriptionService
.getTaxonDescriptions(taxon
, null, null, null, null, TAXONDESCRIPTION_MEDIA_INIT_STRATEGY
);
633 // pars the media and quality parameters
636 // collect all media of the given taxon
637 boolean limitToGalleries
= false;
638 List
<Media
> taxonMedia
= new ArrayList
<Media
>();
639 for(TaxonDescription desc
: p
.getRecords()){
640 if(!limitToGalleries
|| desc
.isImageGallery()){
641 for(DescriptionElementBase element
: desc
.getElements()){
642 for(Media media
: element
.getMedia()){
643 taxonMedia
.add(media
);
649 String
[] pathTokens
= path
.split("/");
651 String
[] mimeTypes
= pathTokens
[mimeTypeTokenPosition
].split(",");
652 String
[] sizeTokens
= pathTokens
[mimeTypeTokenPosition
+ 1].split(",");
653 Integer widthOrDuration
= null;
654 Integer height
= null;
657 List
<Media
> returnMedia
= MediaUtils
.findPreferredMedia(taxonMedia
, mimeTypes
,
658 sizeTokens
, widthOrDuration
, height
, size
);
664 // ---------------------- code snippet preserved for possible later use --------------------
666 // value = {"/*/portal/taxon/*/descriptions"},
667 // method = RequestMethod.GET)
668 // public List<TaxonDescription> doGetDescriptionsbyFeatureTree(HttpServletRequest request, HttpServletResponse response)throws IOException {
669 // TaxonBase tb = getCdmBase(request, response, null, Taxon.class);
670 // if(tb instanceof Taxon){
671 // //T O D O this is a quick and dirty implementation -> generalize
672 // UUID featureTreeUuid = readValueUuid(request, featureTreeUuidPattern);
674 // FeatureTree featureTree = descriptionService.getFeatureTreeByUuid(featureTreeUuid);
675 // Pager<TaxonDescription> p = descriptionService.getTaxonDescriptions((Taxon)tb, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY);
676 // List<TaxonDescription> descriptions = p.getRecords();
678 // if(!featureTree.isDescriptionSeparated()){
680 // TaxonDescription superDescription = TaxonDescription.NewInstance();
681 // //put all descriptionElements in superDescription and make it invisible
682 // for(TaxonDescription description: descriptions){
683 // for(DescriptionElementBase element: description.getElements()){
684 // superDescription.addElement(element);
687 // List<TaxonDescription> separatedDescriptions = new ArrayList<TaxonDescription>(descriptions.size());
688 // separatedDescriptions.add(superDescription);
689 // return separatedDescriptions;
691 // return descriptions;
694 // response.sendError(HttpServletResponse.SC_NOT_FOUND, "invalid type; Taxon expected but " + tb.getClass().getSimpleName() + " found.");