+// $Id$\r
/**\r
* Copyright (C) 2007 EDIT\r
* European Distributed Institute of Taxonomy \r
package eu.etaxonomy.cdm.api.service;\r
\r
import java.util.ArrayList;\r
-import java.util.Collection;\r
import java.util.List;\r
-import java.util.Map;\r
+import java.util.Set;\r
import java.util.UUID;\r
\r
import org.apache.log4j.Logger;\r
import org.springframework.stereotype.Service;\r
import org.springframework.transaction.annotation.Transactional;\r
\r
+import eu.etaxonomy.cdm.api.service.pager.Pager;\r
+import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;\r
import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
-import eu.etaxonomy.cdm.model.common.VersionableEntity;\r
import eu.etaxonomy.cdm.model.description.DescriptionBase;\r
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
import eu.etaxonomy.cdm.model.description.Feature;\r
-import eu.etaxonomy.cdm.model.description.FeatureNode;\r
-import eu.etaxonomy.cdm.model.description.FeatureTree;\r
-import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;\r
+import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;\r
+import eu.etaxonomy.cdm.model.description.Scope;\r
+import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
+import eu.etaxonomy.cdm.model.description.TaxonNameDescription;\r
+import eu.etaxonomy.cdm.model.location.NamedArea;\r
+import eu.etaxonomy.cdm.model.media.Media;\r
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
+import eu.etaxonomy.cdm.model.taxon.Taxon;\r
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;\r
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;\r
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao;\r
+import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionElementDao;\r
+import eu.etaxonomy.cdm.persistence.dao.description.IFeatureDao;\r
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureNodeDao;\r
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureTreeDao;\r
import eu.etaxonomy.cdm.persistence.dao.description.IStatisticalMeasurementValueDao;\r
+import eu.etaxonomy.cdm.persistence.query.OrderHint;\r
\r
/**\r
* @author a.mueller\r
*/\r
@Service\r
@Transactional(readOnly = true)\r
-public class DescriptionServiceImpl extends IdentifiableServiceBase<DescriptionBase> implements IDescriptionService {\r
- \r
+public class DescriptionServiceImpl extends IdentifiableServiceBase<DescriptionBase,IDescriptionDao> implements IDescriptionService {\r
+ \r
private static final Logger logger = Logger.getLogger(DescriptionServiceImpl.class);\r
\r
+ protected IDescriptionElementDao descriptionElementDao;\r
protected IFeatureTreeDao featureTreeDao;\r
protected IFeatureNodeDao featureNodeDao;\r
+ protected IFeatureDao featureDao;\r
protected ITermVocabularyDao vocabularyDao;\r
protected IStatisticalMeasurementValueDao statisticalMeasurementValueDao;\r
\r
- \r
- @Autowired\r
- protected void setDao(IDescriptionDao dao) {\r
- this.dao = dao;\r
- }\r
- \r
@Autowired\r
protected void setFeatureTreeDao(IFeatureTreeDao featureTreeDao) {\r
this.featureTreeDao = featureTreeDao;\r
this.featureNodeDao = featureNodeDao;\r
}\r
\r
+ @Autowired\r
+ protected void setFeatureDao(IFeatureDao featureDao) {\r
+ this.featureDao = featureDao;\r
+ }\r
+ \r
@Autowired\r
protected void setVocabularyDao(ITermVocabularyDao vocabularyDao) {\r
this.vocabularyDao = vocabularyDao;\r
this.statisticalMeasurementValueDao = statisticalMeasurementValueDao;\r
}\r
\r
+ @Autowired\r
+ protected void setDescriptionElementDao(IDescriptionElementDao descriptionElementDao) {\r
+ this.descriptionElementDao = descriptionElementDao;\r
+ }\r
+ \r
/**\r
* \r
*/\r
public DescriptionServiceImpl() {\r
logger.debug("Load DescriptionService Bean");\r
}\r
-\r
+ \r
/* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.api.service.IDescriptionService#getDescriptionBaseByUuid(java.util.UUID)\r
+ * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#generateTitleCache()\r
*/\r
- public DescriptionBase getDescriptionBaseByUuid(UUID uuid) {\r
- return super.getCdmObjectByUuid(uuid);\r
+ public void generateTitleCache() {\r
+ logger.warn("generateTitleCache not yet implemented");\r
}\r
\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.api.service.IDescriptionService#saveDescription(eu.etaxonomy.cdm.model.description.DescriptionBase)\r
- */\r
- @Transactional(readOnly = false)\r
- public UUID saveDescription(DescriptionBase description) {\r
- return super.saveCdmObject(description);\r
+ public TermVocabulary<Feature> getDefaultFeatureVocabulary(){\r
+ String uuidFeature = "b187d555-f06f-4d65-9e53-da7c93f8eaa8";\r
+ UUID featureUuid = UUID.fromString(uuidFeature);\r
+ return (TermVocabulary)vocabularyDao.findByUuid(featureUuid);\r
}\r
\r
- @Transactional(readOnly = false)\r
- public UUID saveStatisticalMeasurementValue(StatisticalMeasurementValue statisticalMeasurementValue) {\r
- return statisticalMeasurementValueDao.saveOrUpdate(statisticalMeasurementValue);\r
+ @Autowired\r
+ protected void setDao(IDescriptionDao dao) {\r
+ this.dao = dao;\r
}\r
- \r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#generateTitleCache()\r
- */\r
- public void generateTitleCache() {\r
- logger.warn("generateTitleCache not yet implemented");\r
+\r
+ public int count(Class<? extends DescriptionBase> type, Boolean hasImages, Boolean hasText,Set<Feature> feature) {\r
+ return dao.countDescriptions(type, hasImages, hasText, feature);\r
}\r
\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.api.service.IDescriptionService#saveFeatureTree(eu.etaxonomy.cdm.model.description.FeatureTree)\r
+ /**\r
+ * FIXME Candidate for harmonization\r
+ * rename -> getElements\r
*/\r
- @Transactional(readOnly = false)\r
- public UUID saveFeatureTree(FeatureTree tree) {\r
- return featureTreeDao.saveOrUpdate(tree);\r
+ public Pager<DescriptionElementBase> getDescriptionElements(DescriptionBase description,\r
+ Set<Feature> features, Class<? extends DescriptionElementBase> type, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {\r
+\r
+ List<DescriptionElementBase> results = listDescriptionElements(description, features, type, pageSize, pageNumber, propertyPaths);\r
+ return new DefaultPagerImpl<DescriptionElementBase>(pageNumber, results.size(), pageSize, results);\r
+ }\r
+\r
+ public List<DescriptionElementBase> listDescriptionElements(DescriptionBase description,\r
+ Set<Feature> features, Class<? extends DescriptionElementBase> type, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {\r
+ Integer numberOfResults = dao.countDescriptionElements(description, features, type);\r
+ \r
+ List<DescriptionElementBase> results = new ArrayList<DescriptionElementBase>();\r
+ if(numberOfResults > 0) { // no point checking again\r
+ results = dao.getDescriptionElements(description, features, type, pageSize, pageNumber, propertyPaths);\r
+ }\r
+ return results;\r
}\r
- \r
- @Transactional(readOnly = false)\r
- public void saveFeatureDataAll(Collection<VersionableEntity<?>> featureData) {\r
\r
- List<FeatureTree> trees = new ArrayList<FeatureTree>();\r
- List<FeatureNode> nodes = new ArrayList<FeatureNode>();\r
+ public Pager<Media> getMedia(DescriptionElementBase descriptionElement, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {\r
+ Integer numberOfResults = descriptionElementDao.countMedia(descriptionElement);\r
\r
- for ( VersionableEntity<?> featureItem : featureData) {\r
- if (featureItem instanceof FeatureTree) {\r
- trees.add((FeatureTree)featureItem);\r
- } else if (featureItem instanceof FeatureNode) {\r
- nodes.add((FeatureNode)featureItem);\r
- } else {\r
- logger.error("Entry of wrong type: " + featureItem.toString());\r
- }\r
+ List<Media> results = new ArrayList<Media>();\r
+ if(numberOfResults > 0) { // no point checking again\r
+ results = descriptionElementDao.getMedia(descriptionElement, pageSize, pageNumber, propertyPaths); \r
}\r
\r
- if (trees.size() > 0) { saveFeatureTreeAll(trees); }\r
- if (nodes.size() > 0) { saveFeatureNodeAll(nodes); }\r
+ return new DefaultPagerImpl<Media>(pageNumber, numberOfResults, pageSize, results);\r
}\r
- \r
- @Transactional(readOnly = false)\r
- public Map<UUID, FeatureTree> saveFeatureTreeAll(Collection<FeatureTree> trees) {\r
- return featureTreeDao.saveAll(trees);\r
+\r
+ public Pager<TaxonDescription> getTaxonDescriptions(Taxon taxon, Set<Scope> scopes, Set<NamedArea> geographicalScope, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {\r
+ Integer numberOfResults = dao.countTaxonDescriptions(taxon, scopes, geographicalScope);\r
+ \r
+ List<TaxonDescription> results = new ArrayList<TaxonDescription>();\r
+ if(numberOfResults > 0) { // no point checking again\r
+ results = dao.getTaxonDescriptions(taxon, scopes, geographicalScope, pageSize, pageNumber, propertyPaths); \r
+ }\r
+ \r
+ return new DefaultPagerImpl<TaxonDescription>(pageNumber, numberOfResults, pageSize, results);\r
}\r
\r
- @Transactional(readOnly = false)\r
- public Map<UUID, FeatureNode> saveFeatureNodeAll(Collection<FeatureNode> trees) {\r
- return featureNodeDao.saveAll(trees);\r
+ public Pager<TaxonNameDescription> getTaxonNameDescriptions(TaxonNameBase name, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {\r
+ Integer numberOfResults = dao.countTaxonNameDescriptions(name);\r
+ \r
+ List<TaxonNameDescription> results = new ArrayList<TaxonNameDescription>();\r
+ if(numberOfResults > 0) { // no point checking again\r
+ results = dao.getTaxonNameDescriptions(name, pageSize, pageNumber,propertyPaths); \r
+ }\r
+ \r
+ return new DefaultPagerImpl<TaxonNameDescription>(pageNumber, numberOfResults, pageSize, results);\r
}\r
\r
- public TermVocabulary<Feature> getFeatureVocabulary(UUID uuid){\r
- TermVocabulary<Feature> featureVocabulary;\r
- try {\r
- featureVocabulary = (TermVocabulary)vocabularyDao.findByUuid(uuid);\r
- } catch (ClassCastException e) {\r
- return null;\r
+ \r
+ public Pager<DescriptionBase> page(Class<? extends DescriptionBase> type, Boolean hasImages, Boolean hasText, Set<Feature> feature, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {\r
+ Integer numberOfResults = dao.countDescriptions(type, hasImages, hasText, feature);\r
+ \r
+ List<DescriptionBase> results = new ArrayList<DescriptionBase>();\r
+ if(numberOfResults > 0) { // no point checking again\r
+ results = dao.listDescriptions(type, hasImages, hasText, feature, pageSize, pageNumber,orderHints,propertyPaths); \r
}\r
- return featureVocabulary;\r
+ \r
+ return new DefaultPagerImpl<DescriptionBase>(pageNumber, numberOfResults, pageSize, results);\r
}\r
\r
- public TermVocabulary<Feature> getDefaultFeatureVocabulary(){\r
- String uuidFeature = "b187d555-f06f-4d65-9e53-da7c93f8eaa8";\r
- UUID featureUuid = UUID.fromString(uuidFeature);\r
- return getFeatureVocabulary(featureUuid);\r
+ /**\r
+ * FIXME Candidate for harmonization\r
+ * Rename: searchByDistribution\r
+ */\r
+ public Pager<TaxonDescription> searchDescriptionByDistribution(Set<NamedArea> namedAreas, PresenceAbsenceTermBase presence, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {\r
+ Integer numberOfResults = dao.countDescriptionByDistribution(namedAreas, presence);\r
+ \r
+ List<TaxonDescription> results = new ArrayList<TaxonDescription>();\r
+ if(numberOfResults > 0) { // no point checking again\r
+ results = dao.searchDescriptionByDistribution(namedAreas, presence, pageSize, pageNumber,orderHints,propertyPaths); \r
+ }\r
+ \r
+ return new DefaultPagerImpl<TaxonDescription>(pageNumber, numberOfResults, pageSize, results);\r
}\r
\r
- public List<FeatureTree> getFeatureTreesAll() {\r
- return featureTreeDao.list();\r
+ /**\r
+ * FIXME Candidate for harmonization\r
+ * move: descriptionElementService.search\r
+ */\r
+ public Pager<DescriptionElementBase> searchElements(Class<? extends DescriptionElementBase> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {\r
+ Integer numberOfResults = descriptionElementDao.count(clazz,queryString);\r
+ \r
+ List<DescriptionElementBase> results = new ArrayList<DescriptionElementBase>();\r
+ if(numberOfResults > 0) { // no point checking again\r
+ results = descriptionElementDao.search(clazz, queryString, pageSize, pageNumber, orderHints, propertyPaths); \r
+ }\r
+ \r
+ return new DefaultPagerImpl<DescriptionElementBase>(pageNumber, numberOfResults, pageSize, results);\r
}\r
+\r
+ /**\r
+ * FIXME Candidate for harmonization\r
+ * descriptionElementService.find\r
+ */\r
+ public DescriptionElementBase getDescriptionElementByUuid(UUID uuid) {\r
+ return descriptionElementDao.findByUuid(uuid);\r
+ } \r
\r
- public List<FeatureNode> getFeatureNodesAll() {\r
- return featureNodeDao.list();\r
+ /**\r
+ * FIXME Candidate for harmonization\r
+ * descriptionElementService.load\r
+ */\r
+ public DescriptionElementBase loadDescriptionElement(UUID uuid, List<String> propertyPaths) {\r
+ return descriptionElementDao.load(uuid, propertyPaths);\r
}\r
\r
- \r
+ /**\r
+ * FIXME Candidate for harmonization\r
+ * descriptionElementService.save\r
+ */\r
+ public UUID saveDescriptionElement(DescriptionElementBase descriptionElement) {\r
+ return descriptionElementDao.save(descriptionElement);\r
+ }\r
+\r
+ /**\r
+ * FIXME Candidate for harmonization\r
+ * descriptionElementService.delete\r
+ */\r
+ public UUID deleteDescriptionElement(DescriptionElementBase descriptionElement) {\r
+ return descriptionElementDao.delete(descriptionElement);\r
+ }\r
+\r
+ public TermVocabulary<Feature> getFeatureVocabulary(UUID uuid) {\r
+ return (TermVocabulary)vocabularyDao.findByUuid(uuid);\r
+ }\r
}\r