1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.api.service;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
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;
|
20
|
|
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.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.taxon.ITaxonDao;
|
30
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
31
|
|
32
|
@Service
|
33
|
@Transactional(propagation = Propagation.SUPPORTS, readOnly = false)
|
34
|
public class PolytomousKeyServiceImpl extends IdentifiableServiceBase<PolytomousKey, IPolytomousKeyDao> implements IPolytomousKeyService {
|
35
|
|
36
|
private IIdentificationKeyDao identificationKeyDao;
|
37
|
private ITaxonDao taxonDao;
|
38
|
|
39
|
|
40
|
@Autowired
|
41
|
protected void setDao(IPolytomousKeyDao dao) {
|
42
|
this.dao = dao;
|
43
|
}
|
44
|
|
45
|
@Autowired
|
46
|
protected void setDao(IIdentificationKeyDao identificationKeyDao) {
|
47
|
this.identificationKeyDao = identificationKeyDao;
|
48
|
}
|
49
|
|
50
|
@Autowired
|
51
|
protected void setDao(ITaxonDao taxonDao) {
|
52
|
this.taxonDao = taxonDao;
|
53
|
}
|
54
|
|
55
|
|
56
|
/* (non-Javadoc)
|
57
|
* @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
|
58
|
*/
|
59
|
@Override
|
60
|
public void updateTitleCache(Class<? extends PolytomousKey> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<PolytomousKey> cacheStrategy, IProgressMonitor monitor) {
|
61
|
if (clazz == null){
|
62
|
clazz = PolytomousKey.class;
|
63
|
}
|
64
|
super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
|
65
|
}
|
66
|
|
67
|
|
68
|
/* (non-Javadoc)
|
69
|
* @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#loadWithNodes(java.util.UUID, java.util.List, java.util.List)
|
70
|
*/
|
71
|
public PolytomousKey loadWithNodes(UUID uuid, List<String> propertyPaths, List<String> nodePaths) {
|
72
|
|
73
|
if(nodePaths == null){
|
74
|
nodePaths = new ArrayList<String>();
|
75
|
}
|
76
|
nodePaths.add("children");
|
77
|
|
78
|
List<String> rootPaths = new ArrayList<String>();
|
79
|
rootPaths.add("root");
|
80
|
for(String path : nodePaths) {
|
81
|
rootPaths.add("root." + path);
|
82
|
}
|
83
|
|
84
|
if(propertyPaths != null) {
|
85
|
rootPaths.addAll(propertyPaths);
|
86
|
}
|
87
|
|
88
|
PolytomousKey polytomousKey = load(uuid, rootPaths);
|
89
|
dao.loadNodes(polytomousKey.getRoot(),nodePaths);
|
90
|
return polytomousKey;
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* Returns the polytomous key specified by the given <code>uuid</code>.
|
95
|
* The specified polytomous key either can be one of those stored in the CDM database or can be the
|
96
|
* DefaultFeatureTree (contains all Features in use).
|
97
|
* The uuid of the DefaultFeatureTree is defined in {@link IFeatureTreeService#DefaultFeatureTreeUuid}.
|
98
|
* The DefaultFeatureTree is also returned if no feature tree at all is stored in the cdm database.
|
99
|
*
|
100
|
* @see eu.etaxonomy.cdm.api.service.ServiceBase#load(java.util.UUID, java.util.List)
|
101
|
*/
|
102
|
@Override
|
103
|
public PolytomousKey load(UUID uuid, List<String> propertyPaths) {
|
104
|
return super.load(uuid, propertyPaths);
|
105
|
}
|
106
|
|
107
|
|
108
|
/* (non-Javadoc)
|
109
|
* @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)
|
110
|
*/
|
111
|
@Override
|
112
|
public Pager<PolytomousKey> findByTaxonomicScope(
|
113
|
TaxonBase taxon, Integer pageSize,
|
114
|
Integer pageNumber, List<String> propertyPaths) {
|
115
|
|
116
|
List<PolytomousKey> list = new ArrayList<PolytomousKey>();
|
117
|
taxon = taxonDao.findById(taxon.getId());
|
118
|
Integer numberOfResults = identificationKeyDao.countByTaxonomicScope(taxon, PolytomousKey.class).intValue();
|
119
|
if(AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)){
|
120
|
list = identificationKeyDao.findByTaxonomicScope(taxon, PolytomousKey.class, pageSize, pageNumber, propertyPaths);
|
121
|
}
|
122
|
Pager<PolytomousKey> pager = new DefaultPagerImpl<PolytomousKey>(pageNumber, numberOfResults, pageSize, list);
|
123
|
return pager;
|
124
|
}
|
125
|
|
126
|
}
|