Project

General

Profile

« Previous | Next » 

Revision d4992817

Added by Andreas Kohlbecker about 13 years ago

splitting PolytomousKeyNodeService from PolytomousKeyService & more methods for IdentificationKeyService

View differences:

.gitattributes
1627 1627
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/INaturalLanguageGenerator.java -text
1628 1628
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/INaturalLanguageTextDataProcessor.java -text
1629 1629
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IOccurrenceService.java -text
1630
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IPolytomousKeyNodeService.java -text
1630 1631
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IPolytomousKeyService.java -text
1631 1632
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IReferenceService.java -text
1632 1633
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IService.java -text
......
1650 1651
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/NamedAreaTree.java -text
1651 1652
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/NaturalLanguageGenerator.java -text
1652 1653
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceImpl.java -text
1654
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeService.java -text
1653 1655
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyServiceImpl.java -text
1654 1656
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ReferenceServiceImpl.java -text
1655 1657
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ServiceBase.java -text
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/description/IIdentificationKeyDao.java
14 14
import org.springframework.dao.DataAccessException;
15 15

  
16 16
import eu.etaxonomy.cdm.model.description.IIdentificationKey;
17
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
17 18

  
18 19
/**
19 20
 * A read-only interface to allow querying across all IIdentificationKey instances, regardless of type
......
43 44
	 * @return
44 45
	 */
45 46
	public int count();
47
	
48
	/**
49
	 * Finds IdentificationKeys which cover the Taxon given as parameter
50
	 * 
51
	 * @param taxon
52
	 *            The Taxon to search IdentificationKeys for
53
	 * @param type
54
	 *            may restrict the type to a specific implementation of
55
	 *            IIdentificationKey
56
	 * @param pageSize
57
	 *            The maximum number of objects returned (can be null for all
58
	 *            matching objects)
59
	 * @param pageNumber
60
	 *            The offset (in pageSize chunks) from the start of the result
61
	 *            set (0 - based, can be null, equivalent of starting at the
62
	 *            beginning of the recordset)
63
	 * @param propertyPaths
64
	 *            properties to be initialized
65
	 * @return a List of IdentificationKeys
66
	 */
67
	public <T extends IIdentificationKey> List<T> findByTaxonomicScope(
68
			TaxonBase taxon, Class<T> type, Integer pageSize,
69
			Integer pageNumber, List<String> propertyPaths);
70

  
71
	/**
72
	 * Counts IdentificationKeys which cover the Taxon given as parameter
73
	 * 
74
	 * @param taxon The Taxon to search IdentificationKeys for
75
	 * @param type may restrict the type to a specific implementation of
76
	 *            IIdentificationKey
77
	 * @return 
78
	 */
79
	public <T extends IIdentificationKey> Long countByTaxonomicScope(TaxonBase taxon, Class<T> type);
46 80
} 
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/IdentificationKeyDaoImpl.java
8 8
import org.springframework.stereotype.Repository;
9 9

  
10 10
import eu.etaxonomy.cdm.model.description.IIdentificationKey;
11
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
11 12
import eu.etaxonomy.cdm.persistence.dao.BeanInitializer;
12 13
import eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao;
13 14
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.DaoBase;
......
47 48
		return results; 
48 49
	}
49 50

  
51
	/* (non-Javadoc)
52
	 * @see eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao#findKeysConvering(eu.etaxonomy.cdm.model.taxon.TaxonBase, java.lang.Class, java.lang.Integer, java.lang.Integer, java.util.List)
53
	 */
54
	@Override
55
	public <T extends IIdentificationKey> List<T> findByTaxonomicScope(
56
			TaxonBase taxon, Class<T> type, Integer pageSize,
57
			Integer pageNumber, List<String> propertyPaths) {
58
		
59
		Query query = getSession().createQuery("select key from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts = (:taxon)");
60
		query.setParameter("taxon", taxon);
61
		List<T> results = query.list();
62
		defaultBeanInitializer.initializeAll(results, propertyPaths);
63
		return results;
64
	}
65
	
66
	/* (non-Javadoc)
67
	 * @see eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao#findKeysConvering(eu.etaxonomy.cdm.model.taxon.TaxonBase, java.lang.Class, java.lang.Integer, java.lang.Integer, java.util.List)
68
	 */
69
	@Override
70
	public <T extends IIdentificationKey> Long countByTaxonomicScope(TaxonBase taxon, Class<T> type) {
71
		
72
		Query query = getSession().createQuery("select count(key) from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts = (:taxon)");
73
		query.setParameter("taxon", taxon);
74
		List<Long> list = query.list();
75
		Long count = 0l; 
76
		for(Long perTypeCount : list){
77
			count += perTypeCount;
78
		}
79
		return count;
80
	}
81

  
50 82
}
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/IdentificationKeyDaoHibernateImplTest.java
9 9

  
10 10
package eu.etaxonomy.cdm.persistence.dao.hibernate.description;
11 11

  
12
import java.util.List;
13
import java.util.UUID;
14

  
15
import junit.framework.Assert;
16

  
12 17
import org.junit.Before;
13 18
import org.junit.Test;
14 19
import org.unitils.dbunit.annotation.DataSet;
15 20
import org.unitils.spring.annotation.SpringBeanByType;
16 21

  
22
import eu.etaxonomy.cdm.model.description.IIdentificationKey;
23
import eu.etaxonomy.cdm.model.description.MediaKey;
24
import eu.etaxonomy.cdm.model.description.MultiAccessKey;
25
import eu.etaxonomy.cdm.model.description.PolytomousKey;
26
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
17 27
import eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao;
28
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
18 29
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
19 30

  
20 31
@DataSet
......
22 33
	
23 34
	@SpringBeanByType
24 35
	IIdentificationKeyDao identificationKeyDao;
36
	@SpringBeanByType
37
	ITaxonDao taxonDao;
38
	UUID taxonUuid = UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
25 39
	
26 40
	@Before
27 41
	public void setUp() {
......
29 43
	}
30 44
	
31 45
	@Test
32
	public void testCountByDistribution() {
46
	public void testList() {
33 47
		identificationKeyDao.list(null, null, null);
34 48
	}
49
	
50
	@Test
51
	public void testFindByTaxonomicScope() {
52
		TaxonBase taxon = taxonDao.findByUuid(taxonUuid);
53
		
54
		Long count1 = identificationKeyDao.countByTaxonomicScope(taxon, IIdentificationKey.class);
55
		Assert.assertTrue(count1.equals(2l));
56
		List<IIdentificationKey> list1 = identificationKeyDao.findByTaxonomicScope(taxon, IIdentificationKey.class, null, null, null);
57
		Assert.assertEquals(list1.size(), 2);
58
		
59
		Long count2 = identificationKeyDao.countByTaxonomicScope(taxon, MediaKey.class);
60
		Assert.assertTrue(count2.equals(2l));
61
		List<MediaKey> list2 = identificationKeyDao.findByTaxonomicScope(taxon, MediaKey.class, null, null, null);
62
		Assert.assertEquals(list2.size(), 2);
63
		
64
		Long count3 = identificationKeyDao.countByTaxonomicScope(taxon, PolytomousKey.class);
65
		Assert.assertTrue(count3.equals(0l));
66
		List<PolytomousKey> list3 = identificationKeyDao.findByTaxonomicScope(taxon, PolytomousKey.class, null, null, null);
67
		Assert.assertEquals(list3.size(), 0);
68
	}
69
	
70
	
35 71

  
36 72
}
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/description/PolytomousKeyDaoHibernateImplTest.xml
1 1
<?xml version='1.0' encoding='UTF-8'?>
2 2
<dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../dataset.xsd">
3
   <POLYTOMOUSKEY ID="1" UUID="bab66772-2c83-428a-bb6d-655d12ac6097" ROOT_ID="1" PROTECTEDTITLECACHE="false"/>
3
  <POLYTOMOUSKEY ID="1" UUID="bab66772-2c83-428a-bb6d-655d12ac6097" ROOT_ID="1" PROTECTEDTITLECACHE="false"/>
4 4
  <POLYTOMOUSKEYNODE ID="1" KEY_ID="1" />
5 5
  <POLYTOMOUSKEYNODE ID="2" KEY_ID="1" PARENT_ID="1" SORTINDEX="0"  STATEMENT_ID="1" QUESTION_ID="2"/>
6 6
  <POLYTOMOUSKEYNODE ID="3" KEY_ID="1" PARENT_ID="1" SORTINDEX="1" STATEMENT_ID="3"/>
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IIdentificationKeyService.java
4 4

  
5 5
import eu.etaxonomy.cdm.api.service.pager.Pager;
6 6
import eu.etaxonomy.cdm.model.description.IIdentificationKey;
7
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
7 8

  
8 9
public interface IIdentificationKeyService {
9 10
	
......
18 19
	 */
19 20
	public Pager<IIdentificationKey> page(Integer pageSize, Integer pageNumber, List<String> propertyPaths);
20 21

  
22
	/**
23
	 * Finds IdentificationKeys which cover the Taxon given as parameter
24
	 * 
25
	 * @param taxon
26
	 *            The Taxon to search IdentificationKeys for
27
	 * @param type
28
	 *            may restrict the type to a specific implementation of
29
	 *            IIdentificationKey
30
	 * @param pageSize
31
	 *            The maximum number of objects returned (can be null for all
32
	 *            matching objects)
33
	 * @param pageNumber
34
	 *            The offset (in pageSize chunks) from the start of the result
35
	 *            set (0 - based, can be null, equivalent of starting at the
36
	 *            beginning of the recordset)
37
	 * @param propertyPaths
38
	 *            properties to be initialized
39
	 * @return a pager of IdentificationKeys
40
	 */
41
	public <T extends IIdentificationKey> Pager<T> findKeysConvering(
42
			TaxonBase taxon, Class<T> type, Integer pageSize,
43
			Integer pageNumber, List<String> propertyPaths);
44

  
21 45
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IPolytomousKeyNodeService.java
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
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.
9
*/
10
package eu.etaxonomy.cdm.api.service;
11

  
12
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
13

  
14
/**
15
 * @author a.kohlbecker
16
 * @date 24.03.2011
17
 *
18
 */
19
public interface IPolytomousKeyNodeService extends IVersionableService<PolytomousKeyNode> {
20

  
21
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IPolytomousKeyService.java
9 9

  
10 10
package eu.etaxonomy.cdm.api.service;
11 11

  
12
import java.util.Collection;
13 12
import java.util.List;
14
import java.util.Map;
15 13
import java.util.UUID;
16 14

  
17 15
import eu.etaxonomy.cdm.model.description.PolytomousKey;
18
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
19 16

  
20 17
public interface IPolytomousKeyService extends IIdentifiableEntityService<PolytomousKey> {
21 18
	
22
	public List<PolytomousKeyNode> getPolytomousKeyNodesAll();
23
	
24 19
	/**
25 20
	 * Loads a polytomous key including all of its nodes (all the way down to the tips of the tree). 
26 21
	 * Because this method automatically adds key nodes recursively, adding "root" to property paths
......
31 26
	 * 
32 27
	 */
33 28
	public PolytomousKey loadWithNodes(UUID uuid, List<String> propertyPaths, List<String> nodePaths);
34

  
35
	public Map<UUID, PolytomousKeyNode> savePolytomousKeyNodesAll(Collection<PolytomousKeyNode> polytomousKeyNodeCollection);
36
	
37
	public Map<UUID, PolytomousKeyNode> saveOrUpdatePolytomousKeyNodesAll(Collection<PolytomousKeyNode> polytomousKeyNodeCollection);
38 29
	
39 30
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IdentificationKeyServiceImpl.java
9 9
import org.springframework.transaction.annotation.Transactional;
10 10

  
11 11
import eu.etaxonomy.cdm.api.service.pager.Pager;
12
import eu.etaxonomy.cdm.api.service.pager.impl.AbstractPagerImpl;
12 13
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
13 14
import eu.etaxonomy.cdm.model.description.IIdentificationKey;
15
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
14 16
import eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao;
15 17

  
16 18
@Service
......
34 36
		}
35 37
		return new DefaultPagerImpl<IIdentificationKey>(pageNumber, numberOfResults, pageSize, results);
36 38
	}
39
	
40
	
41
	public <T extends IIdentificationKey> Pager<T> findKeysConvering(TaxonBase taxon,
42
			Class<T> type, Integer pageSize,
43
			Integer pageNumber, List<String> propertyPaths) {
44
		
45
		Integer numberOfResults = dao.countByTaxonomicScope(taxon, type).intValue();
46
		List<T> results = new ArrayList<T>();
47
		if(AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)){
48
			results = dao.findByTaxonomicScope(taxon, type, pageSize, pageNumber, propertyPaths);
49
		}
50
		return new DefaultPagerImpl<T>(pageNumber, numberOfResults, pageSize, results);
51
	}
37 52

  
38 53
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeService.java
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
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.
9
*/
10
package eu.etaxonomy.cdm.api.service;
11

  
12
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
13
import eu.etaxonomy.cdm.persistence.dao.description.IPolytomousKeyNodeDao;
14

  
15
/**
16
 * @author a.kohlbecker
17
 * @date 24.03.2011
18
 *
19
 */
20
public class PolytomousKeyNodeService  extends VersionableServiceBase<PolytomousKeyNode, IPolytomousKeyNodeDao> implements IPolytomousKeyNodeService {
21

  
22
	/* (non-Javadoc)
23
	 * @see eu.etaxonomy.cdm.api.service.ServiceBase#setDao(eu.etaxonomy.cdm.persistence.dao.common.ICdmEntityDao)
24
	 */
25
	@Override
26
	protected void setDao(IPolytomousKeyNodeDao dao) {
27
		this.dao = dao;
28
	}
29

  
30
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyServiceImpl.java
10 10
package eu.etaxonomy.cdm.api.service;
11 11

  
12 12
import java.util.ArrayList;
13
import java.util.Collection;
14 13
import java.util.List;
15
import java.util.Map;
16
import java.util.Set;
17 14
import java.util.UUID;
18 15

  
19 16
import org.springframework.beans.factory.annotation.Autowired;
......
22 19
import org.springframework.transaction.annotation.Transactional;
23 20

  
24 21
import eu.etaxonomy.cdm.common.IProgressMonitor;
25
import eu.etaxonomy.cdm.model.common.TermVocabulary;
26
import eu.etaxonomy.cdm.model.common.VocabularyEnum;
27
import eu.etaxonomy.cdm.model.description.Feature;
28
import eu.etaxonomy.cdm.model.description.FeatureNode;
29
import eu.etaxonomy.cdm.model.description.FeatureTree;
30 22
import eu.etaxonomy.cdm.model.description.PolytomousKey;
31
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
32
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
33
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureNodeDao;
34
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureTreeDao;
35 23
import eu.etaxonomy.cdm.persistence.dao.description.IPolytomousKeyDao;
36
import eu.etaxonomy.cdm.persistence.dao.description.IPolytomousKeyNodeDao;
37 24
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
38 25

  
39 26
@Service
40 27
@Transactional(propagation = Propagation.SUPPORTS, readOnly = false)
41 28
public class PolytomousKeyServiceImpl extends IdentifiableServiceBase<PolytomousKey, IPolytomousKeyDao> implements IPolytomousKeyService {
42 29

  
43
	IPolytomousKeyNodeDao polytomousKeyNodeDao;
44
	
45 30
	@Autowired
46 31
	protected void setDao(IPolytomousKeyDao dao) {
47 32
		this.dao = dao;
48 33
	}
49
	
50
	@Autowired
51
	protected void setPolytomousKeyNodeDao(IPolytomousKeyNodeDao polytomousKeyNodeDao) {
52
		this.polytomousKeyNodeDao = polytomousKeyNodeDao;
53
	}
54 34

  
55 35

  
56 36
	/* (non-Javadoc)
......
63 43
		}
64 44
		super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
65 45
	}
66

  
67

  
68
	/* (non-Javadoc)
69
	 * @see eu.etaxonomy.cdm.api.service.IPolytomousKeyService#getPolytomousKeyNodesAll()
70
	 */
71
	public List<PolytomousKeyNode> getPolytomousKeyNodesAll() {
72
		return polytomousKeyNodeDao.list();
73
	}
74
	
75
	/* (non-Javadoc)
76
	 * @see eu.etaxonomy.cdm.api.service.IPolytomousKeyService#savePolytomousKeyNodesAll(java.util.Collection)
77
	 */
78
	public Map<UUID, PolytomousKeyNode> savePolytomousKeyNodesAll(Collection<PolytomousKeyNode> polytomousKeyNodeCollection) {
79
		return polytomousKeyNodeDao.saveAll(polytomousKeyNodeCollection);
80
	}
81 46
	
82
	/* (non-Javadoc)
83
	 * @see eu.etaxonomy.cdm.api.service.IPolytomousKeyService#saveOrUpdatePolytomousKeyNodesAll(java.util.Collection)
84
	 */
85
	public Map<UUID, PolytomousKeyNode> saveOrUpdatePolytomousKeyNodesAll(Collection<PolytomousKeyNode> polytomousKeyNodeCollection) {
86
		return polytomousKeyNodeDao.saveOrUpdateAll(polytomousKeyNodeCollection);
87
	}
88 47

  
89 48
	/* (non-Javadoc)
90 49
	 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#loadWithNodes(java.util.UUID, java.util.List, java.util.List)

Also available in: Unified diff