2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.api
.service
.taxonGraph
;
11 import java
.util
.ArrayList
;
12 import java
.util
.List
;
13 import java
.util
.UUID
;
14 import java
.util
.stream
.Collectors
;
16 import org
.apache
.logging
.log4j
.LogManager
;
17 import org
.apache
.logging
.log4j
.Logger
;
18 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
19 import org
.springframework
.stereotype
.Service
;
20 import org
.springframework
.transaction
.annotation
.Transactional
;
22 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
23 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
24 import eu
.etaxonomy
.cdm
.api
.service
.config
.IncludedTaxonConfiguration
;
25 import eu
.etaxonomy
.cdm
.api
.service
.dto
.IncludedTaxaDTO
;
26 import eu
.etaxonomy
.cdm
.api
.service
.dto
.IncludedTaxaDTO
.IncludedTaxon
;
27 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
30 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxonGraph
.ITaxonGraphDao
;
31 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxonGraph
.TaxonGraphException
;
32 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonGraphEdgeDTO
;
33 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
36 * @author a.kohlbecker
41 @Transactional(readOnly
= true)
42 public class TaxonGraphServiceImpl
implements ITaxonGraphService
{
44 private static final Logger logger
= LogManager
.getLogger();
47 private ITaxonGraphDao taxonGraphDao
;
50 private INameService nameService
;
53 private ITaxonService taxonService
;
57 public List
<TaxonGraphEdgeDTO
> edges(UUID fromtaxonUuid
, UUID toTaxonUuid
, boolean includeUnpublished
) throws TaxonGraphException
{
58 return taxonGraphDao
.edges(fromtaxonUuid
, toTaxonUuid
, includeUnpublished
);
62 public List
<TaxonName
> listIncludedNames(String queryString
, MatchMode matchMode
) {
64 if(matchMode
== null){
65 matchMode
= MatchMode
.BEGINNING
;
68 List
<TaxonName
> includedNames
= new ArrayList
<>();
70 IncludedTaxonConfiguration configuration
= new IncludedTaxonConfiguration(null, false, false, false);
72 List
<TaxonName
> matchingNames
= nameService
.findNamesByTitleCache(queryString
, matchMode
, null);
73 for(TaxonName name
: matchingNames
){
74 if(logger
.isDebugEnabled()){
75 logger
.debug("pageIncludedNames() - matching name: " + name
.getTitleCache());
78 Taxon graphTaxon
= taxonGraphDao
.assureSingleTaxon(name
, false);
79 if(graphTaxon
!= null){
80 IncludedTaxaDTO includedTaxaDTO
= taxonService
.listIncludedTaxa(graphTaxon
.getUuid(), configuration
);
81 List
<UUID
> includedTaxaUUIDs
= includedTaxaDTO
.getIncludedTaxa().stream().map(IncludedTaxon
::getTaxonUuid
).collect(Collectors
.toList());
82 List
<TaxonBase
> includedTaxa
= taxonService
.load(includedTaxaUUIDs
, null);
83 List
<TaxonName
> iclNames
= includedTaxa
.stream().map(TaxonBase
::getName
).collect(Collectors
.toList());
84 includedNames
.addAll(iclNames
);
87 } catch(TaxonGraphException e
){
88 logger
.error(e
.getMessage());