2 * Copyright (C) 2009 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.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
17 import org
.springframework
.stereotype
.Service
;
18 import org
.springframework
.transaction
.annotation
.Propagation
;
19 import org
.springframework
.transaction
.annotation
.Transactional
;
21 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
22 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.AbstractPagerImpl
;
23 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.DefaultPagerImpl
;
24 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
25 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
27 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IIdentificationKeyDao
;
28 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IPolytomousKeyDao
;
29 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IPolytomousKeyNodeDao
;
30 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonDao
;
31 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
34 @Transactional(propagation
= Propagation
.SUPPORTS
, readOnly
= false)
35 public class PolytomousKeyServiceImpl
extends IdentifiableServiceBase
<PolytomousKey
, IPolytomousKeyDao
> implements IPolytomousKeyService
{
37 private IIdentificationKeyDao identificationKeyDao
;
38 private ITaxonDao taxonDao
;
40 // private IPolytomousKeyNodeDao nodeDao;
44 protected void setDao(IPolytomousKeyDao dao
) {
49 protected void setDao(IIdentificationKeyDao identificationKeyDao
) {
50 this.identificationKeyDao
= identificationKeyDao
;
54 protected void setDao(ITaxonDao taxonDao
) {
55 this.taxonDao
= taxonDao
;
59 // protected void setDao(IPolytomousKeyNodeDao nodeDao) {
60 // this.nodeDao = nodeDao;
65 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
68 public void updateTitleCache(Class
<?
extends PolytomousKey
> clazz
, Integer stepSize
, IIdentifiableEntityCacheStrategy
<PolytomousKey
> cacheStrategy
, IProgressMonitor monitor
) {
70 clazz
= PolytomousKey
.class;
72 super.updateTitleCacheImpl(clazz
, stepSize
, cacheStrategy
, monitor
);
77 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#loadWithNodes(java.util.UUID, java.util.List, java.util.List)
79 public PolytomousKey
loadWithNodes(UUID uuid
, List
<String
> propertyPaths
, List
<String
> nodePaths
) {
81 if(nodePaths
== null){
82 nodePaths
= new ArrayList
<String
>();
84 nodePaths
.add("children");
86 List
<String
> rootPaths
= new ArrayList
<String
>();
87 rootPaths
.add("root");
88 for(String path
: nodePaths
) {
89 rootPaths
.add("root." + path
);
92 if(propertyPaths
!= null) {
93 rootPaths
.addAll(propertyPaths
);
96 PolytomousKey polytomousKey
= load(uuid
, rootPaths
);
97 dao
.loadNodes(polytomousKey
.getRoot(),nodePaths
);
102 * Returns the polytomous key specified by the given <code>uuid</code>.
104 * @see eu.etaxonomy.cdm.api.service.ServiceBase#load(java.util.UUID, java.util.List)
107 public PolytomousKey
load(UUID uuid
, List
<String
> propertyPaths
) {
108 return super.load(uuid
, propertyPaths
);
113 * @see eu.etaxonomy.cdm.api.service.IPolytomousKeyService#findByTaxonomicScope(eu.etaxonomy.cdm.model.taxon.TaxonBase, java.lang.Class, java.lang.Integer, java.lang.Integer, java.util.List)
116 public Pager
<PolytomousKey
> findByTaxonomicScope(
117 TaxonBase taxon
, Integer pageSize
,
118 Integer pageNumber
, List
<String
> propertyPaths
) {
120 List
<PolytomousKey
> list
= new ArrayList
<PolytomousKey
>();
121 taxon
= taxonDao
.findById(taxon
.getId());
122 Integer numberOfResults
= identificationKeyDao
.countByTaxonomicScope(taxon
, PolytomousKey
.class).intValue();
123 if(AbstractPagerImpl
.hasResultsInRange(numberOfResults
, pageNumber
, pageSize
)){
124 list
= identificationKeyDao
.findByTaxonomicScope(taxon
, PolytomousKey
.class, pageSize
, pageNumber
, propertyPaths
);
126 Pager
<PolytomousKey
> pager
= new DefaultPagerImpl
<PolytomousKey
>(pageNumber
, numberOfResults
, pageSize
, list
);
131 // * @see eu.etaxonomy.cdm.api.service.ServiceBase#delete(eu.etaxonomy.cdm.model.common.CdmBase)
134 // public UUID delete(PolytomousKey key) {
136 //// nodeDao.deleteForKey(key);
138 // return super.delete(key);