Project

General

Profile

Download (4.83 KB) Statistics
| Branch: | Tag: | Revision:
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.Transactional;
19

    
20
import eu.etaxonomy.cdm.api.service.pager.Pager;
21
import eu.etaxonomy.cdm.api.service.pager.impl.AbstractPagerImpl;
22
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
23
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
24
import eu.etaxonomy.cdm.model.description.PolytomousKey;
25
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
26
import eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao;
27
import eu.etaxonomy.cdm.persistence.dao.description.IPolytomousKeyDao;
28
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
29
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
30

    
31
@Service
32
@Transactional(readOnly = false)
33
public class PolytomousKeyServiceImpl extends IdentifiableServiceBase<PolytomousKey, IPolytomousKeyDao> implements IPolytomousKeyService {
34

    
35
	private IIdentificationKeyDao identificationKeyDao;
36
	private ITaxonDao taxonDao;
37

    
38
//	private IPolytomousKeyNodeDao nodeDao;
39

    
40

    
41
	@Override
42
    @Autowired
43
	protected void setDao(IPolytomousKeyDao dao) {
44
		this.dao = dao;
45
	}
46

    
47
	@Autowired
48
	protected void setDao(IIdentificationKeyDao identificationKeyDao) {
49
		this.identificationKeyDao = identificationKeyDao;
50
	}
51

    
52
	@Autowired
53
	protected void setDao(ITaxonDao taxonDao) {
54
		this.taxonDao = taxonDao;
55
	}
56

    
57
//	@Autowired
58
//	protected void setDao(IPolytomousKeyNodeDao nodeDao) {
59
//		this.nodeDao = nodeDao;
60
//	}
61

    
62

    
63
	/* (non-Javadoc)
64
	 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
65
	 */
66
	@Override
67
	public void updateTitleCache(Class<? extends PolytomousKey> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<PolytomousKey> cacheStrategy, IProgressMonitor monitor) {
68
		if (clazz == null){
69
			clazz = PolytomousKey.class;
70
		}
71
		super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
72
	}
73

    
74

    
75
	/* (non-Javadoc)
76
	 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#loadWithNodes(java.util.UUID, java.util.List, java.util.List)
77
	 */
78
	@Override
79
    public PolytomousKey loadWithNodes(UUID uuid, List<String> propertyPaths, List<String> nodePaths) {
80

    
81
		if(nodePaths == null){
82
			nodePaths = new ArrayList<String>();
83
		}
84
		nodePaths.add("children");
85

    
86
		List<String> rootPaths = new ArrayList<String>();
87
		rootPaths.add("root");
88
		for(String path : nodePaths) {
89
			rootPaths.add("root." + path);
90
		}
91

    
92
		if(propertyPaths != null) {
93
		    rootPaths.addAll(propertyPaths);
94
		}
95

    
96
		PolytomousKey polytomousKey = load(uuid, rootPaths);
97
		dao.loadNodes(polytomousKey.getRoot(),nodePaths);
98
		return polytomousKey;
99
	}
100

    
101
	/**
102
	 * Returns the polytomous key specified by the given <code>uuid</code>.
103
	 *
104
	 * @see eu.etaxonomy.cdm.api.service.ServiceBase#load(java.util.UUID, java.util.List)
105
	 */
106
	@Override
107
	public PolytomousKey load(UUID uuid, List<String> propertyPaths) {
108
		return super.load(uuid, propertyPaths);
109
	}
110

    
111

    
112
	/* (non-Javadoc)
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)
114
	 */
115
	@Override
116
	public Pager<PolytomousKey> findByTaxonomicScope(
117
			TaxonBase taxon, Integer pageSize,
118
			Integer pageNumber, List<String> propertyPaths, List<String> nodePaths) {
119

    
120
		List<PolytomousKey> list = new ArrayList<PolytomousKey>();
121
		taxon = taxonDao.findById(taxon.getId());
122
		Long numberOfResults = identificationKeyDao.countByTaxonomicScope(taxon, PolytomousKey.class);
123
		if(AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)){
124
			list = identificationKeyDao.findByTaxonomicScope(taxon, PolytomousKey.class, pageSize, pageNumber, propertyPaths);
125
		}
126
		if (nodePaths != null) {
127
			for (PolytomousKey polytomousKey : list) {
128
				dao.loadNodes(polytomousKey.getRoot(), nodePaths);
129
			}
130
		}
131
		Pager<PolytomousKey> pager = new DefaultPagerImpl<PolytomousKey>(pageNumber, numberOfResults.intValue(), pageSize, list);
132

    
133
		return pager;
134
	}
135

    
136
//	/* (non-Javadoc)
137
//	 * @see eu.etaxonomy.cdm.api.service.ServiceBase#delete(eu.etaxonomy.cdm.model.common.CdmBase)
138
//	 */
139
//	@Override
140
//	public UUID delete(PolytomousKey key) {
141
//
142
////		nodeDao.deleteForKey(key);
143
//
144
//		return super.delete(key);
145
//	}
146

    
147

    
148

    
149
}
(71-71/84)