-// $Id$\r
/**\r
-* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
-* http://www.e-taxonomy.eu\r
-* \r
-* The contents of this file are subject to the Mozilla Public License Version 1.1\r
-* See LICENSE.TXT at the top of this package for the full license terms.\r
-*/\r
+ * Copyright (C) 2007 EDIT\r
+ * European Distributed Institute of Taxonomy\r
+ * http://www.e-taxonomy.eu\r
+ *\r
+ * The contents of this file are subject to the Mozilla Public License Version 1.1\r
+ * See LICENSE.TXT at the top of this package for the full license terms.\r
+ */\r
\r
package eu.etaxonomy.cdm.api.service;\r
\r
+import java.util.ArrayList;\r
import java.util.List;\r
import java.util.Set;\r
import java.util.UUID;\r
import org.apache.log4j.Logger;\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.exception.ReferencedObjectUndeletableException;\r
+import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;\r
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;\r
-import eu.etaxonomy.cdm.model.common.CdmBase;\r
-import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;\r
-import eu.etaxonomy.cdm.model.description.PolytomousKey;\r
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
+import eu.etaxonomy.cdm.model.common.DefinedTerm;\r
import eu.etaxonomy.cdm.model.reference.Reference;\r
+import eu.etaxonomy.cdm.model.reference.ReferenceType;\r
import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
-import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao;\r
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;\r
+import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;\r
+import eu.etaxonomy.cdm.persistence.query.MatchMode;\r
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;\r
\r
\r
@Service\r
@Transactional(readOnly = true)\r
public class ReferenceServiceImpl extends IdentifiableServiceBase<Reference,IReferenceDao> implements IReferenceService {\r
- \r
- static Logger logger = Logger.getLogger(ReferenceServiceImpl.class);\r
- \r
- @Autowired\r
-private ICdmGenericDao genericDao;\r
- /**\r
- * Constructor\r
- */\r
- public ReferenceServiceImpl(){\r
- if (logger.isDebugEnabled()) { logger.debug("Load ReferenceService Bean"); }\r
- }\r
-\r
- /* (non-Javadoc)\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 Reference> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Reference> cacheStrategy, IProgressMonitor monitor) {\r
- if (clazz == null){\r
- clazz = Reference.class;\r
- }\r
- super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);\r
- }\r
-\r
-\r
- @Autowired\r
- protected void setDao(IReferenceDao dao) {\r
- this.dao = dao;\r
- }\r
-\r
- public List<UuidAndTitleCache<Reference>> getUuidAndTitle() {\r
- \r
- return dao.getUuidAndTitle();\r
- }\r
- \r
- public List<Reference> getAllReferencesForPublishing(){\r
- return dao.getAllNotNomenclaturalReferencesForPublishing();\r
- }\r
-\r
- public List<Reference> getAllNomenclaturalReferences() {\r
- \r
- return dao.getAllNomenclaturalReferences();\r
- }\r
-\r
- @Override\r
- public List<TaxonBase> listCoveredTaxa(Reference reference, boolean includeSubordinateReferences, List<String> propertyPaths) {\r
- \r
- List<TaxonBase> taxonList = dao.listCoveredTaxa(reference, includeSubordinateReferences, null, propertyPaths);\r
- \r
- return taxonList;\r
- }\r
- \r
- @Override\r
- public UUID delete(Reference reference) throws ReferencedObjectUndeletableException{\r
- //check whether the reference is used somewhere\r
- Set<CdmBase> referencingObjects = genericDao.getReferencingObjects(reference);\r
- \r
- if (referencingObjects.size()>0){\r
- \r
- throw new ReferencedObjectUndeletableException();\r
- }\r
- \r
- return reference.getUuid();\r
- }\r
+\r
+ static Logger logger = Logger.getLogger(ReferenceServiceImpl.class);\r
+\r
+ /**\r
+ * Constructor\r
+ */\r
+ public ReferenceServiceImpl(){\r
+ if (logger.isDebugEnabled()) { logger.debug("Load ReferenceService Bean"); }\r
+ }\r
+\r
+ @Override\r
+ @Transactional(readOnly = false)\r
+ public void updateCaches(Class<? extends Reference> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Reference> cacheStrategy, IProgressMonitor monitor) {\r
+ if (clazz == null){\r
+ clazz = Reference.class;\r
+ }\r
+ super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);\r
+ }\r
+\r
+ @Override\r
+ @Autowired\r
+ protected void setDao(IReferenceDao dao) {\r
+ this.dao = dao;\r
+ }\r
+\r
+ @Override\r
+ public List<UuidAndTitleCache<Reference>> getUuidAndTitle() {\r
+ return dao.getUuidAndTitle();\r
+ }\r
+\r
+ @Override\r
+ public List<Reference> getAllReferencesForPublishing(){\r
+ return dao.getAllNotNomenclaturalReferencesForPublishing();\r
+ }\r
+\r
+ @Override\r
+ public List<Reference> getAllNomenclaturalReferences() {\r
+ return dao.getAllNomenclaturalReferences();\r
+ }\r
+\r
+ @Override\r
+ public List<TaxonBase> listCoveredTaxa(Reference reference, boolean includeSubordinateReferences, List<String> propertyPaths) {\r
+ List<TaxonBase> taxonList = dao.listCoveredTaxa(reference, includeSubordinateReferences, null, propertyPaths);\r
+ return taxonList;\r
+ }\r
+\r
+ @Override\r
+ public DeleteResult delete(Reference reference) {\r
+ //check whether the reference is used somewhere\r
+ DeleteResult result = isDeletable(reference.getUuid(), null);\r
+\r
+ if (result.isOk()){\r
+ dao.delete(reference);\r
+ result.addDeletedObject(reference);\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ @Transactional(readOnly=false)\r
+ public DeleteResult delete(UUID referenceUuid) {\r
+ return delete(dao.load(referenceUuid));\r
+ }\r
+\r
+ @Override\r
+ public List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCache(Integer limit, String pattern) {\r
+ return dao.getUuidAndAbbrevTitleCache(limit, pattern, null);\r
+ }\r
+\r
+ @Override\r
+ public List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCache(Integer limit, String pattern, ReferenceType type) {\r
+ ReferenceType inReferenceType = null;\r
+ inReferenceType = getInReferenceType(type);\r
+ return dao.getUuidAndAbbrevTitleCache(limit, pattern, inReferenceType);\r
+ }\r
+\r
+ @Override\r
+ public List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCacheForAuthor(Integer limit, String pattern, ReferenceType type) {\r
+ return dao.getUuidAndAbbrevTitleCacheForAuthor(limit, pattern, null);\r
+ }\r
+\r
+ @Override\r
+ public List<UuidAndTitleCache<Reference>> getUuidAndTitleCache(Integer limit, String pattern, ReferenceType type) {\r
+ ReferenceType inReferenceType = null;\r
+ inReferenceType = getInReferenceType(type);\r
+ return dao.getUuidAndTitleCache(limit, pattern, inReferenceType);\r
+ }\r
+\r
+\r
+ @Transactional(readOnly = true)\r
+ @Override\r
+ public List<IdentifiedEntityDTO<Reference>> listByIdentifierAbbrev(\r
+ String identifier, DefinedTerm identifierType, MatchMode matchmode,\r
+ Integer limit) {\r
+\r
+ long numberOfResults = dao.countByIdentifier(Reference.class, identifier, identifierType, matchmode);\r
+ List<Object[]> daoResults = new ArrayList<Object[]>();\r
+ if(numberOfResults > 0) { // no point checking again\r
+ daoResults = dao.findByIdentifierAbbrev( identifier, identifierType,\r
+ matchmode, limit);\r
+ }\r
+\r
+ List<IdentifiedEntityDTO<Reference>> result = new ArrayList<>();\r
+ for (Object[] daoObj : daoResults){\r
+ result.add(new IdentifiedEntityDTO<Reference>((DefinedTerm)daoObj[0], (String)daoObj[1], (UUID)daoObj[2], (String)daoObj[3],(String)daoObj[4]));\r
+\r
+ }\r
+ return result;\r
+ }\r
+\r
+ @Transactional(readOnly = true)\r
+ @Override\r
+ public List<IdentifiedEntityDTO<Reference>> listByIdentifierAndTitleCacheAbbrev(\r
+ String identifier, DefinedTerm identifierType, MatchMode matchmode,\r
+ Integer limit) {\r
+\r
+ long numberOfResults = dao.countByIdentifier(Reference.class, identifier, identifierType, matchmode);\r
+ long numberOfResultsTitle = dao.countByTitle(identifier);\r
+ List<Object[]> daoResults = new ArrayList<>();\r
+ List<UuidAndTitleCache<Reference>> daoResultsTitle = new ArrayList();\r
+ if(numberOfResults > 0) { // no point checking again\r
+ daoResults = dao.findByIdentifierAbbrev( identifier, identifierType,\r
+ matchmode, limit);\r
+ }\r
+ daoResultsTitle = dao.getUuidAndAbbrevTitleCache(100, identifier, null);\r
+\r
+ List<IdentifiedEntityDTO<Reference>> result = new ArrayList<>();\r
+ for (Object[] daoObj : daoResults){\r
+ result.add(new IdentifiedEntityDTO<Reference>((DefinedTerm)daoObj[0], (String)daoObj[1], (UUID)daoObj[2], (String)daoObj[3],(String)daoObj[4]));\r
+\r
+ }\r
+ for (UuidAndTitleCache<Reference> uuidAndTitleCache: daoResultsTitle){\r
+ result.add(new IdentifiedEntityDTO<>(null, null, uuidAndTitleCache.getUuid(), uuidAndTitleCache.getTitleCache(), uuidAndTitleCache.getAbbrevTitleCache()));\r
+ }\r
+ return result;\r
+ }\r
+\r
+\r
+ private ReferenceType getInReferenceType(ReferenceType type){\r
+ ReferenceType inReferenceType = null;\r
+ if (type.equals(ReferenceType.Article)){\r
+ inReferenceType = ReferenceType.Journal;\r
+ } else if (type.equals(ReferenceType.BookSection)){\r
+ inReferenceType = ReferenceType.Book;\r
+ } else if (type.equals(ReferenceType.InProceedings) ){\r
+ inReferenceType = ReferenceType.Proceedings;\r
+ } else if (type.equals(ReferenceType.Book) || type.equals(ReferenceType.Proceedings)){\r
+ inReferenceType = ReferenceType.PrintSeries;\r
+ } else if (type.equals(ReferenceType.Generic)){\r
+ inReferenceType = ReferenceType.Generic;\r
+ }\r
+ return inReferenceType;\r
+ }\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public List<UuidAndTitleCache<Reference>> getUuidAndTitleCacheForUUIDS(Set<UUID> uuids) {\r
+ return dao.getUuidAndTitle(uuids);\r
+ }\r
+\r
}\r