Revision 76d353fe
Added by Andreas Müller almost 7 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/name/RegistrationDaoHibernateImpl.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.persistence.dao.hibernate.name; |
10 | 10 |
|
11 |
import java.util.Collection; |
|
11 | 12 |
import java.util.Collections; |
12 | 13 |
import java.util.List; |
14 |
import java.util.Optional; |
|
13 | 15 |
|
14 | 16 |
import org.apache.log4j.Logger; |
15 | 17 |
import org.hibernate.Query; |
16 | 18 |
import org.springframework.stereotype.Repository; |
17 | 19 |
|
18 | 20 |
import eu.etaxonomy.cdm.model.name.Registration; |
19 |
import eu.etaxonomy.cdm.model.reference.IReference; |
|
21 |
import eu.etaxonomy.cdm.model.name.RegistrationStatus; |
|
22 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
20 | 23 |
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.AnnotatableDaoImpl; |
21 | 24 |
import eu.etaxonomy.cdm.persistence.dao.name.IRegistrationDao; |
22 | 25 |
|
... | ... | |
26 | 29 |
* |
27 | 30 |
*/ |
28 | 31 |
@Repository |
29 |
public class RegistrationDaoHibernateImpl extends AnnotatableDaoImpl<Registration> implements IRegistrationDao { |
|
32 |
public class RegistrationDaoHibernateImpl |
|
33 |
extends AnnotatableDaoImpl<Registration> |
|
34 |
implements IRegistrationDao { |
|
30 | 35 |
|
31 | 36 |
@SuppressWarnings("unused") |
32 | 37 |
private static final Logger logger = Logger.getLogger(RegistrationDaoHibernateImpl.class); |
... | ... | |
38 | 43 |
super(Registration.class); |
39 | 44 |
} |
40 | 45 |
|
46 |
|
|
41 | 47 |
/** |
42 | 48 |
* {@inheritDoc} |
43 | 49 |
*/ |
44 | 50 |
@Override |
45 |
public List<Registration> list(IReference reference, Integer limit, Integer start, |
|
46 |
List<String> propertyPaths) { |
|
47 |
|
|
48 |
if (reference != null && reference.getId() == 0){ |
|
49 |
return Collections.emptyList(); |
|
51 |
public Long count(Optional<Reference> reference, Collection<RegistrationStatus> includedStatus) { |
|
52 |
//return 0 for detached volatile references |
|
53 |
if (isVolatile(reference)){ |
|
54 |
return Long.valueOf(0); |
|
50 | 55 |
} |
56 |
Query query = makeReferenceQuery(reference, includedStatus, true); |
|
57 |
@SuppressWarnings("unchecked") |
|
58 |
List<Long> list = query.list(); |
|
59 |
return list.isEmpty()? 0 : list.get(0); |
|
60 |
} |
|
51 | 61 |
|
52 |
String hql = "SELECT DISTINCT r " |
|
53 |
+ " FROM Registration r LEFT JOIN r.typeDesignations desig " |
|
54 |
+ " LEFT JOIN r.name n " |
|
55 |
+ " WHERE (n IS NOT NULL AND n.nomenclaturalReference =:ref)" |
|
56 |
+ " OR desig.citation =:ref " |
|
57 |
+ " ORDER BY r.id "; |
|
58 |
if (reference == null){ |
|
59 |
hql = "SELECT DISTINCT r " |
|
60 |
+ " FROM Registration r LEFT JOIN r.typeDesignations desig " |
|
61 |
+ " LEFT JOIN r.name n" |
|
62 |
+ " WHERE (r.name IS NULL AND size(r.typeDesignations) = 0 ) " |
|
63 |
+ " OR (n IS NOT NULL AND r.name.nomenclaturalReference IS NULL ) " |
|
64 |
+ " OR (size(r.typeDesignations) > 0 AND desig.citation IS NULL ) " |
|
65 |
+ " ORDER BY r.id "; |
|
66 |
} |
|
62 |
/** |
|
63 |
* {@inheritDoc} |
|
64 |
*/ |
|
65 |
@Override |
|
66 |
public List<Registration> list(Optional<Reference> reference, Collection<RegistrationStatus> includedStatus, |
|
67 |
Integer limit, Integer start, List<String> propertyPaths) { |
|
67 | 68 |
|
68 |
Query query = getSession().createQuery(hql); |
|
69 |
if (reference != null){ |
|
70 |
query.setParameter("ref", reference); |
|
69 |
if (isVolatile(reference)){ |
|
70 |
return Collections.emptyList(); |
|
71 | 71 |
} |
72 | 72 |
|
73 |
Query query = makeReferenceQuery(reference, includedStatus, false); |
|
74 |
|
|
73 | 75 |
// TODO complete .... |
74 | 76 |
if(limit != null /*&& !doCount*/) { |
75 | 77 |
query.setMaxResults(limit); |
... | ... | |
80 | 82 |
|
81 | 83 |
//TODO order hints do not work with queries |
82 | 84 |
|
85 |
@SuppressWarnings("unchecked") |
|
83 | 86 |
List<Registration> results = query.list(); |
84 | 87 |
defaultBeanInitializer.initializeAll(results, propertyPaths); |
85 | 88 |
|
... | ... | |
87 | 90 |
} |
88 | 91 |
|
89 | 92 |
/** |
90 |
* {@inheritDoc} |
|
93 |
* @param reference |
|
94 |
* @return |
|
91 | 95 |
*/ |
92 |
@Override |
|
93 |
public Integer count(IReference reference) { |
|
94 |
// TODO Auto-generated method stub |
|
95 |
return null; |
|
96 |
private boolean isVolatile(Optional<Reference> reference) { |
|
97 |
return reference != null && reference.isPresent() && reference.get().getId() == 0; |
|
96 | 98 |
} |
97 | 99 |
|
100 |
/** |
|
101 |
* @param reference |
|
102 |
* @param includedStatus |
|
103 |
* @param isCount |
|
104 |
* @return |
|
105 |
*/ |
|
106 |
private Query makeReferenceQuery(Optional<Reference> reference, |
|
107 |
Collection<RegistrationStatus> includedStatus, |
|
108 |
boolean isCount) { |
|
109 |
|
|
110 |
String select = "SELECT " + (isCount? " count(DISTINCT r) as cn ": "DISTINCT r "); |
|
111 |
String from = " FROM Registration r LEFT JOIN r.typeDesignations desig " |
|
112 |
+ " LEFT JOIN r.name n "; |
|
113 |
String where = " WHERE (1=1) "; |
|
114 |
String orderBy = isCount ? "" : " ORDER BY r.id "; |
|
115 |
|
|
116 |
if (reference == null){ |
|
117 |
//do nothing |
|
118 |
}else if (reference.isPresent()){ |
|
119 |
where += " AND ((n IS NOT NULL AND n.nomenclaturalReference =:ref)" |
|
120 |
+ " OR desig.citation =:ref " |
|
121 |
+ ")"; |
|
122 |
}else{ //ref is null |
|
123 |
where += " AND ((r.name IS NULL AND size(r.typeDesignations) = 0 ) " |
|
124 |
+ " OR (n IS NOT NULL AND r.name.nomenclaturalReference IS NULL ) " |
|
125 |
+ " OR (size(r.typeDesignations) > 0 AND desig.citation IS NULL )" |
|
126 |
+ ") " |
|
127 |
; |
|
128 |
} |
|
129 |
boolean hasStatus = includedStatus != null && !includedStatus.isEmpty(); |
|
130 |
if (hasStatus){ |
|
131 |
where += " AND r.status IN (:status) "; |
|
132 |
} |
|
133 |
|
|
134 |
String hql = select + from + where + orderBy; |
|
135 |
Query query = getSession().createQuery(hql); |
|
136 |
if (reference != null && reference.isPresent()){ |
|
137 |
query.setParameter("ref", reference.get()); |
|
138 |
} |
|
139 |
if (hasStatus){ |
|
140 |
query.setParameterList("status", includedStatus); |
|
141 |
} |
|
142 |
return query; |
|
143 |
} |
|
144 |
|
|
145 |
|
|
98 | 146 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/name/IRegistrationDao.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.persistence.dao.name; |
10 | 10 |
|
11 |
import java.util.Collection; |
|
11 | 12 |
import java.util.List; |
13 |
import java.util.Optional; |
|
12 | 14 |
|
13 | 15 |
import org.springframework.dao.DataAccessException; |
14 | 16 |
|
15 |
import eu.etaxonomy.cdm.model.common.User; |
|
16 | 17 |
import eu.etaxonomy.cdm.model.name.Registration; |
17 |
import eu.etaxonomy.cdm.model.reference.IReference; |
|
18 |
import eu.etaxonomy.cdm.model.name.RegistrationStatus; |
|
19 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
18 | 20 |
import eu.etaxonomy.cdm.persistence.dao.common.IAnnotatableDao; |
19 | 21 |
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer; |
20 | 22 |
|
... | ... | |
23 | 25 |
* @since May 2, 2017 |
24 | 26 |
* |
25 | 27 |
*/ |
26 |
public interface IRegistrationDao extends IAnnotatableDao<Registration> { |
|
28 |
public interface IRegistrationDao |
|
29 |
extends IAnnotatableDao<Registration> { |
|
27 | 30 |
|
28 | 31 |
|
29 | 32 |
/** |
... | ... | |
44 | 47 |
* If <code>null</code> all registrations with a name or type designation |
45 | 48 |
* that has no reference are returned. Also those registrations |
46 | 49 |
* having no name and type designation at all. |
50 |
* @param includedStatus |
|
47 | 51 |
* @param limit |
48 | 52 |
* the maximum number of entities returned (can be <code>null</code> |
49 | 53 |
* to return all entities) |
... | ... | |
52 | 56 |
* @return |
53 | 57 |
* @throws DataAccessException |
54 | 58 |
*/ |
55 |
public List<Registration> list(IReference reference, Integer limit, Integer start, List<String> propertyPaths); |
|
59 |
public List<Registration> list(Optional<Reference> reference, Collection<RegistrationStatus> includedStatus, |
|
60 |
Integer limit, Integer start, List<String> propertyPaths); |
|
56 | 61 |
|
57 | 62 |
/** |
58 | 63 |
* Counts the Registration instances stored in the database. |
59 | 64 |
* |
60 |
* For detailed description see the according list method {@link #list(Integer, Integer, User, List, List)} |
|
61 |
* |
|
62 |
* @param limit |
|
63 |
* the maximum number of entities returned (can be null to return |
|
64 |
* all entities) |
|
65 |
* @param start |
|
66 |
* @param submitter |
|
67 |
* filters the Registration by the submitter, see {@see Registration#getSubmitter()} |
|
68 |
* @param orderHints |
|
69 |
* Supports path like <code>orderHints.propertyNames</code> which |
|
70 |
* include *-to-one properties like createdBy.username or |
|
71 |
* authorTeam.persistentTitleCache |
|
72 |
* @param propertyPaths |
|
65 |
* For detailed description see the according list method |
|
66 |
* {@link #list(Optional, Collection, Integer, Integer, List)}} |
|
73 | 67 |
* |
74 | 68 |
* @return |
75 | 69 |
*/ |
76 |
Integer count(IReference reference);
|
|
70 |
public Long count(Optional<Reference> reference, Collection<RegistrationStatus> includedStatus);
|
|
77 | 71 |
|
78 | 72 |
} |
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/name/RegistrationDaoHibernateImplTest.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.cdm.persistence.dao.hibernate.name; |
10 | 10 |
|
11 | 11 |
import static org.junit.Assert.assertEquals; |
12 |
import static org.junit.Assert.assertFalse; |
|
13 | 12 |
import static org.junit.Assert.assertTrue; |
14 | 13 |
|
15 | 14 |
import java.io.FileNotFoundException; |
15 |
import java.util.ArrayList; |
|
16 | 16 |
import java.util.List; |
17 |
import java.util.Optional; |
|
17 | 18 |
|
18 | 19 |
import org.junit.Before; |
19 | 20 |
import org.junit.Test; |
20 | 21 |
import org.unitils.spring.annotation.SpringBeanByType; |
21 | 22 |
|
22 | 23 |
import eu.etaxonomy.cdm.model.name.Registration; |
24 |
import eu.etaxonomy.cdm.model.name.RegistrationStatus; |
|
23 | 25 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
24 | 26 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
25 | 27 |
import eu.etaxonomy.cdm.model.name.TaxonNameFactory; |
... | ... | |
51 | 53 |
@Test |
52 | 54 |
public void testListByReference() { |
53 | 55 |
List<Registration> registrationList; |
56 |
List<RegistrationStatus> statusList = new ArrayList<>(); |
|
57 |
statusList.add(RegistrationStatus.PUBLISHED); |
|
58 |
Optional<Reference> fullNullReferenceOptional = null; |
|
54 | 59 |
|
55 | 60 |
//test name with ref |
56 | 61 |
TaxonNameBase<?,?> name = TaxonNameFactory.NewBotanicalInstance(null); |
57 |
Reference nomRef = ReferenceFactory.newBook();
|
|
58 |
name.setNomenclaturalReference(nomRef); |
|
62 |
Optional<Reference> nomRef = Optional.of(ReferenceFactory.newBook());
|
|
63 |
name.setNomenclaturalReference(nomRef.get());
|
|
59 | 64 |
Registration registration = Registration.NewInstance(); |
60 | 65 |
registration.setName(name); |
61 | 66 |
registrationDao.save(registration); |
62 |
registrationList = registrationDao.list( nomRef, null, null,null); |
|
63 |
assertFalse("List should not be empty", registrationList.isEmpty()); |
|
67 |
registrationList = registrationDao.list( nomRef, null, null, null,null); |
|
68 |
assertEquals("List should have 1 entry", 1, registrationList.size()); |
|
69 |
long count = registrationDao.count( nomRef, null); |
|
70 |
assertEquals(1, count); |
|
71 |
// ... with status |
|
72 |
registrationList = registrationDao.list( nomRef, statusList, null, null,null); |
|
73 |
assertTrue("List should be empty", registrationList.isEmpty()); |
|
74 |
registration.setStatus(RegistrationStatus.PUBLISHED); |
|
75 |
registrationList = registrationDao.list( nomRef, statusList, null, null,null); |
|
76 |
assertEquals("List should have 1 entry", 1, registrationList.size()); |
|
77 |
registrationList = registrationDao.list( fullNullReferenceOptional, null, null, null,null); |
|
78 |
assertEquals("In total there should be 1 registrations", 1, registrationList.size()); |
|
79 |
|
|
64 | 80 |
|
65 | 81 |
//test type designation with ref |
66 | 82 |
Registration regWithType = Registration.NewInstance(); |
67 |
Reference desigRef = ReferenceFactory.newArticle();
|
|
83 |
Optional<Reference> desigRef = Optional.of(ReferenceFactory.newArticle());
|
|
68 | 84 |
SpecimenTypeDesignation desig = SpecimenTypeDesignation.NewInstance(); |
69 |
desig.setCitation(desigRef); |
|
85 |
desig.setCitation(desigRef.get());
|
|
70 | 86 |
regWithType.addTypeDesignation(desig); |
71 | 87 |
registrationDao.save(regWithType); |
72 |
registrationList = registrationDao.list(desigRef, null, null, null); |
|
88 |
registrationList = registrationDao.list(desigRef, null, null, null, null);
|
|
73 | 89 |
assertEquals("List should have 1 entry", 1, registrationList.size()); |
90 |
count = registrationDao.count( desigRef, null); |
|
91 |
assertEquals(1, count); |
|
92 |
registrationList = registrationDao.list( fullNullReferenceOptional, null, null, null,null); |
|
93 |
assertEquals("In total there should be 2 registrations", 2, registrationList.size()); |
|
74 | 94 |
|
75 | 95 |
//test unused ref |
76 |
Reference newRef = ReferenceFactory.newArticle();
|
|
77 |
registrationList = registrationDao.list(newRef, null, null, null); |
|
96 |
Optional<Reference> newRef = Optional.of(ReferenceFactory.newArticle());
|
|
97 |
registrationList = registrationDao.list(newRef, null, null, null, null);
|
|
78 | 98 |
assertTrue("List should be empty", registrationList.isEmpty()); |
79 | 99 |
//... and saved |
80 |
referenceDao.save(newRef); |
|
81 |
registrationList = registrationDao.list(newRef, null, null, null); |
|
100 |
referenceDao.save(newRef.get());
|
|
101 |
registrationList = registrationDao.list(newRef, null, null, null, null);
|
|
82 | 102 |
assertTrue("List should be empty", registrationList.isEmpty()); |
103 |
count = registrationDao.count( newRef, null); |
|
104 |
assertEquals(0, count); |
|
83 | 105 |
|
84 | 106 |
|
85 | 107 |
//test null |
86 |
Reference nullRef = null;
|
|
87 |
registrationList = registrationDao.list(nullRef, null, null, null); |
|
108 |
Optional<Reference> nullRef = Optional.empty();
|
|
109 |
registrationList = registrationDao.list(nullRef, null, null, null, null);
|
|
88 | 110 |
assertEquals("List should be empty", 0, registrationList.size()); |
111 |
count = registrationDao.count( nullRef, null); |
|
112 |
assertEquals(0, count); |
|
89 | 113 |
|
90 | 114 |
//... name without ref |
91 | 115 |
Registration regWithUnreferenceName = Registration.NewInstance(); |
92 | 116 |
TaxonNameBase<?,?> nameWithoutRef = TaxonNameFactory.NewBotanicalInstance(null); |
93 | 117 |
regWithUnreferenceName.setName(nameWithoutRef); |
94 | 118 |
registrationDao.save(regWithUnreferenceName); |
95 |
registrationList = registrationDao.list(nullRef, null, null, null); |
|
119 |
registrationList = registrationDao.list(nullRef, null, null, null, null);
|
|
96 | 120 |
assertEquals("List should have 1 entry", 1, registrationList.size()); |
121 |
count = registrationDao.count( nullRef, null); |
|
122 |
assertEquals(1, count); |
|
123 |
registrationList = registrationDao.list( fullNullReferenceOptional, null, null, null,null); |
|
124 |
assertEquals("In total there should be 3 registrations", 3, registrationList.size()); |
|
125 |
|
|
97 | 126 |
|
98 | 127 |
//... registration without name and type designation |
99 | 128 |
Registration emptyRegistration = Registration.NewInstance(); |
100 | 129 |
registrationDao.save(emptyRegistration); |
101 |
registrationList = registrationDao.list(nullRef, null, null, null); |
|
130 |
registrationList = registrationDao.list(nullRef, null, null, null, null);
|
|
102 | 131 |
assertEquals("List should have 2 entries now", 2, registrationList.size()); |
132 |
count = registrationDao.count( nullRef, null); |
|
133 |
assertEquals(2, count); |
|
134 |
registrationList = registrationDao.list( fullNullReferenceOptional, null, null, null,null); |
|
135 |
assertEquals("In total there should be 4 registrations", 4, registrationList.size()); |
|
103 | 136 |
|
104 | 137 |
|
105 | 138 |
//test name and type designation with same ref |
106 | 139 |
TaxonNameBase<?,?> additionalName = TaxonNameFactory.NewBotanicalInstance(null); |
107 |
additionalName.setNomenclaturalReference(desigRef); |
|
140 |
additionalName.setNomenclaturalReference(desigRef.get());
|
|
108 | 141 |
regWithType.setName(additionalName); |
109 |
registrationList = registrationDao.list( desigRef, null, null,null);
|
|
142 |
registrationList = registrationDao.list(desigRef, null, null, null,null);
|
|
110 | 143 |
assertEquals("List should still have 1 entry", 1, registrationList.size()); |
111 | 144 |
assertEquals("",regWithType, registrationList.get(0)); |
145 |
count = registrationDao.count( desigRef, null); |
|
146 |
assertEquals(1, count); |
|
112 | 147 |
|
113 | 148 |
//test dirty data (it is sufficient that 1 reference matches, not necessarily all) |
114 | 149 |
SpecimenTypeDesignation desig2 = SpecimenTypeDesignation.NewInstance(); |
115 |
Reference otherRef = ReferenceFactory.newGeneric();
|
|
116 |
desig2.setCitation(otherRef); |
|
150 |
Optional<Reference> otherRef = Optional.of(ReferenceFactory.newGeneric());
|
|
151 |
desig2.setCitation(otherRef.get());
|
|
117 | 152 |
regWithType.addTypeDesignation(desig2); |
118 | 153 |
registrationDao.saveOrUpdate(regWithType); |
119 |
registrationList = registrationDao.list( desigRef, null, null,null); |
|
154 |
registrationList = registrationDao.list( desigRef, null, null, null,null);
|
|
120 | 155 |
assertEquals("List should still have 1 entry", 1, registrationList.size()); |
121 | 156 |
assertEquals("",regWithType, registrationList.get(0)); |
122 |
registrationList = registrationDao.list( otherRef, null, null,null); |
|
157 |
registrationList = registrationDao.list( otherRef, null, null, null,null);
|
|
123 | 158 |
assertEquals("Also for otherRef the registration should be found", 1, registrationList.size()); |
124 |
assertEquals("",regWithType, registrationList.get(0)); |
|
159 |
assertEquals("", regWithType, registrationList.get(0)); |
|
160 |
count = registrationDao.count( otherRef, null); |
|
161 |
assertEquals(1, count); |
|
162 |
registrationList = registrationDao.list( fullNullReferenceOptional, null, null, null,null); |
|
163 |
assertEquals("In total there should be 4 registrations", 4, registrationList.size()); |
|
125 | 164 |
|
126 | 165 |
//> 1 |
127 | 166 |
Registration registration2 = Registration.NewInstance(); |
128 | 167 |
TaxonNameBase<?,?> name2 = TaxonNameFactory.NewBotanicalInstance(null); |
129 |
name2.setNomenclaturalReference(desigRef); |
|
168 |
name2.setNomenclaturalReference(desigRef.get());
|
|
130 | 169 |
registration2.setName(name2); |
131 | 170 |
registrationDao.save(registration2); |
132 | 171 |
|
133 | 172 |
Registration registration3 = Registration.NewInstance(); |
134 | 173 |
TaxonNameBase<?,?> name3 = TaxonNameFactory.NewBotanicalInstance(null); |
135 |
name3.setNomenclaturalReference(desigRef); |
|
174 |
name3.setNomenclaturalReference(desigRef.get());
|
|
136 | 175 |
registration3.setName(name3); |
137 | 176 |
registrationDao.save(registration3); |
138 | 177 |
|
139 | 178 |
Registration registration4 = Registration.NewInstance(); |
140 | 179 |
SpecimenTypeDesignation desig4 = SpecimenTypeDesignation.NewInstance(); |
141 |
desig4.setCitation(desigRef); |
|
180 |
desig4.setCitation(desigRef.get());
|
|
142 | 181 |
registration4.addTypeDesignation(desig4); |
143 | 182 |
registrationDao.save(registration4); |
144 | 183 |
|
145 |
registrationList = registrationDao.list( desigRef, null, null,null); |
|
184 |
registrationList = registrationDao.list( fullNullReferenceOptional, null, null, null,null); |
|
185 |
assertEquals("In total there should be 7 registrations", 7, registrationList.size()); |
|
186 |
|
|
187 |
count = registrationDao.count( desigRef, null); |
|
188 |
assertEquals(4, count); |
|
189 |
registrationList = registrationDao.list( desigRef, null, null, null,null); |
|
146 | 190 |
assertEquals("List should have 4 entries", 4, registrationList.size()); |
147 |
registrationList = registrationDao.list( desigRef, 3, null,null); |
|
191 |
registrationList = registrationDao.list( desigRef, null, 3, null,null);
|
|
148 | 192 |
assertEquals("List should have 3 entries", 3, registrationList.size()); |
149 |
registrationList = registrationDao.list( desigRef, 3, 2,null); |
|
193 |
registrationList = registrationDao.list( desigRef, null, 3, 2,null);
|
|
150 | 194 |
assertEquals("List should have 2 entries", 2, registrationList.size()); |
151 | 195 |
|
196 |
registrationList = registrationDao.list( fullNullReferenceOptional, statusList, null, null,null); |
|
197 |
assertEquals("In total there should be 1 registration with status published", 1, registrationList.size()); |
|
198 |
|
|
199 |
statusList.add(RegistrationStatus.PREPARATION); |
|
200 |
registrationList = registrationDao.list( fullNullReferenceOptional, statusList, null, null,null); |
|
201 |
assertEquals("In total there should be 7 registration with status preparation or published", 7, registrationList.size()); |
|
202 |
statusList.remove(RegistrationStatus.PUBLISHED); |
|
203 |
registrationList = registrationDao.list( fullNullReferenceOptional, statusList, null, null,null); |
|
204 |
assertEquals("In total there should be 6 registration with status preparation", 6, registrationList.size()); |
|
205 |
|
|
152 | 206 |
} |
153 | 207 |
|
154 | 208 |
/** |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IRegistrationService.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import java.util.Collection; |
12 | 12 |
import java.util.List; |
13 |
import java.util.Optional; |
|
13 | 14 |
|
14 | 15 |
import org.springframework.dao.DataAccessException; |
15 | 16 |
|
... | ... | |
17 | 18 |
import eu.etaxonomy.cdm.model.common.User; |
18 | 19 |
import eu.etaxonomy.cdm.model.name.Registration; |
19 | 20 |
import eu.etaxonomy.cdm.model.name.RegistrationStatus; |
20 |
import eu.etaxonomy.cdm.model.reference.IReference;
|
|
21 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
21 | 22 |
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer; |
22 | 23 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
23 | 24 |
|
... | ... | |
44 | 45 |
* @param reference |
45 | 46 |
* filters the Registration by the reference of the nomenclatural act for which the |
46 | 47 |
* Registration as been created. The name and all type designations associated with |
47 |
* the Registration are sharing the same citation and citation detail. |
|
48 |
* @param includeStatus |
|
48 |
* the Registration are sharing the same citation. |
|
49 |
* If the Optional itself is <code>null</code> the parameter is neglected. |
|
50 |
* If Optional contains the value <code>null</code> all registrations with a name |
|
51 |
* or type designation that has no reference are returned. |
|
52 |
* Also those registrations having no name and type designation at all. |
|
53 |
* @param includedStatus |
|
49 | 54 |
* filters the Registration by the RegistrationStatus. Only Registration having one of the |
50 | 55 |
* supplied status will included. |
51 |
* @param orderHints |
|
52 |
* Supports path like <code>orderHints.propertyNames</code> which |
|
53 |
* include *-to-one properties like createdBy.username or |
|
54 |
* authorTeam.persistentTitleCache |
|
56 |
// * @param orderHints
|
|
57 |
// * Supports path like <code>orderHints.propertyNames</code> which
|
|
58 |
// * include *-to-one properties like createdBy.username or
|
|
59 |
// * authorTeam.persistentTitleCache
|
|
55 | 60 |
* @param propertyPaths |
56 | 61 |
* @return |
57 | 62 |
* @throws DataAccessException |
58 | 63 |
*/ |
59 |
public Pager<Registration> page(Integer pageSize, Integer pageIndex, IReference reference, Collection<RegistrationStatus> includeStatus, List<OrderHint> orderHints, List<String> propertyPaths); |
|
64 |
public Pager<Registration> page(Optional<Reference> reference, Collection<RegistrationStatus> includedStatus, |
|
65 |
Integer pageSize, Integer pageIndex, List<String> propertyPaths); |
|
60 | 66 |
|
61 | 67 |
/** |
62 | 68 |
* Returns a sublist of Registration instances stored in the database. A maximum |
... | ... | |
73 | 79 |
* can be null, equivalent of starting at the beginning of the recordset) |
74 | 80 |
* @param submitter |
75 | 81 |
* The user who submitted the Registration |
76 |
* @param includeStatus |
|
82 |
* @param includedStatus
|
|
77 | 83 |
* filters the Registration by the RegistrationStatus. Only Registration having one of |
78 | 84 |
* the supplied status will included. |
79 | 85 |
* @param orderHints |
... | ... | |
84 | 90 |
* @return |
85 | 91 |
* @throws DataAccessException |
86 | 92 |
*/ |
87 |
public Pager<Registration> page(Integer pageSize, Integer pageIndex, User submitter, Collection<RegistrationStatus> includeStatus, List<OrderHint> orderHints, List<String> propertyPaths); |
|
93 |
public Pager<Registration> page(User submitter, Collection<RegistrationStatus> includedStatus, |
|
94 |
Integer pageSize, Integer pageIndex, List<OrderHint> orderHints, List<String> propertyPaths); |
|
88 | 95 |
|
89 | 96 |
|
90 | 97 |
|
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/RegistrationServiceImpl.java | ||
---|---|---|
11 | 11 |
import java.util.ArrayList; |
12 | 12 |
import java.util.Collection; |
13 | 13 |
import java.util.List; |
14 |
import java.util.Optional; |
|
14 | 15 |
|
15 | 16 |
import org.springframework.beans.factory.annotation.Autowired; |
16 | 17 |
import org.springframework.stereotype.Service; |
... | ... | |
23 | 24 |
import eu.etaxonomy.cdm.model.common.User; |
24 | 25 |
import eu.etaxonomy.cdm.model.name.Registration; |
25 | 26 |
import eu.etaxonomy.cdm.model.name.RegistrationStatus; |
26 |
import eu.etaxonomy.cdm.model.reference.IReference;
|
|
27 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
27 | 28 |
import eu.etaxonomy.cdm.persistence.dao.name.IRegistrationDao; |
28 | 29 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
29 | 30 |
|
... | ... | |
49 | 50 |
* {@inheritDoc} |
50 | 51 |
*/ |
51 | 52 |
@Override |
52 |
public Pager<Registration> page(Integer pageSize, Integer pageIndex, IReference reference,
|
|
53 |
Collection<RegistrationStatus> includeStatus, List<OrderHint> orderHints, List<String> propertyPaths) {
|
|
53 |
public Pager<Registration> page(Optional<Reference> reference, Collection<RegistrationStatus> includedStatus,
|
|
54 |
Integer pageSize, Integer pageIndex, List<String> propertyPaths) {
|
|
54 | 55 |
|
55 |
long numberOfResults = dao.count(reference); |
|
56 |
long numberOfResults = dao.count(reference, includedStatus);
|
|
56 | 57 |
|
57 | 58 |
List<Registration> results = new ArrayList<>(); |
58 | 59 |
if(AbstractPagerImpl.hasResultsInRange(numberOfResults, pageIndex, pageSize)) { |
59 | 60 |
Integer limit = PagerUtils.limitFor(pageSize); |
60 | 61 |
Integer start = PagerUtils.startFor(pageSize, pageIndex); |
61 |
results = dao.list(reference, limit, start, propertyPaths); |
|
62 |
results = dao.list(reference, includedStatus, limit, start, propertyPaths);
|
|
62 | 63 |
} |
63 | 64 |
|
64 | 65 |
return new DefaultPagerImpl<>(pageIndex, numberOfResults, pageSize, results); |
... | ... | |
66 | 67 |
|
67 | 68 |
/** |
68 | 69 |
* {@inheritDoc} |
70 |
* TODO: includedStatus not yet implemented |
|
69 | 71 |
*/ |
70 | 72 |
@Override |
71 |
public Pager<Registration> page(Integer pageSize, Integer pageIndex, User submitter, Collection<RegistrationStatus> includeStatus,
|
|
72 |
List<OrderHint> orderHints, List<String> propertyPaths) { |
|
73 |
public Pager<Registration> page(User submitter, Collection<RegistrationStatus> includedStatus,
|
|
74 |
Integer pageSize, Integer pageIndex, List<OrderHint> orderHints, List<String> propertyPaths) {
|
|
73 | 75 |
|
74 | 76 |
long numberOfResults = dao.count(Registration.class, "submitter", submitter, null); |
75 | 77 |
|
Also available in: Unified diff
ref #6612 implement count for listByRef and add implement filtering by status in listByRef