1 |
dfcd94fb
|
Andreas Kohlbecker
|
// $Id$
|
2 |
25663b56
|
Andreas Müller
|
/**
|
3 |
|
|
* Copyright (C) 2007 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 |
|
|
|
11 |
2d993c6e
|
Andreas Müller
|
package eu.etaxonomy.cdm.api.service;
|
12 |
|
|
|
13 |
d57c0df0
|
ben.clark
|
import java.util.ArrayList;
|
14 |
d391964a
|
Andreas Kohlbecker
|
import java.util.Comparator;
|
15 |
d57c0df0
|
ben.clark
|
import java.util.List;
|
16 |
|
|
import java.util.Set;
|
17 |
|
|
import java.util.UUID;
|
18 |
|
|
|
19 |
2d993c6e
|
Andreas Müller
|
import org.apache.log4j.Logger;
|
20 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
21 |
|
|
import org.springframework.stereotype.Service;
|
22 |
2a56d8c1
|
ben.clark
|
import org.springframework.transaction.annotation.Propagation;
|
23 |
2d993c6e
|
Andreas Müller
|
import org.springframework.transaction.annotation.Transactional;
|
24 |
|
|
|
25 |
24700eab
|
a.babadshanjan
|
import eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator;
|
26 |
a6f05c62
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.config.MatchingTaxonConfigurator;
|
27 |
d57c0df0
|
ben.clark
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
28 |
|
|
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
|
29 |
f197a589
|
Andreas Müller
|
import eu.etaxonomy.cdm.common.IProgressMonitor;
|
30 |
b6cb1182
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
31 |
24700eab
|
a.babadshanjan
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
32 |
|
|
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
|
33 |
7a931ddb
|
a.babadshanjan
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
34 |
b6cb1182
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
|
35 |
2eecc314
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
|
36 |
b79861eb
|
Katja Luther
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
37 |
02cf6cb7
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
38 |
b79861eb
|
Katja Luther
|
import eu.etaxonomy.cdm.model.media.Media;
|
39 |
|
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
40 |
892efc69
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.model.media.MediaUtils;
|
41 |
9b62c409
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
42 |
d57c0df0
|
ben.clark
|
import eu.etaxonomy.cdm.model.name.Rank;
|
43 |
02cf6cb7
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
44 |
1d36aa54
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
45 |
15ce3c9c
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
46 |
02cf6cb7
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
47 |
|
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
|
48 |
|
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
|
49 |
2d993c6e
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
50 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
51 |
a6f05c62
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
52 |
281bc0c7
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
53 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
54 |
24700eab
|
a.babadshanjan
|
import eu.etaxonomy.cdm.persistence.dao.common.IOrderedTermVocabularyDao;
|
55 |
|
|
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;
|
56 |
2d993c6e
|
Andreas Müller
|
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
|
57 |
855f3dd0
|
Andreas Müller
|
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
|
58 |
65c22e25
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
59 |
d44277a9
|
ben.clark
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
60 |
f197a589
|
Andreas Müller
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
61 |
2d993c6e
|
Andreas Müller
|
|
62 |
|
|
|
63 |
65c22e25
|
Andreas Kohlbecker
|
/**
|
64 |
|
|
* @author a.kohlbecker
|
65 |
|
|
* @date 10.09.2010
|
66 |
|
|
*
|
67 |
|
|
*/
|
68 |
2d993c6e
|
Andreas Müller
|
@Service
|
69 |
2a56d8c1
|
ben.clark
|
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
|
70 |
01c21ead
|
n.hoffmann
|
public class TaxonServiceImpl extends IdentifiableServiceBase<TaxonBase,ITaxonDao> implements ITaxonService{
|
71 |
800cb472
|
Andreas Müller
|
private static final Logger logger = Logger.getLogger(TaxonServiceImpl.class);
|
72 |
2d993c6e
|
Andreas Müller
|
|
73 |
24700eab
|
a.babadshanjan
|
@Autowired
|
74 |
|
|
private ITaxonNameDao nameDao;
|
75 |
e0dbe59a
|
ben.clark
|
|
76 |
24700eab
|
a.babadshanjan
|
@Autowired
|
77 |
|
|
private IOrderedTermVocabularyDao orderedVocabularyDao;
|
78 |
7a1d87e3
|
a.babadshanjan
|
|
79 |
|
|
/**
|
80 |
|
|
* Constructor
|
81 |
|
|
*/
|
82 |
|
|
public TaxonServiceImpl(){
|
83 |
|
|
if (logger.isDebugEnabled()) { logger.debug("Load TaxonService Bean"); }
|
84 |
|
|
}
|
85 |
2d993c6e
|
Andreas Müller
|
|
86 |
e0dbe59a
|
ben.clark
|
/**
|
87 |
|
|
* FIXME Candidate for harmonization
|
88 |
|
|
* rename searchByName ?
|
89 |
|
|
*/
|
90 |
1d36aa54
|
Andreas Müller
|
public List<TaxonBase> searchTaxaByName(String name, Reference sec) {
|
91 |
d57c0df0
|
ben.clark
|
return dao.getTaxaByName(name, sec);
|
92 |
2d993c6e
|
Andreas Müller
|
}
|
93 |
c4e812bc
|
ben.clark
|
|
94 |
e0dbe59a
|
ben.clark
|
/**
|
95 |
|
|
* FIXME Candidate for harmonization
|
96 |
c4e812bc
|
ben.clark
|
* list(Synonym.class, ...)
|
97 |
e0dbe59a
|
ben.clark
|
* (non-Javadoc)
|
98 |
c4e812bc
|
ben.clark
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getAllSynonyms(int, int)
|
99 |
d93c0aaf
|
Andreas Müller
|
*/
|
100 |
c4e812bc
|
ben.clark
|
public List<Synonym> getAllSynonyms(int limit, int start) {
|
101 |
|
|
return dao.getAllSynonyms(limit, start);
|
102 |
07eb2b2b
|
a.babadshanjan
|
}
|
103 |
|
|
|
104 |
e0dbe59a
|
ben.clark
|
/**
|
105 |
|
|
* FIXME Candidate for harmonization
|
106 |
c4e812bc
|
ben.clark
|
* list(Taxon.class, ...)
|
107 |
e0dbe59a
|
ben.clark
|
* (non-Javadoc)
|
108 |
c4e812bc
|
ben.clark
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getAllTaxa(int, int)
|
109 |
d93c0aaf
|
Andreas Müller
|
*/
|
110 |
c4e812bc
|
ben.clark
|
public List<Taxon> getAllTaxa(int limit, int start) {
|
111 |
|
|
return dao.getAllTaxa(limit, start);
|
112 |
643cfd14
|
a.babadshanjan
|
}
|
113 |
d93c0aaf
|
Andreas Müller
|
|
114 |
e0dbe59a
|
ben.clark
|
/**
|
115 |
|
|
* FIXME Candidate for harmonization
|
116 |
1d36aa54
|
Andreas Müller
|
* merge with getRootTaxa(Reference sec, ..., ...)
|
117 |
e0dbe59a
|
ben.clark
|
* (non-Javadoc)
|
118 |
1d36aa54
|
Andreas Müller
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getRootTaxa(eu.etaxonomy.cdm.model.reference.Reference, boolean)
|
119 |
855f3dd0
|
Andreas Müller
|
*/
|
120 |
1d36aa54
|
Andreas Müller
|
public List<Taxon> getRootTaxa(Reference sec, CdmFetch cdmFetch, boolean onlyWithChildren) {
|
121 |
855f3dd0
|
Andreas Müller
|
if (cdmFetch == null){
|
122 |
|
|
cdmFetch = CdmFetch.NO_FETCH();
|
123 |
|
|
}
|
124 |
d57c0df0
|
ben.clark
|
return dao.getRootTaxa(sec, cdmFetch, onlyWithChildren, false);
|
125 |
349fae93
|
Andreas Müller
|
}
|
126 |
1fce1de6
|
Andreas Müller
|
|
127 |
a400a105
|
m.doering
|
|
128 |
7a1d87e3
|
a.babadshanjan
|
/* (non-Javadoc)
|
129 |
1d36aa54
|
Andreas Müller
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getRootTaxa(eu.etaxonomy.cdm.model.name.Rank, eu.etaxonomy.cdm.model.reference.Reference, boolean, boolean)
|
130 |
7a1d87e3
|
a.babadshanjan
|
*/
|
131 |
1fce1de6
|
Andreas Müller
|
public List<Taxon> getRootTaxa(Rank rank, Reference sec, boolean onlyWithChildren,boolean withMisapplications, List<String> propertyPaths) {
|
132 |
9b62c409
|
Andreas Kohlbecker
|
return dao.getRootTaxa(rank, sec, null, onlyWithChildren, withMisapplications, propertyPaths);
|
133 |
7a1d87e3
|
a.babadshanjan
|
}
|
134 |
|
|
|
135 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
136 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getAllRelationships(int, int)
|
137 |
|
|
*/
|
138 |
7a931ddb
|
a.babadshanjan
|
public List<RelationshipBase> getAllRelationships(int limit, int start){
|
139 |
d57c0df0
|
ben.clark
|
return dao.getAllRelationships(limit, start);
|
140 |
7a931ddb
|
a.babadshanjan
|
}
|
141 |
|
|
|
142 |
e0dbe59a
|
ben.clark
|
/**
|
143 |
|
|
* FIXME Candidate for harmonization
|
144 |
|
|
* is this the same as termService.getVocabulary(VocabularyEnum.TaxonRelationshipType) ?
|
145 |
|
|
*/
|
146 |
bb4f5701
|
n.hoffmann
|
@Deprecated
|
147 |
24700eab
|
a.babadshanjan
|
public OrderedTermVocabulary<TaxonRelationshipType> getTaxonRelationshipTypeVocabulary() {
|
148 |
|
|
|
149 |
|
|
String taxonRelTypeVocabularyId = "15db0cf7-7afc-4a86-a7d4-221c73b0c9ac";
|
150 |
|
|
UUID uuid = UUID.fromString(taxonRelTypeVocabularyId);
|
151 |
|
|
OrderedTermVocabulary<TaxonRelationshipType> taxonRelTypeVocabulary =
|
152 |
|
|
(OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
|
153 |
|
|
return taxonRelTypeVocabulary;
|
154 |
|
|
}
|
155 |
|
|
|
156 |
fd992c0d
|
n.hoffmann
|
|
157 |
02cf6cb7
|
Andreas Müller
|
|
158 |
f4cfc931
|
n.hoffmann
|
/*
|
159 |
|
|
* (non-Javadoc)
|
160 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#swapSynonymWithAcceptedTaxon(eu.etaxonomy.cdm.model.taxon.Synonym)
|
161 |
|
|
*/
|
162 |
|
|
@Transactional(readOnly = false)
|
163 |
7d8e086d
|
n.hoffmann
|
public void swapSynonymAndAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon){
|
164 |
f4cfc931
|
n.hoffmann
|
|
165 |
7d8e086d
|
n.hoffmann
|
TaxonNameBase synonymName = synonym.getName();
|
166 |
|
|
synonymName.removeTaxonBase(synonym);
|
167 |
|
|
TaxonNameBase taxonName = acceptedTaxon.getName();
|
168 |
|
|
taxonName.removeTaxonBase(acceptedTaxon);
|
169 |
f4cfc931
|
n.hoffmann
|
|
170 |
7d8e086d
|
n.hoffmann
|
synonym.setName(taxonName);
|
171 |
|
|
acceptedTaxon.setName(synonymName);
|
172 |
8a433654
|
n.hoffmann
|
|
173 |
7d8e086d
|
n.hoffmann
|
// the accepted taxon needs a new uuid because the concept has changed
|
174 |
|
|
// FIXME this leads to an error "HibernateException: immutable natural identifier of an instance of eu.etaxonomy.cdm.model.taxon.Taxon was altered"
|
175 |
|
|
//acceptedTaxon.setUuid(UUID.randomUUID());
|
176 |
f4cfc931
|
n.hoffmann
|
}
|
177 |
892efc69
|
Andreas Kohlbecker
|
|
178 |
af8f90fb
|
n.hoffmann
|
|
179 |
0fe25ffd
|
Andreas Müller
|
/* (non-Javadoc)
|
180 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#changeSynonymToAcceptedTaxon(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon)
|
181 |
|
|
*/
|
182 |
ffa78fd4
|
Andreas Müller
|
//TODO correct delete handling still needs to be implemented / checked
|
183 |
aee5abae
|
Andreas Müller
|
@Override
|
184 |
ffa78fd4
|
Andreas Müller
|
@Transactional(readOnly = false)
|
185 |
aee5abae
|
Andreas Müller
|
public Taxon changeSynonymToAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon, boolean deleteSynonym, boolean copyCitationInfo, Reference citation, String microCitation) throws IllegalArgumentException{
|
186 |
|
|
|
187 |
|
|
TaxonNameBase acceptedName = acceptedTaxon.getName();
|
188 |
|
|
TaxonNameBase synonymName = synonym.getName();
|
189 |
|
|
HomotypicalGroup synonymHomotypicGroup = synonymName.getHomotypicalGroup();
|
190 |
|
|
if (acceptedName.getHomotypicalGroup().equals(synonymHomotypicGroup)){
|
191 |
|
|
String message = "The accepted taxon and the synonym are part of the same homotypical group and therefore can not be both accepted.";
|
192 |
|
|
throw new IllegalArgumentException(message);
|
193 |
|
|
}
|
194 |
af8f90fb
|
n.hoffmann
|
|
195 |
ad3249f9
|
Katja Luther
|
Taxon newAcceptedTaxon = Taxon.NewInstance(synonymName, acceptedTaxon.getSec());
|
196 |
af8f90fb
|
n.hoffmann
|
|
197 |
aee5abae
|
Andreas Müller
|
SynonymRelationshipType relType = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF();
|
198 |
|
|
List<Synonym> heteroSynonyms = synonymHomotypicGroup.getSynonymsInGroup(acceptedTaxon.getSec());
|
199 |
|
|
for (Synonym heteroSynonym : heteroSynonyms){
|
200 |
|
|
if (synonym.equals(heteroSynonym)){
|
201 |
|
|
acceptedTaxon.removeSynonym(heteroSynonym, false);
|
202 |
|
|
}else{
|
203 |
|
|
heteroSynonym.replaceAcceptedTaxon(newAcceptedTaxon, relType, copyCitationInfo, citation, microCitation);
|
204 |
|
|
}
|
205 |
|
|
}
|
206 |
|
|
|
207 |
ad3249f9
|
Katja Luther
|
//synonym.getName().removeTaxonBase(synonym);
|
208 |
ffa78fd4
|
Andreas Müller
|
//TODO correct delete handling still needs to be implemented / checked
|
209 |
aee5abae
|
Andreas Müller
|
if (deleteSynonym){
|
210 |
|
|
try {
|
211 |
ad3249f9
|
Katja Luther
|
this.dao.flush();
|
212 |
aee5abae
|
Andreas Müller
|
this.delete(synonym);
|
213 |
ad3249f9
|
Katja Luther
|
|
214 |
aee5abae
|
Andreas Müller
|
} catch (Exception e) {
|
215 |
|
|
logger.info("Can't delete old synonym from database");
|
216 |
|
|
}
|
217 |
|
|
}
|
218 |
|
|
|
219 |
ffa78fd4
|
Andreas Müller
|
|
220 |
af8f90fb
|
n.hoffmann
|
return newAcceptedTaxon;
|
221 |
|
|
}
|
222 |
636d99d1
|
n.hoffmann
|
|
223 |
1d36aa54
|
Andreas Müller
|
public Taxon changeSynonymToRelatedTaxon(Synonym synonym, Taxon toTaxon, TaxonRelationshipType taxonRelationshipType, Reference citation, String microcitation){
|
224 |
636d99d1
|
n.hoffmann
|
|
225 |
|
|
// Get name from synonym
|
226 |
|
|
TaxonNameBase<?, ?> synonymName = synonym.getName();
|
227 |
|
|
|
228 |
|
|
// remove synonym from taxon
|
229 |
|
|
toTaxon.removeSynonym(synonym);
|
230 |
|
|
|
231 |
|
|
// Create a taxon with synonym name
|
232 |
|
|
Taxon fromTaxon = Taxon.NewInstance(synonymName, null);
|
233 |
|
|
|
234 |
|
|
// Add taxon relation
|
235 |
|
|
fromTaxon.addTaxonRelation(toTaxon, taxonRelationshipType, citation, microcitation);
|
236 |
|
|
|
237 |
|
|
// since we are swapping names, we have to detach the name from the synonym completely.
|
238 |
|
|
// Otherwise the synonym will still be in the list of typified names.
|
239 |
|
|
synonym.getName().removeTaxonBase(synonym);
|
240 |
|
|
|
241 |
|
|
return fromTaxon;
|
242 |
|
|
}
|
243 |
ffa78fd4
|
Andreas Müller
|
|
244 |
1188e04a
|
Andreas Müller
|
/* (non-Javadoc)
|
245 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#changeHomotypicalGroupOfSynonym(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.name.HomotypicalGroup, eu.etaxonomy.cdm.model.taxon.Taxon, boolean, boolean)
|
246 |
|
|
*/
|
247 |
|
|
@Transactional(readOnly = false)
|
248 |
|
|
@Override
|
249 |
|
|
public void changeHomotypicalGroupOfSynonym(Synonym synonym, HomotypicalGroup newHomotypicalGroup, Taxon targetTaxon,
|
250 |
|
|
boolean removeFromOtherTaxa, boolean setBasionymRelationIfApplicable){
|
251 |
|
|
// Get synonym name
|
252 |
|
|
TaxonNameBase synonymName = synonym.getName();
|
253 |
|
|
HomotypicalGroup oldHomotypicalGroup = synonymName.getHomotypicalGroup();
|
254 |
|
|
|
255 |
|
|
|
256 |
|
|
// Switch groups
|
257 |
|
|
oldHomotypicalGroup.removeTypifiedName(synonymName);
|
258 |
|
|
newHomotypicalGroup.addTypifiedName(synonymName);
|
259 |
|
|
|
260 |
|
|
//remove existing basionym relationships
|
261 |
|
|
synonymName.removeBasionyms();
|
262 |
|
|
|
263 |
|
|
//add basionym relationship
|
264 |
|
|
if (setBasionymRelationIfApplicable){
|
265 |
|
|
Set<TaxonNameBase> basionyms = newHomotypicalGroup.getBasionyms();
|
266 |
|
|
for (TaxonNameBase basionym : basionyms){
|
267 |
|
|
synonymName.addBasionym(basionym);
|
268 |
|
|
}
|
269 |
|
|
}
|
270 |
|
|
|
271 |
|
|
//set synonym relationship correctly
|
272 |
|
|
// SynonymRelationship relToTaxon = null;
|
273 |
|
|
boolean relToTargetTaxonExists = false;
|
274 |
|
|
Set<SynonymRelationship> existingRelations = synonym.getSynonymRelations();
|
275 |
|
|
for (SynonymRelationship rel : existingRelations){
|
276 |
|
|
Taxon acceptedTaxon = rel.getAcceptedTaxon();
|
277 |
|
|
boolean isTargetTaxon = acceptedTaxon != null && acceptedTaxon.equals(targetTaxon);
|
278 |
|
|
HomotypicalGroup acceptedGroup = acceptedTaxon.getHomotypicGroup();
|
279 |
|
|
boolean isHomotypicToTaxon = acceptedGroup.equals(newHomotypicalGroup);
|
280 |
|
|
SynonymRelationshipType newRelationType = isHomotypicToTaxon? SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF() : SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF();
|
281 |
|
|
rel.setType(newRelationType);
|
282 |
|
|
//TODO handle citation and microCitation
|
283 |
|
|
|
284 |
|
|
if (isTargetTaxon){
|
285 |
|
|
relToTargetTaxonExists = true;
|
286 |
|
|
}else{
|
287 |
|
|
if (removeFromOtherTaxa){
|
288 |
|
|
acceptedTaxon.removeSynonym(synonym, false);
|
289 |
|
|
}else{
|
290 |
|
|
//do nothing
|
291 |
|
|
}
|
292 |
|
|
}
|
293 |
|
|
}
|
294 |
|
|
if (targetTaxon != null && ! relToTargetTaxonExists ){
|
295 |
|
|
Taxon acceptedTaxon = targetTaxon;
|
296 |
|
|
HomotypicalGroup acceptedGroup = acceptedTaxon.getHomotypicGroup();
|
297 |
|
|
boolean isHomotypicToTaxon = acceptedGroup.equals(newHomotypicalGroup);
|
298 |
|
|
SynonymRelationshipType relType = isHomotypicToTaxon? SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF() : SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF();
|
299 |
|
|
//TODO handle citation and microCitation
|
300 |
|
|
Reference citation = null;
|
301 |
|
|
String microCitation = null;
|
302 |
|
|
acceptedTaxon.addSynonym(synonym, relType, citation, microCitation);
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
}
|
306 |
|
|
|
307 |
a400a105
|
m.doering
|
|
308 |
b17d9121
|
Andreas Müller
|
/* (non-Javadoc)
|
309 |
f197a589
|
Andreas Müller
|
* @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
|
310 |
b17d9121
|
Andreas Müller
|
*/
|
311 |
|
|
@Override
|
312 |
f197a589
|
Andreas Müller
|
public void updateTitleCache(Class<? extends TaxonBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<TaxonBase> cacheStrategy, IProgressMonitor monitor) {
|
313 |
|
|
if (clazz == null){
|
314 |
|
|
clazz = TaxonBase.class;
|
315 |
|
|
}
|
316 |
|
|
super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
|
317 |
a400a105
|
m.doering
|
}
|
318 |
f197a589
|
Andreas Müller
|
|
319 |
d57c0df0
|
ben.clark
|
@Autowired
|
320 |
|
|
protected void setDao(ITaxonDao dao) {
|
321 |
|
|
this.dao = dao;
|
322 |
|
|
}
|
323 |
|
|
|
324 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
325 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#findTaxaByName(java.lang.Class, java.lang.String, java.lang.String, java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, java.lang.Integer, java.lang.Integer)
|
326 |
|
|
*/
|
327 |
a9e5cd74
|
ben.clark
|
public Pager<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize,Integer pageNumber) {
|
328 |
|
|
Integer numberOfResults = dao.countTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, rank);
|
329 |
d57c0df0
|
ben.clark
|
|
330 |
|
|
List<TaxonBase> results = new ArrayList<TaxonBase>();
|
331 |
|
|
if(numberOfResults > 0) { // no point checking again
|
332 |
a9e5cd74
|
ben.clark
|
results = dao.findTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, rank, pageSize, pageNumber);
|
333 |
d57c0df0
|
ben.clark
|
}
|
334 |
|
|
|
335 |
|
|
return new DefaultPagerImpl<TaxonBase>(pageNumber, numberOfResults, pageSize, results);
|
336 |
|
|
}
|
337 |
|
|
|
338 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
339 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#listTaxaByName(java.lang.Class, java.lang.String, java.lang.String, java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, java.lang.Integer, java.lang.Integer)
|
340 |
|
|
*/
|
341 |
eaf661e6
|
em.lee
|
public List<TaxonBase> listTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize,Integer pageNumber) {
|
342 |
|
|
Integer numberOfResults = dao.countTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, rank);
|
343 |
|
|
|
344 |
|
|
List<TaxonBase> results = new ArrayList<TaxonBase>();
|
345 |
|
|
if(numberOfResults > 0) { // no point checking again
|
346 |
|
|
results = dao.findTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, rank, pageSize, pageNumber);
|
347 |
|
|
}
|
348 |
|
|
|
349 |
|
|
return results;
|
350 |
|
|
}
|
351 |
|
|
|
352 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
353 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#listToTaxonRelationships(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
|
354 |
|
|
*/
|
355 |
d40f8755
|
Andreas Kohlbecker
|
public List<TaxonRelationship> listToTaxonRelationships(Taxon taxon, TaxonRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
|
356 |
|
|
Integer numberOfResults = dao.countTaxonRelationships(taxon, type, TaxonRelationship.Direction.relatedTo);
|
357 |
d57c0df0
|
ben.clark
|
|
358 |
|
|
List<TaxonRelationship> results = new ArrayList<TaxonRelationship>();
|
359 |
|
|
if(numberOfResults > 0) { // no point checking again
|
360 |
d40f8755
|
Andreas Kohlbecker
|
results = dao.getTaxonRelationships(taxon, type, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedTo);
|
361 |
d57c0df0
|
ben.clark
|
}
|
362 |
d40f8755
|
Andreas Kohlbecker
|
return results;
|
363 |
|
|
}
|
364 |
|
|
|
365 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
366 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#pageToTaxonRelationships(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
|
367 |
|
|
*/
|
368 |
d40f8755
|
Andreas Kohlbecker
|
public Pager<TaxonRelationship> pageToTaxonRelationships(Taxon taxon, TaxonRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
369 |
cba96ea5
|
ben.clark
|
Integer numberOfResults = dao.countTaxonRelationships(taxon, type, TaxonRelationship.Direction.relatedTo);
|
370 |
|
|
|
371 |
|
|
List<TaxonRelationship> results = new ArrayList<TaxonRelationship>();
|
372 |
|
|
if(numberOfResults > 0) { // no point checking again
|
373 |
|
|
results = dao.getTaxonRelationships(taxon, type, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedTo);
|
374 |
|
|
}
|
375 |
|
|
return new DefaultPagerImpl<TaxonRelationship>(pageNumber, numberOfResults, pageSize, results);
|
376 |
d40f8755
|
Andreas Kohlbecker
|
}
|
377 |
|
|
|
378 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
379 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#listFromTaxonRelationships(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
|
380 |
|
|
*/
|
381 |
d40f8755
|
Andreas Kohlbecker
|
public List<TaxonRelationship> listFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
|
382 |
|
|
Integer numberOfResults = dao.countTaxonRelationships(taxon, type, TaxonRelationship.Direction.relatedFrom);
|
383 |
d57c0df0
|
ben.clark
|
|
384 |
d40f8755
|
Andreas Kohlbecker
|
List<TaxonRelationship> results = new ArrayList<TaxonRelationship>();
|
385 |
|
|
if(numberOfResults > 0) { // no point checking again
|
386 |
|
|
results = dao.getTaxonRelationships(taxon, type, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedFrom);
|
387 |
|
|
}
|
388 |
|
|
return results;
|
389 |
|
|
}
|
390 |
|
|
|
391 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
392 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#pageFromTaxonRelationships(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
|
393 |
|
|
*/
|
394 |
d40f8755
|
Andreas Kohlbecker
|
public Pager<TaxonRelationship> pageFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
395 |
cba96ea5
|
ben.clark
|
Integer numberOfResults = dao.countTaxonRelationships(taxon, type, TaxonRelationship.Direction.relatedFrom);
|
396 |
|
|
|
397 |
|
|
List<TaxonRelationship> results = new ArrayList<TaxonRelationship>();
|
398 |
|
|
if(numberOfResults > 0) { // no point checking again
|
399 |
|
|
results = dao.getTaxonRelationships(taxon, type, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedFrom);
|
400 |
|
|
}
|
401 |
|
|
return new DefaultPagerImpl<TaxonRelationship>(pageNumber, numberOfResults, pageSize, results);
|
402 |
d57c0df0
|
ben.clark
|
}
|
403 |
|
|
|
404 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
405 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getSynonyms(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
|
406 |
|
|
*/
|
407 |
d44277a9
|
ben.clark
|
public Pager<SynonymRelationship> getSynonyms(Taxon taxon, SynonymRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
408 |
d57c0df0
|
ben.clark
|
Integer numberOfResults = dao.countSynonyms(taxon, type);
|
409 |
|
|
|
410 |
|
|
List<SynonymRelationship> results = new ArrayList<SynonymRelationship>();
|
411 |
|
|
if(numberOfResults > 0) { // no point checking again
|
412 |
d44277a9
|
ben.clark
|
results = dao.getSynonyms(taxon, type, pageSize, pageNumber, orderHints, propertyPaths);
|
413 |
d57c0df0
|
ben.clark
|
}
|
414 |
|
|
|
415 |
|
|
return new DefaultPagerImpl<SynonymRelationship>(pageNumber, numberOfResults, pageSize, results);
|
416 |
|
|
}
|
417 |
9b62c409
|
Andreas Kohlbecker
|
|
418 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
419 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getSynonyms(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
|
420 |
|
|
*/
|
421 |
219ab499
|
ben.clark
|
public Pager<SynonymRelationship> getSynonyms(Synonym synonym, SynonymRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
422 |
|
|
Integer numberOfResults = dao.countSynonyms(synonym, type);
|
423 |
|
|
|
424 |
|
|
List<SynonymRelationship> results = new ArrayList<SynonymRelationship>();
|
425 |
|
|
if(numberOfResults > 0) { // no point checking again
|
426 |
|
|
results = dao.getSynonyms(synonym, type, pageSize, pageNumber, orderHints, propertyPaths);
|
427 |
|
|
}
|
428 |
|
|
|
429 |
|
|
return new DefaultPagerImpl<SynonymRelationship>(pageNumber, numberOfResults, pageSize, results);
|
430 |
|
|
}
|
431 |
|
|
|
432 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
433 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getHomotypicSynonymsByHomotypicGroup(eu.etaxonomy.cdm.model.taxon.Taxon, java.util.List)
|
434 |
|
|
*/
|
435 |
9b62c409
|
Andreas Kohlbecker
|
public List<Synonym> getHomotypicSynonymsByHomotypicGroup(Taxon taxon, List<String> propertyPaths){
|
436 |
|
|
Taxon t = (Taxon)dao.load(taxon.getUuid(), propertyPaths);
|
437 |
|
|
return t.getHomotypicSynonymsByHomotypicGroup();
|
438 |
|
|
}
|
439 |
|
|
|
440 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
441 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getHeterotypicSynonymyGroups(eu.etaxonomy.cdm.model.taxon.Taxon, java.util.List)
|
442 |
|
|
*/
|
443 |
9b62c409
|
Andreas Kohlbecker
|
public List<List<Synonym>> getHeterotypicSynonymyGroups(Taxon taxon, List<String> propertyPaths){
|
444 |
|
|
Taxon t = (Taxon)dao.load(taxon.getUuid(), propertyPaths);
|
445 |
|
|
List<HomotypicalGroup> hsgl = t.getHeterotypicSynonymyGroups();
|
446 |
|
|
List<List<Synonym>> heterotypicSynonymyGroups = new ArrayList<List<Synonym>>(hsgl.size());
|
447 |
|
|
for(HomotypicalGroup hsg : hsgl){
|
448 |
|
|
heterotypicSynonymyGroups.add(hsg.getSynonymsInGroup(t.getSec()));
|
449 |
|
|
}
|
450 |
|
|
return heterotypicSynonymyGroups;
|
451 |
|
|
}
|
452 |
24700eab
|
a.babadshanjan
|
|
453 |
e66d9d39
|
Katja Luther
|
public List<UuidAndTitleCache<TaxonBase>> findTaxaAndNamesForEditor(ITaxonServiceConfigurator configurator){
|
454 |
|
|
|
455 |
|
|
List<UuidAndTitleCache<TaxonBase>> result = new ArrayList<UuidAndTitleCache<TaxonBase>>();
|
456 |
|
|
Class<? extends TaxonBase> clazz = null;
|
457 |
|
|
if ((configurator.isDoTaxa() && configurator.isDoSynonyms())) {
|
458 |
|
|
clazz = TaxonBase.class;
|
459 |
|
|
//propertyPath.addAll(configurator.getTaxonPropertyPath());
|
460 |
|
|
//propertyPath.addAll(configurator.getSynonymPropertyPath());
|
461 |
|
|
} else if(configurator.isDoTaxa()) {
|
462 |
|
|
clazz = Taxon.class;
|
463 |
|
|
//propertyPath = configurator.getTaxonPropertyPath();
|
464 |
|
|
} else if (configurator.isDoSynonyms()) {
|
465 |
|
|
clazz = Synonym.class;
|
466 |
|
|
//propertyPath = configurator.getSynonymPropertyPath();
|
467 |
|
|
}
|
468 |
|
|
|
469 |
5d8d15f2
|
Katja Luther
|
|
470 |
f77b32f4
|
n.hoffmann
|
result = dao.getTaxaByNameForEditor(clazz, configurator.getTitleSearchStringSqlized(), configurator.getClassification(), configurator.getMatchMode(), configurator.getNamedAreas());
|
471 |
e66d9d39
|
Katja Luther
|
return result;
|
472 |
|
|
}
|
473 |
65c22e25
|
Andreas Kohlbecker
|
/* (non-Javadoc)
|
474 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#findTaxaAndNames(eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator)
|
475 |
|
|
*/
|
476 |
24700eab
|
a.babadshanjan
|
public Pager<IdentifiableEntity> findTaxaAndNames(ITaxonServiceConfigurator configurator) {
|
477 |
|
|
|
478 |
|
|
List<IdentifiableEntity> results = new ArrayList<IdentifiableEntity>();
|
479 |
7a9cb249
|
a.babadshanjan
|
int numberOfResults = 0; // overall number of results (as opposed to number of results per page)
|
480 |
|
|
List<TaxonBase> taxa = null;
|
481 |
24700eab
|
a.babadshanjan
|
|
482 |
7a9cb249
|
a.babadshanjan
|
// Taxa and synonyms
|
483 |
40ae36a4
|
Andreas Kohlbecker
|
long numberTaxaResults = 0L;
|
484 |
7a9cb249
|
a.babadshanjan
|
|
485 |
40ae36a4
|
Andreas Kohlbecker
|
Class<? extends TaxonBase> clazz = null;
|
486 |
892efc69
|
Andreas Kohlbecker
|
List<String> propertyPath = new ArrayList<String>();
|
487 |
e3def986
|
f.revilla
|
if(configurator.getTaxonPropertyPath() != null){
|
488 |
65c22e25
|
Andreas Kohlbecker
|
propertyPath.addAll(configurator.getTaxonPropertyPath());
|
489 |
|
|
}
|
490 |
829679d4
|
n.hoffmann
|
if ((configurator.isDoTaxa() && configurator.isDoSynonyms())) {
|
491 |
40ae36a4
|
Andreas Kohlbecker
|
clazz = TaxonBase.class;
|
492 |
892efc69
|
Andreas Kohlbecker
|
//propertyPath.addAll(configurator.getTaxonPropertyPath());
|
493 |
|
|
//propertyPath.addAll(configurator.getSynonymPropertyPath());
|
494 |
7a9cb249
|
a.babadshanjan
|
} else if(configurator.isDoTaxa()) {
|
495 |
a918f676
|
Andreas Kohlbecker
|
clazz = Taxon.class;
|
496 |
892efc69
|
Andreas Kohlbecker
|
//propertyPath = configurator.getTaxonPropertyPath();
|
497 |
7a9cb249
|
a.babadshanjan
|
} else if (configurator.isDoSynonyms()) {
|
498 |
a918f676
|
Andreas Kohlbecker
|
clazz = Synonym.class;
|
499 |
892efc69
|
Andreas Kohlbecker
|
//propertyPath = configurator.getSynonymPropertyPath();
|
500 |
40ae36a4
|
Andreas Kohlbecker
|
}
|
501 |
|
|
|
502 |
|
|
if(clazz != null){
|
503 |
65c22e25
|
Andreas Kohlbecker
|
if(configurator.getPageSize() != null){ // no point counting if we need all anyway
|
504 |
|
|
numberTaxaResults =
|
505 |
|
|
dao.countTaxaByName(clazz,
|
506 |
f77b32f4
|
n.hoffmann
|
configurator.getTitleSearchStringSqlized(), configurator.getClassification(), configurator.getMatchMode(),
|
507 |
65c22e25
|
Andreas Kohlbecker
|
configurator.getNamedAreas());
|
508 |
|
|
}
|
509 |
e66d9d39
|
Katja Luther
|
|
510 |
65c22e25
|
Andreas Kohlbecker
|
if(configurator.getPageSize() == null || numberTaxaResults > configurator.getPageSize() * configurator.getPageNumber()){ // no point checking again if less results
|
511 |
40ae36a4
|
Andreas Kohlbecker
|
taxa = dao.getTaxaByName(clazz,
|
512 |
f77b32f4
|
n.hoffmann
|
configurator.getTitleSearchStringSqlized(), configurator.getClassification(), configurator.getMatchMode(),
|
513 |
861721b1
|
Andreas Kohlbecker
|
configurator.getNamedAreas(), configurator.getPageSize(),
|
514 |
892efc69
|
Andreas Kohlbecker
|
configurator.getPageNumber(), propertyPath);
|
515 |
40ae36a4
|
Andreas Kohlbecker
|
}
|
516 |
24700eab
|
a.babadshanjan
|
}
|
517 |
|
|
|
518 |
7a9cb249
|
a.babadshanjan
|
if (logger.isDebugEnabled()) { logger.debug(numberTaxaResults + " matching taxa counted"); }
|
519 |
|
|
|
520 |
d40f8755
|
Andreas Kohlbecker
|
if(taxa != null){
|
521 |
|
|
results.addAll(taxa);
|
522 |
|
|
}
|
523 |
7a9cb249
|
a.babadshanjan
|
|
524 |
|
|
numberOfResults += numberTaxaResults;
|
525 |
e25724b6
|
em.lee
|
|
526 |
7a9cb249
|
a.babadshanjan
|
// Names without taxa
|
527 |
24700eab
|
a.babadshanjan
|
if (configurator.isDoNamesWithoutTaxa()) {
|
528 |
7a9cb249
|
a.babadshanjan
|
int numberNameResults = 0;
|
529 |
9cc4226b
|
Katja Luther
|
|
530 |
7a1d87e3
|
a.babadshanjan
|
List<? extends TaxonNameBase<?,?>> names =
|
531 |
f77b32f4
|
n.hoffmann
|
nameDao.findByName(configurator.getTitleSearchStringSqlized(), configurator.getMatchMode(),
|
532 |
e6555980
|
em.lee
|
configurator.getPageSize(), configurator.getPageNumber(), null, configurator.getTaxonNamePropertyPath());
|
533 |
7a1d87e3
|
a.babadshanjan
|
if (logger.isDebugEnabled()) { logger.debug(names.size() + " matching name(s) found"); }
|
534 |
|
|
if (names.size() > 0) {
|
535 |
24700eab
|
a.babadshanjan
|
for (TaxonNameBase<?,?> taxonName : names) {
|
536 |
|
|
if (taxonName.getTaxonBases().size() == 0) {
|
537 |
7a1d87e3
|
a.babadshanjan
|
results.add(taxonName);
|
538 |
|
|
numberNameResults++;
|
539 |
24700eab
|
a.babadshanjan
|
}
|
540 |
|
|
}
|
541 |
7a1d87e3
|
a.babadshanjan
|
if (logger.isDebugEnabled()) { logger.debug(numberNameResults + " matching name(s) without taxa found"); }
|
542 |
24700eab
|
a.babadshanjan
|
numberOfResults += numberNameResults;
|
543 |
|
|
}
|
544 |
|
|
}
|
545 |
7a1d87e3
|
a.babadshanjan
|
|
546 |
7a9cb249
|
a.babadshanjan
|
// Taxa from common names
|
547 |
9cc4226b
|
Katja Luther
|
|
548 |
7a1d87e3
|
a.babadshanjan
|
if (configurator.isDoTaxaByCommonNames()) {
|
549 |
9cc4226b
|
Katja Luther
|
taxa = null;
|
550 |
|
|
numberTaxaResults = 0;
|
551 |
65c22e25
|
Andreas Kohlbecker
|
if(configurator.getPageSize() != null){// no point counting if we need all anyway
|
552 |
f77b32f4
|
n.hoffmann
|
numberTaxaResults = dao.countTaxaByCommonName(configurator.getTitleSearchStringSqlized(), configurator.getClassification(), configurator.getMatchMode(), configurator.getNamedAreas());
|
553 |
65c22e25
|
Andreas Kohlbecker
|
}
|
554 |
|
|
if(configurator.getPageSize() == null || numberTaxaResults > configurator.getPageSize() * configurator.getPageNumber()){
|
555 |
f77b32f4
|
n.hoffmann
|
taxa = dao.getTaxaByCommonName(configurator.getTitleSearchStringSqlized(), configurator.getClassification(), configurator.getMatchMode(), configurator.getNamedAreas(), configurator.getPageSize(), configurator.getPageNumber(), configurator.getTaxonPropertyPath());
|
556 |
9cc4226b
|
Katja Luther
|
}
|
557 |
|
|
if(taxa != null){
|
558 |
|
|
results.addAll(taxa);
|
559 |
|
|
}
|
560 |
|
|
numberOfResults += numberTaxaResults;
|
561 |
|
|
|
562 |
7a1d87e3
|
a.babadshanjan
|
}
|
563 |
|
|
|
564 |
892efc69
|
Andreas Kohlbecker
|
return new DefaultPagerImpl<IdentifiableEntity>
|
565 |
24700eab
|
a.babadshanjan
|
(configurator.getPageNumber(), numberOfResults, configurator.getPageSize(), results);
|
566 |
|
|
}
|
567 |
b79861eb
|
Katja Luther
|
|
568 |
01c21ead
|
n.hoffmann
|
public List<UuidAndTitleCache<TaxonBase>> getTaxonUuidAndTitleCache(){
|
569 |
|
|
return dao.getUuidAndTitleCache();
|
570 |
b79861eb
|
Katja Luther
|
}
|
571 |
9cd8b927
|
Katja Luther
|
|
572 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
573 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getAllMedia(eu.etaxonomy.cdm.model.taxon.Taxon, int, int, int, java.lang.String[])
|
574 |
|
|
*/
|
575 |
a4e49cfa
|
Katja Luther
|
public List<MediaRepresentation> getAllMedia(Taxon taxon, int size, int height, int widthOrDuration, String[] mimeTypes){
|
576 |
9cd8b927
|
Katja Luther
|
List<MediaRepresentation> medRep = new ArrayList<MediaRepresentation>();
|
577 |
a4e49cfa
|
Katja Luther
|
taxon = (Taxon)dao.load(taxon.getUuid());
|
578 |
9cd8b927
|
Katja Luther
|
Set<TaxonDescription> descriptions = taxon.getDescriptions();
|
579 |
|
|
for (TaxonDescription taxDesc: descriptions){
|
580 |
|
|
Set<DescriptionElementBase> elements = taxDesc.getElements();
|
581 |
|
|
for (DescriptionElementBase descElem: elements){
|
582 |
|
|
for(Media media : descElem.getMedia()){
|
583 |
|
|
|
584 |
|
|
//find the best matching representation
|
585 |
d907eaa7
|
Andreas Kohlbecker
|
medRep.add(MediaUtils.findBestMatchingRepresentation(media, null, size, height, widthOrDuration, mimeTypes));
|
586 |
9cd8b927
|
Katja Luther
|
|
587 |
|
|
}
|
588 |
|
|
}
|
589 |
|
|
}
|
590 |
|
|
return medRep;
|
591 |
|
|
}
|
592 |
9cc4226b
|
Katja Luther
|
|
593 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
594 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#findTaxaByID(java.util.Set)
|
595 |
|
|
*/
|
596 |
9cc4226b
|
Katja Luther
|
public List<TaxonBase> findTaxaByID(Set<Integer> listOfIDs) {
|
597 |
|
|
return this.dao.findById(listOfIDs);
|
598 |
|
|
}
|
599 |
|
|
|
600 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
601 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#countAllRelationships()
|
602 |
|
|
*/
|
603 |
9cc4226b
|
Katja Luther
|
public int countAllRelationships() {
|
604 |
|
|
return this.dao.countAllRelationships();
|
605 |
|
|
}
|
606 |
|
|
|
607 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
608 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#createAllInferredSynonyms(eu.etaxonomy.cdm.model.taxon.Classification, eu.etaxonomy.cdm.model.taxon.Taxon)
|
609 |
|
|
*/
|
610 |
1d36aa54
|
Andreas Müller
|
public List<Synonym> createAllInferredSynonyms(Classification tree,
|
611 |
9cc4226b
|
Katja Luther
|
Taxon taxon) {
|
612 |
|
|
|
613 |
|
|
return this.dao.createAllInferredSynonyms(taxon, tree);
|
614 |
|
|
}
|
615 |
|
|
|
616 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
617 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#createInferredSynonyms(eu.etaxonomy.cdm.model.taxon.Classification, eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType)
|
618 |
|
|
*/
|
619 |
1d36aa54
|
Andreas Müller
|
public List<Synonym> createInferredSynonyms(Classification tree, Taxon taxon, SynonymRelationshipType type) {
|
620 |
9cc4226b
|
Katja Luther
|
|
621 |
|
|
return this.dao.createInferredSynonyms(taxon, tree, type);
|
622 |
|
|
}
|
623 |
|
|
|
624 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
625 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#findIdenticalTaxonNames(java.util.List)
|
626 |
|
|
*/
|
627 |
9cc4226b
|
Katja Luther
|
public List<TaxonNameBase> findIdenticalTaxonNames(List<String> propertyPath) {
|
628 |
|
|
|
629 |
|
|
return this.dao.findIdenticalTaxonNames(propertyPath);
|
630 |
|
|
}
|
631 |
|
|
|
632 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
633 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#findIdenticalTaxonNameIds(java.util.List)
|
634 |
|
|
*/
|
635 |
892efc69
|
Andreas Kohlbecker
|
public List<TaxonNameBase> findIdenticalTaxonNameIds(List<String> propertyPath) {
|
636 |
|
|
|
637 |
|
|
return this.dao.findIdenticalNamesNew(propertyPath);
|
638 |
|
|
}
|
639 |
|
|
|
640 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
641 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getPhylumName(eu.etaxonomy.cdm.model.name.TaxonNameBase)
|
642 |
|
|
*/
|
643 |
9cc4226b
|
Katja Luther
|
public String getPhylumName(TaxonNameBase name){
|
644 |
|
|
return this.dao.getPhylumName(name);
|
645 |
|
|
}
|
646 |
|
|
|
647 |
|
|
private class TaxonAndNameComparator implements Comparator{
|
648 |
|
|
|
649 |
|
|
public int compare(Object arg0, Object arg1) {
|
650 |
|
|
IdentifiableEntity castArg0 = (IdentifiableEntity) arg0;
|
651 |
|
|
IdentifiableEntity castArg1 = (IdentifiableEntity) arg1;
|
652 |
|
|
return castArg0.compareTo(castArg1);
|
653 |
|
|
}
|
654 |
|
|
|
655 |
|
|
}
|
656 |
892efc69
|
Andreas Kohlbecker
|
|
657 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
658 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteSynonymRelationships(eu.etaxonomy.cdm.model.taxon.Synonym)
|
659 |
|
|
*/
|
660 |
892efc69
|
Andreas Kohlbecker
|
public long deleteSynonymRelationships(Synonym syn) {
|
661 |
|
|
|
662 |
|
|
return dao.deleteSynonymRelationships(syn);
|
663 |
|
|
}
|
664 |
|
|
|
665 |
|
|
|
666 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
667 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#listSynonymRelationships(eu.etaxonomy.cdm.model.taxon.TaxonBase, eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction)
|
668 |
|
|
*/
|
669 |
892efc69
|
Andreas Kohlbecker
|
public List<SynonymRelationship> listSynonymRelationships(
|
670 |
|
|
TaxonBase taxonBase, SynonymRelationshipType type, Integer pageSize, Integer pageNumber,
|
671 |
|
|
List<OrderHint> orderHints, List<String> propertyPaths, Direction direction) {
|
672 |
|
|
Integer numberOfResults = dao.countSynonymRelationships(taxonBase, type, direction);
|
673 |
|
|
|
674 |
|
|
List<SynonymRelationship> results = new ArrayList<SynonymRelationship>();
|
675 |
|
|
if(numberOfResults > 0) { // no point checking again
|
676 |
|
|
results = dao.getSynonymRelationships(taxonBase, type, pageSize, pageNumber, orderHints, propertyPaths, direction);
|
677 |
|
|
}
|
678 |
|
|
return results;
|
679 |
|
|
}
|
680 |
65c22e25
|
Andreas Kohlbecker
|
|
681 |
|
|
/* (non-Javadoc)
|
682 |
ceec7c69
|
Andreas Müller
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#findBestMatchingTaxon(java.lang.String)
|
683 |
65c22e25
|
Andreas Kohlbecker
|
*/
|
684 |
|
|
@Override
|
685 |
|
|
public Taxon findBestMatchingTaxon(String taxonName) {
|
686 |
a6f05c62
|
Andreas Müller
|
MatchingTaxonConfigurator config = MatchingTaxonConfigurator.NewInstance();
|
687 |
|
|
config.setTaxonNameTitle(taxonName);
|
688 |
|
|
return findBestMatchingTaxon(config);
|
689 |
|
|
}
|
690 |
|
|
|
691 |
|
|
|
692 |
|
|
|
693 |
|
|
@Override
|
694 |
|
|
public Taxon findBestMatchingTaxon(MatchingTaxonConfigurator config) {
|
695 |
65c22e25
|
Andreas Kohlbecker
|
|
696 |
f34ca874
|
Andreas Müller
|
Taxon bestCandidate = null;
|
697 |
65c22e25
|
Andreas Kohlbecker
|
try{
|
698 |
3180d917
|
Andreas Kohlbecker
|
// 1. search for acceptet taxa
|
699 |
a6f05c62
|
Andreas Müller
|
List<TaxonBase> taxonList = dao.findByNameTitleCache(Taxon.class, config.getTaxonNameTitle(), null, MatchMode.EXACT, null, 0, null, null);
|
700 |
f34ca874
|
Andreas Müller
|
boolean bestCandidateMatchesSecUuid = false;
|
701 |
|
|
boolean bestCandidateIsInClassification = false;
|
702 |
a6f05c62
|
Andreas Müller
|
int countEqualCandidates = 0;
|
703 |
|
|
for(TaxonBase taxonBaseCandidate : taxonList){
|
704 |
65c22e25
|
Andreas Kohlbecker
|
if(taxonBaseCandidate instanceof Taxon){
|
705 |
a6f05c62
|
Andreas Müller
|
Taxon newCanditate = CdmBase.deproxy(taxonBaseCandidate, Taxon.class);
|
706 |
f34ca874
|
Andreas Müller
|
boolean newCandidateMatchesSecUuid = isMatchesSecUuid(newCanditate, config);
|
707 |
|
|
if (! newCandidateMatchesSecUuid && config.isOnlyMatchingSecUuid() ){
|
708 |
a6f05c62
|
Andreas Müller
|
continue;
|
709 |
f34ca874
|
Andreas Müller
|
}else if(newCandidateMatchesSecUuid && ! bestCandidateMatchesSecUuid){
|
710 |
|
|
bestCandidate = newCanditate;
|
711 |
a6f05c62
|
Andreas Müller
|
countEqualCandidates = 1;
|
712 |
f34ca874
|
Andreas Müller
|
bestCandidateMatchesSecUuid = true;
|
713 |
a6f05c62
|
Andreas Müller
|
continue;
|
714 |
65c22e25
|
Andreas Kohlbecker
|
}
|
715 |
a6f05c62
|
Andreas Müller
|
|
716 |
f34ca874
|
Andreas Müller
|
boolean newCandidateInClassification = isInClassification(newCanditate, config);
|
717 |
|
|
if (! newCandidateInClassification && config.isOnlyMatchingClassificationUuid()){
|
718 |
a6f05c62
|
Andreas Müller
|
continue;
|
719 |
f34ca874
|
Andreas Müller
|
}else if (newCandidateInClassification && ! bestCandidateIsInClassification){
|
720 |
|
|
bestCandidate = newCanditate;
|
721 |
|
|
countEqualCandidates = 1;
|
722 |
|
|
bestCandidateIsInClassification = true;
|
723 |
|
|
continue;
|
724 |
|
|
}
|
725 |
|
|
if (bestCandidate == null){
|
726 |
|
|
bestCandidate = newCanditate;
|
727 |
a6f05c62
|
Andreas Müller
|
countEqualCandidates = 1;
|
728 |
|
|
continue;
|
729 |
|
|
}
|
730 |
|
|
|
731 |
|
|
}else{ //not Taxon.class
|
732 |
|
|
continue;
|
733 |
|
|
}
|
734 |
|
|
countEqualCandidates++;
|
735 |
|
|
|
736 |
|
|
}
|
737 |
f34ca874
|
Andreas Müller
|
if (bestCandidate != null){
|
738 |
a6f05c62
|
Andreas Müller
|
if(countEqualCandidates > 1){
|
739 |
f34ca874
|
Andreas Müller
|
logger.info(countEqualCandidates + " equally matching TaxonBases found, using first accepted Taxon: " + bestCandidate.getTitleCache());
|
740 |
|
|
return bestCandidate;
|
741 |
a6f05c62
|
Andreas Müller
|
} else {
|
742 |
f34ca874
|
Andreas Müller
|
logger.info("using accepted Taxon: " + bestCandidate.getTitleCache());
|
743 |
|
|
return bestCandidate;
|
744 |
65c22e25
|
Andreas Kohlbecker
|
}
|
745 |
|
|
}
|
746 |
3180d917
|
Andreas Kohlbecker
|
|
747 |
a6f05c62
|
Andreas Müller
|
|
748 |
3180d917
|
Andreas Kohlbecker
|
// 2. search for synonyms
|
749 |
a6f05c62
|
Andreas Müller
|
if (config.isIncludeSynonyms()){
|
750 |
|
|
List<TaxonBase> synonymList = dao.findByNameTitleCache(Synonym.class, config.getTaxonNameTitle(), null, MatchMode.EXACT, null, 0, null, null);
|
751 |
|
|
for(TaxonBase taxonBase : synonymList){
|
752 |
|
|
if(taxonBase instanceof Synonym){
|
753 |
|
|
Synonym synonym = CdmBase.deproxy(taxonBase, Synonym.class);
|
754 |
|
|
Set<Taxon> acceptetdCandidates = synonym.getAcceptedTaxa();
|
755 |
|
|
if(!acceptetdCandidates.isEmpty()){
|
756 |
f34ca874
|
Andreas Müller
|
bestCandidate = acceptetdCandidates.iterator().next();
|
757 |
a6f05c62
|
Andreas Müller
|
if(acceptetdCandidates.size() == 1){
|
758 |
f34ca874
|
Andreas Müller
|
logger.info(acceptetdCandidates.size() + " Accepted taxa found for synonym " + taxonBase.getTitleCache() + ", using first one: " + bestCandidate.getTitleCache());
|
759 |
|
|
return bestCandidate;
|
760 |
a6f05c62
|
Andreas Müller
|
} else {
|
761 |
f34ca874
|
Andreas Müller
|
logger.info("using accepted Taxon " + bestCandidate.getTitleCache() + "for synonym " + taxonBase.getTitleCache());
|
762 |
|
|
return bestCandidate;
|
763 |
a6f05c62
|
Andreas Müller
|
}
|
764 |
|
|
//TODO extend method: search using treeUUID, using SecUUID, first find accepted then include synonyms until a matching taxon is found
|
765 |
3180d917
|
Andreas Kohlbecker
|
}
|
766 |
|
|
}
|
767 |
|
|
}
|
768 |
|
|
}
|
769 |
|
|
|
770 |
65c22e25
|
Andreas Kohlbecker
|
} catch (Exception e){
|
771 |
|
|
logger.error(e);
|
772 |
|
|
}
|
773 |
|
|
|
774 |
f34ca874
|
Andreas Müller
|
return bestCandidate;
|
775 |
65c22e25
|
Andreas Kohlbecker
|
}
|
776 |
b6cb1182
|
Andreas Müller
|
|
777 |
a6f05c62
|
Andreas Müller
|
private boolean isInClassification(Taxon taxon, MatchingTaxonConfigurator config) {
|
778 |
|
|
UUID configClassificationUuid = config.getClassificationUuid();
|
779 |
|
|
if (configClassificationUuid == null){
|
780 |
|
|
return false;
|
781 |
|
|
}
|
782 |
|
|
for (TaxonNode node : taxon.getTaxonNodes()){
|
783 |
|
|
UUID classUuid = node.getClassification().getUuid();
|
784 |
|
|
if (configClassificationUuid.equals(classUuid)){
|
785 |
|
|
return true;
|
786 |
|
|
}
|
787 |
|
|
}
|
788 |
|
|
return false;
|
789 |
|
|
}
|
790 |
|
|
|
791 |
|
|
private boolean isMatchesSecUuid(Taxon taxon, MatchingTaxonConfigurator config) {
|
792 |
|
|
UUID configSecUuid = config.getSecUuid();
|
793 |
|
|
if (configSecUuid == null){
|
794 |
|
|
return false;
|
795 |
|
|
}
|
796 |
|
|
UUID taxonSecUuid = (taxon.getSec() == null)? null : taxon.getSec().getUuid();
|
797 |
|
|
return configSecUuid.equals(taxonSecUuid);
|
798 |
|
|
}
|
799 |
|
|
|
800 |
ceec7c69
|
Andreas Müller
|
/* (non-Javadoc)
|
801 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#findBestMatchingSynonym(java.lang.String)
|
802 |
|
|
*/
|
803 |
b6cb1182
|
Andreas Müller
|
@Override
|
804 |
|
|
public Synonym findBestMatchingSynonym(String taxonName) {
|
805 |
|
|
List<TaxonBase> synonymList = dao.findByNameTitleCache(Synonym.class, taxonName, null, MatchMode.EXACT, null, 0, null, null);
|
806 |
|
|
if(! synonymList.isEmpty()){
|
807 |
|
|
Synonym result = CdmBase.deproxy(synonymList.iterator().next(), Synonym.class);
|
808 |
|
|
if(synonymList.size() == 1){
|
809 |
|
|
logger.info(synonymList.size() + " Synonym found " + result.getTitleCache() );
|
810 |
|
|
return result;
|
811 |
|
|
} else {
|
812 |
|
|
logger.info("Several matching synonyms found. Using first: " + result.getTitleCache());
|
813 |
|
|
return result;
|
814 |
|
|
}
|
815 |
|
|
}
|
816 |
|
|
return null;
|
817 |
|
|
}
|
818 |
15ce3c9c
|
n.hoffmann
|
|
819 |
|
|
/* (non-Javadoc)
|
820 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#moveSynonymToAnotherTaxon(eu.etaxonomy.cdm.model.taxon.SynonymRelationship, eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)
|
821 |
|
|
*/
|
822 |
|
|
@Override
|
823 |
|
|
public Taxon moveSynonymToAnotherTaxon(SynonymRelationship synonymRelation,
|
824 |
|
|
Taxon toTaxon, SynonymRelationshipType synonymRelationshipType, Reference reference, String referenceDetail) {
|
825 |
|
|
Taxon fromTaxon = synonymRelation.getAcceptedTaxon();
|
826 |
fd992c0d
|
n.hoffmann
|
|
827 |
|
|
toTaxon.addSynonym(synonymRelation.getSynonym(), synonymRelationshipType, reference, referenceDetail);
|
828 |
15ce3c9c
|
n.hoffmann
|
|
829 |
|
|
fromTaxon.removeSynonymRelation(synonymRelation);
|
830 |
fd992c0d
|
n.hoffmann
|
|
831 |
15ce3c9c
|
n.hoffmann
|
return toTaxon;
|
832 |
|
|
}
|
833 |
7d399d75
|
n.hoffmann
|
|
834 |
|
|
/* (non-Javadoc)
|
835 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getUuidAndTitleCacheTaxon()
|
836 |
|
|
*/
|
837 |
|
|
@Override
|
838 |
|
|
public List<UuidAndTitleCache<TaxonBase>> getUuidAndTitleCacheTaxon() {
|
839 |
|
|
return dao.getUuidAndTitleCacheTaxon();
|
840 |
|
|
}
|
841 |
|
|
|
842 |
|
|
/* (non-Javadoc)
|
843 |
|
|
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getUuidAndTitleCacheSynonym()
|
844 |
|
|
*/
|
845 |
|
|
@Override
|
846 |
|
|
public List<UuidAndTitleCache<TaxonBase>> getUuidAndTitleCacheSynonym() {
|
847 |
|
|
return dao.getUuidAndTitleCacheSynonym();
|
848 |
|
|
}
|
849 |
b6cb1182
|
Andreas Müller
|
|
850 |
|
|
|
851 |
2d993c6e
|
Andreas Müller
|
}
|