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
.api
.service
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Comparator
;
15 import java
.util
.HashSet
;
16 import java
.util
.List
;
18 import java
.util
.UUID
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
22 import org
.springframework
.stereotype
.Service
;
23 import org
.springframework
.transaction
.annotation
.Propagation
;
24 import org
.springframework
.transaction
.annotation
.Transactional
;
26 import eu
.etaxonomy
.cdm
.api
.service
.config
.ITaxonServiceConfigurator
;
27 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
28 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.DefaultPagerImpl
;
29 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
30 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
31 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermVocabulary
;
32 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
33 import eu
.etaxonomy
.cdm
.model
.common
.UuidAndTitleCache
;
34 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
35 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
36 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
37 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
38 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
39 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
40 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
41 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
42 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
43 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
44 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
45 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
46 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
47 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
48 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
49 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
50 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
51 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
52 import eu
.etaxonomy
.cdm
.persistence
.dao
.BeanInitializer
;
53 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IOrderedTermVocabularyDao
;
54 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionDao
;
55 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITaxonNameDao
;
56 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonDao
;
57 import eu
.etaxonomy
.cdm
.persistence
.fetch
.CdmFetch
;
58 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
62 @Transactional(propagation
= Propagation
.SUPPORTS
, readOnly
= true)
63 public class TaxonServiceImpl
extends IdentifiableServiceBase
<TaxonBase
,ITaxonDao
> implements ITaxonService
{
64 private static final Logger logger
= Logger
.getLogger(TaxonServiceImpl
.class);
67 private ITaxonNameDao nameDao
;
71 private IOrderedTermVocabularyDao orderedVocabularyDao
;
73 private IDescriptionDao descriptionDao
;
75 private BeanInitializer defaultBeanInitializer
;
77 private Comparator
<?
super TaxonNode
> taxonNodeComparator
;
79 public void setTaxonNodeComparator(ITaxonNodeComparator
<?
super TaxonNode
> taxonNodeComparator
){
80 this.taxonNodeComparator
= (Comparator
<?
super TaxonNode
>) taxonNodeComparator
;
86 public TaxonServiceImpl(){
87 if (logger
.isDebugEnabled()) { logger
.debug("Load TaxonService Bean"); }
91 * FIXME Candidate for harmonization
92 * rename searchByName ?
94 public List
<TaxonBase
> searchTaxaByName(String name
, ReferenceBase sec
) {
95 return dao
.getTaxaByName(name
, sec
);
99 * FIXME Candidate for harmonization
100 * list(Synonym.class, ...)
102 * @see eu.etaxonomy.cdm.api.service.ITaxonService#getAllSynonyms(int, int)
104 public List
<Synonym
> getAllSynonyms(int limit
, int start
) {
105 return dao
.getAllSynonyms(limit
, start
);
109 * FIXME Candidate for harmonization
110 * list(Taxon.class, ...)
112 * @see eu.etaxonomy.cdm.api.service.ITaxonService#getAllTaxa(int, int)
114 public List
<Taxon
> getAllTaxa(int limit
, int start
) {
115 return dao
.getAllTaxa(limit
, start
);
120 * FIXME Candidate for harmonization
121 * merge with getRootTaxa(ReferenceBase sec, ..., ...)
123 * @see eu.etaxonomy.cdm.api.service.ITaxonService#getRootTaxa(eu.etaxonomy.cdm.model.reference.ReferenceBase)
125 public List
<Taxon
> getRootTaxa(ReferenceBase sec
){
126 return getRootTaxa(sec
, CdmFetch
.FETCH_CHILDTAXA(), true);
130 * FIXME Candidate for harmonization
131 * merge with getRootTaxa(ReferenceBase sec, ..., ...)
133 * @see eu.etaxonomy.cdm.api.service.ITaxonService#getRootTaxa(eu.etaxonomy.cdm.model.reference.ReferenceBase, boolean)
135 public List
<Taxon
> getRootTaxa(ReferenceBase sec
, CdmFetch cdmFetch
, boolean onlyWithChildren
) {
136 if (cdmFetch
== null){
137 cdmFetch
= CdmFetch
.NO_FETCH();
139 return dao
.getRootTaxa(sec
, cdmFetch
, onlyWithChildren
, false);
143 * FIXME Candidate for harmonization
144 * merge with getRootTaxa(ReferenceBase sec, ..., ...)
146 * @see eu.etaxonomy.cdm.api.service.ITaxonService#getRootTaxa(eu.etaxonomy.cdm.model.reference.ReferenceBase, boolean, boolean)
148 public List
<Taxon
> getRootTaxa(ReferenceBase sec
, boolean onlyWithChildren
,
149 boolean withMisapplications
) {
150 return dao
.getRootTaxa(sec
, null, onlyWithChildren
, withMisapplications
);
154 * @see eu.etaxonomy.cdm.api.service.ITaxonService#getRootTaxa(eu.etaxonomy.cdm.model.name.Rank, eu.etaxonomy.cdm.model.reference.ReferenceBase, boolean, boolean)
156 public List
<Taxon
> getRootTaxa(Rank rank
, ReferenceBase sec
, boolean onlyWithChildren
,
157 boolean withMisapplications
, List
<String
> propertyPaths
) {
158 return dao
.getRootTaxa(rank
, sec
, null, onlyWithChildren
, withMisapplications
, propertyPaths
);
161 public List
<RelationshipBase
> getAllRelationships(int limit
, int start
){
162 return dao
.getAllRelationships(limit
, start
);
166 * FIXME Candidate for harmonization
167 * is this the same as termService.getVocabulary(VocabularyEnum.TaxonRelationshipType) ?
170 public OrderedTermVocabulary
<TaxonRelationshipType
> getTaxonRelationshipTypeVocabulary() {
172 String taxonRelTypeVocabularyId
= "15db0cf7-7afc-4a86-a7d4-221c73b0c9ac";
173 UUID uuid
= UUID
.fromString(taxonRelTypeVocabularyId
);
174 OrderedTermVocabulary
<TaxonRelationshipType
> taxonRelTypeVocabulary
=
175 (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(uuid
);
176 return taxonRelTypeVocabulary
;
180 * @see eu.etaxonomy.cdm.api.service.ITaxonService#makeTaxonSynonym(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.Taxon)
182 @Transactional(readOnly
= false)
183 public Synonym
changeAcceptedTaxonToSynonym(TaxonNode oldTaxonNode
, TaxonNode newAcceptedTaxonNode
, SynonymRelationshipType synonymRelationshipType
, ReferenceBase citation
, String citationMicroReference
) {
185 // TODO at the moment this method only moves synonym-, concept relations and descriptions to the new accepted taxon
186 // in a future version we also want to move cdm data like annotations, marker, so., but we will need a policy for that
187 if (oldTaxonNode
== null || newAcceptedTaxonNode
== null || oldTaxonNode
.getTaxon().getName() == null){
188 throw new IllegalArgumentException("A mandatory parameter was null.");
191 if(oldTaxonNode
.equals(newAcceptedTaxonNode
)){
192 throw new IllegalArgumentException("Taxon can not be made synonym of its own.");
195 Taxon oldTaxon
= (Taxon
) HibernateProxyHelper
.deproxy(oldTaxonNode
.getTaxon());
196 Taxon newAcceptedTaxon
= (Taxon
) HibernateProxyHelper
.deproxy(newAcceptedTaxonNode
.getTaxon());
198 // Move oldTaxon to newTaxon
199 TaxonNameBase
<?
,?
> synonymName
= oldTaxon
.getName();
200 if (synonymRelationshipType
== null){
201 if (synonymName
.isHomotypic(newAcceptedTaxon
.getName())){
202 synonymRelationshipType
= SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF();
204 synonymRelationshipType
= SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF();
207 SynonymRelationship synonmyRelationship
= newAcceptedTaxon
.addSynonymName(synonymName
, synonymRelationshipType
, citation
, citationMicroReference
);
209 //Move Synonym Relations to new Taxon
210 for(SynonymRelationship synRelation
: oldTaxon
.getSynonymRelations()){
211 newAcceptedTaxon
.addSynonym(synRelation
.getSynonym(), synRelation
.getType(),
212 synRelation
.getCitation(), synRelation
.getCitationMicroReference());
217 if(oldTaxonNode
.getChildNodes() != null && oldTaxonNode
.getChildNodes().size() != 0){
218 for(TaxonNode childNode
: oldTaxonNode
.getChildNodes()){
219 newAcceptedTaxonNode
.addChildNode(childNode
, childNode
.getReference(), childNode
.getMicroReference(), childNode
.getSynonymToBeUsed());
223 //Move Taxon RelationShips to new Taxon
224 Set
<TaxonRelationship
> obsoleteTaxonRelationships
= new HashSet
<TaxonRelationship
>();
225 for(TaxonRelationship taxonRelationship
: oldTaxon
.getTaxonRelations()){
226 Taxon fromTaxon
= (Taxon
) HibernateProxyHelper
.deproxy(taxonRelationship
.getFromTaxon());
227 Taxon toTaxon
= (Taxon
) HibernateProxyHelper
.deproxy(taxonRelationship
.getToTaxon());
228 if (fromTaxon
== oldTaxon
){
229 newAcceptedTaxon
.addTaxonRelation(taxonRelationship
.getToTaxon(), taxonRelationship
.getType(),
230 taxonRelationship
.getCitation(), taxonRelationship
.getCitationMicroReference());
232 }else if(toTaxon
== oldTaxon
){
233 taxonRelationship
.getFromTaxon().addTaxonRelation(newAcceptedTaxon
, taxonRelationship
.getType(),
234 taxonRelationship
.getCitation(), taxonRelationship
.getCitationMicroReference());
237 logger
.warn("Taxon is not part of its own Taxonrelationship");
239 // Remove old relationships
240 taxonRelationship
.setToTaxon(null);
241 taxonRelationship
.setFromTaxon(null);
244 //Move descriptions to new taxon
245 for(TaxonDescription oldDescription
: oldTaxon
.getDescriptions()){
247 TaxonDescription newDescription
= TaxonDescription
.NewInstance(newAcceptedTaxon
);
248 newDescription
.setTitleCache("Description copied from " + oldTaxon
+ ". Old title: " + oldDescription
.getTitleCache());
250 for(DescriptionElementBase element
: oldDescription
.getElements()){
251 newDescription
.addElement(element
);
255 oldTaxonNode
.delete();
257 return synonmyRelationship
.getSynonym();
262 * @see eu.etaxonomy.cdm.api.service.ITaxonService#swapSynonymWithAcceptedTaxon(eu.etaxonomy.cdm.model.taxon.Synonym)
264 @Transactional(readOnly
= false)
265 public void swapSynonymAndAcceptedTaxon(Synonym synonym
, Taxon acceptedTaxon
, SynonymRelationshipType synonymRelationshipType
){
267 // create a new synonym with the old acceptedName
268 TaxonNameBase oldAcceptedTaxonName
= acceptedTaxon
.getName();
270 // store the synonyms name
271 TaxonNameBase newAcceptedTaxonName
= synonym
.getName();
273 // remove synonym from oldAcceptedTaxon
274 acceptedTaxon
.removeSynonym(synonym
);
276 // make synonym name the accepted taxons name
277 acceptedTaxon
.setName(newAcceptedTaxonName
);
279 // add the new synonym to the acceptedTaxon
280 if(synonymRelationshipType
== null){
281 synonymRelationshipType
= SynonymRelationshipType
.SYNONYM_OF();
284 acceptedTaxon
.addSynonymName(oldAcceptedTaxonName
, synonymRelationshipType
);
289 * @see eu.etaxonomy.cdm.api.service.ITaxonService#makeSynonymAcceptedTaxon(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon)
291 public Taxon
changeSynonymToAcceptedTaxon(Synonym synonym
, Taxon acceptedTaxon
){
293 Taxon newAcceptedTaxon
= Taxon
.NewInstance(synonym
.getName(), acceptedTaxon
.getSec());
295 acceptedTaxon
.removeSynonym(synonym
);
297 // since we are swapping names, we have to detach the name from the synonym completely.
298 // Otherwise the synonym will still be in the list of typified names.
299 synonym
.getName().removeTaxonBase(synonym
);
301 return newAcceptedTaxon
;
304 public Taxon
changeSynonymToRelatedTaxon(Synonym synonym
, Taxon toTaxon
, TaxonRelationshipType taxonRelationshipType
, ReferenceBase citation
, String microcitation
){
306 // Get name from synonym
307 TaxonNameBase
<?
, ?
> synonymName
= synonym
.getName();
309 // remove synonym from taxon
310 toTaxon
.removeSynonym(synonym
);
312 // Create a taxon with synonym name
313 Taxon fromTaxon
= Taxon
.NewInstance(synonymName
, null);
315 // Add taxon relation
316 fromTaxon
.addTaxonRelation(toTaxon
, taxonRelationshipType
, citation
, microcitation
);
318 // since we are swapping names, we have to detach the name from the synonym completely.
319 // Otherwise the synonym will still be in the list of typified names.
320 synonym
.getName().removeTaxonBase(synonym
);
325 public void generateTitleCache() {
326 generateTitleCache(true);
329 public void generateTitleCache(boolean forceProtected
) {
330 logger
.warn("generateTitleCache not yet fully implemented!");
334 protected void setDao(ITaxonDao dao
) {
338 public Pager
<TaxonBase
> findTaxaByName(Class
<?
extends TaxonBase
> clazz
, String uninomial
, String infragenericEpithet
, String specificEpithet
, String infraspecificEpithet
, Rank rank
, Integer pageSize
,Integer pageNumber
) {
339 Integer numberOfResults
= dao
.countTaxaByName(clazz
, uninomial
, infragenericEpithet
, specificEpithet
, infraspecificEpithet
, rank
);
341 List
<TaxonBase
> results
= new ArrayList
<TaxonBase
>();
342 if(numberOfResults
> 0) { // no point checking again
343 results
= dao
.findTaxaByName(clazz
, uninomial
, infragenericEpithet
, specificEpithet
, infraspecificEpithet
, rank
, pageSize
, pageNumber
);
346 return new DefaultPagerImpl
<TaxonBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
349 public List
<TaxonRelationship
> listToTaxonRelationships(Taxon taxon
, TaxonRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
){
350 Integer numberOfResults
= dao
.countTaxonRelationships(taxon
, type
, TaxonRelationship
.Direction
.relatedTo
);
352 List
<TaxonRelationship
> results
= new ArrayList
<TaxonRelationship
>();
353 if(numberOfResults
> 0) { // no point checking again
354 results
= dao
.getTaxonRelationships(taxon
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
, TaxonRelationship
.Direction
.relatedTo
);
359 public Pager
<TaxonRelationship
> pageToTaxonRelationships(Taxon taxon
, TaxonRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
360 Integer numberOfResults
= dao
.countTaxonRelationships(taxon
, type
, TaxonRelationship
.Direction
.relatedTo
);
362 List
<TaxonRelationship
> results
= new ArrayList
<TaxonRelationship
>();
363 if(numberOfResults
> 0) { // no point checking again
364 results
= dao
.getTaxonRelationships(taxon
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
, TaxonRelationship
.Direction
.relatedTo
);
366 return new DefaultPagerImpl
<TaxonRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
369 public List
<TaxonRelationship
> listFromTaxonRelationships(Taxon taxon
, TaxonRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
){
370 Integer numberOfResults
= dao
.countTaxonRelationships(taxon
, type
, TaxonRelationship
.Direction
.relatedFrom
);
372 List
<TaxonRelationship
> results
= new ArrayList
<TaxonRelationship
>();
373 if(numberOfResults
> 0) { // no point checking again
374 results
= dao
.getTaxonRelationships(taxon
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
, TaxonRelationship
.Direction
.relatedFrom
);
379 public Pager
<TaxonRelationship
> pageFromTaxonRelationships(Taxon taxon
, TaxonRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
380 Integer numberOfResults
= dao
.countTaxonRelationships(taxon
, type
, TaxonRelationship
.Direction
.relatedFrom
);
382 List
<TaxonRelationship
> results
= new ArrayList
<TaxonRelationship
>();
383 if(numberOfResults
> 0) { // no point checking again
384 results
= dao
.getTaxonRelationships(taxon
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
, TaxonRelationship
.Direction
.relatedFrom
);
386 return new DefaultPagerImpl
<TaxonRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
389 public Pager
<SynonymRelationship
> getSynonyms(Taxon taxon
, SynonymRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
390 Integer numberOfResults
= dao
.countSynonyms(taxon
, type
);
392 List
<SynonymRelationship
> results
= new ArrayList
<SynonymRelationship
>();
393 if(numberOfResults
> 0) { // no point checking again
394 results
= dao
.getSynonyms(taxon
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
397 return new DefaultPagerImpl
<SynonymRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
400 public Pager
<SynonymRelationship
> getSynonyms(Synonym synonym
, SynonymRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
401 Integer numberOfResults
= dao
.countSynonyms(synonym
, type
);
403 List
<SynonymRelationship
> results
= new ArrayList
<SynonymRelationship
>();
404 if(numberOfResults
> 0) { // no point checking again
405 results
= dao
.getSynonyms(synonym
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
408 return new DefaultPagerImpl
<SynonymRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
411 public List
<Synonym
> getHomotypicSynonymsByHomotypicGroup(Taxon taxon
, List
<String
> propertyPaths
){
412 Taxon t
= (Taxon
)dao
.load(taxon
.getUuid(), propertyPaths
);
413 return t
.getHomotypicSynonymsByHomotypicGroup();
416 public List
<List
<Synonym
>> getHeterotypicSynonymyGroups(Taxon taxon
, List
<String
> propertyPaths
){
417 Taxon t
= (Taxon
)dao
.load(taxon
.getUuid(), propertyPaths
);
418 List
<HomotypicalGroup
> hsgl
= t
.getHeterotypicSynonymyGroups();
419 List
<List
<Synonym
>> heterotypicSynonymyGroups
= new ArrayList
<List
<Synonym
>>(hsgl
.size());
420 for(HomotypicalGroup hsg
: hsgl
){
421 heterotypicSynonymyGroups
.add(hsg
.getSynonymsInGroup(t
.getSec()));
423 return heterotypicSynonymyGroups
;
426 public Pager
<IdentifiableEntity
> findTaxaAndNames(ITaxonServiceConfigurator configurator
) {
428 List
<IdentifiableEntity
> results
= new ArrayList
<IdentifiableEntity
>();
429 int numberOfResults
= 0; // overall number of results (as opposed to number of results per page)
430 List
<TaxonBase
> taxa
= null;
433 long numberTaxaResults
= 0L;
435 Class
<?
extends TaxonBase
> clazz
= null;
436 if ((configurator
.isDoTaxa() && configurator
.isDoSynonyms())) {
437 clazz
= TaxonBase
.class;
438 } else if(configurator
.isDoTaxa()) {
440 } else if (configurator
.isDoSynonyms()) {
441 clazz
= Synonym
.class;
446 dao
.countTaxaByName(clazz
,
447 configurator
.getSearchString(), configurator
.getTaxonomicTree(), configurator
.getMatchMode(),
448 configurator
.getNamedAreas());
449 if(numberTaxaResults
> configurator
.getPageSize() * configurator
.getPageNumber()){ // no point checking again if less results
450 taxa
= dao
.getTaxaByName(clazz
,
451 configurator
.getSearchString(), configurator
.getTaxonomicTree(), configurator
.getMatchMode(),
452 configurator
.getNamedAreas(), configurator
.getPageSize(),
453 configurator
.getPageNumber(), configurator
.getTaxonPropertyPath());
457 if (logger
.isDebugEnabled()) { logger
.debug(numberTaxaResults
+ " matching taxa counted"); }
460 results
.addAll(taxa
);
463 numberOfResults
+= numberTaxaResults
;
465 // Names without taxa
466 if (configurator
.isDoNamesWithoutTaxa()) {
467 int numberNameResults
= 0;
468 //FIXME implement search by area
469 List
<?
extends TaxonNameBase
<?
,?
>> names
=
470 nameDao
.findByName(configurator
.getSearchString(), configurator
.getMatchMode(),
471 configurator
.getPageSize(), configurator
.getPageNumber(), null, configurator
.getTaxonNamePropertyPath());
472 if (logger
.isDebugEnabled()) { logger
.debug(names
.size() + " matching name(s) found"); }
473 if (names
.size() > 0) {
474 for (TaxonNameBase
<?
,?
> taxonName
: names
) {
475 if (taxonName
.getTaxonBases().size() == 0) {
476 results
.add(taxonName
);
480 if (logger
.isDebugEnabled()) { logger
.debug(numberNameResults
+ " matching name(s) without taxa found"); }
481 numberOfResults
+= numberNameResults
;
485 // Taxa from common names
486 // FIXME the matching common names also must be returned
487 // FIXME implement search by area
488 if (configurator
.isDoTaxaByCommonNames()) {
489 int numberCommonNameResults
= 0;
490 List
<CommonTaxonName
> commonTaxonNames
=
491 descriptionDao
.searchDescriptionByCommonName(configurator
.getSearchString(),
492 configurator
.getMatchMode(), configurator
.getPageSize(), configurator
.getPageNumber());
493 if (logger
.isDebugEnabled()) { logger
.debug(commonTaxonNames
.size() + " matching common name(s) found"); }
494 if (commonTaxonNames
.size() > 0) {
495 for (CommonTaxonName commonTaxonName
: commonTaxonNames
) {
496 DescriptionBase description
= commonTaxonName
.getInDescription();
497 description
= HibernateProxyHelper
.deproxy(description
, DescriptionBase
.class);
498 if (description
instanceof TaxonDescription
) {
499 TaxonDescription taxonDescription
= HibernateProxyHelper
.deproxy(description
, TaxonDescription
.class);
500 Taxon taxon
= taxonDescription
.getTaxon();
501 taxon
= HibernateProxyHelper
.deproxy(taxon
, Taxon
.class);
502 if (!results
.contains(taxon
) && !taxon
.isMisappliedName()) {
503 defaultBeanInitializer
.initialize(taxon
, configurator
.getTaxonPropertyPath());
505 numberCommonNameResults
++;
508 logger
.warn("Description of " + commonTaxonName
.getName() + " is not an instance of TaxonDescription");
511 numberOfResults
+= numberCommonNameResults
;
515 //FIXME does not work any more after model change
516 logger
.warn("Sort does currently not work on identifiable entities due to model changes (duplicated implementation of the Comparable interface).");
517 //Collections.sort(results);
518 return new DefaultPagerImpl
<IdentifiableEntity
>
519 (configurator
.getPageNumber(), numberOfResults
, configurator
.getPageSize(), results
);
522 public List
<UuidAndTitleCache
<TaxonBase
>> getTaxonUuidAndTitleCache(){
523 return dao
.getUuidAndTitleCache();
526 public List
<MediaRepresentation
> getAllMedia(Taxon taxon
, int size
, int height
, int widthOrDuration
, String
[] mimeTypes
){
527 List
<MediaRepresentation
> medRep
= new ArrayList
<MediaRepresentation
>();
528 taxon
= (Taxon
)dao
.load(taxon
.getUuid());
529 Set
<TaxonDescription
> descriptions
= taxon
.getDescriptions();
530 for (TaxonDescription taxDesc
: descriptions
){
531 Set
<DescriptionElementBase
> elements
= taxDesc
.getElements();
532 for (DescriptionElementBase descElem
: elements
){
533 for(Media media
: descElem
.getMedia()){
535 //find the best matching representation
536 medRep
.add(media
.findBestMatchingRepresentation(size
, height
, widthOrDuration
, mimeTypes
));