import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import org.apache.lucene.search.grouping.TopGroups;
import org.apache.lucene.search.join.ScoreMode;
import org.apache.lucene.util.BytesRef;
+import org.hibernate.criterion.Criterion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import eu.etaxonomy.cdm.api.service.search.SearchResultBuilder;
import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
+import eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator;
+import eu.etaxonomy.cdm.compare.taxon.TaxonComparator;
import eu.etaxonomy.cdm.exception.UnpublishedException;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.hibernate.search.AcceptedTaxonBridge;
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
import eu.etaxonomy.cdm.model.location.NamedArea;
import eu.etaxonomy.cdm.model.media.Media;
+import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingEnum;
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
import eu.etaxonomy.cdm.model.name.IZoologicalName;
import eu.etaxonomy.cdm.model.name.Rank;
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.taxon.Classification;
-import eu.etaxonomy.cdm.model.taxon.HomotypicGroupTaxonComparator;
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.Synonym;
import eu.etaxonomy.cdm.model.taxon.SynonymType;
@Autowired
private IDescriptionService descriptionService;
+
+ @Autowired
+ private IReferenceService referenceService;
//
// @Autowired
// private IOrderedTermVocabularyDao orderedVocabularyDao;
// ****************************** METHODS ********************************/
-
- /**
- * {@inheritDoc}
- */
@Override
public TaxonBase load(UUID uuid, boolean includeUnpublished, List<String> propertyPaths) {
return dao.load(uuid, includeUnpublished, propertyPaths);
UpdateResult result = new UpdateResult();
acceptedTaxon.removeSynonym(synonym);
TaxonName synonymName = synonym.getName();
- boolean sameHomotypicGroup = synonymName.getHomotypicalGroup().equals(acceptedTaxon.getName().getHomotypicalGroup());
+ TaxonName taxonName = HibernateProxyHelper.deproxy(acceptedTaxon.getName());
+
+ boolean sameHomotypicGroup = synonymName.getHomotypicalGroup().equals(taxonName.getHomotypicalGroup());
synonymName.removeTaxonBase(synonym);
- TaxonName taxonName = HibernateProxyHelper.deproxy(acceptedTaxon.getName(), TaxonName.class);
//taxonName.removeTaxonBase(acceptedTaxon);
List<Synonym> synonyms = new ArrayList<>();
for (Synonym syn: synonyms){
acceptedTaxon.removeSynonym(syn);
}
- Taxon newTaxon = (Taxon)acceptedTaxon.clone();
+ Taxon newTaxon = acceptedTaxon.clone();
+ newTaxon.getDescriptions().clear();
+ Set<TaxonDescription> descriptionsToCopy = new HashSet<>();
+ for (TaxonDescription desc: acceptedTaxon.getDescriptions()){
+ descriptionsToCopy.add(desc);
+ }
+ for (TaxonDescription description: descriptionsToCopy){
+ newTaxon.addDescription(description);
+ }
newTaxon.setName(synonymName);
newTaxon.setSec(synonym.getSec());
+ newTaxon.setPublish(synonym.isPublish());
for (Synonym syn: synonyms){
if (!syn.getName().equals(newTaxon.getName())){
newTaxon.addSynonym(syn, syn.getType());
newTaxon.removeTaxonRelation(taxonRelationship);
}
-
for(TaxonRelationship taxonRelationship : acceptedTaxon.getTaxonRelations()){
Taxon fromTaxon = HibernateProxyHelper.deproxy(taxonRelationship.getFromTaxon());
Taxon toTaxon = HibernateProxyHelper.deproxy(taxonRelationship.getToTaxon());
taxonRelationship.setFromTaxon(null);
}
-
//Move descriptions to new taxon
List<TaxonDescription> descriptions = new ArrayList<TaxonDescription>( newTaxon.getDescriptions()); //to avoid concurrent modification errors (newAcceptedTaxon.addDescription() modifies also oldtaxon.descritpions())
for(TaxonDescription description : descriptions){
// //oldTaxon.removeDescription(description, false);
// newTaxon.addDescription(description);
}
- List<TaxonNode> nodes = new ArrayList(acceptedTaxon.getTaxonNodes());
+ List<TaxonNode> nodes = new ArrayList<>(acceptedTaxon.getTaxonNodes());
for (TaxonNode node: nodes){
node = HibernateProxyHelper.deproxy(node, TaxonNode.class);
TaxonNode parent = node.getParent();
}
}
- Synonym newSynonym = (Synonym)synonym.clone();
+ Synonym newSynonym = synonym.clone();
newSynonym.setName(taxonName);
newSynonym.setSec(acceptedTaxon.getSec());
+ newSynonym.setPublish(acceptedTaxon.isPublish());
if (sameHomotypicGroup){
newTaxon.addSynonym(newSynonym, SynonymType.HOMOTYPIC_SYNONYM_OF());
}else{
}
result.includeResult(deleteResult);
return result;
-
-
}
-
@Override
@Transactional(readOnly = false)
- public UpdateResult changeSynonymToAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon, boolean deleteSynonym) {
+ public UpdateResult changeSynonymToAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon, Reference newSecRef, String microRef, boolean deleteSynonym) {
UpdateResult result = new UpdateResult();
TaxonName acceptedName = acceptedTaxon.getName();
TaxonName synonymName = synonym.getName();
result.setAbort();
return result;
}
-
- Taxon newAcceptedTaxon = Taxon.NewInstance(synonymName, acceptedTaxon.getSec());
+ Taxon newAcceptedTaxon = Taxon.NewInstance(synonymName, newSecRef, microRef);
+ newAcceptedTaxon.setPublish(synonym.isPublish());
dao.save(newAcceptedTaxon);
result.setCdmEntity(newAcceptedTaxon);
SynonymType relTypeForGroup = SynonymType.HOMOTYPIC_SYNONYM_OF();
public UpdateResult changeSynonymToAcceptedTaxon(UUID synonymUuid,
UUID acceptedTaxonUuid,
UUID newParentNodeUuid,
+ UUID newSec,
+ String microReference,
+ SecReferenceHandlingEnum secHandling,
boolean deleteSynonym) {
UpdateResult result = new UpdateResult();
Synonym synonym = CdmBase.deproxy(dao.load(synonymUuid), Synonym.class);
Taxon acceptedTaxon = CdmBase.deproxy(dao.load(acceptedTaxonUuid), Taxon.class);
- result = changeSynonymToAcceptedTaxon(synonym, acceptedTaxon, deleteSynonym);
- Taxon newTaxon = (Taxon)result.getCdmEntity();
TaxonNode newParentNode = taxonNodeDao.load(newParentNodeUuid);
+ Reference newSecRef = null;
+ switch (secHandling){
+ case AlwaysDelete:
+ newSecRef = null;
+ break;
+ case KeepAlways:
+ newSecRef = synonym.getSec();
+ break;
+ case UseNewParentSec:
+ newSecRef = newParentNode.getTaxon() != null? newParentNode.getTaxon().getSec(): null;
+ break;
+ case KeepWhenSame:
+ Reference parentSec = newParentNode.getTaxon() != null? newParentNode.getTaxon().getSec(): null;
+ Reference synSec = synonym.getSec();
+ if (parentSec != null && synSec != null && parentSec.equals(synSec)){
+ newSecRef = synonym.getSec();
+ }else{
+ newSecRef = CdmBase.deproxy(referenceService.load(newSec));
+ }
+ case WarningSelect:
+ newSecRef = CdmBase.deproxy(referenceService.load(newSec));
+
+ default:
+ break;
+ }
+
+
+ result = changeSynonymToAcceptedTaxon(synonym, acceptedTaxon, newSecRef, microReference, deleteSynonym);
+ Taxon newTaxon = (Taxon)result.getCdmEntity();
+
TaxonNode newNode = newParentNode.addChildTaxon(newTaxon, null, null);
taxonNodeDao.save(newNode);
result.addUpdatedObject(newTaxon);
result.addUpdatedObject(acceptedTaxon);
result.setCdmEntity(newNode);
return result;
- }
-
-
+ }
@Override
@Transactional(readOnly = false)
*/
// Create a taxon with synonym name
Taxon fromTaxon = Taxon.NewInstance(synonymName, null);
+ fromTaxon.setPublish(synonym.isPublish());
save(fromTaxon);
fromTaxon.setAppendedPhrase(synonym.getAppendedPhrase());
SynonymType relType = isHomotypicToTaxon? SynonymType.HOMOTYPIC_SYNONYM_OF() : SynonymType.HETEROTYPIC_SYNONYM_OF();
targetTaxon.addSynonym(synonym, relType);
}
-
}
@Override
this.dao = dao;
}
-
@Override
- public Pager<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet,
+ public <T extends TaxonBase> Pager<T> findTaxaByName(Class<T> clazz, String uninomial, String infragenericEpithet, String specificEpithet,
String infraspecificEpithet, String authorshipCache, Rank rank, Integer pageSize,Integer pageNumber, List<String> propertyPaths) {
long numberOfResults = dao.countTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, authorshipCache, rank);
- List<TaxonBase> results = new ArrayList<>();
+ List<T> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again
results = dao.findTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, authorshipCache, rank,
pageSize, pageNumber, propertyPaths);
}
@Override
- public List<TaxonBase> listTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet,
+ public <T extends TaxonBase> List<T> listTaxaByName(Class<T> clazz, String uninomial, String infragenericEpithet, String specificEpithet,
String infraspecificEpithet, String authorshipCache, Rank rank, Integer pageSize,Integer pageNumber, List<String> propertyPaths) {
-
return findTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infragenericEpithet, authorshipCache, rank,
pageSize, pageNumber, propertyPaths).getRecords();
}
return relatedTaxa;
}
-
/**
* Recursively collect related taxa for the given <code>taxon</code> . The returned list will also include the
* <code>taxon</code> supplied as parameter.
taxon = (Taxon)dao.load(taxon.getUuid(), propertyPaths);
HomotypicGroupTaxonComparator comparator = new HomotypicGroupTaxonComparator(taxon);
-
//homotypic
result.add(taxon.getHomotypicSynonymsByHomotypicGroup(comparator));
}
return result;
-
}
@Override
@Override
public Pager<IdentifiableEntity> findTaxaAndNames(IFindTaxaAndNamesConfigurator configurator) {
+ @SuppressWarnings("rawtypes")
List<IdentifiableEntity> results = new ArrayList<>();
long numberOfResults = 0; // overall number of results (as opposed to number of results per page)
List<TaxonBase> taxa = null;
configurator.getMatchMode(), configurator.getNamedAreas(), configurator.isIncludeUnpublished(),
configurator.getOrder(), configurator.getPageSize(), configurator.getPageNumber(), propertyPath);
}
- }
+ }
if (logger.isDebugEnabled()) { logger.debug(numberTaxaResults + " matching taxa counted"); }
if(includeOccurrences != null && includeOccurrences) {
logger.trace("listMedia() - includeOccurrences");
+ @SuppressWarnings("rawtypes")
Set<SpecimenOrObservationBase> specimensOrObservations = new HashSet<>();
// --- Specimens
for (Taxon t : taxa) {
}
}
-
logger.trace("listMedia() - initialize");
beanInitializer.initializeAll(taxonMedia, propertyPath);
return this.dao.countSynonyms(onlyAttachedToTaxon);
}
-
-
@Override
@Transactional(readOnly=false)
public DeleteResult deleteTaxon(UUID taxonUUID, TaxonDeletionConfigurator config, UUID classificationUuid) {
configRelTaxon.setDeleteConceptRelationships(true);
for (TaxonRelationship taxRel: taxon.getTaxonRelations()){
- if (config.isDeleteMisappliedNamesAndInvalidDesignations()
- && taxRel.getType().isMisappliedNameOrInvalidDesignation()
+ if (config.isDeleteMisappliedNames()
+ && taxRel.getType().isMisappliedName()
&& taxon.equals(taxRel.getToTaxon())){
this.deleteTaxon(taxRel.getFromTaxon().getUuid(), config, classificationUuid);
} else if (config.isDeleteConceptRelationships() && taxRel.getType().isConceptRelationship()){
break;
}
removeDescriptions.add(desc);
-
-
}
if (result.isOk()){
for (TaxonDescription desc: removeDescriptions){
}
}
-
- if (! config.isDeleteTaxonNodes() || (!config.isDeleteInAllClassifications() && classification == null && taxon.getTaxonNodes().size() > 1)){
- result.addException(new Exception( "Taxon can't be deleted as it is used in more than one classification."));
- }else{
- if (taxon.getTaxonNodes().size() != 0){
- Set<TaxonNode> nodes = taxon.getTaxonNodes();
- Iterator<TaxonNode> iterator = nodes.iterator();
- TaxonNode node = null;
- boolean deleteChildren;
- if (config.getTaxonNodeConfig().getChildHandling().equals(ChildHandling.DELETE)){
- deleteChildren = true;
- }else {
- deleteChildren = false;
- }
- boolean success = true;
- if (!config.isDeleteInAllClassifications() && !(classification == null)){
- while (iterator.hasNext()){
- node = iterator.next();
- if (node.getClassification().equals(classification)){
- break;
- }
- node = null;
- }
- if (node != null){
- HibernateProxyHelper.deproxy(node, TaxonNode.class);
- success =taxon.removeTaxonNode(node, deleteChildren);
- nodeService.delete(node);
- result.addDeletedObject(node);
- } else {
- result.setError();
- result.addException(new Exception("The taxon can not be deleted because it is not used in defined classification."));
+ if (! config.isDeleteTaxonNodes() || (!config.isDeleteInAllClassifications() && classification == null && taxon.getTaxonNodes().size() > 1)){
+ result.addException(new Exception( "Taxon can't be deleted as it is used in more than one classification."));
+ }else{
+ if (taxon.getTaxonNodes().size() != 0){
+ Set<TaxonNode> nodes = taxon.getTaxonNodes();
+ Iterator<TaxonNode> iterator = nodes.iterator();
+ TaxonNode node = null;
+ boolean deleteChildren;
+ if (config.getTaxonNodeConfig().getChildHandling().equals(ChildHandling.DELETE)){
+ deleteChildren = true;
+ }else {
+ deleteChildren = false;
}
- } else if (config.isDeleteInAllClassifications()){
- List<TaxonNode> nodesList = new ArrayList<>();
- nodesList.addAll(taxon.getTaxonNodes());
- for (ITaxonTreeNode treeNode: nodesList){
- TaxonNode taxonNode = (TaxonNode) treeNode;
- if(!deleteChildren){
- Object[] childNodes = taxonNode.getChildNodes().toArray();
- for (Object childNode: childNodes){
- TaxonNode childNodeCast = (TaxonNode) childNode;
- taxonNode.getParent().addChildNode(childNodeCast, childNodeCast.getReference(), childNodeCast.getMicroReference());
+ boolean success = true;
+ if (!config.isDeleteInAllClassifications() && !(classification == null)){
+ while (iterator.hasNext()){
+ node = iterator.next();
+ if (node.getClassification().equals(classification)){
+ break;
}
+ node = null;
+ }
+ if (node != null){
+ HibernateProxyHelper.deproxy(node, TaxonNode.class);
+ success =taxon.removeTaxonNode(node, deleteChildren);
+ nodeService.delete(node);
+ result.addDeletedObject(node);
+ } else {
+ result.setError();
+ result.addException(new Exception("The taxon can not be deleted because it is not used in defined classification."));
+ }
+ } else if (config.isDeleteInAllClassifications()){
+ List<TaxonNode> nodesList = new ArrayList<>();
+ nodesList.addAll(taxon.getTaxonNodes());
+ for (ITaxonTreeNode treeNode: nodesList){
+ TaxonNode taxonNode = (TaxonNode) treeNode;
+ if(!deleteChildren){
+ Object[] childNodes = taxonNode.getChildNodes().toArray();
+ for (Object childNode: childNodes){
+ TaxonNode childNodeCast = (TaxonNode) childNode;
+ taxonNode.getParent().addChildNode(childNodeCast, childNodeCast.getReference(), childNodeCast.getMicroReference());
+ }
+ }
+ }
+ config.getTaxonNodeConfig().setDeleteElement(false);
+ DeleteResult resultNodes = nodeService.deleteTaxonNodes(nodesList, config);
+ if (!resultNodes.isOk()){
+ result.addExceptions(resultNodes.getExceptions());
+ result.setStatus(resultNodes.getStatus());
+ } else {
+ result.addUpdatedObjects(resultNodes.getUpdatedObjects());
}
}
- config.getTaxonNodeConfig().setDeleteElement(false);
- DeleteResult resultNodes = nodeService.deleteTaxonNodes(nodesList, config);
- if (!resultNodes.isOk()){
- result.addExceptions(resultNodes.getExceptions());
- result.setStatus(resultNodes.getStatus());
- } else {
- result.addUpdatedObjects(resultNodes.getUpdatedObjects());
+ if (!success){
+ result.setError();
+ result.addException(new Exception("The taxon can not be deleted because the taxon node can not be removed."));
}
}
- if (!success){
- result.setError();
- result.addException(new Exception("The taxon can not be deleted because the taxon node can not be removed."));
- }
- }
- }
- TaxonName name = taxon.getName();
- taxon.setName(null);
- this.saveOrUpdate(taxon);
-
- if ((taxon.getTaxonNodes() == null || taxon.getTaxonNodes().size()== 0) && result.isOk()){
- try{
- dao.delete(taxon);
- result.addDeletedObject(taxon);
- }catch(Exception e){
- result.addException(e);
- result.setError();
}
- } else {
- result.setError();
- result.addException(new Exception("The Taxon can't be deleted because it is used in a classification."));
+ TaxonName name = taxon.getName();
+ taxon.setName(null);
+ this.saveOrUpdate(taxon);
+
+ if ((taxon.getTaxonNodes() == null || taxon.getTaxonNodes().size()== 0) && result.isOk()){
+ try{
+ dao.delete(taxon);
+ result.addDeletedObject(taxon);
+ }catch(Exception e){
+ result.addException(e);
+ result.setError();
+ }
+ } else {
+ result.setError();
+ result.addException(new Exception("The Taxon can't be deleted because it is used in a classification."));
- }
- //TaxonName
- if (config.isDeleteNameIfPossible() && result.isOk()){
- DeleteResult nameResult = new DeleteResult();
- //remove name if possible (and required)
- if (name != null ){
- nameResult = nameService.delete(name.getUuid(), config.getNameDeletionConfig());
- }
- if (nameResult.isError() || nameResult.isAbort()){
- result.addRelatedObject(name);
- result.addExceptions(nameResult.getExceptions());
- }else{
- result.includeResult(nameResult);
- }
- }
+ }
+ //TaxonName
+ if (config.isDeleteNameIfPossible() && result.isOk()){
+ DeleteResult nameResult = new DeleteResult();
+ //remove name if possible (and required)
+ if (name != null ){
+ nameResult = nameService.delete(name.getUuid(), config.getNameDeletionConfig());
+ }
+ if (nameResult.isError() || nameResult.isAbort()){
+ result.addRelatedObject(name);
+ result.addExceptions(nameResult.getExceptions());
+ }else{
+ result.includeResult(nameResult);
+ }
+ }
}
return result;
-
}
@Override
@Transactional(readOnly = false)
public DeleteResult deleteSynonym(UUID synonymUuid, SynonymDeletionConfigurator config) {
return deleteSynonym((Synonym)dao.load(synonymUuid), config);
-
}
-
@Override
@Transactional(readOnly = false)
public DeleteResult deleteSynonym(Synonym synonym, SynonymDeletionConfigurator config) {
result.addDeletedObject(name);
}
}
-
}
return result;
}
@Override
public Map<String, Map<UUID,Set<TaxonName>>> findIdenticalTaxonNames(List<UUID> sourceRefUuids, List<String> propertyPaths) {
- return this.dao.findIdenticalNamesNew(sourceRefUuids, propertyPaths);
+ return this.dao.findIdenticalNames(sourceRefUuids, propertyPaths);
}
-
@Override
public Taxon findBestMatchingTaxon(String taxonName) {
MatchingTaxonConfigurator config = MatchingTaxonConfigurator.NewInstance();
countEqualCandidates = 1;
continue;
}
-
}else{ //not Taxon.class
continue;
}
}
}
-
// 2. search for synonyms
if (config.isIncludeSynonyms()){
List<TaxonBase> synonymList = dao.findByNameTitleCache(false, true, config.isIncludeUnpublished(),
}
@Override
- public <T extends TaxonBase> List<UuidAndTitleCache<T>> getUuidAndTitleCache(Class<T> clazz, Integer limit, String pattern) {
+ public <T extends TaxonBase>List<UuidAndTitleCache<T>> getUuidAndTitleCache(Class<T> clazz, Integer limit, String pattern) {
+
return dao.getUuidAndTitleCache(clazz, limit, pattern);
}
// --- initialize taxa, thighlight matches ....
ISearchResultBuilder searchResultBuilder = new SearchResultBuilder(luceneSearch, luceneSearch.getQuery());
+ @SuppressWarnings("rawtypes")
List<SearchResult<TaxonBase>> searchResults = searchResultBuilder.createResultSet(
topDocsResultSet, luceneSearch.getHighlightFields(), dao, idFieldMap, propertyPaths);
return new DefaultPagerImpl<>(pageNumber, totalHits, pageSize, searchResults);
}
+ @Transactional(readOnly = true)
+ @Override
+ public <S extends TaxonBase> Pager<S> findByTitleWithRestrictions(Class<S> clazz, String queryString, MatchMode matchmode, List<Restriction<?>> restrictions, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
+ long numberOfResults = dao.countByTitleWithRestrictions(clazz, queryString, matchmode, restrictions);
+
+ long numberOfResults_doubtful = dao.countByTitleWithRestrictions(clazz, "?".concat(queryString), matchmode, restrictions);
+ List<S> results = new ArrayList<>();
+ if(numberOfResults > 0 || numberOfResults_doubtful > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
+
+ results = dao.findByTitleWithRestrictions(clazz, queryString, matchmode, restrictions, pageSize, pageNumber, orderHints, propertyPaths);
+ results.addAll(dao.findByTitleWithRestrictions(clazz, "?".concat(queryString), matchmode, restrictions, pageSize, pageNumber, orderHints, propertyPaths));
+ }
+ Collections.sort(results, new TaxonComparator());
+ return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
+ }
+
+ @Transactional(readOnly = true)
+ @Override
+ public <S extends TaxonBase> Pager<S> findByTitle(Class<S> clazz, String queryString,MatchMode matchmode, List<Criterion> criteria, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
+ long numberOfResults = dao.countByTitle(clazz, queryString, matchmode, criteria);
+ //check whether there are doubtful taxa matching
+ long numberOfResults_doubtful = dao.countByTitle(clazz, "?".concat(queryString), matchmode, criteria);
+ List<S> results = new ArrayList<>();
+ if(numberOfResults > 0 || numberOfResults_doubtful > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
+ if (numberOfResults > 0){
+ results = dao.findByTitle(clazz, queryString, matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths);
+ }else{
+ results = new ArrayList<>();
+ }
+ if (numberOfResults_doubtful > 0){
+ results.addAll(dao.findByTitle(clazz, "?".concat(queryString), matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths));
+ }
+ }
+ Collections.sort(results, new TaxonComparator());
+ return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
+ }
+
@Override
public Pager<SearchResult<TaxonBase>> findByDistribution(List<NamedArea> areaFilter, List<PresenceAbsenceTerm> statusFilter,
Classification classification, TaxonNode subtree,
// SortField[] sortFields = new SortField[]{SortField.FIELD_SCORE, new SortField("id", SortField.STRING, false)};
// SortField[] sortFields = new SortField[]{new SortField(NomenclaturalSortOrderBrigde.NAME_SORT_FIELD_NAME, SortField.STRING, false)};
-
boolean addDistributionFilter = namedAreas != null && namedAreas.size() > 0;
List<LuceneSearch> luceneSearches = new ArrayList<>();
}
}
-
// search by pro parte synonyms
if(searchModes.contains(TaxaAndNamesSearchMode.doSynonyms)) {
//TODO merge with misapplied name search once #7487 is fixed
}
}//end pro parte synonyms
-
-
LuceneMultiSearch multiSearch = new LuceneMultiSearch(luceneIndexToolProvider,
luceneSearches.toArray(new LuceneSearch[luceneSearches.size()]));
-
if(addDistributionFilter){
// B)
Classification classification, TaxonNode subtree, List<Feature> features, List<Language> languages,
boolean highlightFragments, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws IOException, LuceneParseException {
-
LuceneSearch luceneSearch = prepareByDescriptionElementFullTextSearch(clazz, queryString, classification, subtree, features, languages, highlightFragments);
// --- execute search
int totalHits = topDocsResultSet != null ? topDocsResultSet.totalGroupCount : 0;
return new DefaultPagerImpl<>(pageNumber, Long.valueOf(totalHits), pageSize, searchResults);
-
}
-
@Override
public Pager<SearchResult<TaxonBase>> findByEverythingFullText(String queryString,
Classification classification, TaxonNode subtree, boolean includeUnpublished, List<Language> languages, boolean highlightFragments,
int totalHits = topDocsResultSet != null ? topDocsResultSet.totalGroupCount : 0;
return new DefaultPagerImpl<>(pageNumber, Long.valueOf(totalHits), pageSize, searchResults);
-
}
-
/**
* @param clazz
* @param queryString
@Override
public List<Synonym> createInferredSynonyms(Taxon taxon, Classification classification, SynonymType type, boolean doWithMisappliedNames){
-
List <Synonym> inferredSynonyms = new ArrayList<>();
List<Synonym> inferredSynonymsToBeRemoved = new ArrayList<>();
}
if (!taxonNames.isEmpty()){
- List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);
- IZoologicalName name;
- if (!synNotInCDM.isEmpty()){
- inferredSynonymsToBeRemoved.clear();
-
- for (Synonym syn :inferredSynonyms){
- name = getZoologicalName(syn.getName().getUuid(), zooHashMap);
- if (!synNotInCDM.contains(name.getNameCache())){
- inferredSynonymsToBeRemoved.add(syn);
+ List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);
+ if (!synNotInCDM.isEmpty()){
+ inferredSynonymsToBeRemoved.clear();
+
+ for (Synonym syn :inferredSynonyms){
+ IZoologicalName name = getZoologicalName(syn.getName().getUuid(), zooHashMap);
+ if (!synNotInCDM.contains(name.getNameCache())){
+ inferredSynonymsToBeRemoved.add(syn);
+ }
}
- }
- // Remove identified Synonyms from inferredSynonyms
- for (Synonym synonym : inferredSynonymsToBeRemoved) {
- inferredSynonyms.remove(synonym);
+ // Remove identified Synonyms from inferredSynonyms
+ for (Synonym synonym : inferredSynonymsToBeRemoved) {
+ inferredSynonyms.remove(synonym);
+ }
}
}
- }
- }else if (type.equals(SynonymType.INFERRED_GENUS_OF())){
+ }else if (type.equals(SynonymType.INFERRED_GENUS_OF())){
- for (Synonym synonymRelationOfTaxon:synonymsOfTaxon){
-
- inferredGenus = createInferredGenus(taxon,
- zooHashMap, taxonName, epithetOfTaxon,
- genusOfTaxon, taxonNames, zooParentName, synonymRelationOfTaxon);
-
- inferredSynonyms.add(inferredGenus);
- zooHashMap.put(inferredGenus.getName().getUuid(), inferredGenus.getName());
- taxonNames.add(inferredGenus.getName().getNameCache());
- }
-
- if (doWithMisappliedNames){
+ for (Synonym synonymRelationOfTaxon:synonymsOfTaxon){
- for (TaxonRelationship taxonRelationship: taxonRelListTaxon){
- Taxon misappliedName = taxonRelationship.getFromTaxon();
- inferredGenus = createInferredGenus(taxon, zooHashMap, taxonName, infraspecificEpithetOfTaxon, genusOfTaxon, taxonNames, zooParentName, misappliedName);
+ inferredGenus = createInferredGenus(taxon,
+ zooHashMap, taxonName, epithetOfTaxon,
+ genusOfTaxon, taxonNames, zooParentName, synonymRelationOfTaxon);
inferredSynonyms.add(inferredGenus);
zooHashMap.put(inferredGenus.getName().getUuid(), inferredGenus.getName());
- taxonNames.add(inferredGenus.getName().getNameCache());
+ taxonNames.add(inferredGenus.getName().getNameCache());
}
- }
-
- if (!taxonNames.isEmpty()){
- List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);
- IZoologicalName name;
- if (!synNotInCDM.isEmpty()){
- inferredSynonymsToBeRemoved.clear();
+ if (doWithMisappliedNames){
- for (Synonym syn :inferredSynonyms){
- name = getZoologicalName(syn.getName().getUuid(), zooHashMap);
- if (!synNotInCDM.contains(name.getNameCache())){
- inferredSynonymsToBeRemoved.add(syn);
- }
- }
+ for (TaxonRelationship taxonRelationship: taxonRelListTaxon){
+ Taxon misappliedName = taxonRelationship.getFromTaxon();
+ inferredGenus = createInferredGenus(taxon, zooHashMap, taxonName, infraspecificEpithetOfTaxon, genusOfTaxon, taxonNames, zooParentName, misappliedName);
- // Remove identified Synonyms from inferredSynonyms
- for (Synonym synonym : inferredSynonymsToBeRemoved) {
- inferredSynonyms.remove(synonym);
+ inferredSynonyms.add(inferredGenus);
+ zooHashMap.put(inferredGenus.getName().getUuid(), inferredGenus.getName());
+ taxonNames.add(inferredGenus.getName().getNameCache());
}
}
- }
-
- }else if (type.equals(SynonymType.POTENTIAL_COMBINATION_OF())){
-
- Reference sourceReference = null; // TODO: Determination of sourceReference is redundant
- //for all synonyms of the parent...
- for (Synonym synonymRelationOfParent:synonyMsOfParent){
- TaxonName synName;
- HibernateProxyHelper.deproxy(synonymRelationOfParent);
-
- synName = synonymRelationOfParent.getName();
- // Set the sourceReference
- sourceReference = synonymRelationOfParent.getSec();
- // Determine the idInSource
- String idInSourceParent = getIdInSource(synonymRelationOfParent);
-
- IZoologicalName parentSynZooName = getZoologicalName(synName.getUuid(), zooHashMap);
- String synParentGenus = parentSynZooName.getGenusOrUninomial();
- String synParentInfragenericName = null;
- String synParentSpecificEpithet = null;
-
- if (parentSynZooName.isInfraGeneric()){
- synParentInfragenericName = parentSynZooName.getInfraGenericEpithet();
- }
- if (parentSynZooName.isSpecies()){
- synParentSpecificEpithet = parentSynZooName.getSpecificEpithet();
- }
-
- /* if (synGenusName != null && !synonymsGenus.containsKey(synGenusName)){
- synonymsGenus.put(synGenusName, idInSource);
- }*/
-
- //for all synonyms of the taxon
-
- for (Synonym synonymRelationOfTaxon:synonymsOfTaxon){
-
- IZoologicalName zooSynName = getZoologicalName(synonymRelationOfTaxon.getName().getUuid(), zooHashMap);
- potentialCombination = createPotentialCombination(idInSourceParent, parentSynZooName, zooSynName,
- synParentGenus,
- synParentInfragenericName,
- synParentSpecificEpithet, synonymRelationOfTaxon, zooHashMap);
+ if (!taxonNames.isEmpty()){
+ List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);
+ IZoologicalName name;
+ if (!synNotInCDM.isEmpty()){
+ inferredSynonymsToBeRemoved.clear();
- taxon.addSynonym(potentialCombination, SynonymType.POTENTIAL_COMBINATION_OF());
- inferredSynonyms.add(potentialCombination);
- zooHashMap.put(potentialCombination.getName().getUuid(), potentialCombination.getName());
- taxonNames.add(potentialCombination.getName().getNameCache());
+ for (Synonym syn :inferredSynonyms){
+ name = getZoologicalName(syn.getName().getUuid(), zooHashMap);
+ if (!synNotInCDM.contains(name.getNameCache())){
+ inferredSynonymsToBeRemoved.add(syn);
+ }
+ }
+ // Remove identified Synonyms from inferredSynonyms
+ for (Synonym synonym : inferredSynonymsToBeRemoved) {
+ inferredSynonyms.remove(synonym);
+ }
+ }
}
- }
-
- if (doWithMisappliedNames){
-
- for (TaxonRelationship parentRelationship: taxonRelListParent){
+ }else if (type.equals(SynonymType.POTENTIAL_COMBINATION_OF())){
- TaxonName misappliedParentName;
-
- Taxon misappliedParent = parentRelationship.getFromTaxon();
- misappliedParentName = misappliedParent.getName();
+ Reference sourceReference = null; // TODO: Determination of sourceReference is redundant
+ //for all synonyms of the parent...
+ for (Synonym synonymRelationOfParent:synonyMsOfParent){
+ TaxonName synName;
+ HibernateProxyHelper.deproxy(synonymRelationOfParent);
- HibernateProxyHelper.deproxy(misappliedParent);
+ synName = synonymRelationOfParent.getName();
// Set the sourceReference
- sourceReference = misappliedParent.getSec();
+ sourceReference = synonymRelationOfParent.getSec();
// Determine the idInSource
- String idInSourceParent = getIdInSource(misappliedParent);
+ String idInSourceParent = getIdInSource(synonymRelationOfParent);
- IZoologicalName parentSynZooName = getZoologicalName(misappliedParentName.getUuid(), zooHashMap);
+ IZoologicalName parentSynZooName = getZoologicalName(synName.getUuid(), zooHashMap);
String synParentGenus = parentSynZooName.getGenusOrUninomial();
String synParentInfragenericName = null;
String synParentSpecificEpithet = null;
synParentSpecificEpithet = parentSynZooName.getSpecificEpithet();
}
+ /* if (synGenusName != null && !synonymsGenus.containsKey(synGenusName)){
+ synonymsGenus.put(synGenusName, idInSource);
+ }*/
- for (TaxonRelationship taxonRelationship: taxonRelListTaxon){
- Taxon misappliedName = taxonRelationship.getFromTaxon();
- IZoologicalName zooMisappliedName = getZoologicalName(misappliedName.getName().getUuid(), zooHashMap);
- potentialCombination = createPotentialCombination(
- idInSourceParent, parentSynZooName, zooMisappliedName,
+ //for all synonyms of the taxon
+
+ for (Synonym synonymRelationOfTaxon:synonymsOfTaxon){
+
+ IZoologicalName zooSynName = getZoologicalName(synonymRelationOfTaxon.getName().getUuid(), zooHashMap);
+ potentialCombination = createPotentialCombination(idInSourceParent, parentSynZooName, zooSynName,
synParentGenus,
synParentInfragenericName,
- synParentSpecificEpithet, misappliedName, zooHashMap);
-
+ synParentSpecificEpithet, synonymRelationOfTaxon, zooHashMap);
taxon.addSynonym(potentialCombination, SynonymType.POTENTIAL_COMBINATION_OF());
inferredSynonyms.add(potentialCombination);
taxonNames.add(potentialCombination.getName().getNameCache());
}
}
- }
- if (!taxonNames.isEmpty()){
- List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);
- IZoologicalName name;
- if (!synNotInCDM.isEmpty()){
- inferredSynonymsToBeRemoved.clear();
- for (Synonym syn :inferredSynonyms){
- try{
- name = syn.getName();
- }catch (ClassCastException e){
- name = getZoologicalName(syn.getName().getUuid(), zooHashMap);
+ if (doWithMisappliedNames){
+
+ for (TaxonRelationship parentRelationship: taxonRelListParent){
+
+ TaxonName misappliedParentName;
+
+ Taxon misappliedParent = parentRelationship.getFromTaxon();
+ misappliedParentName = misappliedParent.getName();
+
+ HibernateProxyHelper.deproxy(misappliedParent);
+
+ // Set the sourceReference
+ sourceReference = misappliedParent.getSec();
+
+ // Determine the idInSource
+ String idInSourceParent = getIdInSource(misappliedParent);
+
+ IZoologicalName parentSynZooName = getZoologicalName(misappliedParentName.getUuid(), zooHashMap);
+ String synParentGenus = parentSynZooName.getGenusOrUninomial();
+ String synParentInfragenericName = null;
+ String synParentSpecificEpithet = null;
+
+ if (parentSynZooName.isInfraGeneric()){
+ synParentInfragenericName = parentSynZooName.getInfraGenericEpithet();
+ }
+ if (parentSynZooName.isSpecies()){
+ synParentSpecificEpithet = parentSynZooName.getSpecificEpithet();
}
- if (!synNotInCDM.contains(name.getNameCache())){
- inferredSynonymsToBeRemoved.add(syn);
+
+ for (TaxonRelationship taxonRelationship: taxonRelListTaxon){
+ Taxon misappliedName = taxonRelationship.getFromTaxon();
+ IZoologicalName zooMisappliedName = getZoologicalName(misappliedName.getName().getUuid(), zooHashMap);
+ potentialCombination = createPotentialCombination(
+ idInSourceParent, parentSynZooName, zooMisappliedName,
+ synParentGenus,
+ synParentInfragenericName,
+ synParentSpecificEpithet, misappliedName, zooHashMap);
+
+ taxon.addSynonym(potentialCombination, SynonymType.POTENTIAL_COMBINATION_OF());
+ inferredSynonyms.add(potentialCombination);
+ zooHashMap.put(potentialCombination.getName().getUuid(), potentialCombination.getName());
+ taxonNames.add(potentialCombination.getName().getNameCache());
+ }
+ }
+ }
+
+ if (!taxonNames.isEmpty()){
+ List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);
+ IZoologicalName name;
+ if (!synNotInCDM.isEmpty()){
+ inferredSynonymsToBeRemoved.clear();
+ for (Synonym syn :inferredSynonyms){
+ try{
+ name = syn.getName();
+ }catch (ClassCastException e){
+ name = getZoologicalName(syn.getName().getUuid(), zooHashMap);
+ }
+ if (!synNotInCDM.contains(name.getNameCache())){
+ inferredSynonymsToBeRemoved.add(syn);
+ }
+ }
+ // Remove identified Synonyms from inferredSynonyms
+ for (Synonym synonym : inferredSynonymsToBeRemoved) {
+ inferredSynonyms.remove(synonym);
}
- }
- // Remove identified Synonyms from inferredSynonyms
- for (Synonym synonym : inferredSynonymsToBeRemoved) {
- inferredSynonyms.remove(synonym);
}
}
- }
}
}else {
logger.info("The synonym type is not defined.");
}
}
}
-
}
return inferredSynonyms;
inferredSynName.setInfraGenericEpithet(synParentInfragenericName);
}
-
potentialCombination = Synonym.NewInstance(inferredSynName, null);
// Set the sourceReference
synName = syn.getName();
IZoologicalName synZooName = getZoologicalName(synName.getUuid(), zooHashMap);
String synSpeciesEpithetName = synZooName.getSpecificEpithet();
- /* if (synonymsEpithet != null && !synonymsEpithet.contains(synSpeciesEpithetName)){
+ /* if (synonymsEpithet != null && !synonymsEpithet.contains(synSpeciesEpithetName)){
synonymsEpithet.add(synSpeciesEpithetName);
}*/
inferredSynName = TaxonNameFactory.NewZoologicalInstance(taxon.getName().getRank());
//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...
-
inferredSynName.setGenusOrUninomial(genusOfTaxon);
if (zooParentName.isInfraGeneric()){
inferredSynName.setInfraGenericEpithet(zooParentName.getInfraGenericEpithet());
inferredSynName.setInfraSpecificEpithet(synZooName.getInfraGenericEpithet());
}
-
inferredGenus = Synonym.NewInstance(inferredSynName, null);
// Set the sourceReference
synSpecificEpithet = zooSynName.getSpecificEpithet();
}
- /* if (synGenusName != null && !synonymsGenus.containsKey(synGenusName)){
+ /* if (synGenusName != null && !synonymsGenus.containsKey(synGenusName)){
synonymsGenus.put(synGenusName, idInSource);
}*/
inferredSynName.addSource(originalSource);
-
-
taxon.addSynonym(inferredEpithet, SynonymType.INFERRED_EPITHET_OF());
return inferredEpithet;
logger.warn("No idInSource for TaxonBase " + taxonBase.getUuid() + " - " + taxonBase.getTitleCache());
}
-
return idInSource;
}
-
/**
* Returns the citation for a given Synonym.
* @param syn
Set<CdmBase> references = commonService.getReferencingObjectsForDeletion(taxonBase);
if (taxonBase instanceof Taxon){
TaxonDeletionConfigurator taxonConfig = (TaxonDeletionConfigurator) config;
- List<String> propertyPaths = new ArrayList();
+ List<String> propertyPaths = new ArrayList<>();
propertyPaths.add("taxonNodes");
Taxon taxon = (Taxon)load(taxonBaseUuid, propertyPaths);
result = isDeletableForTaxon(references, taxonConfig );
+
+ if (taxonConfig.isDeleteNameIfPossible()){
+ if (taxonBase.getName() != null){
+ DeleteResult nameResult = nameService.isDeletable(taxonBase.getName().getUuid(), taxonConfig.getNameDeletionConfig(), taxon.getUuid());
+ if (!nameResult.isOk()){
+ result.addExceptions(nameResult.getExceptions());
+ }
+ }
+
+ }
}else{
SynonymDeletionConfigurator synonymConfig = (SynonymDeletionConfigurator) config;
result = isDeletableForSynonym(references, synonymConfig);
+ if (synonymConfig.isDeleteNameIfPossible()){
+ DeleteResult nameResult = nameService.isDeletable(taxonBase.getName().getUuid(), synonymConfig.getNameDeletionConfig(), taxonBase.getUuid());
+ if (!nameResult.isOk()){
+ result.addExceptions(nameResult.getExceptions());
+ }
+ }
}
+
return result;
}
result.addRelatedObject(ref);
result.setAbort();
}
+
}
return result;
}
-
-
private DeleteResult isDeletableForTaxon(Set<CdmBase> references, TaxonDeletionConfigurator config){
String message = null;
DeleteResult result = new DeleteResult();
}
if (!config.isDeleteTaxonRelationships() && (ref instanceof TaxonRelationship)){
- if (!config.isDeleteMisappliedNamesAndInvalidDesignations() &&
- (((TaxonRelationship)ref).getType().isMisappliedNameOrInvalidDesignation())){
+ if (!config.isDeleteMisappliedNames() &&
+ (((TaxonRelationship)ref).getType().isMisappliedName())){
message = "The taxon can't be deleted as long as it has misapplied names or invalid designations.";
} else{
message = "The taxon can't be deleted as long as it belongs to taxon relationship.";
message = "Taxon can't be deleted as it is used in an identification key. Remove from identification key prior to deleting this taxon";
}
-
/* //PolytomousKeyNode
if (referencingObject.isInstanceOf(PolytomousKeyNode.class)){
String message = "Taxon" + taxon.getTitleCache() + " can't be deleted as it is used in polytomous key node";
@Override
public List<TaxonBase> findTaxaByName(MatchingTaxonConfigurator config){
+ @SuppressWarnings("rawtypes")
List<TaxonBase> taxonList = dao.getTaxaByName(true, config.isIncludeSynonyms(), false, false, false,
config.getTaxonNameTitle(), null, null, MatchMode.EXACT, null, config.isIncludeSynonyms(), null, 0, 0, config.getPropertyPath());
return taxonList;
return result;
}
- @Override
+ @Override
public UpdateResult moveFactualDateToAnotherTaxon(UUID fromTaxonUuid, UUID toTaxonUuid){
UpdateResult result = new UpdateResult();
return this.swapSynonymAndAcceptedTaxon(syn, taxon, setNameInSource);
}
- /**
- * {@inheritDoc}
- */
@Override
public TaxonRelationshipsDTO listTaxonRelationships(UUID taxonUuid, Set<TaxonRelationshipType> directTypes,
Set<TaxonRelationshipType> inversTypes,
return dto;
}
}
-
}