import org.apache.log4j.Logger;\r
import org.apache.lucene.index.CorruptIndexException;\r
import org.apache.lucene.queryParser.ParseException;\r
+import org.apache.lucene.search.BooleanClause.Occur;\r
+import org.apache.lucene.search.BooleanQuery;\r
+import org.apache.lucene.search.Query;\r
+import org.apache.lucene.search.SortField;\r
import org.apache.lucene.search.TopDocs;\r
import org.springframework.beans.factory.annotation.Autowired;\r
import org.springframework.stereotype.Service;\r
import org.springframework.transaction.annotation.Propagation;\r
import org.springframework.transaction.annotation.Transactional;\r
\r
-import eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator;\r
+import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;\r
import eu.etaxonomy.cdm.api.service.config.MatchingTaxonConfigurator;\r
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;\r
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;\r
import eu.etaxonomy.cdm.api.service.pager.Pager;\r
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;\r
import eu.etaxonomy.cdm.api.service.search.ISearchResultBuilder;\r
+import eu.etaxonomy.cdm.api.service.search.LuceneSearch;\r
+import eu.etaxonomy.cdm.api.service.search.QueryFactory;\r
import eu.etaxonomy.cdm.api.service.search.SearchResult;\r
+import eu.etaxonomy.cdm.api.service.search.SearchResultBuilder;\r
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;\r
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;\r
+import eu.etaxonomy.cdm.hibernate.search.DefinedTermBaseClassBridge;\r
+import eu.etaxonomy.cdm.hibernate.search.MultilanguageTextFieldBridge;\r
import eu.etaxonomy.cdm.model.common.CdmBase;\r
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;\r
import eu.etaxonomy.cdm.model.common.IdentifiableSource;\r
+import eu.etaxonomy.cdm.model.common.Language;\r
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;\r
import eu.etaxonomy.cdm.model.common.RelationshipBase;\r
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;\r
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;\r
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
+import eu.etaxonomy.cdm.model.description.Feature;\r
import eu.etaxonomy.cdm.model.description.IIdentificationKey;\r
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;\r
import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
import eu.etaxonomy.cdm.persistence.query.MatchMode;\r
import eu.etaxonomy.cdm.persistence.query.OrderHint;\r
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;\r
-import eu.etaxonomy.cdm.search.LuceneSearch;\r
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;\r
\r
\r
@Service\r
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)\r
public class TaxonServiceImpl extends IdentifiableServiceBase<TaxonBase,ITaxonDao> implements ITaxonService{\r
- private static final Logger logger = Logger.getLogger(TaxonServiceImpl.class);\r
+ private static final Logger logger = Logger.getLogger(TaxonServiceImpl.class);\r
\r
- public static final String POTENTIAL_COMBINATION_NAMESPACE = "Potential combination";\r
+ public static final String POTENTIAL_COMBINATION_NAMESPACE = "Potential combination";\r
\r
- public static final String INFERRED_EPITHET_NAMESPACE = "Inferred epithet";\r
+ public static final String INFERRED_EPITHET_NAMESPACE = "Inferred epithet";\r
\r
- public static final String INFERRED_GENUS_NAMESPACE = "Inferred genus";\r
+ public static final String INFERRED_GENUS_NAMESPACE = "Inferred genus";\r
\r
\r
@Autowired\r
private ITaxonNameDao nameDao;\r
\r
@Autowired\r
- private ISearchResultBuilder searchResultBuilder;\r
+ private INameService nameService;\r
\r
- @Autowired\r
- private INameService nameService;\r
-\r
- @Autowired\r
- private ICdmGenericDao genericDao;\r
+ @Autowired\r
+ private ICdmGenericDao genericDao;\r
\r
- @Autowired\r
- private IDescriptionService descriptionService;\r
+ @Autowired\r
+ private IDescriptionService descriptionService;\r
\r
@Autowired\r
private IOrderedTermVocabularyDao orderedVocabularyDao;\r
- \r
- /**\r
- * Constructor\r
- */\r
- public TaxonServiceImpl(){\r
- if (logger.isDebugEnabled()) { logger.debug("Load TaxonService Bean"); }\r
- }\r
+\r
+ /**\r
+ * Constructor\r
+ */\r
+ public TaxonServiceImpl(){\r
+ if (logger.isDebugEnabled()) { logger.debug("Load TaxonService Bean"); }\r
+ }\r
\r
/**\r
* FIXME Candidate for harmonization\r
* @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)\r
*/\r
@Override\r
+ @Transactional(readOnly = false)\r
public void updateTitleCache(Class<? extends TaxonBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<TaxonBase> cacheStrategy, IProgressMonitor monitor) {\r
if (clazz == null){\r
clazz = TaxonBase.class;\r
return heterotypicSynonymyGroups;\r
}\r
\r
- public List<UuidAndTitleCache<TaxonBase>> findTaxaAndNamesForEditor(ITaxonServiceConfigurator configurator){\r
+ public List<UuidAndTitleCache<TaxonBase>> findTaxaAndNamesForEditor(IFindTaxaAndNamesConfigurator configurator){\r
\r
List<UuidAndTitleCache<TaxonBase>> result = new ArrayList<UuidAndTitleCache<TaxonBase>>();\r
// Class<? extends TaxonBase> clazz = null;\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#findTaxaAndNames(eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator)\r
*/\r
- public Pager<IdentifiableEntity> findTaxaAndNames(ITaxonServiceConfigurator configurator) {\r
+ public Pager<IdentifiableEntity> findTaxaAndNames(IFindTaxaAndNamesConfigurator configurator) {\r
\r
List<IdentifiableEntity> results = new ArrayList<IdentifiableEntity>();\r
int numberOfResults = 0; // overall number of results (as opposed to number of results per page)\r
return medRep;\r
}\r
\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.api.service.ITaxonService#listTaxonDescriptionMedia(eu.etaxonomy.cdm.model.taxon.Taxon, boolean)\r
+ */\r
+ public List<Media> listTaxonDescriptionMedia(Taxon taxon, boolean limitToGalleries, List<String> propertyPath){\r
+\r
+ Pager<TaxonDescription> p =\r
+ descriptionService.getTaxonDescriptions(taxon, null, null, null, null, propertyPath);\r
+\r
+ // pars the media and quality parameters\r
+\r
+\r
+ // collect all media of the given taxon\r
+ List<Media> taxonMedia = new ArrayList<Media>();\r
+ List<Media> taxonGalleryMedia = new ArrayList<Media>();\r
+ for(TaxonDescription desc : p.getRecords()){\r
+\r
+ if(desc.isImageGallery()){\r
+ for(DescriptionElementBase element : desc.getElements()){\r
+ for(Media media : element.getMedia()){\r
+ taxonGalleryMedia.add(media);\r
+ }\r
+ }\r
+ } else if(!limitToGalleries){\r
+ for(DescriptionElementBase element : desc.getElements()){\r
+ for(Media media : element.getMedia()){\r
+ taxonMedia.add(media);\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ taxonGalleryMedia.addAll(taxonMedia);\r
+ return taxonGalleryMedia;\r
+ }\r
+\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#findTaxaByID(java.util.Set)\r
*/\r
return this.dao.findById(listOfIDs);\r
}\r
\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.api.service.ITaxonService#findTaxonByUuid(UUID uuid, List<String> propertyPaths)\r
+ */\r
+ public TaxonBase findTaxonByUuid(UUID uuid, List<String> propertyPaths){\r
+ return this.dao.findByUuid(uuid, null ,propertyPaths);\r
+ }\r
+\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#countAllRelationships()\r
*/\r
return this.dao.countAllRelationships();\r
}\r
\r
- \r
\r
- \r
+\r
+\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#findIdenticalTaxonNames(java.util.List)\r
*/\r
return this.dao.findIdenticalTaxonNames(propertyPath);\r
}\r
\r
- \r
- /* (non-Javadoc)\r
+\r
+ /* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteTaxon(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator)\r
*/\r
@Override\r
public void deleteTaxon(Taxon taxon, TaxonDeletionConfigurator config) throws ReferencedObjectUndeletableException {\r
- if (config == null){\r
- config = new TaxonDeletionConfigurator();\r
- }\r
- \r
- // TaxonNode\r
- if (! config.isDeleteTaxonNodes()){\r
- if (taxon.getTaxonNodes().size() > 0){\r
- String message = "Taxon can't be deleted as it is used in a classification node. Remove taxon from all classifications prior to deletion.";\r
- throw new ReferencedObjectUndeletableException(message);\r
- }\r
- }\r
- \r
- \r
- // SynonymRelationShip\r
- if (config.isDeleteSynonymRelations()){\r
- boolean removeSynonymNameFromHomotypicalGroup = false;\r
- for (SynonymRelationship synRel : taxon.getSynonymRelations()){\r
- Synonym synonym = synRel.getSynonym();\r
- taxon.removeSynonymRelation(synRel, removeSynonymNameFromHomotypicalGroup);\r
- if (config.isDeleteSynonymsIfPossible()){\r
- //TODO which value\r
- boolean newHomotypicGroupIfNeeded = true;\r
- deleteSynonym(synonym, taxon, config.isDeleteNameIfPossible(), newHomotypicGroupIfNeeded);\r
- }else{\r
- deleteSynonymRelationships(synonym, taxon);\r
- }\r
- }\r
- }\r
- \r
- // TaxonRelationship \r
- if (! config.isDeleteTaxonRelationships()){\r
- if (taxon.getTaxonRelations().size() > 0){\r
- String message = "Taxon can't be deleted as it is related to another taxon. Remove taxon from all relations to other taxa prior to deletion.";\r
- throw new ReferencedObjectUndeletableException(message);\r
- }\r
- }\r
- \r
- \r
- // TaxonDescription\r
- Set<TaxonDescription> descriptions = taxon.getDescriptions();\r
- \r
- for (TaxonDescription desc: descriptions){\r
- if (config.isDeleteDescriptions()){\r
- //TODO use description delete configurator ?\r
- //FIXME check if description is ALWAYS deletable\r
- descriptionService.delete(desc); \r
- }else{\r
- if (desc.getDescribedSpecimenOrObservations().size()>0){\r
- String message = "Taxon can't be deleted as it is used in a TaxonDescription" +\r
- " which also describes specimens or abservations";\r
- throw new ReferencedObjectUndeletableException(message);\r
- }\r
- }\r
- }\r
- \r
- \r
- //check references with only reverse mapping\r
- Set<CdmBase> referencingObjects = genericDao.getReferencingObjects(taxon);\r
- for (CdmBase referencingObject : referencingObjects){\r
- //IIdentificationKeys (Media, Polytomous, MultiAccess)\r
- if (HibernateProxyHelper.isInstanceOf(referencingObject, IIdentificationKey.class)){\r
- String message = "Taxon can't be deleted as it is used in an identification key. Remove from identification key prior to deleting this name";\r
- message = String.format(message, CdmBase.deproxy(referencingObject, DerivedUnitBase.class).getTitleCache());\r
- throw new ReferencedObjectUndeletableException(message);\r
- }\r
- \r
- \r
- //PolytomousKeyNode\r
- if (referencingObject.isInstanceOf(PolytomousKeyNode.class)){\r
- String message = "Taxon can't be deleted as it is used in polytomous key node";\r
- throw new ReferencedObjectUndeletableException(message);\r
- }\r
- \r
- //TaxonInteraction\r
- if (referencingObject.isInstanceOf(TaxonInteraction.class)){\r
- String message = "Taxon can't be deleted as it is used in taxonInteraction#taxon2";\r
- throw new ReferencedObjectUndeletableException(message);\r
- }\r
- }\r
- \r
- \r
- //TaxonNameBase\r
- if (config.isDeleteNameIfPossible()){\r
- try {\r
- nameService.delete(taxon.getName(), config.getNameDeletionConfig());\r
- } catch (ReferencedObjectUndeletableException e) {\r
- //do nothing\r
- if (logger.isDebugEnabled()){logger.debug("Name could not be deleted");}\r
- }\r
- }\r
+ if (config == null){\r
+ config = new TaxonDeletionConfigurator();\r
+ }\r
+\r
+ // TaxonNode\r
+ if (! config.isDeleteTaxonNodes()){\r
+ if (taxon.getTaxonNodes().size() > 0){\r
+ String message = "Taxon can't be deleted as it is used in a classification node. Remove taxon from all classifications prior to deletion.";\r
+ throw new ReferencedObjectUndeletableException(message);\r
+ }\r
+ }\r
+\r
+\r
+ // SynonymRelationShip\r
+ if (config.isDeleteSynonymRelations()){\r
+ boolean removeSynonymNameFromHomotypicalGroup = false;\r
+ for (SynonymRelationship synRel : taxon.getSynonymRelations()){\r
+ Synonym synonym = synRel.getSynonym();\r
+ taxon.removeSynonymRelation(synRel, removeSynonymNameFromHomotypicalGroup);\r
+ if (config.isDeleteSynonymsIfPossible()){\r
+ //TODO which value\r
+ boolean newHomotypicGroupIfNeeded = true;\r
+ deleteSynonym(synonym, taxon, config.isDeleteNameIfPossible(), newHomotypicGroupIfNeeded);\r
+ }else{\r
+ deleteSynonymRelationships(synonym, taxon);\r
+ }\r
+ }\r
+ }\r
+\r
+ // TaxonRelationship\r
+ if (! config.isDeleteTaxonRelationships()){\r
+ if (taxon.getTaxonRelations().size() > 0){\r
+ String message = "Taxon can't be deleted as it is related to another taxon. Remove taxon from all relations to other taxa prior to deletion.";\r
+ throw new ReferencedObjectUndeletableException(message);\r
+ }\r
+ }\r
+\r
+\r
+ // TaxonDescription\r
+ Set<TaxonDescription> descriptions = taxon.getDescriptions();\r
+\r
+ for (TaxonDescription desc: descriptions){\r
+ if (config.isDeleteDescriptions()){\r
+ //TODO use description delete configurator ?\r
+ //FIXME check if description is ALWAYS deletable\r
+ descriptionService.delete(desc);\r
+ }else{\r
+ if (desc.getDescribedSpecimenOrObservations().size()>0){\r
+ String message = "Taxon can't be deleted as it is used in a TaxonDescription" +\r
+ " which also describes specimens or abservations";\r
+ throw new ReferencedObjectUndeletableException(message);\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ //check references with only reverse mapping\r
+ Set<CdmBase> referencingObjects = genericDao.getReferencingObjects(taxon);\r
+ for (CdmBase referencingObject : referencingObjects){\r
+ //IIdentificationKeys (Media, Polytomous, MultiAccess)\r
+ if (HibernateProxyHelper.isInstanceOf(referencingObject, IIdentificationKey.class)){\r
+ String message = "Taxon can't be deleted as it is used in an identification key. Remove from identification key prior to deleting this name";\r
+ message = String.format(message, CdmBase.deproxy(referencingObject, DerivedUnitBase.class).getTitleCache());\r
+ throw new ReferencedObjectUndeletableException(message);\r
+ }\r
+\r
+\r
+ //PolytomousKeyNode\r
+ if (referencingObject.isInstanceOf(PolytomousKeyNode.class)){\r
+ String message = "Taxon can't be deleted as it is used in polytomous key node";\r
+ throw new ReferencedObjectUndeletableException(message);\r
+ }\r
+\r
+ //TaxonInteraction\r
+ if (referencingObject.isInstanceOf(TaxonInteraction.class)){\r
+ String message = "Taxon can't be deleted as it is used in taxonInteraction#taxon2";\r
+ throw new ReferencedObjectUndeletableException(message);\r
+ }\r
+ }\r
+\r
+\r
+ //TaxonNameBase\r
+ if (config.isDeleteNameIfPossible()){\r
+ try {\r
+ nameService.delete(taxon.getName(), config.getNameDeletionConfig());\r
+ } catch (ReferencedObjectUndeletableException e) {\r
+ //do nothing\r
+ if (logger.isDebugEnabled()){logger.debug("Name could not be deleted");}\r
+ }\r
+ }\r
\r
}\r
\r
return this.dao.getPhylumName(name);\r
}\r
\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteSynonymRelationships(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon)\r
- */\r
- public long deleteSynonymRelationships(Synonym syn, Taxon taxon) {\r
- return dao.deleteSynonymRelationships(syn, taxon);\r
- }\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteSynonymRelationships(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon)\r
+ */\r
+ public long deleteSynonymRelationships(Synonym syn, Taxon taxon) {\r
+ return dao.deleteSynonymRelationships(syn, taxon);\r
+ }\r
\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteSynonymRelationships(eu.etaxonomy.cdm.model.taxon.Synonym)\r
}\r
\r
@Override\r
- public Pager<SearchResult<TaxonBase>> findByDescriptionElementFullText(Class<? extends DescriptionElementBase> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,\r
- List<String> propertyPaths) throws CorruptIndexException, IOException, ParseException {\r
+ public Pager<SearchResult<TaxonBase>> findByFullText(\r
+ Class<? extends TaxonBase> clazz, String queryString,\r
+ Classification classification, List<Language> languages,\r
+ boolean highlightFragments, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws CorruptIndexException, IOException, ParseException {\r
+\r
+// // -- set defaults\r
+// Class<? extends TaxonBase> directorySelectClass = TaxonBase.class;\r
+// if(clazz != null){\r
+// directorySelectClass = clazz;\r
+// }\r
+ return null;\r
+\r
+ }\r
+\r
+ @Override\r
+ public Pager<SearchResult<TaxonBase>> findByDescriptionElementFullText(\r
+ Class<? extends DescriptionElementBase> clazz, String queryString,\r
+ Classification classification, List<Feature> features, List<Language> languages,\r
+ boolean highlightFragments, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws CorruptIndexException, IOException, ParseException {\r
+\r
+ // -- set defaults\r
+ Class<? extends DescriptionElementBase> directorySelectClass = DescriptionElementBase.class;\r
+ if(clazz != null){\r
+ directorySelectClass = clazz;\r
+ }\r
+\r
+\r
+ BooleanQuery finalQuery = new BooleanQuery();\r
+ BooleanQuery textQuery = new BooleanQuery();\r
+\r
+ LuceneSearch luceneSearch = new LuceneSearch(getSession(), directorySelectClass);\r
+ QueryFactory queryFactory = new QueryFactory(luceneSearch);\r
+\r
+ // ---- search criteria\r
+ textQuery.add(queryFactory.newTermQuery("titleCache", queryString), Occur.SHOULD);\r
+\r
+ // common name\r
+ Query nameQuery;\r
+ if(languages == null || languages.size() == 0){\r
+ nameQuery = queryFactory.newTermQuery("name", queryString);\r
+ } else {\r
+ nameQuery = new BooleanQuery();\r
+ BooleanQuery languageSubQuery = new BooleanQuery();\r
+ for(Language lang : languages){\r
+ languageSubQuery.add(queryFactory.newTermQuery("language.uuid", lang.getUuid().toString()), Occur.SHOULD);\r
+ }\r
+ ((BooleanQuery) nameQuery).add(queryFactory.newTermQuery("name", queryString), Occur.MUST);\r
+ ((BooleanQuery) nameQuery).add(languageSubQuery, Occur.MUST);\r
+ }\r
+ textQuery.add(nameQuery, Occur.SHOULD);\r
+\r
+\r
+ // text field from TextData\r
+ textQuery.add(queryFactory.newLocalizedTermQuery("text", queryString, languages), Occur.SHOULD);\r
+\r
+ // --- TermBase fields - by representation ----\r
+ // state field from CategoricalData\r
+ textQuery.add(queryFactory.newLocalizedTermQuery("states.state.representation", queryString, languages), Occur.SHOULD);\r
\r
- String luceneQueryTemplate = "titleCache:%1$s OR multilanguageText.text:%1$s OR name:%1$s";\r
- String luceneQuery = String.format(luceneQueryTemplate, queryString);\r
+ // state field from CategoricalData\r
+ textQuery.add(queryFactory.newLocalizedTermQuery("states.modifyingText", queryString, languages), Occur.SHOULD);\r
\r
- LuceneSearch luceneSearch = new LuceneSearch(getSession(), clazz);\r
- TopDocs topDocsResultSet = luceneSearch.executeSearch(luceneQuery);\r
- List<SearchResult<TaxonBase>> searchResults = searchResultBuilder.createResultSetFromIds(luceneSearch, topDocsResultSet, dao, "inDescription.taxon.id");\r
+ finalQuery.add(textQuery, Occur.MUST);\r
+ // --- classification ----\r
+\r
+ if(classification != null){\r
+ finalQuery.add(queryFactory.newEntityIdQuery("inDescription.taxon.taxonNodes.classification.id", classification), Occur.MUST);\r
+ }\r
+\r
+ // --- IdentifieableEntity fields - by uuid\r
+ if(features != null && features.size() > 0 ){\r
+ finalQuery.add(queryFactory.newEntityUuidQuery("feature.uuid", features), Occur.MUST);\r
+ }\r
+\r
+ // the description must be associated with a taxon\r
+ finalQuery.add(queryFactory.newIdNotNullQuery("inDescription.taxon.id"), Occur.MUST);\r
+\r
+ SortField[] sortFields = new SortField[]{SortField.FIELD_SCORE, new SortField("inDescription.taxon.titleCache__sort", false)};\r
+\r
+ TopDocs topDocsResultSet = luceneSearch.executeSearch(finalQuery, clazz, pageSize, pageNumber, sortFields);\r
+\r
+ String[] highlightFields = null;\r
+ if(highlightFragments){\r
+ highlightFields = queryFactory.getTextFieldNames().toArray(new String[queryFactory.getTextFieldNames().size()]);\r
+ }\r
+\r
+ // initialize taxa, thighlight matches ....\r
+ ISearchResultBuilder searchResultBuilder = new SearchResultBuilder(luceneSearch, finalQuery);\r
+ List<SearchResult<TaxonBase>> searchResults = searchResultBuilder.createResultSet(\r
+ topDocsResultSet, highlightFields, dao, "inDescription.taxon.id", propertyPaths);\r
\r
return new DefaultPagerImpl<SearchResult<TaxonBase>>(pageNumber, searchResults.size(), pageSize, searchResults);\r
\r
}\r
- \r
- public List<Synonym> createInferredSynonyms(Taxon taxon, Classification classification, SynonymRelationshipType type){\r
+\r
+ /**\r
+ * DefinedTerm representations and MultilanguageString maps are stored in the Lucene index by the {@link DefinedTermBaseClassBridge}\r
+ * and {@link MultilanguageTextFieldBridge } in a consistent way. One field per language and also in one additional field for all languages.\r
+ * This method is a convenient means to retrieve a Lucene query string for such the fields.\r
+ *\r
+ * @param name name of the term field as in the Lucene index. Must be field created by {@link DefinedTermBaseClassBridge}\r
+ * or {@link MultilanguageTextFieldBridge }\r
+ * @param languages the languages to search for exclusively. Can be <code>null</code> to search in all languages\r
+ * @param stringBuilder a StringBuilder to be reused, if <code>null</code> a new StringBuilder will be instantiated and is returned\r
+ * @return the StringBuilder given a parameter or a new one if the stringBuilder parameter was null.\r
+ *\r
+ * TODO move to utiliy class !!!!!!!!\r
+ */\r
+ private StringBuilder appendLocalizedFieldQuery(String name, List<Language> languages, StringBuilder stringBuilder) {\r
+\r
+ if(stringBuilder == null){\r
+ stringBuilder = new StringBuilder();\r
+ }\r
+ if(languages == null || languages.size() == 0){\r
+ stringBuilder.append(name + ".ALL:(%1$s) ");\r
+ } else {\r
+ for(Language lang : languages){\r
+ stringBuilder.append(name + "." + lang.getUuid().toString() + ":(%1$s) ");\r
+ }\r
+ }\r
+ return stringBuilder;\r
+ }\r
+\r
+ public List<Synonym> createInferredSynonyms(Taxon taxon, Classification classification, SynonymRelationshipType type, boolean doWithMisappliedNames){\r
List <Synonym> inferredSynonyms = new ArrayList<Synonym>();\r
List<Synonym> inferredSynonymsToBeRemoved = new ArrayList<Synonym>();\r
\r
HashMap <UUID, ZoologicalName> zooHashMap = new HashMap<UUID, ZoologicalName>();\r
- \r
+\r
+\r
UUID uuid= taxon.getName().getUuid();\r
ZoologicalName taxonName = getZoologicalName(uuid, zooHashMap);\r
String epithetOfTaxon = null;\r
String infragenericEpithetOfTaxon = null;\r
String infraspecificEpithetOfTaxon = null;\r
if (taxonName.isSpecies()){\r
- epithetOfTaxon= taxonName.getSpecificEpithet();\r
+ epithetOfTaxon= taxonName.getSpecificEpithet();\r
} else if (taxonName.isInfraGeneric()){\r
- infragenericEpithetOfTaxon = taxonName.getInfraGenericEpithet();\r
+ infragenericEpithetOfTaxon = taxonName.getInfraGenericEpithet();\r
} else if (taxonName.isInfraSpecific()){\r
- infraspecificEpithetOfTaxon = taxonName.getInfraSpecificEpithet();\r
+ infraspecificEpithetOfTaxon = taxonName.getInfraSpecificEpithet();\r
}\r
String genusOfTaxon = taxonName.getGenusOrUninomial();\r
Set<TaxonNode> nodes = taxon.getTaxonNodes();\r
\r
if (node.getClassification().equals(classification)){\r
if (!node.isTopmostNode()){\r
- TaxonNode parent = (TaxonNode)node.getParent();\r
- parent = (TaxonNode)HibernateProxyHelper.deproxy(parent);\r
- TaxonNameBase parentName = parent.getTaxon().getName();\r
- ZoologicalName zooParentName = HibernateProxyHelper.deproxy(parentName, ZoologicalName.class);\r
- Taxon parentTaxon = (Taxon)HibernateProxyHelper.deproxy(parent.getTaxon());\r
- Rank rankOfTaxon = taxonName.getRank();\r
- \r
- \r
- //create inferred synonyms for species, subspecies or subgenus\r
- if (parentName.isGenus() || parentName.isSpecies() || parentName.getRank().equals(Rank.SUBGENUS())){\r
- \r
- Synonym inferredEpithet;\r
- Synonym inferredGenus = null;\r
- Synonym potentialCombination;\r
- \r
- List<String> propertyPaths = new ArrayList<String>();\r
- propertyPaths.add("synonym");\r
- propertyPaths.add("synonym.name");\r
- List<OrderHint> orderHints = new ArrayList<OrderHint>();\r
- orderHints.add(new OrderHint("relatedFrom.titleCache", SortOrder.ASCENDING));\r
- \r
- List<SynonymRelationship> synonymRelationshipsOfGenus = dao.getSynonyms(parentTaxon, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), null, null,orderHints,propertyPaths);\r
- List<SynonymRelationship> synonymRelationshipsOfTaxon= dao.getSynonyms(taxon, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), null, null,orderHints,propertyPaths);\r
- \r
- if (type.equals(SynonymRelationshipType.INFERRED_EPITHET_OF())){\r
- \r
- for (SynonymRelationship synonymRelationOfGenus:synonymRelationshipsOfGenus){\r
- TaxonNameBase synName;\r
- ZoologicalName inferredSynName;\r
- Synonym syn = synonymRelationOfGenus.getSynonym();\r
- HibernateProxyHelper.deproxy(syn);\r
- \r
- // Determine the idInSource\r
- String idInSourceSyn = getIdInSource(syn);\r
- String idInSourceTaxon = getIdInSource(taxon);\r
- // Determine the sourceReference\r
- Reference sourceReference = syn.getSec();\r
- \r
- synName = syn.getName();\r
- ZoologicalName zooName = getZoologicalName(synName.getUuid(), zooHashMap);\r
- String synGenusName = zooName.getGenusOrUninomial();\r
- String synInfraGenericEpithet = null;\r
- String synSpecificEpithet = null;\r
- if (zooName.isInfraGeneric()){\r
- synInfraGenericEpithet = zooName.getInfraGenericEpithet();\r
- } else if (zooName.isSpecies()){\r
- synSpecificEpithet = zooName.getSpecificEpithet();\r
- }\r
- \r
- /* if (synGenusName != null && !synonymsGenus.containsKey(synGenusName)){\r
- synonymsGenus.put(synGenusName, idInSource);\r
- }*/\r
- \r
- inferredSynName = ZoologicalName.NewInstance(rankOfTaxon);\r
- \r
- // DEBUG TODO: for subgenus or subspecies the infrageneric or infraspecific epithet should be used!!!\r
- if (epithetOfTaxon == null && infragenericEpithetOfTaxon == null && infraspecificEpithetOfTaxon == null) {\r
- logger.error("This specificEpithet is NULL" + taxon.getTitleCache());\r
- }\r
- inferredSynName.setGenusOrUninomial(synGenusName);\r
- if (inferredSynName.isSpecies()){\r
- if (parentName.isInfraGeneric()){\r
- inferredSynName.setInfraGenericEpithet(synInfraGenericEpithet);\r
- }\r
- inferredSynName.setSpecificEpithet(epithetOfTaxon);\r
- } else if (inferredSynName.isInfraGeneric()) {\r
- inferredSynName.setInfraGenericEpithet(infragenericEpithetOfTaxon);\r
- } else if (inferredSynName.isInfraSpecific()){\r
- inferredSynName.setSpecificEpithet(synSpecificEpithet);\r
- inferredSynName.setInfraSpecificEpithet(infraspecificEpithetOfTaxon);\r
- }\r
- \r
- inferredEpithet = Synonym.NewInstance(inferredSynName, null);\r
- \r
- // Set the sourceReference\r
- inferredEpithet.setSec(sourceReference);\r
- \r
- /* Add the original source\r
- if (idInSource != null) {\r
- IdentifiableSource originalSource = IdentifiableSource.NewInstance(idInSource, "InferredEpithetOf", syn.getSec(), null);\r
- \r
- // Add the citation\r
- Reference citation = getCitation(syn);\r
- if (citation != null) {\r
- originalSource.setCitation(citation);\r
- inferredEpithet.addSource(originalSource);\r
- }\r
- }*/\r
- String taxonId = idInSourceTaxon+ "; " + idInSourceSyn;\r
- \r
- IdentifiableSource originalSource;\r
- originalSource = IdentifiableSource.NewInstance(taxonId, INFERRED_EPITHET_NAMESPACE, sourceReference, null);\r
- \r
- inferredEpithet.addSource(originalSource);\r
- \r
- originalSource = IdentifiableSource.NewInstance(taxonId, INFERRED_EPITHET_NAMESPACE, sourceReference, null);\r
- \r
- inferredSynName.addSource(originalSource);\r
- \r
- \r
- \r
- taxon.addSynonym(inferredEpithet, SynonymRelationshipType.INFERRED_EPITHET_OF());\r
- inferredSynonyms.add(inferredEpithet);\r
- inferredSynName.generateTitle();\r
- zooHashMap.put(inferredSynName.getUuid(), inferredSynName);\r
- taxonNames.add(inferredSynName.getNameCache());\r
- }\r
- \r
- if (!taxonNames.isEmpty()){\r
- List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);\r
- ZoologicalName name;\r
- if (!synNotInCDM.isEmpty()){\r
- inferredSynonymsToBeRemoved.clear();\r
- \r
- for (Synonym syn :inferredSynonyms){\r
- name = getZoologicalName(syn.getName().getUuid(), zooHashMap);\r
- if (!synNotInCDM.contains(name.getNameCache())){\r
- inferredSynonymsToBeRemoved.add(syn);\r
- }\r
- }\r
- \r
- // Remove identified Synonyms from inferredSynonyms\r
- for (Synonym synonym : inferredSynonymsToBeRemoved) {\r
- inferredSynonyms.remove(synonym);\r
- }\r
- }\r
+ TaxonNode parent = (TaxonNode)node.getParent();\r
+ parent = (TaxonNode)HibernateProxyHelper.deproxy(parent);\r
+ TaxonNameBase parentName = parent.getTaxon().getName();\r
+ ZoologicalName zooParentName = HibernateProxyHelper.deproxy(parentName, ZoologicalName.class);\r
+ Taxon parentTaxon = (Taxon)HibernateProxyHelper.deproxy(parent.getTaxon());\r
+ Rank rankOfTaxon = taxonName.getRank();\r
+\r
+\r
+ //create inferred synonyms for species, subspecies\r
+ if ((parentName.isGenus() || parentName.isSpecies() || parentName.getRank().equals(Rank.SUBGENUS())) ){\r
+\r
+ Synonym inferredEpithet = null;\r
+ Synonym inferredGenus = null;\r
+ Synonym potentialCombination = null;\r
+\r
+ List<String> propertyPaths = new ArrayList<String>();\r
+ propertyPaths.add("synonym");\r
+ propertyPaths.add("synonym.name");\r
+ List<OrderHint> orderHints = new ArrayList<OrderHint>();\r
+ orderHints.add(new OrderHint("relatedFrom.titleCache", SortOrder.ASCENDING));\r
+\r
+ List<SynonymRelationship> synonymRelationshipsOfParent = dao.getSynonyms(parentTaxon, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), null, null,orderHints,propertyPaths);\r
+ List<SynonymRelationship> synonymRelationshipsOfTaxon= dao.getSynonyms(taxon, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), null, null,orderHints,propertyPaths);\r
+\r
+ List<TaxonRelationship> taxonRelListParent = null;\r
+ List<TaxonRelationship> taxonRelListTaxon = null;\r
+ if (doWithMisappliedNames){\r
+ taxonRelListParent = dao.getTaxonRelationships(parentTaxon, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), null, null, orderHints, propertyPaths, Direction.relatedTo);\r
+ taxonRelListTaxon = dao.getTaxonRelationships(taxon, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), null, null, orderHints, propertyPaths, Direction.relatedTo);\r
+ }\r
+\r
+\r
+ if (type.equals(SynonymRelationshipType.INFERRED_EPITHET_OF())){\r
+ Set<String> genusNames = new HashSet<String>();\r
+\r
+ for (SynonymRelationship synonymRelationOfParent:synonymRelationshipsOfParent){\r
+ Synonym syn = synonymRelationOfParent.getSynonym();\r
+\r
+ inferredEpithet = createInferredEpithets(taxon,\r
+ zooHashMap, taxonName, epithetOfTaxon,\r
+ infragenericEpithetOfTaxon,\r
+ infraspecificEpithetOfTaxon,\r
+ taxonNames, parentName,\r
+ syn);\r
+\r
+\r
+ inferredSynonyms.add(inferredEpithet);\r
+ zooHashMap.put(inferredEpithet.getName().getUuid(), (ZoologicalName)inferredEpithet.getName());\r
+ taxonNames.add(((ZoologicalName)inferredEpithet.getName()).getNameCache());\r
+ }\r
+\r
+ if (doWithMisappliedNames){\r
+\r
+ for (TaxonRelationship taxonRelationship: taxonRelListParent){\r
+ Taxon misappliedName = taxonRelationship.getFromTaxon();\r
+\r
+ inferredEpithet = createInferredEpithets(taxon,\r
+ zooHashMap, taxonName, epithetOfTaxon,\r
+ infragenericEpithetOfTaxon,\r
+ infraspecificEpithetOfTaxon,\r
+ taxonNames, parentName,\r
+ misappliedName);\r
+\r
+ inferredSynonyms.add(inferredEpithet);\r
+ zooHashMap.put(inferredEpithet.getName().getUuid(), (ZoologicalName)inferredEpithet.getName());\r
+ taxonNames.add(((ZoologicalName)inferredEpithet.getName()).getNameCache());\r
+ }\r
+ }\r
+\r
+ if (!taxonNames.isEmpty()){\r
+ List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);\r
+ ZoologicalName name;\r
+ if (!synNotInCDM.isEmpty()){\r
+ inferredSynonymsToBeRemoved.clear();\r
+\r
+ for (Synonym syn :inferredSynonyms){\r
+ name = getZoologicalName(syn.getName().getUuid(), zooHashMap);\r
+ if (!synNotInCDM.contains(name.getNameCache())){\r
+ inferredSynonymsToBeRemoved.add(syn);\r
+ }\r
+ }\r
+\r
+ // Remove identified Synonyms from inferredSynonyms\r
+ for (Synonym synonym : inferredSynonymsToBeRemoved) {\r
+ inferredSynonyms.remove(synonym);\r
+ }\r
+ }\r
}\r
\r
}else if (type.equals(SynonymRelationshipType.INFERRED_GENUS_OF())){\r
ZoologicalName inferredSynName;\r
\r
Synonym syn = synonymRelationOfTaxon.getSynonym();\r
- synName =syn.getName();\r
- HibernateProxyHelper.deproxy(syn);\r
+ inferredGenus = createInferredGenus(taxon,\r
+ zooHashMap, taxonName, epithetOfTaxon,\r
+ genusOfTaxon, taxonNames, zooParentName, syn);\r
\r
- // Determine the idInSource\r
- String idInSourceSyn = getIdInSource(syn);\r
- String idInSourceTaxon = getIdInSource(taxon);\r
- // Determine the sourceReference\r
- Reference sourceReference = syn.getSec();\r
-\r
- synName = syn.getName();\r
- ZoologicalName synZooName = getZoologicalName(synName.getUuid(), zooHashMap);\r
- String synSpeciesEpithetName = synZooName.getSpecificEpithet();\r
- /* if (synonymsEpithet != null && !synonymsEpithet.contains(synSpeciesEpithetName)){\r
- synonymsEpithet.add(synSpeciesEpithetName);\r
- }*/\r
- \r
- inferredSynName = ZoologicalName.NewInstance(rankOfTaxon);\r
- //TODO:differ between parent is genus and taxon is species, parent is subgenus and taxon is species, parent is species and taxon is subspecies and parent is genus and taxon is subgenus...\r
-\r
-\r
- inferredSynName.setGenusOrUninomial(genusOfTaxon);\r
- \r
- if (taxonName.isSpecies()){\r
- inferredSynName.setSpecificEpithet(synSpeciesEpithetName);\r
- if (zooParentName.isInfraGeneric()){\r
- inferredSynName.setInfraGenericEpithet(zooParentName.getInfraGenericEpithet());\r
- }\r
- }\r
- if (taxonName.isInfraSpecific()){\r
- inferredSynName.setSpecificEpithet(epithetOfTaxon);\r
- inferredSynName.setInfraSpecificEpithet(synZooName.getInfraGenericEpithet());\r
- }\r
- if (taxonName.isInfraGeneric()){\r
- inferredSynName.setInfraGenericEpithet(synZooName.getInfraGenericEpithet());\r
- }\r
- \r
- inferredGenus = Synonym.NewInstance(inferredSynName, null);\r
+ inferredSynonyms.add(inferredGenus);\r
+ zooHashMap.put(inferredGenus.getName().getUuid(), (ZoologicalName)inferredGenus.getName());\r
+ taxonNames.add(( (ZoologicalName)inferredGenus.getName()).getNameCache());\r
\r
- // Set the sourceReference\r
- inferredGenus.setSec(sourceReference);\r
-\r
- // Add the original source\r
- if (idInSourceSyn != null && idInSourceTaxon != null) {\r
- IdentifiableSource originalSource = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceTaxon, INFERRED_GENUS_NAMESPACE, sourceReference, null);\r
- inferredGenus.addSource(originalSource);\r
- \r
- originalSource = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceTaxon, INFERRED_GENUS_NAMESPACE, sourceReference, null);\r
- inferredSynName.addSource(originalSource);\r
- \r
- }\r
\r
- taxon.addSynonym(inferredGenus, SynonymRelationshipType.INFERRED_GENUS_OF());\r
- inferredSynonyms.add(inferredGenus);\r
- inferredSynName.generateTitle();\r
- zooHashMap.put(inferredSynName.getUuid(), inferredSynName);\r
- taxonNames.add(inferredSynName.getNameCache());\r
}\r
\r
+ if (doWithMisappliedNames){\r
+\r
+ for (TaxonRelationship taxonRelationship: taxonRelListTaxon){\r
+ Taxon misappliedName = taxonRelationship.getFromTaxon();\r
+ inferredGenus = createInferredGenus(taxon, zooHashMap, taxonName, infraspecificEpithetOfTaxon, genusOfTaxon, taxonNames, zooParentName, misappliedName);\r
+\r
+ inferredSynonyms.add(inferredGenus);\r
+ zooHashMap.put(inferredGenus.getName().getUuid(), (ZoologicalName)inferredGenus.getName());\r
+ taxonNames.add(( (ZoologicalName)inferredGenus.getName()).getNameCache());\r
+ }\r
+ }\r
+\r
+\r
if (!taxonNames.isEmpty()){\r
List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);\r
ZoologicalName name;\r
Reference sourceReference = null; // TODO: Determination of sourceReference is redundant\r
ZoologicalName inferredSynName;\r
//for all synonyms of the parent...\r
- for (SynonymRelationship synonymRelationOfGenus:synonymRelationshipsOfGenus){\r
+ for (SynonymRelationship synonymRelationOfParent:synonymRelationshipsOfParent){\r
TaxonNameBase synName;\r
- Synonym synParent = synonymRelationOfGenus.getSynonym();\r
+ Synonym synParent = synonymRelationOfParent.getSynonym();\r
synName = synParent.getName();\r
\r
HibernateProxyHelper.deproxy(synParent);\r
// Determine the idInSource\r
String idInSourceParent = getIdInSource(synParent);\r
\r
- ZoologicalName parentZooName = getZoologicalName(synName.getUuid(), zooHashMap);\r
- String synParentGenus = parentZooName.getGenusOrUninomial();\r
+ ZoologicalName parentSynZooName = getZoologicalName(synName.getUuid(), zooHashMap);\r
+ String synParentGenus = parentSynZooName.getGenusOrUninomial();\r
String synParentInfragenericName = null;\r
String synParentSpecificEpithet = null;\r
- \r
- if (parentZooName.isInfraGeneric()){\r
- synParentInfragenericName = parentZooName.getInfraGenericEpithet();\r
+\r
+ if (parentSynZooName.isInfraGeneric()){\r
+ synParentInfragenericName = parentSynZooName.getInfraGenericEpithet();\r
}\r
- if (parentZooName.isSpecies()){\r
- synParentSpecificEpithet = parentZooName.getSpecificEpithet();\r
+ if (parentSynZooName.isSpecies()){\r
+ synParentSpecificEpithet = parentSynZooName.getSpecificEpithet();\r
}\r
- \r
+\r
/* if (synGenusName != null && !synonymsGenus.containsKey(synGenusName)){\r
synonymsGenus.put(synGenusName, idInSource);\r
}*/\r
- \r
+\r
//for all synonyms of the taxon\r
- \r
+\r
for (SynonymRelationship synonymRelationOfTaxon:synonymRelationshipsOfTaxon){\r
\r
Synonym syn = synonymRelationOfTaxon.getSynonym();\r
- HibernateProxyHelper.deproxy(syn);\r
-\r
- // Set sourceReference\r
- sourceReference = syn.getSec();\r
-\r
- ZoologicalName zooName = getZoologicalName(syn.getName().getUuid(), zooHashMap);\r
- String synTaxonSpecificEpithet = zooName.getSpecificEpithet();\r
- String synTaxonInfragenericName = null;\r
- String synTaxonInfraSpecificName= null;\r
- \r
- if (parentZooName.isSpecies()){\r
- synTaxonInfraSpecificName = zooName.getInfraSpecificEpithet();\r
- }\r
- if (zooName.isInfraGeneric()){\r
- synTaxonInfragenericName = zooName.getInfraGenericEpithet();\r
- }\r
- \r
- /*if (epithetName != null && !synonymsEpithet.contains(epithetName)){\r
- synonymsEpithet.add(epithetName);\r
- }*/\r
- \r
- //create potential combinations...\r
- inferredSynName = ZoologicalName.NewInstance(rankOfTaxon);\r
- \r
- inferredSynName.setGenusOrUninomial(synParentGenus);\r
- if (taxonName.isSpecies()){\r
- inferredSynName.setSpecificEpithet(synTaxonSpecificEpithet);\r
- if (parentName.isInfraGeneric()){\r
- inferredSynName.setInfraGenericEpithet(synTaxonInfragenericName);\r
- }\r
- }\r
- if (taxonName.isInfraSpecific()){\r
- inferredSynName.setSpecificEpithet(synParentSpecificEpithet);\r
- inferredSynName.setInfraSpecificEpithet(synTaxonInfraSpecificName);\r
- }\r
- if (taxonName.isInfraGeneric()){\r
- inferredSynName.setInfraGenericEpithet(synTaxonInfragenericName);\r
- }\r
- \r
- \r
- potentialCombination = Synonym.NewInstance(inferredSynName, null);\r
+ ZoologicalName zooSynName = getZoologicalName(syn.getName().getUuid(), zooHashMap);\r
+ potentialCombination = createPotentialCombination(idInSourceParent, parentSynZooName, zooSynName,\r
+ synParentGenus,\r
+ synParentInfragenericName,\r
+ synParentSpecificEpithet, syn, zooHashMap);\r
+\r
+ taxon.addSynonym(potentialCombination, SynonymRelationshipType.POTENTIAL_COMBINATION_OF());\r
+ inferredSynonyms.add(potentialCombination);\r
+ zooHashMap.put(potentialCombination.getName().getUuid(), (ZoologicalName)potentialCombination.getName());\r
+ taxonNames.add(( (ZoologicalName)potentialCombination.getName()).getNameCache());\r
+\r
+ }\r
+\r
+\r
+ }\r
+\r
+ if (doWithMisappliedNames){\r
+\r
+ for (TaxonRelationship parentRelationship: taxonRelListParent){\r
+\r
+ TaxonNameBase misappliedParentName;\r
+\r
+ Taxon misappliedParent = parentRelationship.getFromTaxon();\r
+ misappliedParentName = misappliedParent.getName();\r
+\r
+ HibernateProxyHelper.deproxy(misappliedParent);\r
\r
// Set the sourceReference\r
- potentialCombination.setSec(sourceReference);\r
+ sourceReference = misappliedParent.getSec();\r
\r
- \r
// Determine the idInSource\r
- String idInSourceSyn= getIdInSource(syn);\r
- \r
- if (idInSourceParent != null && idInSourceSyn != null) {\r
-// IdentifiableSource originalSourceGenus = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceParent, POTENTIAL_COMBINATION_NAMESPACE, sourceReference, null);\r
-// inferredGenus.addSource(originalSourceGenus);\r
- \r
- IdentifiableSource originalSource = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceParent, POTENTIAL_COMBINATION_NAMESPACE, sourceReference, null);\r
- inferredSynName.addSource(originalSource);\r
- \r
+ String idInSourceParent = getIdInSource(misappliedParent);\r
+\r
+ ZoologicalName parentSynZooName = getZoologicalName(misappliedParentName.getUuid(), zooHashMap);\r
+ String synParentGenus = parentSynZooName.getGenusOrUninomial();\r
+ String synParentInfragenericName = null;\r
+ String synParentSpecificEpithet = null;\r
+\r
+ if (parentSynZooName.isInfraGeneric()){\r
+ synParentInfragenericName = parentSynZooName.getInfraGenericEpithet();\r
+ }\r
+ if (parentSynZooName.isSpecies()){\r
+ synParentSpecificEpithet = parentSynZooName.getSpecificEpithet();\r
}\r
- \r
-// if (idInSourceTaxon != null) {\r
-// IdentifiableSource originalSourceTaxon = IdentifiableSource.NewInstance(idInSourceTaxon, "PotentialCombinationOf", sourceReference, null);\r
-// if (sourceReference != null) {\r
-// originalSourceTaxon.setCitation(sourceReference);\r
-// potentialCombination.addSource(originalSourceTaxon);\r
-// }\r
-// }\r
-// if (idInSourceParent != null){\r
-// IdentifiableSource originalSourceParent = IdentifiableSource.NewInstance(idInSourceParent, "PotentialCombinationOf", sourceReference, null);\r
-// if (sourceReference != null) {\r
-// originalSourceParent.setCitation(sourceReference);\r
-// potentialCombination.addSource(originalSourceParent);\r
-// }\r
-// }\r
- \r
- // Add the citation\r
- \r
- \r
\r
- inferredSynonyms.add(potentialCombination);\r
- inferredSynName.generateTitle();\r
- zooHashMap.put(inferredSynName.getUuid(), inferredSynName);\r
- taxonNames.add(inferredSynName.getNameCache());\r
- \r
+\r
+ for (TaxonRelationship taxonRelationship: taxonRelListTaxon){\r
+ Taxon misappliedName = taxonRelationship.getFromTaxon();\r
+ ZoologicalName zooMisappliedName = getZoologicalName(misappliedName.getName().getUuid(), zooHashMap);\r
+ potentialCombination = createPotentialCombination(\r
+ idInSourceParent, parentSynZooName, zooMisappliedName,\r
+ synParentGenus,\r
+ synParentInfragenericName,\r
+ synParentSpecificEpithet, misappliedName, zooHashMap);\r
+\r
+\r
+ taxon.addSynonym(potentialCombination, SynonymRelationshipType.POTENTIAL_COMBINATION_OF());\r
+ inferredSynonyms.add(potentialCombination);\r
+ zooHashMap.put(potentialCombination.getName().getUuid(), (ZoologicalName)potentialCombination.getName());\r
+ taxonNames.add(( (ZoologicalName)potentialCombination.getName()).getNameCache());\r
+ }\r
}\r
- \r
}\r
+\r
if (!taxonNames.isEmpty()){\r
- List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);\r
+ List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);\r
ZoologicalName name;\r
if (!synNotInCDM.isEmpty()){\r
- inferredSynonymsToBeRemoved.clear();\r
- for (Synonym syn :inferredSynonyms){\r
- try{\r
- name = (ZoologicalName) syn.getName();\r
+ inferredSynonymsToBeRemoved.clear();\r
+ for (Synonym syn :inferredSynonyms){\r
+ try{\r
+ name = (ZoologicalName) syn.getName();\r
}catch (ClassCastException e){\r
- name = getZoologicalName(syn.getName().getUuid(), zooHashMap);\r
+ name = getZoologicalName(syn.getName().getUuid(), zooHashMap);\r
}\r
if (!synNotInCDM.contains(name.getNameCache())){\r
- inferredSynonymsToBeRemoved.add(syn);\r
+ inferredSynonymsToBeRemoved.add(syn);\r
}\r
}\r
- // Remove identified Synonyms from inferredSynonyms\r
+ // Remove identified Synonyms from inferredSynonyms\r
for (Synonym synonym : inferredSynonymsToBeRemoved) {\r
- inferredSynonyms.remove(synonym);\r
+ inferredSynonyms.remove(synonym);\r
}\r
}\r
}\r
}\r
}\r
}\r
- \r
+\r
}\r
\r
return inferredSynonyms;\r
}\r
\r
+ private Synonym createPotentialCombination(String idInSourceParent,\r
+ ZoologicalName parentSynZooName, ZoologicalName zooSynName, String synParentGenus,\r
+ String synParentInfragenericName, String synParentSpecificEpithet,\r
+ TaxonBase syn, HashMap<UUID, ZoologicalName> zooHashMap) {\r
+ Synonym potentialCombination;\r
+ Reference sourceReference;\r
+ ZoologicalName inferredSynName;\r
+ HibernateProxyHelper.deproxy(syn);\r
+\r
+ // Set sourceReference\r
+ sourceReference = syn.getSec();\r
+ if (sourceReference == null){\r
+ logger.warn("The synonym has no sec reference because it is a misapplied name! Take the sec reference of taxon");\r
+ //TODO:Remove\r
+ if (!parentSynZooName.getTaxa().isEmpty()){\r
+ TaxonBase taxon = parentSynZooName.getTaxa().iterator().next();\r
+\r
+ sourceReference = taxon.getSec();\r
+ }\r
+ }\r
+ String synTaxonSpecificEpithet = zooSynName.getSpecificEpithet();\r
+\r
+ String synTaxonInfraSpecificName= null;\r
+\r
+ if (parentSynZooName.isSpecies()){\r
+ synTaxonInfraSpecificName = zooSynName.getInfraSpecificEpithet();\r
+ }\r
+\r
+ /*if (epithetName != null && !synonymsEpithet.contains(epithetName)){\r
+ synonymsEpithet.add(epithetName);\r
+ }*/\r
+\r
+ //create potential combinations...\r
+ inferredSynName = ZoologicalName.NewInstance(syn.getName().getRank());\r
+\r
+ inferredSynName.setGenusOrUninomial(synParentGenus);\r
+ if (zooSynName.isSpecies()){\r
+ inferredSynName.setSpecificEpithet(synTaxonSpecificEpithet);\r
+ if (parentSynZooName.isInfraGeneric()){\r
+ inferredSynName.setInfraGenericEpithet(synParentInfragenericName);\r
+ }\r
+ }\r
+ if (zooSynName.isInfraSpecific()){\r
+ inferredSynName.setSpecificEpithet(synParentSpecificEpithet);\r
+ inferredSynName.setInfraSpecificEpithet(synTaxonInfraSpecificName);\r
+ }\r
+ if (parentSynZooName.isInfraGeneric()){\r
+ inferredSynName.setInfraGenericEpithet(synParentInfragenericName);\r
+ }\r
+\r
+\r
+ potentialCombination = Synonym.NewInstance(inferredSynName, null);\r
+\r
+ // Set the sourceReference\r
+ potentialCombination.setSec(sourceReference);\r
+\r
+\r
+ // Determine the idInSource\r
+ String idInSourceSyn= getIdInSource(syn);\r
+\r
+ if (idInSourceParent != null && idInSourceSyn != null) {\r
+ IdentifiableSource originalSource = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceParent, POTENTIAL_COMBINATION_NAMESPACE, sourceReference, null);\r
+ inferredSynName.addSource(originalSource);\r
+ originalSource = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceParent, POTENTIAL_COMBINATION_NAMESPACE, sourceReference, null);\r
+ potentialCombination.addSource(originalSource);\r
+ }\r
+\r
+ inferredSynName.generateTitle();\r
+\r
+ return potentialCombination;\r
+ }\r
+\r
+ private Synonym createInferredGenus(Taxon taxon,\r
+ HashMap<UUID, ZoologicalName> zooHashMap, ZoologicalName taxonName,\r
+ String epithetOfTaxon, String genusOfTaxon,\r
+ List<String> taxonNames, ZoologicalName zooParentName,\r
+ TaxonBase syn) {\r
+\r
+ Synonym inferredGenus;\r
+ TaxonNameBase synName;\r
+ ZoologicalName inferredSynName;\r
+ synName =syn.getName();\r
+ HibernateProxyHelper.deproxy(syn);\r
+\r
+ // Determine the idInSource\r
+ String idInSourceSyn = getIdInSource(syn);\r
+ String idInSourceTaxon = getIdInSource(taxon);\r
+ // Determine the sourceReference\r
+ Reference sourceReference = syn.getSec();\r
+\r
+ //logger.warn(sourceReference.getTitleCache());\r
+\r
+ synName = syn.getName();\r
+ ZoologicalName synZooName = getZoologicalName(synName.getUuid(), zooHashMap);\r
+ String synSpeciesEpithetName = synZooName.getSpecificEpithet();\r
+ /* if (synonymsEpithet != null && !synonymsEpithet.contains(synSpeciesEpithetName)){\r
+ synonymsEpithet.add(synSpeciesEpithetName);\r
+ }*/\r
+\r
+ inferredSynName = ZoologicalName.NewInstance(taxon.getName().getRank());\r
+ //TODO:differ between parent is genus and taxon is species, parent is subgenus and taxon is species, parent is species and taxon is subspecies and parent is genus and taxon is subgenus...\r
+\r
+\r
+ inferredSynName.setGenusOrUninomial(genusOfTaxon);\r
+ if (zooParentName.isInfraGeneric()){\r
+ inferredSynName.setInfraGenericEpithet(zooParentName.getInfraGenericEpithet());\r
+ }\r
+\r
+ if (taxonName.isSpecies()){\r
+ inferredSynName.setSpecificEpithet(synSpeciesEpithetName);\r
+ }\r
+ if (taxonName.isInfraSpecific()){\r
+ inferredSynName.setSpecificEpithet(epithetOfTaxon);\r
+ inferredSynName.setInfraSpecificEpithet(synZooName.getInfraGenericEpithet());\r
+ }\r
+\r
+\r
+ inferredGenus = Synonym.NewInstance(inferredSynName, null);\r
+\r
+ // Set the sourceReference\r
+ inferredGenus.setSec(sourceReference);\r
+\r
+ // Add the original source\r
+ if (idInSourceSyn != null && idInSourceTaxon != null) {\r
+ IdentifiableSource originalSource = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceTaxon, INFERRED_GENUS_NAMESPACE, sourceReference, null);\r
+ inferredGenus.addSource(originalSource);\r
+\r
+ originalSource = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceTaxon, INFERRED_GENUS_NAMESPACE, sourceReference, null);\r
+ inferredSynName.addSource(originalSource);\r
+ originalSource = null;\r
+\r
+ }else{\r
+ logger.error("There is an idInSource missing: " + idInSourceSyn + " of Synonym or " + idInSourceTaxon + " of Taxon");\r
+ IdentifiableSource originalSource = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceTaxon, INFERRED_GENUS_NAMESPACE, sourceReference, null);\r
+ inferredGenus.addSource(originalSource);\r
+\r
+ originalSource = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceTaxon, INFERRED_GENUS_NAMESPACE, sourceReference, null);\r
+ inferredSynName.addSource(originalSource);\r
+ originalSource = null;\r
+ }\r
+\r
+ taxon.addSynonym(inferredGenus, SynonymRelationshipType.INFERRED_GENUS_OF());\r
+\r
+ inferredSynName.generateTitle();\r
+\r
+\r
+ return inferredGenus;\r
+ }\r
+\r
+ private Synonym createInferredEpithets(Taxon taxon,\r
+ HashMap<UUID, ZoologicalName> zooHashMap, ZoologicalName taxonName,\r
+ String epithetOfTaxon, String infragenericEpithetOfTaxon,\r
+ String infraspecificEpithetOfTaxon, List<String> taxonNames,\r
+ TaxonNameBase parentName, TaxonBase syn) {\r
+\r
+ Synonym inferredEpithet;\r
+ TaxonNameBase synName;\r
+ ZoologicalName inferredSynName;\r
+ HibernateProxyHelper.deproxy(syn);\r
+\r
+ // Determine the idInSource\r
+ String idInSourceSyn = getIdInSource(syn);\r
+ String idInSourceTaxon = getIdInSource(taxon);\r
+ // Determine the sourceReference\r
+ Reference sourceReference = syn.getSec();\r
+\r
+ if (sourceReference == null){\r
+ logger.warn("The synonym has no sec reference because it is a misapplied name! Take the sec reference of taxon");\r
+ //TODO:Remove\r
+ System.out.println("The synonym has no sec reference because it is a misapplied name! Take the sec reference of taxon" + taxon.getSec());\r
+ sourceReference = taxon.getSec();\r
+ }\r
+\r
+ synName = syn.getName();\r
+ ZoologicalName zooSynName = getZoologicalName(synName.getUuid(), zooHashMap);\r
+ String synGenusName = zooSynName.getGenusOrUninomial();\r
+ String synInfraGenericEpithet = null;\r
+ String synSpecificEpithet = null;\r
+\r
+ if (zooSynName.getInfraGenericEpithet() != null){\r
+ synInfraGenericEpithet = zooSynName.getInfraGenericEpithet();\r
+ }\r
+\r
+ if (zooSynName.isInfraSpecific()){\r
+ synSpecificEpithet = zooSynName.getSpecificEpithet();\r
+ }\r
+\r
+ /* if (synGenusName != null && !synonymsGenus.containsKey(synGenusName)){\r
+ synonymsGenus.put(synGenusName, idInSource);\r
+ }*/\r
+\r
+ inferredSynName = ZoologicalName.NewInstance(taxon.getName().getRank());\r
+\r
+ // DEBUG TODO: for subgenus or subspecies the infrageneric or infraspecific epithet should be used!!!\r
+ if (epithetOfTaxon == null && infragenericEpithetOfTaxon == null && infraspecificEpithetOfTaxon == null) {\r
+ logger.error("This specificEpithet is NULL" + taxon.getTitleCache());\r
+ }\r
+ inferredSynName.setGenusOrUninomial(synGenusName);\r
+\r
+ if (parentName.isInfraGeneric()){\r
+ inferredSynName.setInfraGenericEpithet(synInfraGenericEpithet);\r
+ }\r
+ if (taxonName.isSpecies()){\r
+ inferredSynName.setSpecificEpithet(epithetOfTaxon);\r
+ }else if (taxonName.isInfraSpecific()){\r
+ inferredSynName.setSpecificEpithet(synSpecificEpithet);\r
+ inferredSynName.setInfraSpecificEpithet(infraspecificEpithetOfTaxon);\r
+ }\r
+\r
+ inferredEpithet = Synonym.NewInstance(inferredSynName, null);\r
+\r
+ // Set the sourceReference\r
+ inferredEpithet.setSec(sourceReference);\r
+\r
+ /* Add the original source\r
+ if (idInSource != null) {\r
+ IdentifiableSource originalSource = IdentifiableSource.NewInstance(idInSource, "InferredEpithetOf", syn.getSec(), null);\r
+\r
+ // Add the citation\r
+ Reference citation = getCitation(syn);\r
+ if (citation != null) {\r
+ originalSource.setCitation(citation);\r
+ inferredEpithet.addSource(originalSource);\r
+ }\r
+ }*/\r
+ String taxonId = idInSourceTaxon+ "; " + idInSourceSyn;\r
+\r
+ IdentifiableSource originalSource;\r
+ originalSource = IdentifiableSource.NewInstance(taxonId, INFERRED_EPITHET_NAMESPACE, sourceReference, null);\r
+\r
+ inferredEpithet.addSource(originalSource);\r
+\r
+ originalSource = IdentifiableSource.NewInstance(taxonId, INFERRED_EPITHET_NAMESPACE, sourceReference, null);\r
+\r
+ inferredSynName.addSource(originalSource);\r
+\r
+\r
+\r
+ taxon.addSynonym(inferredEpithet, SynonymRelationshipType.INFERRED_EPITHET_OF());\r
+\r
+ inferredSynName.generateTitle();\r
+ return inferredEpithet;\r
+ }\r
+\r
/**\r
* Returns an existing ZoologicalName or extends an internal hashmap if it does not exist.\r
* Very likely only useful for createInferredSynonyms().\r
}\r
return taxonName;\r
}\r
- \r
+\r
/**\r
* Returns the idInSource for a given Synonym.\r
* @param syn\r
}\r
count++;\r
}\r
+ } else if (sources.size() == 0){\r
+ logger.warn("No idInSource for TaxonBase " + taxonBase.getUuid() + " - " + taxonBase.getTitleCache());\r
}\r
\r
+\r
return idInSource;\r
}\r
- \r
+\r
\r
/**\r
* Returns the citation for a given Synonym.\r
\r
return citation;\r
}\r
- \r
- public List<Synonym> createAllInferredSynonyms(Taxon taxon, Classification tree){\r
+\r
+ public List<Synonym> createAllInferredSynonyms(Taxon taxon, Classification tree, boolean doWithMisappliedNames){\r
List <Synonym> inferredSynonyms = new ArrayList<Synonym>();\r
\r
- inferredSynonyms.addAll(createInferredSynonyms(taxon, tree, SynonymRelationshipType.INFERRED_EPITHET_OF()));\r
- inferredSynonyms.addAll(createInferredSynonyms(taxon, tree, SynonymRelationshipType.INFERRED_GENUS_OF()));\r
- inferredSynonyms.addAll(createInferredSynonyms(taxon, tree, SynonymRelationshipType.POTENTIAL_COMBINATION_OF()));\r
+ inferredSynonyms.addAll(createInferredSynonyms(taxon, tree, SynonymRelationshipType.INFERRED_EPITHET_OF(), doWithMisappliedNames));\r
+ inferredSynonyms.addAll(createInferredSynonyms(taxon, tree, SynonymRelationshipType.INFERRED_GENUS_OF(), doWithMisappliedNames));\r
+ inferredSynonyms.addAll(createInferredSynonyms(taxon, tree, SynonymRelationshipType.POTENTIAL_COMBINATION_OF(), doWithMisappliedNames));\r
\r
return inferredSynonyms;\r
}\r