1 |
c2f269f9
|
Andreas Kohlbecker
|
// $Id$
|
2 |
25663b56
|
Andreas Müller
|
/**
|
3 |
|
|
* Copyright (C) 2007 EDIT
|
4 |
60802362
|
Andreas Kohlbecker
|
* European Distributed Institute of Taxonomy
|
5 |
25663b56
|
Andreas Müller
|
* http://www.e-taxonomy.eu
|
6 |
60802362
|
Andreas Kohlbecker
|
*
|
7 |
25663b56
|
Andreas Müller
|
* 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 |
|
|
|
11 |
2d993c6e
|
Andreas Müller
|
package eu.etaxonomy.cdm.api.service;
|
12 |
|
|
|
13 |
676033bb
|
Cherian Mathew
|
import java.io.IOException;
|
14 |
d57c0df0
|
ben.clark
|
import java.util.ArrayList;
|
15 |
835342d0
|
Andreas Müller
|
import java.util.Collection;
|
16 |
676033bb
|
Cherian Mathew
|
import java.util.HashMap;
|
17 |
ad45fc6d
|
Andreas Müller
|
import java.util.HashSet;
|
18 |
835342d0
|
Andreas Müller
|
import java.util.List;
|
19 |
|
|
import java.util.Map;
|
20 |
59e259f3
|
Andreas Müller
|
import java.util.Set;
|
21 |
835342d0
|
Andreas Müller
|
import java.util.UUID;
|
22 |
|
|
|
23 |
2d993c6e
|
Andreas Müller
|
import org.apache.log4j.Logger;
|
24 |
cb312388
|
Cherian Mathew
|
import org.apache.lucene.analysis.SimpleAnalyzer;
|
25 |
676033bb
|
Cherian Mathew
|
import org.apache.lucene.index.CorruptIndexException;
|
26 |
|
|
import org.apache.lucene.index.Term;
|
27 |
|
|
import org.apache.lucene.queryParser.ParseException;
|
28 |
|
|
import org.apache.lucene.search.BooleanQuery;
|
29 |
cb312388
|
Cherian Mathew
|
import org.apache.lucene.search.Explanation;
|
30 |
|
|
import org.apache.lucene.search.FuzzyLikeThisQuery;
|
31 |
|
|
import org.apache.lucene.search.Query;
|
32 |
676033bb
|
Cherian Mathew
|
import org.apache.lucene.search.SortField;
|
33 |
|
|
import org.apache.lucene.search.BooleanClause.Occur;
|
34 |
cb312388
|
Cherian Mathew
|
import org.apache.lucene.search.TermQuery;
|
35 |
676033bb
|
Cherian Mathew
|
import org.apache.lucene.search.TopDocs;
|
36 |
cb312388
|
Cherian Mathew
|
import org.apache.lucene.search.WildcardQuery;
|
37 |
676033bb
|
Cherian Mathew
|
import org.apache.lucene.search.regex.RegexQuery;
|
38 |
cb312388
|
Cherian Mathew
|
import org.apache.lucene.util.Version;
|
39 |
c4e812bc
|
ben.clark
|
import org.hibernate.criterion.Criterion;
|
40 |
2d993c6e
|
Andreas Müller
|
import org.springframework.beans.factory.annotation.Autowired;
|
41 |
069095b0
|
a.babadshanjan
|
import org.springframework.beans.factory.annotation.Qualifier;
|
42 |
2d993c6e
|
Andreas Müller
|
import org.springframework.stereotype.Service;
|
43 |
|
|
import org.springframework.transaction.annotation.Transactional;
|
44 |
|
|
|
45 |
692ecda8
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
|
46 |
77a59193
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
|
47 |
d57c0df0
|
ben.clark
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
48 |
76de813f
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.api.service.pager.impl.AbstractPagerImpl;
|
49 |
d57c0df0
|
ben.clark
|
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
|
50 |
cb312388
|
Cherian Mathew
|
import eu.etaxonomy.cdm.api.service.search.DocumentSearchResult;
|
51 |
676033bb
|
Cherian Mathew
|
import eu.etaxonomy.cdm.api.service.search.ISearchResultBuilder;
|
52 |
|
|
import eu.etaxonomy.cdm.api.service.search.LuceneSearch;
|
53 |
|
|
import eu.etaxonomy.cdm.api.service.search.QueryFactory;
|
54 |
|
|
import eu.etaxonomy.cdm.api.service.search.SearchResult;
|
55 |
|
|
import eu.etaxonomy.cdm.api.service.search.SearchResultBuilder;
|
56 |
79c0eaa0
|
Andreas Müller
|
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
|
57 |
676033bb
|
Cherian Mathew
|
import eu.etaxonomy.cdm.model.CdmBaseType;
|
58 |
06cf1237
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
59 |
59e259f3
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.DescriptionElementSource;
|
60 |
676033bb
|
Cherian Mathew
|
import eu.etaxonomy.cdm.model.common.Language;
|
61 |
de7b09aa
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
|
62 |
b663dd6a
|
a.babadshanjan
|
import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
|
63 |
e05a4f8d
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
64 |
80f41560
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
|
65 |
fbd2aad8
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
66 |
82c4b637
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
|
67 |
488d0b2c
|
a.babadshanjan
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
68 |
d57c0df0
|
ben.clark
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
69 |
|
|
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
|
70 |
|
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
71 |
835342d0
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
72 |
ec301055
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
73 |
7a50082f
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
74 |
835342d0
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
75 |
7a1d87e3
|
a.babadshanjan
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
76 |
835342d0
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.Rank;
|
77 |
2a56d8c1
|
ben.clark
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
78 |
835342d0
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
79 |
7a50082f
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
80 |
59e259f3
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
|
81 |
|
|
import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao;
|
82 |
835342d0
|
Andreas Müller
|
import eu.etaxonomy.cdm.persistence.dao.common.IOrderedTermVocabularyDao;
|
83 |
6a03e3f0
|
a.babadshanjan
|
import eu.etaxonomy.cdm.persistence.dao.common.IReferencedEntityDao;
|
84 |
de7b09aa
|
Andreas Müller
|
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
|
85 |
488d0b2c
|
a.babadshanjan
|
import eu.etaxonomy.cdm.persistence.dao.name.IHomotypicalGroupDao;
|
86 |
7a50082f
|
Andreas Müller
|
import eu.etaxonomy.cdm.persistence.dao.name.INomenclaturalStatusDao;
|
87 |
2d993c6e
|
Andreas Müller
|
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;
|
88 |
7a50082f
|
Andreas Müller
|
import eu.etaxonomy.cdm.persistence.dao.name.ITypeDesignationDao;
|
89 |
f779051f
|
Andreas Müller
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
90 |
d44277a9
|
ben.clark
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
91 |
e1650418
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
|
92 |
f197a589
|
Andreas Müller
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
93 |
676033bb
|
Cherian Mathew
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
94 |
2d993c6e
|
Andreas Müller
|
|
95 |
|
|
|
96 |
|
|
@Service
|
97 |
77b4a247
|
Andreas Kohlbecker
|
@Transactional(readOnly = true)
|
98 |
d57c0df0
|
ben.clark
|
public class NameServiceImpl extends IdentifiableServiceBase<TaxonNameBase,ITaxonNameDao> implements INameService {
|
99 |
60802362
|
Andreas Kohlbecker
|
static private final Logger logger = Logger.getLogger(NameServiceImpl.class);
|
100 |
|
|
|
101 |
|
|
@Autowired
|
102 |
|
|
protected ITermVocabularyDao vocabularyDao;
|
103 |
|
|
@Autowired
|
104 |
|
|
protected IOrderedTermVocabularyDao orderedVocabularyDao;
|
105 |
|
|
@Autowired
|
106 |
|
|
@Qualifier("refEntDao")
|
107 |
069095b0
|
a.babadshanjan
|
protected IReferencedEntityDao<ReferencedEntityBase> referencedEntityDao;
|
108 |
60802362
|
Andreas Kohlbecker
|
@Autowired
|
109 |
|
|
private INomenclaturalStatusDao nomStatusDao;
|
110 |
|
|
@Autowired
|
111 |
|
|
private ITypeDesignationDao typeDesignationDao;
|
112 |
|
|
@Autowired
|
113 |
|
|
private IHomotypicalGroupDao homotypicalGroupDao;
|
114 |
51fe2d8a
|
Andreas Kohlbecker
|
@Autowired
|
115 |
|
|
private ICdmGenericDao genericDao;
|
116 |
60802362
|
Andreas Kohlbecker
|
|
117 |
|
|
/**
|
118 |
|
|
* Constructor
|
119 |
|
|
*/
|
120 |
|
|
public NameServiceImpl(){
|
121 |
|
|
if (logger.isDebugEnabled()) { logger.debug("Load NameService Bean"); }
|
122 |
|
|
}
|
123 |
|
|
|
124 |
51fe2d8a
|
Andreas Kohlbecker
|
//********************* METHODS ****************************************************************//
|
125 |
|
|
|
126 |
|
|
/* (non-Javadoc)
|
127 |
|
|
* @see eu.etaxonomy.cdm.api.service.ServiceBase#delete(eu.etaxonomy.cdm.model.common.CdmBase)
|
128 |
|
|
*/
|
129 |
|
|
@Override
|
130 |
|
|
public UUID delete(TaxonNameBase name){
|
131 |
|
|
NameDeletionConfigurator config = new NameDeletionConfigurator();
|
132 |
|
|
try {
|
133 |
|
|
return delete(name, config);
|
134 |
|
|
} catch (ReferencedObjectUndeletableException e) {
|
135 |
|
|
//TODO throw DeleteException - current implementation is preliminary for testing
|
136 |
|
|
throw new RuntimeException(e);
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
/* (non-Javadoc)
|
141 |
|
|
* @see eu.etaxonomy.cdm.api.service.INameService#delete(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.api.service.NameDeletionConfigurator)
|
142 |
|
|
*/
|
143 |
|
|
@Override
|
144 |
|
|
public UUID delete(TaxonNameBase name, NameDeletionConfigurator config) throws ReferencedObjectUndeletableException{
|
145 |
|
|
if (name == null){
|
146 |
|
|
return null;
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
//remove references to this name
|
150 |
|
|
removeNameRelationshipsByDeleteConfig(name, config);
|
151 |
|
|
|
152 |
|
|
//check if this name is still used somewhere
|
153 |
|
|
|
154 |
|
|
//name relationships
|
155 |
|
|
if (! name.getNameRelations().isEmpty()){
|
156 |
|
|
String message = "Name can't be deleted as it is used in name relationship(s). Remove name relationships prior to deletion.";
|
157 |
|
|
throw new ReferencedObjectUndeletableException(message);
|
158 |
692ecda8
|
Andreas Müller
|
// return null;
|
159 |
51fe2d8a
|
Andreas Kohlbecker
|
}
|
160 |
|
|
|
161 |
|
|
//concepts
|
162 |
|
|
if (! name.getTaxonBases().isEmpty()){
|
163 |
|
|
String message = "Name can't be deleted as it is used in concept(s). Remove or change concept prior to deletion.";
|
164 |
|
|
throw new ReferencedObjectUndeletableException(message);
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
//hybrid relationships
|
168 |
|
|
if (name.isInstanceOf(NonViralName.class)){
|
169 |
|
|
NonViralName nvn = CdmBase.deproxy(name, NonViralName.class);
|
170 |
0707577b
|
Andreas Müller
|
// if (! nvn.getHybridChildRelations().isEmpty()){
|
171 |
|
|
// String message = "Name can't be deleted as it is a child in (a) hybrid relationship(s). Remove hybrid relationships prior to deletion.";
|
172 |
|
|
// throw new RuntimeException(message);
|
173 |
|
|
// }
|
174 |
51fe2d8a
|
Andreas Kohlbecker
|
if (! nvn.getHybridParentRelations().isEmpty()){
|
175 |
|
|
String message = "Name can't be deleted as it is a parent in (a) hybrid relationship(s). Remove hybrid relationships prior to deletion.";
|
176 |
|
|
throw new ReferencedObjectUndeletableException(message);
|
177 |
|
|
}
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
//all type designation relationships are removed as they belong to the name
|
181 |
|
|
deleteTypeDesignation(name, null);
|
182 |
ec301055
|
Andreas Müller
|
// //type designations
|
183 |
|
|
// if (! name.getTypeDesignations().isEmpty()){
|
184 |
|
|
// String message = "Name can't be deleted as it has types. Remove types prior to deletion.";
|
185 |
692ecda8
|
Andreas Müller
|
// throw new ReferrencedObjectUndeletableException(message);
|
186 |
ec301055
|
Andreas Müller
|
// }
|
187 |
80f41560
|
Andreas Müller
|
|
188 |
51fe2d8a
|
Andreas Kohlbecker
|
//check references with only reverse mapping
|
189 |
|
|
Set<CdmBase> referencingObjects = genericDao.getReferencingObjects(name);
|
190 |
|
|
for (CdmBase referencingObject : referencingObjects){
|
191 |
|
|
//DerivedUnitBase?.storedUnder
|
192 |
|
|
if (referencingObject.isInstanceOf(DerivedUnitBase.class)){
|
193 |
|
|
String message = "Name can't be deleted as it is used as derivedUnit#storedUnder by %s. Remove 'stored under' prior to deleting this name";
|
194 |
|
|
message = String.format(message, CdmBase.deproxy(referencingObject, DerivedUnitBase.class).getTitleCache());
|
195 |
|
|
throw new ReferencedObjectUndeletableException(message);
|
196 |
|
|
}
|
197 |
|
|
//DescriptionElementSource#nameUsedInSource
|
198 |
|
|
if (referencingObject.isInstanceOf(DescriptionElementSource.class)){
|
199 |
|
|
String message = "Name can't be deleted as it is used as descriptionElementSource#nameUsedInSource";
|
200 |
|
|
throw new ReferencedObjectUndeletableException(message);
|
201 |
|
|
}
|
202 |
|
|
//NameTypeDesignation#typeName
|
203 |
|
|
if (referencingObject.isInstanceOf(NameTypeDesignation.class)){
|
204 |
|
|
String message = "Name can't be deleted as it is used as a name type in a NameTypeDesignation";
|
205 |
|
|
throw new ReferencedObjectUndeletableException(message);
|
206 |
|
|
}
|
207 |
|
|
|
208 |
|
|
//TaxonNameDescriptions#taxonName
|
209 |
|
|
//deleted via cascade?
|
210 |
|
|
|
211 |
|
|
//NomenclaturalStatus
|
212 |
|
|
//deleted via cascade?
|
213 |
|
|
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
//TODO inline references
|
217 |
|
|
|
218 |
|
|
dao.delete(name);
|
219 |
|
|
return name.getUuid();
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
/* (non-Javadoc)
|
223 |
|
|
* @see eu.etaxonomy.cdm.api.service.INameService#deleteTypeDesignation(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.model.name.TypeDesignationBase)
|
224 |
|
|
*/
|
225 |
|
|
@Override
|
226 |
|
|
public void deleteTypeDesignation(TaxonNameBase name, TypeDesignationBase typeDesignation){
|
227 |
|
|
if (name == null && typeDesignation == null){
|
228 |
|
|
return;
|
229 |
|
|
}else if (name != null && typeDesignation != null){
|
230 |
|
|
removeSingleDesignation(name, typeDesignation);
|
231 |
|
|
}else if (name != null){
|
232 |
|
|
Set<TypeDesignationBase> designationSet = new HashSet<TypeDesignationBase>(name.getTypeDesignations());
|
233 |
|
|
for (Object o : designationSet){
|
234 |
|
|
TypeDesignationBase desig = CdmBase.deproxy(o, TypeDesignationBase.class);
|
235 |
|
|
removeSingleDesignation(name, desig);
|
236 |
|
|
}
|
237 |
|
|
}else if (typeDesignation != null){
|
238 |
|
|
Set<TaxonNameBase> nameSet = new HashSet<TaxonNameBase>(typeDesignation.getTypifiedNames());
|
239 |
|
|
for (Object o : nameSet){
|
240 |
|
|
TaxonNameBase singleName = CdmBase.deproxy(o, TaxonNameBase.class);
|
241 |
|
|
removeSingleDesignation(singleName, typeDesignation);
|
242 |
|
|
}
|
243 |
|
|
}
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
/**
|
247 |
|
|
* @param name
|
248 |
|
|
* @param typeDesignation
|
249 |
|
|
*/
|
250 |
|
|
private void removeSingleDesignation(TaxonNameBase name, TypeDesignationBase typeDesignation) {
|
251 |
|
|
name.removeTypeDesignation(typeDesignation);
|
252 |
|
|
if (typeDesignation.getTypifiedNames().isEmpty()){
|
253 |
|
|
typeDesignation.removeType();
|
254 |
|
|
typeDesignationDao.delete(typeDesignation);
|
255 |
|
|
}
|
256 |
|
|
}
|
257 |
60802362
|
Andreas Kohlbecker
|
|
258 |
59e259f3
|
Andreas Müller
|
|
259 |
51fe2d8a
|
Andreas Kohlbecker
|
|
260 |
|
|
/**
|
261 |
|
|
* @param name
|
262 |
|
|
* @param config
|
263 |
|
|
*/
|
264 |
|
|
private void removeNameRelationshipsByDeleteConfig(TaxonNameBase name, NameDeletionConfigurator config) {
|
265 |
|
|
if (config.isRemoveAllNameRelationships()){
|
266 |
|
|
Set<NameRelationship> rels = name.getNameRelations();
|
267 |
|
|
for (NameRelationship rel : rels){
|
268 |
|
|
name.removeNameRelationship(rel);
|
269 |
|
|
}
|
270 |
|
|
}else{
|
271 |
|
|
//relations to this name
|
272 |
|
|
Set<NameRelationship> rels = name.getRelationsToThisName();
|
273 |
|
|
for (NameRelationship rel : rels){
|
274 |
|
|
if (config.isIgnoreHasBasionym() && NameRelationshipType.BASIONYM().equals(rel.getType() )){
|
275 |
|
|
name.removeNameRelationship(rel);
|
276 |
|
|
}else if (config.isIgnoreHasReplacedSynonym() && NameRelationshipType.REPLACED_SYNONYM().equals(rel.getType())){
|
277 |
|
|
name.removeNameRelationship(rel);
|
278 |
|
|
}
|
279 |
|
|
}
|
280 |
|
|
//relations from this name
|
281 |
|
|
rels = name.getRelationsFromThisName();
|
282 |
|
|
for (NameRelationship rel : rels){
|
283 |
|
|
if (config.isIgnoreIsBasionymFor() && NameRelationshipType.BASIONYM().equals(rel.getType()) ){
|
284 |
|
|
name.removeNameRelationship(rel);
|
285 |
|
|
}else if (config.isIgnoreIsReplacedSynonymFor() && NameRelationshipType.REPLACED_SYNONYM().equals(rel.getType())){
|
286 |
|
|
name.removeNameRelationship(rel);
|
287 |
|
|
}
|
288 |
|
|
}
|
289 |
|
|
|
290 |
|
|
}
|
291 |
|
|
}
|
292 |
|
|
|
293 |
|
|
//********************* METHODS ****************************************************************//
|
294 |
|
|
|
295 |
|
|
/**
|
296 |
|
|
* @deprecated To be removed for harmonization see http://dev.e-taxonomy.eu/trac/wiki/CdmLibraryConventions
|
297 |
e80bea19
|
Andreas Kohlbecker
|
* duplicate of findByName
|
298 |
51fe2d8a
|
Andreas Kohlbecker
|
*/
|
299 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
300 |
51fe2d8a
|
Andreas Kohlbecker
|
@Deprecated
|
301 |
60802362
|
Andreas Kohlbecker
|
public List getNamesByName(String name){
|
302 |
|
|
return super.findCdmObjectsByTitle(name);
|
303 |
|
|
}
|
304 |
|
|
|
305 |
51fe2d8a
|
Andreas Kohlbecker
|
/**
|
306 |
e80bea19
|
Andreas Kohlbecker
|
* TODO candidate for harmonization
|
307 |
|
|
* new name findByName
|
308 |
51fe2d8a
|
Andreas Kohlbecker
|
*/
|
309 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
310 |
60802362
|
Andreas Kohlbecker
|
public List<NonViralName> getNamesByNameCache(String nameCache){
|
311 |
|
|
List result = dao.findByName(nameCache, MatchMode.EXACT, null, null, null, null);
|
312 |
|
|
return result;
|
313 |
|
|
}
|
314 |
51fe2d8a
|
Andreas Kohlbecker
|
|
315 |
|
|
|
316 |
|
|
/**
|
317 |
e80bea19
|
Andreas Kohlbecker
|
* TODO candidate for harmonization
|
318 |
|
|
* new name saveHomotypicalGroups
|
319 |
|
|
*
|
320 |
|
|
* findByTitle
|
321 |
51fe2d8a
|
Andreas Kohlbecker
|
*/
|
322 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
323 |
7a4c11ed
|
Cherian Mathew
|
public List<NonViralName> findNamesByTitleCache(String titleCache, MatchMode matchMode, List<String> propertyPaths){
|
324 |
|
|
List result = dao.findByTitle(titleCache, matchMode, null, null, null ,propertyPaths);
|
325 |
|
|
return result;
|
326 |
|
|
}
|
327 |
f2fdd2e7
|
Andreas Kohlbecker
|
|
328 |
4acc3f44
|
Cherian Mathew
|
/**
|
329 |
|
|
* TODO candidate for harmonization
|
330 |
|
|
* new name saveHomotypicalGroups
|
331 |
|
|
*
|
332 |
|
|
* findByTitle
|
333 |
|
|
*/
|
334 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
335 |
4acc3f44
|
Cherian Mathew
|
public List<NonViralName> findNamesByNameCache(String nameCache, MatchMode matchMode, List<String> propertyPaths){
|
336 |
|
|
List result = dao.findByName(nameCache, matchMode, null, null, null ,propertyPaths);
|
337 |
|
|
return result;
|
338 |
|
|
}
|
339 |
51fe2d8a
|
Andreas Kohlbecker
|
|
340 |
|
|
/**
|
341 |
|
|
* @deprecated To be removed for harmonization see http://dev.e-taxonomy.eu/trac/wiki/CdmLibraryConventions
|
342 |
a13c5f66
|
Andreas Müller
|
* Replace by load(UUID, propertyPaths)
|
343 |
51fe2d8a
|
Andreas Kohlbecker
|
*/
|
344 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
345 |
51fe2d8a
|
Andreas Kohlbecker
|
@Deprecated
|
346 |
7a4c11ed
|
Cherian Mathew
|
public NonViralName findNameByUuid(UUID uuid, List<String> propertyPaths){
|
347 |
51fe2d8a
|
Andreas Kohlbecker
|
return (NonViralName)dao.findByUuid(uuid, null ,propertyPaths);
|
348 |
7a4c11ed
|
Cherian Mathew
|
}
|
349 |
60802362
|
Andreas Kohlbecker
|
|
350 |
51fe2d8a
|
Andreas Kohlbecker
|
/**
|
351 |
e80bea19
|
Andreas Kohlbecker
|
* TODO candidate for harmonization
|
352 |
51fe2d8a
|
Andreas Kohlbecker
|
*/
|
353 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
354 |
60802362
|
Andreas Kohlbecker
|
public List getNamesByName(String name, CdmBase sessionObject){
|
355 |
|
|
return super.findCdmObjectsByTitle(name, sessionObject);
|
356 |
|
|
}
|
357 |
|
|
|
358 |
51fe2d8a
|
Andreas Kohlbecker
|
/**
|
359 |
|
|
* @deprecated To be removed for harmonization see http://dev.e-taxonomy.eu/trac/wiki/CdmLibraryConventions
|
360 |
|
|
* duplicate of findByTitle(clazz, queryString, matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths)
|
361 |
|
|
*/
|
362 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
363 |
51fe2d8a
|
Andreas Kohlbecker
|
@Deprecated
|
364 |
60802362
|
Andreas Kohlbecker
|
public List findNamesByTitle(String title){
|
365 |
|
|
return super.findCdmObjectsByTitle(title);
|
366 |
|
|
}
|
367 |
|
|
|
368 |
51fe2d8a
|
Andreas Kohlbecker
|
/**
|
369 |
|
|
* @deprecated To be removed for harmonization see http://dev.e-taxonomy.eu/trac/wiki/CdmLibraryConventions
|
370 |
e80bea19
|
Andreas Kohlbecker
|
* duplicate of findByTitle()
|
371 |
51fe2d8a
|
Andreas Kohlbecker
|
*/
|
372 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
373 |
51fe2d8a
|
Andreas Kohlbecker
|
@Deprecated
|
374 |
60802362
|
Andreas Kohlbecker
|
public List findNamesByTitle(String title, CdmBase sessionObject){
|
375 |
|
|
return super.findCdmObjectsByTitle(title, sessionObject);
|
376 |
|
|
}
|
377 |
|
|
|
378 |
51fe2d8a
|
Andreas Kohlbecker
|
/**
|
379 |
|
|
* TODO candidate for harmonization
|
380 |
|
|
* new name saveHomotypicalGroups
|
381 |
|
|
*/
|
382 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
383 |
60802362
|
Andreas Kohlbecker
|
@Transactional(readOnly = false)
|
384 |
|
|
public Map<UUID, HomotypicalGroup> saveAllHomotypicalGroups(Collection<HomotypicalGroup> homotypicalGroups){
|
385 |
|
|
return homotypicalGroupDao.saveAll(homotypicalGroups);
|
386 |
|
|
}
|
387 |
|
|
|
388 |
51fe2d8a
|
Andreas Kohlbecker
|
/**
|
389 |
|
|
* TODO candidate for harmonization
|
390 |
|
|
* new name saveTypeDesignations
|
391 |
|
|
*/
|
392 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
393 |
60802362
|
Andreas Kohlbecker
|
@Transactional(readOnly = false)
|
394 |
|
|
public Map<UUID, TypeDesignationBase> saveTypeDesignationAll(Collection<TypeDesignationBase> typeDesignationCollection){
|
395 |
|
|
return typeDesignationDao.saveAll(typeDesignationCollection);
|
396 |
|
|
}
|
397 |
|
|
|
398 |
51fe2d8a
|
Andreas Kohlbecker
|
/**
|
399 |
|
|
* TODO candidate for harmonization
|
400 |
|
|
* new name saveReferencedEntities
|
401 |
|
|
*/
|
402 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
403 |
60802362
|
Andreas Kohlbecker
|
@Transactional(readOnly = false)
|
404 |
|
|
public Map<UUID, ReferencedEntityBase> saveReferencedEntitiesAll(Collection<ReferencedEntityBase> referencedEntityCollection){
|
405 |
|
|
return referencedEntityDao.saveAll(referencedEntityCollection);
|
406 |
|
|
}
|
407 |
|
|
|
408 |
51fe2d8a
|
Andreas Kohlbecker
|
/**
|
409 |
|
|
* TODO candidate for harmonization
|
410 |
|
|
* new name getNames
|
411 |
|
|
*/
|
412 |
60802362
|
Andreas Kohlbecker
|
public List<TaxonNameBase> getAllNames(int limit, int start){
|
413 |
|
|
return dao.list(limit, start);
|
414 |
|
|
}
|
415 |
|
|
|
416 |
51fe2d8a
|
Andreas Kohlbecker
|
/**
|
417 |
|
|
* TODO candidate for harmonization
|
418 |
|
|
* new name getNomenclaturalStatus
|
419 |
|
|
*/
|
420 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
421 |
60802362
|
Andreas Kohlbecker
|
public List<NomenclaturalStatus> getAllNomenclaturalStatus(int limit, int start){
|
422 |
|
|
return nomStatusDao.list(limit, start);
|
423 |
|
|
}
|
424 |
|
|
|
425 |
51fe2d8a
|
Andreas Kohlbecker
|
/**
|
426 |
|
|
* TODO candidate for harmonization
|
427 |
|
|
* new name getTypeDesignations
|
428 |
|
|
*/
|
429 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
430 |
60802362
|
Andreas Kohlbecker
|
public List<TypeDesignationBase> getAllTypeDesignations(int limit, int start){
|
431 |
|
|
return typeDesignationDao.getAllTypeDesignations(limit, start);
|
432 |
|
|
}
|
433 |
|
|
/**
|
434 |
|
|
* FIXME Candidate for harmonization
|
435 |
|
|
* homotypicalGroupService.list
|
436 |
|
|
*/
|
437 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
438 |
60802362
|
Andreas Kohlbecker
|
public List<HomotypicalGroup> getAllHomotypicalGroups(int limit, int start){
|
439 |
|
|
return homotypicalGroupDao.list(limit, start);
|
440 |
|
|
}
|
441 |
|
|
|
442 |
|
|
/**
|
443 |
|
|
* FIXME Candidate for harmonization
|
444 |
|
|
* remove
|
445 |
|
|
*/
|
446 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
447 |
60802362
|
Andreas Kohlbecker
|
@Deprecated
|
448 |
|
|
public List<RelationshipBase> getAllRelationships(int limit, int start){
|
449 |
00b93cdd
|
Andreas Müller
|
return dao.getAllRelationships(limit, start);
|
450 |
60802362
|
Andreas Kohlbecker
|
}
|
451 |
|
|
|
452 |
|
|
/**
|
453 |
|
|
* FIXME Candidate for harmonization
|
454 |
f2fdd2e7
|
Andreas Kohlbecker
|
* is this not the same as termService.getVocabulary(VocabularyEnum.Rank)
|
455 |
|
|
* since this returns OrderedTermVocabulary
|
456 |
|
|
*
|
457 |
60802362
|
Andreas Kohlbecker
|
* (non-Javadoc)
|
458 |
|
|
* @see eu.etaxonomy.cdm.api.service.INameService#getRankVocabulary()
|
459 |
|
|
*/
|
460 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
461 |
60802362
|
Andreas Kohlbecker
|
public OrderedTermVocabulary<Rank> getRankVocabulary() {
|
462 |
|
|
String uuidString = "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b";
|
463 |
|
|
UUID uuid = UUID.fromString(uuidString);
|
464 |
|
|
OrderedTermVocabulary<Rank> rankVocabulary =
|
465 |
|
|
(OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
|
466 |
|
|
return rankVocabulary;
|
467 |
|
|
}
|
468 |
|
|
|
469 |
|
|
/**
|
470 |
|
|
* FIXME Candidate for harmonization
|
471 |
|
|
* is this the same as termService.getVocabulary(VocabularyEnum.NameRelationshipType)
|
472 |
|
|
* (non-Javadoc)
|
473 |
|
|
* @see eu.etaxonomy.cdm.api.service.INameService#getNameRelationshipTypeVocabulary()
|
474 |
|
|
*/
|
475 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
476 |
60802362
|
Andreas Kohlbecker
|
public TermVocabulary<NameRelationshipType> getNameRelationshipTypeVocabulary() {
|
477 |
|
|
String uuidString = "6878cb82-c1a4-4613-b012-7e73b413c8cd";
|
478 |
|
|
UUID uuid = UUID.fromString(uuidString);
|
479 |
|
|
TermVocabulary<NameRelationshipType> nameRelTypeVocabulary =
|
480 |
f2fdd2e7
|
Andreas Kohlbecker
|
vocabularyDao.findByUuid(uuid);
|
481 |
60802362
|
Andreas Kohlbecker
|
return nameRelTypeVocabulary;
|
482 |
|
|
}
|
483 |
|
|
|
484 |
|
|
/**
|
485 |
|
|
* FIXME Candidate for harmonization
|
486 |
|
|
* is this the same as termService.getVocabulary(VocabularyEnum.StatusType)
|
487 |
|
|
* (non-Javadoc)
|
488 |
|
|
* @see eu.etaxonomy.cdm.api.service.INameService#getStatusTypeVocabulary()
|
489 |
|
|
*/
|
490 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
491 |
60802362
|
Andreas Kohlbecker
|
public TermVocabulary<NomenclaturalStatusType> getStatusTypeVocabulary() {
|
492 |
|
|
String uuidString = "bb28cdca-2f8a-4f11-9c21-517e9ae87f1f";
|
493 |
|
|
UUID uuid = UUID.fromString(uuidString);
|
494 |
|
|
TermVocabulary<NomenclaturalStatusType> nomStatusTypeVocabulary =
|
495 |
f2fdd2e7
|
Andreas Kohlbecker
|
vocabularyDao.findByUuid(uuid);
|
496 |
60802362
|
Andreas Kohlbecker
|
return nomStatusTypeVocabulary;
|
497 |
|
|
}
|
498 |
|
|
|
499 |
|
|
/**
|
500 |
|
|
* FIXME Candidate for harmonization
|
501 |
|
|
* is this the same as termService.getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus)
|
502 |
|
|
* (non-Javadoc)
|
503 |
|
|
* @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
|
504 |
|
|
*/
|
505 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
506 |
60802362
|
Andreas Kohlbecker
|
public TermVocabulary<SpecimenTypeDesignationStatus> getSpecimenTypeDesignationStatusVocabulary() {
|
507 |
|
|
String uuidString = "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
|
508 |
|
|
UUID uuid = UUID.fromString(uuidString);
|
509 |
|
|
TermVocabulary<SpecimenTypeDesignationStatus> typeDesigStatusVocabulary =
|
510 |
f2fdd2e7
|
Andreas Kohlbecker
|
vocabularyDao.findByUuid(uuid);
|
511 |
60802362
|
Andreas Kohlbecker
|
return typeDesigStatusVocabulary;
|
512 |
|
|
}
|
513 |
|
|
|
514 |
|
|
/**
|
515 |
|
|
* FIXME Candidate for harmonization
|
516 |
|
|
* is this the same as termService.getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus)
|
517 |
|
|
* and also seems to duplicate the above method, differing only in the DAO used and the return type
|
518 |
|
|
* (non-Javadoc)
|
519 |
|
|
* @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
|
520 |
|
|
*/
|
521 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
522 |
60802362
|
Andreas Kohlbecker
|
public OrderedTermVocabulary<SpecimenTypeDesignationStatus> getSpecimenTypeDesignationVocabulary() {
|
523 |
|
|
String uuidString = "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
|
524 |
|
|
UUID uuid = UUID.fromString(uuidString);
|
525 |
|
|
OrderedTermVocabulary<SpecimenTypeDesignationStatus> typeDesignationVocabulary =
|
526 |
|
|
(OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
|
527 |
|
|
return typeDesignationVocabulary;
|
528 |
|
|
}
|
529 |
|
|
|
530 |
|
|
|
531 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
532 |
60802362
|
Andreas Kohlbecker
|
@Autowired
|
533 |
|
|
protected void setDao(ITaxonNameDao dao) {
|
534 |
|
|
this.dao = dao;
|
535 |
|
|
}
|
536 |
|
|
|
537 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
538 |
60802362
|
Andreas Kohlbecker
|
public Pager<HybridRelationship> getHybridNames(NonViralName name, HybridRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
539 |
d57c0df0
|
ben.clark
|
Integer numberOfResults = dao.countHybridNames(name, type);
|
540 |
60802362
|
Andreas Kohlbecker
|
|
541 |
|
|
List<HybridRelationship> results = new ArrayList<HybridRelationship>();
|
542 |
|
|
if(AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)) { // no point checking again
|
543 |
|
|
results = dao.getHybridNames(name, type, pageSize, pageNumber,orderHints,propertyPaths);
|
544 |
|
|
}
|
545 |
|
|
|
546 |
|
|
return new DefaultPagerImpl<HybridRelationship>(pageNumber, numberOfResults, pageSize, results);
|
547 |
|
|
}
|
548 |
|
|
|
549 |
|
|
/* (non-Javadoc)
|
550 |
|
|
* @see eu.etaxonomy.cdm.api.service.INameService#listNameRelationships(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, eu.etaxonomy.cdm.model.name.NameRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
|
551 |
|
|
*/
|
552 |
|
|
@Override
|
553 |
|
|
public List<NameRelationship> listNameRelationships(TaxonNameBase name, Direction direction, NameRelationshipType type, Integer pageSize,
|
554 |
|
|
Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
555 |
|
|
|
556 |
|
|
Integer numberOfResults = dao.countNameRelationships(name, NameRelationship.Direction.relatedFrom, type);
|
557 |
|
|
|
558 |
|
|
List<NameRelationship> results = new ArrayList<NameRelationship>();
|
559 |
|
|
if (AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)) { // no point checking again
|
560 |
|
|
results = dao.getNameRelationships(name, direction, type, pageSize, pageNumber, orderHints, propertyPaths);
|
561 |
|
|
}
|
562 |
|
|
return results;
|
563 |
|
|
}
|
564 |
|
|
|
565 |
cb312388
|
Cherian Mathew
|
|
566 |
|
|
protected LuceneSearch prepareFindByFuzzyNameSearch(Class<? extends CdmBase> clazz,
|
567 |
676033bb
|
Cherian Mathew
|
NonViralName nvn,
|
568 |
|
|
float accuracy,
|
569 |
|
|
List<Language> languages,
|
570 |
cb312388
|
Cherian Mathew
|
boolean highlightFragments) {
|
571 |
|
|
String similarity = Float.toString(accuracy);
|
572 |
|
|
String searchSuffix = "~" + similarity;
|
573 |
|
|
|
574 |
|
|
|
575 |
|
|
BooleanQuery finalQuery = new BooleanQuery();
|
576 |
|
|
BooleanQuery textQuery = new BooleanQuery();
|
577 |
|
|
|
578 |
|
|
LuceneSearch luceneSearch = new LuceneSearch(getSession(), TaxonNameBase.class);
|
579 |
|
|
QueryFactory queryFactory = new QueryFactory(luceneSearch);
|
580 |
|
|
|
581 |
|
|
SortField[] sortFields = new SortField[]{SortField.FIELD_SCORE, new SortField("titleCache__sort", SortField.STRING, false)};
|
582 |
|
|
luceneSearch.setSortFields(sortFields);
|
583 |
|
|
|
584 |
|
|
// ---- search criteria
|
585 |
|
|
luceneSearch.setClazz(clazz);
|
586 |
|
|
|
587 |
|
|
|
588 |
|
|
if(nvn.getGenusOrUninomial() != null && !nvn.getGenusOrUninomial().equals("")) {
|
589 |
|
|
textQuery.add(queryFactory.newTermQuery("genusOrUninomial", nvn.getGenusOrUninomial() + searchSuffix), Occur.SHOULD);
|
590 |
|
|
|
591 |
|
|
} else {
|
592 |
|
|
textQuery.add(new RegexQuery (new Term ("genusOrUninomial", "^[a-zA-Z]*")), Occur.MUST_NOT);
|
593 |
|
|
}
|
594 |
|
|
|
595 |
|
|
if(nvn.getInfraGenericEpithet() != null && !nvn.getInfraGenericEpithet().equals("")){
|
596 |
|
|
textQuery.add(queryFactory.newTermQuery("infraGenericEpithet", nvn.getInfraGenericEpithet() + searchSuffix), Occur.SHOULD);
|
597 |
|
|
} else {
|
598 |
|
|
textQuery.add(new RegexQuery (new Term ("infraGenericEpithet", "^[a-zA-Z]*")), Occur.MUST_NOT);
|
599 |
|
|
}
|
600 |
|
|
|
601 |
|
|
if(nvn.getSpecificEpithet() != null && !nvn.getSpecificEpithet().equals("")){
|
602 |
|
|
textQuery.add(queryFactory.newTermQuery("specificEpithet", nvn.getSpecificEpithet() + searchSuffix), Occur.SHOULD);
|
603 |
|
|
|
604 |
|
|
} else {
|
605 |
|
|
textQuery.add(new RegexQuery (new Term ("specificEpithet", "^[a-zA-Z]*")), Occur.MUST_NOT);
|
606 |
|
|
}
|
607 |
|
|
|
608 |
|
|
if(nvn.getInfraSpecificEpithet() != null && !nvn.getInfraSpecificEpithet().equals("")){
|
609 |
|
|
textQuery.add(queryFactory.newTermQuery("infraSpecificEpithet", nvn.getInfraSpecificEpithet() + searchSuffix), Occur.SHOULD);
|
610 |
|
|
} else {
|
611 |
|
|
textQuery.add(new RegexQuery (new Term ("infraSpecificEpithet", "^[a-zA-Z]*")), Occur.MUST_NOT);
|
612 |
|
|
}
|
613 |
|
|
|
614 |
|
|
if(nvn.getAuthorshipCache() != null && !nvn.getAuthorshipCache().equals("")){
|
615 |
|
|
textQuery.add(queryFactory.newTermQuery("authorshipCache", nvn.getAuthorshipCache() + searchSuffix), Occur.SHOULD);
|
616 |
|
|
} else {
|
617 |
|
|
//textQuery.add(new RegexQuery (new Term ("authorshipCache", "^[a-zA-Z]*")), Occur.MUST_NOT);
|
618 |
|
|
}
|
619 |
|
|
|
620 |
|
|
finalQuery.add(textQuery, Occur.MUST);
|
621 |
|
|
|
622 |
|
|
luceneSearch.setQuery(finalQuery);
|
623 |
|
|
|
624 |
|
|
if(highlightFragments){
|
625 |
|
|
luceneSearch.setHighlightFields(queryFactory.getTextFieldNamesAsArray());
|
626 |
|
|
}
|
627 |
|
|
return luceneSearch;
|
628 |
|
|
}
|
629 |
|
|
|
630 |
|
|
protected LuceneSearch prepareFindByExactNameSearch(Class<? extends CdmBase> clazz,
|
631 |
|
|
String name,
|
632 |
|
|
boolean wildcard,
|
633 |
|
|
List<Language> languages,
|
634 |
676033bb
|
Cherian Mathew
|
boolean highlightFragments) {
|
635 |
|
|
BooleanQuery finalQuery = new BooleanQuery();
|
636 |
|
|
BooleanQuery textQuery = new BooleanQuery();
|
637 |
|
|
|
638 |
|
|
LuceneSearch luceneSearch = new LuceneSearch(getSession(), TaxonNameBase.class);
|
639 |
|
|
QueryFactory queryFactory = new QueryFactory(luceneSearch);
|
640 |
|
|
|
641 |
|
|
SortField[] sortFields = new SortField[]{SortField.FIELD_SCORE, new SortField("titleCache__sort", SortField.STRING, false)};
|
642 |
|
|
luceneSearch.setSortFields(sortFields);
|
643 |
|
|
|
644 |
|
|
// ---- search criteria
|
645 |
|
|
luceneSearch.setClazz(clazz);
|
646 |
|
|
|
647 |
|
|
|
648 |
|
|
|
649 |
cb312388
|
Cherian Mathew
|
if(name != null && !name.equals("")) {
|
650 |
|
|
if(wildcard) {
|
651 |
|
|
textQuery.add(new WildcardQuery(new Term("nameCache", name + "*")), Occur.MUST);
|
652 |
|
|
} else {
|
653 |
|
|
textQuery.add(queryFactory.newTermQuery("nameCache", name, false), Occur.MUST);
|
654 |
|
|
}
|
655 |
|
|
}
|
656 |
676033bb
|
Cherian Mathew
|
|
657 |
|
|
finalQuery.add(textQuery, Occur.MUST);
|
658 |
|
|
|
659 |
cb312388
|
Cherian Mathew
|
luceneSearch.setQuery(textQuery);
|
660 |
676033bb
|
Cherian Mathew
|
|
661 |
|
|
if(highlightFragments){
|
662 |
|
|
luceneSearch.setHighlightFields(queryFactory.getTextFieldNamesAsArray());
|
663 |
|
|
}
|
664 |
|
|
return luceneSearch;
|
665 |
|
|
}
|
666 |
|
|
|
667 |
|
|
public List<SearchResult<TaxonNameBase>> findByNameFuzzySearch(
|
668 |
|
|
String name,
|
669 |
|
|
float accuracy,
|
670 |
|
|
List<Language> languages,
|
671 |
|
|
boolean highlightFragments,
|
672 |
|
|
List<String> propertyPaths,
|
673 |
|
|
int maxNoOfResults) throws CorruptIndexException, IOException, ParseException {
|
674 |
|
|
|
675 |
|
|
logger.info("Name to fuzzy search for : " + name);
|
676 |
|
|
// parse the input name
|
677 |
|
|
NonViralNameParserImpl parser = new NonViralNameParserImpl();
|
678 |
|
|
NonViralName nvn = parser.parseFullName(name);
|
679 |
|
|
if(name != null && !name.equals("") && nvn == null) {
|
680 |
|
|
throw new ParseException("Could not parse name " + name);
|
681 |
|
|
}
|
682 |
cb312388
|
Cherian Mathew
|
LuceneSearch luceneSearch = prepareFindByFuzzyNameSearch(null, nvn, accuracy, languages, highlightFragments);
|
683 |
676033bb
|
Cherian Mathew
|
|
684 |
|
|
// --- execute search
|
685 |
|
|
TopDocs topDocs = luceneSearch.executeSearch(maxNoOfResults);
|
686 |
cb312388
|
Cherian Mathew
|
|
687 |
|
|
|
688 |
676033bb
|
Cherian Mathew
|
Map<CdmBaseType, String> idFieldMap = new HashMap<CdmBaseType, String>();
|
689 |
|
|
idFieldMap.put(CdmBaseType.NONVIRALNAME, "id");
|
690 |
|
|
|
691 |
|
|
// --- initialize taxa, highlight matches ....
|
692 |
|
|
ISearchResultBuilder searchResultBuilder = new SearchResultBuilder(luceneSearch, luceneSearch.getQuery());
|
693 |
|
|
|
694 |
|
|
@SuppressWarnings("rawtypes")
|
695 |
|
|
List<SearchResult<TaxonNameBase>> searchResults = searchResultBuilder.createResultSet(
|
696 |
|
|
topDocs, luceneSearch.getHighlightFields(), dao, idFieldMap, propertyPaths);
|
697 |
|
|
|
698 |
|
|
return searchResults;
|
699 |
|
|
|
700 |
|
|
}
|
701 |
cb312388
|
Cherian Mathew
|
|
702 |
|
|
public List<DocumentSearchResult> findByNameFuzzySearch(
|
703 |
|
|
String name,
|
704 |
|
|
float accuracy,
|
705 |
|
|
List<Language> languages,
|
706 |
|
|
boolean highlightFragments,
|
707 |
|
|
int maxNoOfResults) throws CorruptIndexException, IOException, ParseException {
|
708 |
|
|
|
709 |
|
|
logger.info("Name to fuzzy search for : " + name);
|
710 |
|
|
// parse the input name
|
711 |
|
|
NonViralNameParserImpl parser = new NonViralNameParserImpl();
|
712 |
|
|
NonViralName nvn = parser.parseFullName(name);
|
713 |
|
|
if(name != null && !name.equals("") && nvn == null) {
|
714 |
|
|
throw new ParseException("Could not parse name " + name);
|
715 |
|
|
}
|
716 |
|
|
LuceneSearch luceneSearch = prepareFindByFuzzyNameSearch(null, nvn, accuracy, languages, highlightFragments);
|
717 |
|
|
|
718 |
|
|
// --- execute search
|
719 |
|
|
TopDocs topDocs = luceneSearch.executeSearch(maxNoOfResults);
|
720 |
|
|
// for(int i = 0; i < topDocs.scoreDocs.length ; i++) {
|
721 |
|
|
// Explanation exp = luceneSearch.getSearcher().explain(luceneSearch.getQuery(), topDocs.scoreDocs[i].doc);
|
722 |
|
|
// System.out.println("-----------------------");
|
723 |
|
|
// System.out.println(exp.toString());
|
724 |
|
|
// }
|
725 |
|
|
|
726 |
|
|
Map<CdmBaseType, String> idFieldMap = new HashMap<CdmBaseType, String>();
|
727 |
|
|
|
728 |
|
|
// --- initialize taxa, highlight matches ....
|
729 |
|
|
ISearchResultBuilder searchResultBuilder = new SearchResultBuilder(luceneSearch, luceneSearch.getQuery());
|
730 |
|
|
|
731 |
|
|
@SuppressWarnings("rawtypes")
|
732 |
|
|
List<DocumentSearchResult> searchResults = searchResultBuilder.createResultSet(topDocs, luceneSearch.getHighlightFields());
|
733 |
|
|
|
734 |
|
|
return searchResults;
|
735 |
|
|
}
|
736 |
|
|
|
737 |
|
|
public List<DocumentSearchResult> findByNameExactSearch(
|
738 |
|
|
String name,
|
739 |
|
|
boolean wildcard,
|
740 |
|
|
List<Language> languages,
|
741 |
|
|
boolean highlightFragments,
|
742 |
|
|
int maxNoOfResults) throws CorruptIndexException, IOException, ParseException {
|
743 |
|
|
|
744 |
|
|
logger.info("Name to fuzzy search for : " + name);
|
745 |
|
|
|
746 |
|
|
LuceneSearch luceneSearch = prepareFindByExactNameSearch(null, name, wildcard, languages, highlightFragments);
|
747 |
|
|
|
748 |
|
|
// --- execute search
|
749 |
|
|
TopDocs topDocs = luceneSearch.executeSearch(maxNoOfResults);
|
750 |
|
|
Map<CdmBaseType, String> idFieldMap = new HashMap<CdmBaseType, String>();
|
751 |
|
|
|
752 |
|
|
// --- initialize taxa, highlight matches ....
|
753 |
|
|
ISearchResultBuilder searchResultBuilder = new SearchResultBuilder(luceneSearch, luceneSearch.getQuery());
|
754 |
|
|
|
755 |
|
|
@SuppressWarnings("rawtypes")
|
756 |
|
|
List<DocumentSearchResult> searchResults = searchResultBuilder.createResultSet(topDocs, luceneSearch.getHighlightFields());
|
757 |
|
|
|
758 |
|
|
return searchResults;
|
759 |
|
|
}
|
760 |
|
|
|
761 |
60802362
|
Andreas Kohlbecker
|
/* (non-Javadoc)
|
762 |
|
|
* @see eu.etaxonomy.cdm.api.service.INameService#pageNameRelationships(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, eu.etaxonomy.cdm.model.name.NameRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
|
763 |
|
|
*/
|
764 |
|
|
@Override
|
765 |
|
|
public Pager<NameRelationship> pageNameRelationships(TaxonNameBase name, Direction direction, NameRelationshipType type, Integer pageSize,
|
766 |
|
|
Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
767 |
|
|
List<NameRelationship> results = listNameRelationships(name, direction, type, pageSize, pageNumber, orderHints, propertyPaths);
|
768 |
|
|
return new DefaultPagerImpl<NameRelationship>(pageNumber, results.size(), pageSize, results);
|
769 |
|
|
}
|
770 |
|
|
|
771 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
772 |
60802362
|
Andreas Kohlbecker
|
public List<NameRelationship> listFromNameRelationships(TaxonNameBase name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
773 |
|
|
return listNameRelationships(name, Direction.relatedFrom, type, pageSize, pageNumber, orderHints, propertyPaths);
|
774 |
|
|
}
|
775 |
|
|
|
776 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
777 |
60802362
|
Andreas Kohlbecker
|
public Pager<NameRelationship> pageFromNameRelationships(TaxonNameBase name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
778 |
|
|
List<NameRelationship> results = listNameRelationships(name, Direction.relatedFrom, type, pageSize, pageNumber, orderHints, propertyPaths);
|
779 |
|
|
return new DefaultPagerImpl<NameRelationship>(pageNumber, results.size(), pageSize, results);
|
780 |
|
|
}
|
781 |
|
|
|
782 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
783 |
60802362
|
Andreas Kohlbecker
|
public List<NameRelationship> listToNameRelationships(TaxonNameBase name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
784 |
|
|
return listNameRelationships(name, Direction.relatedTo, type, pageSize, pageNumber, orderHints, propertyPaths);
|
785 |
|
|
}
|
786 |
|
|
|
787 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
788 |
60802362
|
Andreas Kohlbecker
|
public Pager<NameRelationship> pageToNameRelationships(TaxonNameBase name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
789 |
|
|
List<NameRelationship> results = listNameRelationships(name, Direction.relatedTo, type, pageSize, pageNumber, orderHints, propertyPaths);
|
790 |
|
|
return new DefaultPagerImpl<NameRelationship>(pageNumber, results.size(), pageSize, results);
|
791 |
|
|
}
|
792 |
|
|
|
793 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
794 |
60802362
|
Andreas Kohlbecker
|
public Pager<TypeDesignationBase> getTypeDesignations(TaxonNameBase name, SpecimenTypeDesignationStatus status,
|
795 |
|
|
Integer pageSize, Integer pageNumber) {
|
796 |
|
|
return getTypeDesignations(name, status, pageSize, pageNumber, null);
|
797 |
|
|
}
|
798 |
|
|
|
799 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
800 |
60802362
|
Andreas Kohlbecker
|
public Pager<TypeDesignationBase> getTypeDesignations(TaxonNameBase name, SpecimenTypeDesignationStatus status,
|
801 |
|
|
Integer pageSize, Integer pageNumber, List<String> propertyPaths){
|
802 |
d57c0df0
|
ben.clark
|
Integer numberOfResults = dao.countTypeDesignations(name, status);
|
803 |
60802362
|
Andreas Kohlbecker
|
|
804 |
|
|
List<TypeDesignationBase> results = new ArrayList<TypeDesignationBase>();
|
805 |
|
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
806 |
|
|
results = dao.getTypeDesignations(name, status, pageSize, pageNumber, propertyPaths);
|
807 |
|
|
}
|
808 |
|
|
|
809 |
|
|
return new DefaultPagerImpl<TypeDesignationBase>(pageNumber, numberOfResults, pageSize, results);
|
810 |
|
|
}
|
811 |
|
|
|
812 |
e0dbe59a
|
ben.clark
|
/**
|
813 |
|
|
* FIXME Candidate for harmonization
|
814 |
60802362
|
Andreas Kohlbecker
|
* rename search
|
815 |
e0dbe59a
|
ben.clark
|
*/
|
816 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
817 |
60802362
|
Andreas Kohlbecker
|
public Pager<TaxonNameBase> searchNames(String uninomial,String infraGenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
|
818 |
|
|
List<String> propertyPaths) {
|
819 |
d57c0df0
|
ben.clark
|
Integer numberOfResults = dao.countNames(uninomial, infraGenericEpithet, specificEpithet, infraspecificEpithet, rank);
|
820 |
60802362
|
Andreas Kohlbecker
|
|
821 |
|
|
List<TaxonNameBase> results = new ArrayList<TaxonNameBase>();
|
822 |
|
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
823 |
|
|
results = dao.searchNames(uninomial, infraGenericEpithet, specificEpithet, infraspecificEpithet, rank, pageSize, pageNumber, orderHints, propertyPaths);
|
824 |
|
|
}
|
825 |
|
|
|
826 |
|
|
return new DefaultPagerImpl<TaxonNameBase>(pageNumber, numberOfResults, pageSize, results);
|
827 |
|
|
}
|
828 |
|
|
|
829 |
|
|
/* (non-Javadoc)
|
830 |
|
|
* @see eu.etaxonomy.cdm.api.service.INameService#getUuidAndTitleCacheOfNames()
|
831 |
|
|
*/
|
832 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
833 |
60802362
|
Andreas Kohlbecker
|
public List<UuidAndTitleCache> getUuidAndTitleCacheOfNames() {
|
834 |
|
|
return dao.getUuidAndTitleCacheOfNames();
|
835 |
|
|
}
|
836 |
|
|
|
837 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
838 |
60802362
|
Andreas Kohlbecker
|
public Pager<TaxonNameBase> findByName(Class<? extends TaxonNameBase> clazz, String queryString, MatchMode matchmode, List<Criterion> criteria, Integer pageSize,Integer pageNumber, List<OrderHint> orderHints,List<String> propertyPaths) {
|
839 |
|
|
Integer numberOfResults = dao.countByName(clazz, queryString, matchmode, criteria);
|
840 |
|
|
|
841 |
|
|
List<TaxonNameBase> results = new ArrayList<TaxonNameBase>();
|
842 |
|
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
843 |
|
|
results = dao.findByName(clazz, queryString, matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths);
|
844 |
|
|
}
|
845 |
|
|
|
846 |
|
|
return new DefaultPagerImpl<TaxonNameBase>(pageNumber, numberOfResults, pageSize, results);
|
847 |
|
|
}
|
848 |
|
|
|
849 |
f2fdd2e7
|
Andreas Kohlbecker
|
@Override
|
850 |
60802362
|
Andreas Kohlbecker
|
public HomotypicalGroup findHomotypicalGroup(UUID uuid) {
|
851 |
|
|
return homotypicalGroupDao.findByUuid(uuid);
|
852 |
|
|
}
|
853 |
|
|
|
854 |
|
|
|
855 |
|
|
/* (non-Javadoc)
|
856 |
|
|
* @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
|
857 |
|
|
*/
|
858 |
|
|
@Override
|
859 |
4116e48b
|
Andreas Müller
|
@Transactional(readOnly = false)
|
860 |
60802362
|
Andreas Kohlbecker
|
public void updateTitleCache(Class<? extends TaxonNameBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<TaxonNameBase> cacheStrategy, IProgressMonitor monitor) {
|
861 |
|
|
if (clazz == null){
|
862 |
|
|
clazz = TaxonNameBase.class;
|
863 |
|
|
}
|
864 |
|
|
super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
|
865 |
|
|
}
|
866 |
|
|
|
867 |
|
|
|
868 |
|
|
@Override
|
869 |
|
|
protected void setOtherCachesNull(TaxonNameBase name) {
|
870 |
|
|
if (name.isInstanceOf(NonViralName.class)){
|
871 |
a13c5f66
|
Andreas Müller
|
NonViralName<?> nvn = CdmBase.deproxy(name, NonViralName.class);
|
872 |
60802362
|
Andreas Kohlbecker
|
if (! nvn.isProtectedNameCache()){
|
873 |
|
|
nvn.setNameCache(null, false);
|
874 |
|
|
}
|
875 |
|
|
if (! nvn.isProtectedAuthorshipCache()){
|
876 |
|
|
nvn.setAuthorshipCache(null, false);
|
877 |
|
|
}
|
878 |
|
|
if (! nvn.isProtectedFullTitleCache()){
|
879 |
|
|
nvn.setFullTitleCache(null, false);
|
880 |
|
|
}
|
881 |
|
|
}
|
882 |
|
|
}
|
883 |
|
|
|
884 |
|
|
/* (non-Javadoc)
|
885 |
|
|
* @see eu.etaxonomy.cdm.api.service.INameService#getTaggedName(eu.etaxonomy.cdm.model.name.TaxonNameBase)
|
886 |
|
|
*/
|
887 |
|
|
@Override
|
888 |
|
|
public List<TaggedText> getTaggedName(UUID uuid) {
|
889 |
|
|
TaxonNameBase taxonNameBase = dao.load(uuid);
|
890 |
|
|
List taggedName = taxonNameBase.getTaggedName();
|
891 |
|
|
return taggedName;
|
892 |
|
|
}
|
893 |
|
|
|
894 |
|
|
|
895 |
2d993c6e
|
Andreas Müller
|
}
|