import java.util.EnumSet;\r
import java.util.HashMap;\r
import java.util.HashSet;\r
+import java.util.Iterator;\r
import java.util.List;\r
import java.util.Map;\r
import java.util.Set;\r
\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.SynonymDeletionConfigurator;\r
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;\r
+import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator.ChildHandling;\r
import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;\r
import eu.etaxonomy.cdm.api.service.exception.HomotypicalGroupChangeException;\r
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;\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.DocIdBitSetPrinter;\r
import eu.etaxonomy.cdm.api.service.search.ILuceneIndexToolProvider;\r
import eu.etaxonomy.cdm.api.service.search.ISearchResultBuilder;\r
import eu.etaxonomy.cdm.api.service.search.LuceneMultiSearch;\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.OriginalSourceType;\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.media.Media;\r
import eu.etaxonomy.cdm.model.media.MediaRepresentation;\r
import eu.etaxonomy.cdm.model.media.MediaUtils;\r
+import eu.etaxonomy.cdm.model.molecular.Amplification;\r
import eu.etaxonomy.cdm.model.molecular.DnaSample;\r
import eu.etaxonomy.cdm.model.molecular.Sequence;\r
+import eu.etaxonomy.cdm.model.molecular.SingleRead;\r
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;\r
import eu.etaxonomy.cdm.model.name.Rank;\r
import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
import eu.etaxonomy.cdm.model.name.ZoologicalName;\r
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;\r
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;\r
import eu.etaxonomy.cdm.model.reference.Reference;\r
import eu.etaxonomy.cdm.model.taxon.Classification;\r
import eu.etaxonomy.cdm.model.taxon.TaxonNode;\r
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;\r
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;\r
-import eu.etaxonomy.cdm.persistence.dao.AbstractBeanInitializer;\r
import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao;\r
import eu.etaxonomy.cdm.persistence.dao.common.IOrderedTermVocabularyDao;\r
+import eu.etaxonomy.cdm.persistence.dao.initializer.AbstractBeanInitializer;\r
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;\r
import eu.etaxonomy.cdm.persistence.dao.occurrence.IOccurrenceDao;\r
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;\r
\r
@Autowired\r
private INameService nameService;\r
+ \r
+ @Autowired\r
+ private ITaxonNodeService nodeService;\r
+ \r
\r
@Autowired\r
private ICdmGenericDao genericDao;\r
@Autowired\r
private ILuceneIndexToolProvider luceneIndexToolProvider;\r
\r
-\r
/**\r
* Constructor\r
*/\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#changeSynonymToAcceptedTaxon(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon)\r
*/\r
- //TODO correct delete handling still needs to be implemented / checked\r
+ \r
@Override\r
@Transactional(readOnly = false)\r
public Taxon changeSynonymToAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon, boolean deleteSynonym, boolean copyCitationInfo, Reference citation, String microCitation) throws HomotypicalGroupChangeException{\r
-\r
+ \r
TaxonNameBase<?,?> acceptedName = acceptedTaxon.getName();\r
TaxonNameBase<?,?> synonymName = synonym.getName();\r
HomotypicalGroup synonymHomotypicGroup = synonymName.getHomotypicalGroup();\r
}\r
\r
//synonym.getName().removeTaxonBase(synonym);\r
- //TODO correct delete handling still needs to be implemented / checked\r
+ \r
if (deleteSynonym){\r
// deleteSynonym(synonym, taxon, false);\r
try {\r
this.dao.flush();\r
- this.delete(synonym);\r
+ this.deleteSynonym(synonym, acceptedTaxon, new SynonymDeletionConfigurator());\r
\r
} catch (Exception e) {\r
logger.info("Can't delete old synonym from database");\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#findTaxaByName(java.lang.Class, java.lang.String, java.lang.String, java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, java.lang.Integer, java.lang.Integer)\r
*/\r
@Override\r
- public Pager<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz,\r
- String uninomial, String infragenericEpithet, String specificEpithet,\r
- String infraspecificEpithet, Rank rank, Integer pageSize,Integer pageNumber) {\r
+ public Pager<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize,Integer pageNumber) {\r
Integer numberOfResults = dao.countTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, rank);\r
\r
List<TaxonBase> results = new ArrayList<TaxonBase>();\r
return new DefaultPagerImpl<TaxonBase>(pageNumber, numberOfResults, pageSize, results);\r
}\r
\r
-\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#listTaxaByName(java.lang.Class, java.lang.String, java.lang.String, java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, java.lang.Integer, java.lang.Integer)\r
*/\r
}\r
for (SpecimenOrObservationBase occurrence : specimensOrObservations) {\r
\r
- taxonMedia.addAll(occurrence.getMedia());\r
+// direct media removed from specimen #3597\r
+// taxonMedia.addAll(occurrence.getMedia());\r
\r
// SpecimenDescriptions\r
Set<SpecimenDescription> specimenDescriptions = occurrence.getSpecimenDescriptions();\r
}\r
\r
// Collection\r
- if (occurrence instanceof DerivedUnitBase) {\r
- if (((DerivedUnitBase) occurrence).getCollection() != null){\r
- taxonMedia.addAll(((DerivedUnitBase) occurrence).getCollection().getMedia());\r
+ //TODO why may collections have media attached? #\r
+ if (occurrence.isInstanceOf(DerivedUnit.class)) {\r
+ DerivedUnit derivedUnit = CdmBase.deproxy(occurrence, DerivedUnit.class);\r
+ if (derivedUnit.getCollection() != null){\r
+ taxonMedia.addAll(derivedUnit.getCollection().getMedia());\r
}\r
}\r
\r
- // Chromatograms\r
- if (occurrence instanceof DnaSample) {\r
- Set<Sequence> sequences = ((DnaSample) occurrence).getSequences();\r
+ // pherograms & gelPhotos\r
+ if (occurrence.isInstanceOf(DnaSample.class)) {\r
+ DnaSample dnaSample = CdmBase.deproxy(occurrence, DnaSample.class);\r
+ Set<Sequence> sequences = dnaSample.getSequences();\r
+ //we do show only those gelPhotos which lead to a consensus sequence\r
for (Sequence sequence : sequences) {\r
- taxonMedia.addAll(sequence.getChromatograms());\r
+ Set<Media> dnaRelatedMedia = new HashSet<Media>();\r
+ for (SingleRead singleRead : sequence.getSingleReads()){\r
+ Amplification amplification = singleRead.getAmplification();\r
+ dnaRelatedMedia.add(amplification.getGelPhoto());\r
+ dnaRelatedMedia.add(singleRead.getPherogram());\r
+ dnaRelatedMedia.remove(null);\r
+ }\r
+ taxonMedia.addAll(dnaRelatedMedia);\r
}\r
}\r
\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
+ public UUID deleteTaxon(Taxon taxon, TaxonDeletionConfigurator config, Classification classification) throws DataChangeNoRollbackException {\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
if (config.isDeleteSynonymsIfPossible()){\r
//TODO which value\r
boolean newHomotypicGroupIfNeeded = true;\r
- deleteSynonym(synonym, taxon, config.isDeleteNameIfPossible(), newHomotypicGroupIfNeeded);\r
+ SynonymDeletionConfigurator synConfig = new SynonymDeletionConfigurator();\r
+ \r
+ deleteSynonym(synonym, taxon, synConfig);\r
}else{\r
deleteSynonymRelationships(synonym, taxon);\r
}\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
+ } else{\r
+ for (TaxonRelationship taxRel: taxon.getTaxonRelations()){\r
+ \r
+ \r
+ \r
+ if (config.isDeleteMisappliedNamesAndInvalidDesignations()){\r
+ if (taxRel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) || taxRel.getType().equals(TaxonRelationshipType.INVALID_DESIGNATION_FOR())){\r
+ if (taxon.equals(taxRel.getToTaxon())){\r
+ this.deleteTaxon(taxRel.getFromTaxon(), config, classification);\r
+ }\r
+ }\r
+ }\r
+ taxon.removeTaxonRelation(taxRel);\r
+ /*if (taxFrom.equals(taxon)){\r
+ try{\r
+ this.deleteTaxon(taxTo, taxConf, classification);\r
+ } catch(DataChangeNoRollbackException e){\r
+ logger.debug("A related taxon will not be deleted." + e.getMessage());\r
+ }\r
+ } else {\r
+ try{\r
+ this.deleteTaxon(taxFrom, taxConf, classification);\r
+ } catch(DataChangeNoRollbackException e){\r
+ logger.debug("A related taxon will not be deleted." + e.getMessage());\r
+ }\r
+ \r
+ }*/\r
+ }\r
}\r
\r
\r
+ \r
+ \r
// TaxonDescription\r
+ if (config.isDeleteDescriptions()){\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
+ //TODO use description delete configurator ?\r
+ //FIXME check if description is ALWAYS deletable\r
+ if (desc.getDescribedSpecimenOrObservation() != null){\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
+ descriptionService.delete(desc);\r
+ taxon.removeDescription(desc);\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
+ //check references with only reverse mapping\r
+ String message = checkForReferences(taxon);\r
+ if (message != null){\r
+ throw new ReferencedObjectUndeletableException(message.toString());\r
+ }\r
+ \r
+ if (! config.isDeleteTaxonNodes() || (!config.isDeleteInAllClassifications() && classification == null )){\r
+ if (taxon.getTaxonNodes().size() > 0){\r
+ message = "Taxon can't be deleted as it is used in a classification node. Remove taxon from all classifications prior to deletion or define a classification where it should be deleted or adapt the taxon deletion configurator.";\r
throw new ReferencedObjectUndeletableException(message);\r
}\r
+ }else{\r
+ if (taxon.getTaxonNodes().size() != 0){\r
+ Set<TaxonNode> nodes = taxon.getTaxonNodes();\r
+ Iterator<TaxonNode> iterator = nodes.iterator();\r
+ TaxonNode node = null;\r
+ boolean deleteChildren;\r
+ if (config.getTaxonNodeConfig().getChildHandling().equals(ChildHandling.DELETE)){\r
+ deleteChildren = true;\r
+ }else {\r
+ deleteChildren = false;\r
+ }\r
+ boolean success = true;\r
+ if (!config.isDeleteInAllClassifications() && !(classification == null)){\r
+ while (iterator.hasNext()){\r
+ node = iterator.next();\r
+ if (node.getClassification().equals(classification)){\r
+ break;\r
+ }\r
+ node = null;\r
+ }\r
+ if (node != null){\r
+ success =taxon.removeTaxonNode(node, deleteChildren);\r
+ } else {\r
+ message = "Taxon is not used in defined classification";\r
+ throw new DataChangeNoRollbackException(message);\r
+ }\r
+ } else if (config.isDeleteInAllClassifications()){\r
+ List<TaxonNode> nodesList = new ArrayList<TaxonNode>();\r
+ nodesList.addAll(taxon.getTaxonNodes());\r
+ \r
+ for (TaxonNode taxonNode: nodesList){\r
+ if(deleteChildren){\r
+ Object[] childNodes = taxonNode.getChildNodes().toArray();\r
+ for (Object childNode: childNodes){\r
+ TaxonNode childNodeCast = (TaxonNode) childNode;\r
+ deleteTaxon(childNodeCast.getTaxon(), config, classification);\r
+ \r
+ }\r
+ \r
+ /*for (TaxonNode childNode: taxonNode.getChildNodes()){\r
+ deleteTaxon(childNode.getTaxon(), config, classification);\r
+ \r
+ }*/\r
+ //taxon.removeTaxonNode(taxonNode);\r
+ } else{\r
+ Object[] childNodes = taxonNode.getChildNodes().toArray();\r
+ for (Object childNode: childNodes){\r
+ TaxonNode childNodeCast = (TaxonNode) childNode;\r
+ taxonNode.getParent().addChildNode(childNodeCast, childNodeCast.getReference(), childNodeCast.getMicroReference());\r
+ }\r
+ \r
+ //taxon.removeTaxonNode(taxonNode);\r
+ }\r
+ }\r
+ \r
+ \r
+ \r
+ nodeService.deleteTaxonNodes(nodesList);\r
+ \r
+ }\r
+ if (!success){\r
+ message = "The taxon node could not be deleted.";\r
+ throw new DataChangeNoRollbackException(message);\r
+ }\r
+ }\r
}\r
-\r
-\r
//TaxonNameBase\r
if (config.isDeleteNameIfPossible()){\r
try {\r
- nameService.delete(taxon.getName(), config.getNameDeletionConfig());\r
+ \r
+ //TaxonNameBase name = nameService.find(taxon.getName().getUuid());\r
+ TaxonNameBase name = (TaxonNameBase)HibernateProxyHelper.deproxy(taxon.getName());\r
+ //check whether taxon will be deleted or not\r
+ if (taxon.getTaxonNodes() == null || taxon.getTaxonNodes().size()== 0){\r
+ taxon = (Taxon) HibernateProxyHelper.deproxy(taxon);\r
+ name.removeTaxonBase(taxon);\r
+ nameService.save(name);\r
+ nameService.delete(name, config.getNameDeletionConfig());\r
+ }\r
} catch (ReferencedObjectUndeletableException e) {\r
//do nothing\r
if (logger.isDebugEnabled()){logger.debug("Name could not be deleted");}\r
+ \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
+ taxon.removeDescription(desc);\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 observations";\r
+ throw new ReferencedObjectUndeletableException(message);\r
}\r
+ }\r
+ }*/\r
+ \r
+ \r
+\r
+ if (taxon.getTaxonNodes() == null || taxon.getTaxonNodes().size()== 0){\r
+ dao.delete(taxon);\r
+ return taxon.getUuid();\r
+ } else{\r
+ message = "Taxon can't be deleted as it is used in another Taxonnode";\r
+ throw new ReferencedObjectUndeletableException(message);\r
+ }\r
+ \r
+\r
+ }\r
+ \r
+ private String checkForReferences(Taxon taxon){\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" + taxon.getTitleCache() + "can't be deleted as it is used in an identification key. Remove from identification key prior to deleting this name";\r
+ \r
+ return message;\r
+ }\r
+\r
\r
+ //PolytomousKeyNode\r
+ if (referencingObject.isInstanceOf(PolytomousKeyNode.class)){\r
+ String message = "Taxon" + taxon.getTitleCache() + " can't be deleted as it is used in polytomous key node";\r
+ return 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
+ return message;\r
+ }\r
+ }\r
+ referencingObjects = null;\r
+ return null;\r
+ }\r
+ \r
+ @Transactional(readOnly = false)\r
+ public UUID delete(Synonym syn){\r
+ UUID result = syn.getUuid();\r
+ this.deleteSynonym(syn, null);\r
+ return result;\r
+ }\r
+ \r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteSynonym(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon, boolean, boolean)\r
*/\r
@Transactional(readOnly = false)\r
@Override\r
- public void deleteSynonym(Synonym synonym, Taxon taxon, boolean removeNameIfPossible,boolean newHomotypicGroupIfNeeded) {\r
+ public void deleteSynonym(Synonym synonym, SynonymDeletionConfigurator config) {\r
+ deleteSynonym(synonym, null, config);\r
+ \r
+ }\r
+ \r
+\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteSynonym(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon, boolean, boolean)\r
+ */\r
+ @Transactional(readOnly = false)\r
+ @Override\r
+ public void deleteSynonym(Synonym synonym, Taxon taxon, SynonymDeletionConfigurator config) {\r
if (synonym == null){\r
return;\r
}\r
+ if (config == null){\r
+ config = new SynonymDeletionConfigurator();\r
+ }\r
synonym = CdmBase.deproxy(dao.merge(synonym), Synonym.class);\r
\r
//remove synonymRelationship\r
}\r
for (Taxon relatedTaxon : taxonSet){\r
// dao.deleteSynonymRelationships(synonym, relatedTaxon);\r
- relatedTaxon.removeSynonym(synonym, newHomotypicGroupIfNeeded);\r
+ relatedTaxon.removeSynonym(synonym, config.isNewHomotypicGroupIfNeeded());\r
}\r
this.saveOrUpdate(synonym);\r
\r
//TODO remove name from homotypical group?\r
\r
//remove synonym (if necessary)\r
+ \r
+ \r
if (synonym.getSynonymRelations().isEmpty()){\r
TaxonNameBase<?,?> name = synonym.getName();\r
synonym.setName(null);\r
dao.delete(synonym);\r
\r
//remove name if possible (and required)\r
- if (name != null && removeNameIfPossible){\r
+ if (name != null && config.isDeleteNameIfPossible()){\r
try{\r
- nameService.delete(name, new NameDeletionConfigurator());\r
- }catch (DataChangeNoRollbackException ex){\r
+ nameService.delete(name, config.getNameDeletionConfig());\r
+ }catch (ReferencedObjectUndeletableException ex){\r
+ System.err.println("Name wasn't deleted as it is referenced");\r
if (logger.isDebugEnabled()) {\r
logger.debug("Name wasn't deleted as it is referenced");\r
}\r
\r
BooleanQuery finalQuery = new BooleanQuery();\r
\r
- LuceneSearch luceneSearch = new LuceneSearch(luceneIndexToolProvider, TaxonBase.class);\r
+ LuceneSearch luceneSearch = new LuceneSearch(luceneIndexToolProvider, GroupByTaxonClassBridge.GROUPBY_TAXON_FIELD, TaxonBase.class);\r
QueryFactory taxonBaseQueryFactory = luceneIndexToolProvider.newQueryFactoryFor(TaxonBase.class);\r
\r
BooleanQuery joinFromQuery = new BooleanQuery();\r
Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths)\r
throws CorruptIndexException, IOException, ParseException, LuceneMultiSearchException {\r
\r
+ // FIXME: allow taxonomic ordering\r
+ // hql equivalent: order by t.name.genusOrUninomial, case when t.name.specificEpithet like '\"%\"' then 1 else 0 end, t.name.specificEpithet, t.name.rank desc, t.name.nameCache";\r
+ // this require building a special sort column by a special classBridge\r
if(highlightFragments){\r
logger.warn("findTaxaAndNamesByFullText() : fragment highlighting is " +\r
"currently not fully supported by this method and thus " +\r
Query byCommonNameJoinQuery = descriptionElementQueryFactory.newJoinQuery(\r
"inDescription.taxon.id",\r
"id",\r
- createByDescriptionElementFullTextQuery(queryString, classification, null, languages, descriptionElementQueryFactory),\r
+ QueryFactory.addTypeRestriction(\r
+ createByDescriptionElementFullTextQuery(queryString, classification, null, languages, descriptionElementQueryFactory)\r
+ , CommonTaxonName.class\r
+ ),\r
CommonTaxonName.class);\r
logger.debug("byCommonNameJoinQuery: " + byCommonNameJoinQuery.toString());\r
LuceneSearch byCommonNameSearch = new LuceneSearch(luceneIndexToolProvider, GroupByTaxonClassBridge.GROUPBY_TAXON_FIELD, Taxon.class);\r
String fromField = "inDescription.taxon.id"; // in DescriptionElementBase index\r
\r
/*\r
- * Here java seems to have a wired and nasty bug which took me bugging be really for hours until I found this solution:\r
+ * Here i was facing wired and nasty bug which took me bugging be really for hours until I found this solution.\r
+ * Maybe this is a but in java itself java.\r
*\r
* When the string toField is constructed by using the expression TaxonRelationshipType.MISAPPLIED_NAME_FOR().getUuid().toString()\r
* directly:\r
* String toField = "relation." + misappliedNameForUuid +".to.id";\r
*\r
* Comparing both strings by the String.equals method returns true, so both String are identical.\r
+ *\r
+ * The bug occurs when running eu.etaxonomy.cdm.api.service.TaxonServiceSearchTest in eclipse and in maven and seems to to be\r
+ * dependent from a specific jvm (openjdk6 6b27-1.12.6-1ubuntu0.13.04.2, openjdk7 7u25-2.3.10-1ubuntu0.13.04.2, oracle jdk1.7.0_25 tested)\r
+ * The bug is persistent after a reboot of the development computer.\r
*/\r
- String misappliedNameForUuid = TaxonRelationshipType.MISAPPLIED_NAME_FOR().getUuid().toString();\r
- String toField = "relation." + misappliedNameForUuid +".to.id";\r
- System.out.println("relation.1ed87175-59dd-437e-959e-0d71583d8417.to.id".equals("relation." + misappliedNameForUuid +".to.id") ? " > identical" : " > different");\r
- System.out.println("relation.1ed87175-59dd-437e-959e-0d71583d8417.to.id".equals("relation." + TaxonRelationshipType.MISAPPLIED_NAME_FOR().getUuid().toString() +".to.id") ? " > identical" : " > different");\r
+// String misappliedNameForUuid = TaxonRelationshipType.MISAPPLIED_NAME_FOR().getUuid().toString();\r
+// String toField = "relation." + misappliedNameForUuid +".to.id";\r
+ String toField = "relation.1ed87175-59dd-437e-959e-0d71583d8417.to.id";\r
+// System.out.println("relation.1ed87175-59dd-437e-959e-0d71583d8417.to.id".equals("relation." + misappliedNameForUuid +".to.id") ? " > identical" : " > different");\r
+// System.out.println("relation.1ed87175-59dd-437e-959e-0d71583d8417.to.id".equals("relation." + TaxonRelationshipType.MISAPPLIED_NAME_FOR().getUuid().toString() +".to.id") ? " > identical" : " > different");\r
\r
BooleanQuery byDistributionQuery = createByDistributionQuery(namedAreaList, distributionStatusList, distributionFilterQueryFactory);\r
-\r
Query taxonAreaJoinQuery = distributionFilterQueryFactory.newJoinQuery(fromField, toField, byDistributionQuery, Distribution.class);\r
-\r
QueryWrapperFilter filter = new QueryWrapperFilter(taxonAreaJoinQuery);\r
+\r
+// debug code for bug described above\r
DocIdSet filterMatchSet = filter.getDocIdSet(luceneIndexToolProvider.getIndexReaderFor(Taxon.class));\r
- System.err.println(DocIdBitSetPrinter.docsAsString(filterMatchSet, 100));\r
- luceneIndexToolProvider.getIndexReaderFor(Taxon.class);\r
+// System.err.println(DocIdBitSetPrinter.docsAsString(filterMatchSet, 100));\r
\r
multiIndexByAreaFilter.add(filter, Occur.SHOULD);\r
}\r
luceneSearches.toArray(new LuceneSearch[luceneSearches.size()]));\r
\r
\r
- if(false && addDistributionFilter){\r
+ if(addDistributionFilter){\r
\r
// B)\r
// in this case we need a filter which uses a join query\r
\r
// --- TermBase fields - by representation ----\r
// state field from CategoricalData\r
- textQuery.add(descriptionElementQueryFactory.newDefinedTermQuery("states.state", queryString, languages), Occur.SHOULD);\r
+ textQuery.add(descriptionElementQueryFactory.newDefinedTermQuery("stateData.state", queryString, languages), Occur.SHOULD);\r
\r
// state field from CategoricalData\r
- textQuery.add(descriptionElementQueryFactory.newDefinedTermQuery("states.modifyingText", queryString, languages), Occur.SHOULD);\r
+ textQuery.add(descriptionElementQueryFactory.newDefinedTermQuery("stateData.modifyingText", queryString, languages), Occur.SHOULD);\r
\r
// area field from Distribution\r
textQuery.add(descriptionElementQueryFactory.newDefinedTermQuery("area", queryString, languages), Occur.SHOULD);\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
+ IdentifiableSource originalSource = IdentifiableSource.NewInstance(OriginalSourceType.Transformation, idInSourceSyn + "; " + idInSourceParent, POTENTIAL_COMBINATION_NAMESPACE, sourceReference, null);\r
inferredSynName.addSource(originalSource);\r
- originalSource = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceParent, POTENTIAL_COMBINATION_NAMESPACE, sourceReference, null);\r
+ originalSource = IdentifiableSource.NewInstance(OriginalSourceType.Transformation, idInSourceSyn + "; " + idInSourceParent, POTENTIAL_COMBINATION_NAMESPACE, sourceReference, null);\r
potentialCombination.addSource(originalSource);\r
}\r
\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
+ IdentifiableSource originalSource = IdentifiableSource.NewInstance(OriginalSourceType.Transformation,\r
+ idInSourceSyn + "; " + idInSourceTaxon, INFERRED_GENUS_NAMESPACE, sourceReference, null);\r
inferredGenus.addSource(originalSource);\r
\r
- originalSource = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceTaxon, INFERRED_GENUS_NAMESPACE, sourceReference, null);\r
+ originalSource = IdentifiableSource.NewInstance(OriginalSourceType.Transformation,\r
+ 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
+ IdentifiableSource originalSource = IdentifiableSource.NewInstance(OriginalSourceType.Transformation,\r
+ idInSourceSyn + "; " + idInSourceTaxon, INFERRED_GENUS_NAMESPACE, sourceReference, null);\r
inferredGenus.addSource(originalSource);\r
\r
- originalSource = IdentifiableSource.NewInstance(idInSourceSyn + "; " + idInSourceTaxon, INFERRED_GENUS_NAMESPACE, sourceReference, null);\r
+ originalSource = IdentifiableSource.NewInstance(OriginalSourceType.Transformation,\r
+ idInSourceSyn + "; " + idInSourceTaxon, INFERRED_GENUS_NAMESPACE, sourceReference, null);\r
inferredSynName.addSource(originalSource);\r
originalSource = null;\r
}\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" + taxon.getSec());\r
- sourceReference = taxon.getSec();\r
+ logger.warn("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
String taxonId = idInSourceTaxon+ "; " + idInSourceSyn;\r
\r
\r
- IdentifiableSource originalSource = IdentifiableSource.NewInstance(taxonId, INFERRED_EPITHET_NAMESPACE, sourceReference, null);\r
+ IdentifiableSource originalSource = IdentifiableSource.NewInstance(OriginalSourceType.Transformation,\r
+ taxonId, INFERRED_EPITHET_NAMESPACE, sourceReference, null);\r
\r
inferredEpithet.addSource(originalSource);\r
\r
- originalSource = IdentifiableSource.NewInstance(taxonId, INFERRED_EPITHET_NAMESPACE, sourceReference, null);\r
+ originalSource = IdentifiableSource.NewInstance(OriginalSourceType.Transformation,\r
+ taxonId, INFERRED_EPITHET_NAMESPACE, sourceReference, null);\r
\r
inferredSynName.addSource(originalSource);\r
\r