-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
package eu.etaxonomy.cdm.api.service;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
import eu.etaxonomy.cdm.api.service.pager.Pager;
import eu.etaxonomy.cdm.api.service.pager.impl.AbstractPagerImpl;
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
import eu.etaxonomy.cdm.model.common.TermVocabulary;
import eu.etaxonomy.cdm.model.description.DescriptionBase;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
import eu.etaxonomy.cdm.model.description.Distribution;
import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.description.FeatureTree;
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
+import eu.etaxonomy.cdm.model.description.SpecimenDescription;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
import eu.etaxonomy.cdm.model.description.TextData;
import eu.etaxonomy.cdm.model.location.NamedArea;
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
import eu.etaxonomy.cdm.model.media.Media;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.name.TaxonName;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao;
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionElementDao;
+import eu.etaxonomy.cdm.persistence.dao.description.IDescriptiveDataSetDao;
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureDao;
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureNodeDao;
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureTreeDao;
import eu.etaxonomy.cdm.persistence.dao.description.IStatisticalMeasurementValueDao;
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
+import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
import eu.etaxonomy.cdm.persistence.dto.TermDto;
import eu.etaxonomy.cdm.persistence.query.OrderHint;
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
/**
* @author a.mueller
- * @created 24.06.2008
- * @version 1.0
- */
-/**
* @author a.kohlbecker
- * @date Dec 5, 2013
+ *
+ * @since 24.06.2008
*
*/
@Service
@Transactional(readOnly = true)
-public class DescriptionServiceImpl extends IdentifiableServiceBase<DescriptionBase,IDescriptionDao> implements IDescriptionService {
+public class DescriptionServiceImpl
+ extends IdentifiableServiceBase<DescriptionBase,IDescriptionDao>
+ implements IDescriptionService {
private static final Logger logger = Logger.getLogger(DescriptionServiceImpl.class);
protected IDescriptionElementDao descriptionElementDao;
protected IFeatureTreeDao featureTreeDao;
+ protected IDescriptiveDataSetDao descriptiveDataSetDao;
protected IFeatureNodeDao featureNodeDao;
protected IFeatureDao featureDao;
protected ITermVocabularyDao vocabularyDao;
protected IDefinedTermDao definedTermDao;
protected IStatisticalMeasurementValueDao statisticalMeasurementValueDao;
protected ITaxonDao taxonDao;
+ protected ITaxonNodeDao taxonNodeDao;
+ protected IDescriptiveDataSetDao dataSetDao;
+
+ @Autowired
+ private IProgressMonitorService progressMonitorService;
//TODO change to Interface
private NaturalLanguageGenerator naturalLanguageGenerator;
this.featureTreeDao = featureTreeDao;
}
+ @Autowired
+ protected void setDescriptiveDataSetDao(IDescriptiveDataSetDao descriptiveDataSetDao) {
+ this.descriptiveDataSetDao = descriptiveDataSetDao;
+ }
+
@Autowired
protected void setFeatureNodeDao(IFeatureNodeDao featureNodeDao) {
this.featureNodeDao = featureNodeDao;
this.taxonDao = taxonDao;
}
+ @Autowired
+ protected void setTaxonNodeDao(ITaxonNodeDao taxonNodeDao) {
+ this.taxonNodeDao = taxonNodeDao;
+ }
+
+ @Autowired
+ protected void setDataSetDao(IDescriptiveDataSetDao dataSetDao) {
+ this.dataSetDao = dataSetDao;
+ }
+
/**
*
*/
}
@Override
- public int count(Class<? extends DescriptionBase> type, Boolean hasImages, Boolean hasText,Set<Feature> feature) {
+ public long count(Class<? extends DescriptionBase> type, Boolean hasImages, Boolean hasText,Set<Feature> feature) {
return dao.countDescriptions(type, hasImages, hasText, feature);
}
Set<Feature> features, Class<T> type, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
List<T> results = listDescriptionElements(description, descriptionType, features, type, pageSize, pageNumber, propertyPaths);
- return new DefaultPagerImpl<T>(pageNumber, results.size(), pageSize, results);
+ return new DefaultPagerImpl<>(pageNumber, results.size(), pageSize, results);
}
@Override
Class<? extends DescriptionBase> descriptionType, Set<Feature> features, Class<T> type, Integer pageSize, Integer pageNumber,
List<String> propertyPaths) {
- Integer numberOfResults = dao.countDescriptionElements(description, descriptionType, features, type);
+ long numberOfResults = dao.countDescriptionElements(description, descriptionType, features, type);
List<T> results = new ArrayList<T>();
- if(AbstractPagerImpl.hasResultsInRange(numberOfResults.longValue(), pageNumber, pageSize)) {
+ if(AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)) {
results = dao.getDescriptionElements(description, descriptionType, features, type, pageSize, pageNumber, propertyPaths);
}
return results;
@Override
public Pager<Annotation> getDescriptionElementAnnotations(DescriptionElementBase annotatedObj, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
- Integer numberOfResults = descriptionElementDao.countAnnotations(annotatedObj, status);
+ long numberOfResults = descriptionElementDao.countAnnotations(annotatedObj, status);
- List<Annotation> results = new ArrayList<Annotation>();
+ List<Annotation> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
results = descriptionElementDao.getAnnotations(annotatedObj, status, pageSize, pageNumber, orderHints, propertyPaths);
}
- return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results);
+ return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
-
@Override
public Pager<Media> getMedia(DescriptionElementBase descriptionElement, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
Integer numberOfResults = descriptionElementDao.countMedia(descriptionElement);
return listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
}
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.api.service.IDescriptionService#pageMarkedTaxonDescriptions(eu.etaxonomy.cdm.model.taxon.Taxon, java.util.Set, java.util.Set, java.util.Set, java.lang.Integer, java.lang.Integer, java.util.List)
- */
@Override
public Pager<TaxonDescription> pageTaxonDescriptions(Taxon taxon, Set<DefinedTerm> scopes, Set<NamedArea> geographicalScope, Set<MarkerType> markerTypes, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
- Integer numberOfResults = dao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
+ long numberOfResults = dao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
- List<TaxonDescription> results = new ArrayList<TaxonDescription>();
+ List<TaxonDescription> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
results = dao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
}
- return new DefaultPagerImpl<TaxonDescription>(pageNumber, numberOfResults, pageSize, results);
+ return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
@Override
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.api.service.IDescriptionService#listTaxonDescriptionMedia(UUID, boolean, Set, Integer, Integer, List)
- */
@Override
public List<Media> listTaxonDescriptionMedia(UUID taxonUuid, boolean limitToGalleries, Set<MarkerType> markerTypes, Integer pageSize, Integer pageNumber, List<String> propertyPaths){
return this.dao.listTaxonDescriptionMedia(taxonUuid, limitToGalleries, markerTypes, pageSize, pageNumber, propertyPaths);
}
- /*
- * @see IDescriptionService#countTaxonDescriptionMedia(UUID, boolean, Set)
- */
@Override
public int countTaxonDescriptionMedia(UUID taxonUuid, boolean limitToGalleries, Set<MarkerType> markerTypes){
return this.dao.countTaxonDescriptionMedia(taxonUuid, limitToGalleries, markerTypes);
}
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.api.service.IDescriptionService#getOrderedDistributions(java.util.Set, boolean, boolean, java.util.Set, java.util.List)
- */
@Override
@Deprecated
public DistributionTree getOrderedDistributions(
distList.clear();
distList.addAll(filteredDistributions);
- return DescriptionUtility.orderDistributions(definedTermDao, omitLevels, distList, hiddenAreaMarkerTypes);
+ return DescriptionUtility.orderDistributions(definedTermDao, omitLevels, distList, hiddenAreaMarkerTypes, null);
}
@Override
- public Pager<TaxonNameDescription> getTaxonNameDescriptions(TaxonNameBase name, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
- Integer numberOfResults = dao.countTaxonNameDescriptions(name);
+ public Pager<TaxonNameDescription> getTaxonNameDescriptions(TaxonName name, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
+ long numberOfResults = dao.countTaxonNameDescriptions(name);
- List<TaxonNameDescription> results = new ArrayList<TaxonNameDescription>();
+ List<TaxonNameDescription> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
results = dao.getTaxonNameDescriptions(name, pageSize, pageNumber,propertyPaths);
}
- return new DefaultPagerImpl<TaxonNameDescription>(pageNumber, numberOfResults, pageSize, results);
+ return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
@Override
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) {
- Integer numberOfResults = dao.countDescriptions(type, hasImages, hasText, feature);
+ long numberOfResults = dao.countDescriptions(type, hasImages, hasText, feature);
- List<DescriptionBase> results = new ArrayList<DescriptionBase>();
+ @SuppressWarnings("rawtypes")
+ List<DescriptionBase> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
results = dao.listDescriptions(type, hasImages, hasText, feature, pageSize, pageNumber,orderHints,propertyPaths);
}
- return new DefaultPagerImpl<DescriptionBase>(pageNumber, numberOfResults, pageSize, results);
+ return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
/**
*/
@Override
public Pager<TaxonDescription> searchDescriptionByDistribution(Set<NamedArea> namedAreas, PresenceAbsenceTerm presence, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
- Integer numberOfResults = dao.countDescriptionByDistribution(namedAreas, presence);
+ long numberOfResults = dao.countDescriptionByDistribution(namedAreas, presence);
- List<TaxonDescription> results = new ArrayList<TaxonDescription>();
+ List<TaxonDescription> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
results = dao.searchDescriptionByDistribution(namedAreas, presence, pageSize, pageNumber,orderHints,propertyPaths);
}
- return new DefaultPagerImpl<TaxonDescription>(pageNumber, numberOfResults, pageSize, results);
+ return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
/**
* move: descriptionElementService.search
*/
@Override
- public Pager<DescriptionElementBase> searchElements(Class<? extends DescriptionElementBase> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
- Integer numberOfResults = descriptionElementDao.count(clazz, queryString);
+// public Pager<T> searchElements(Class<? extends T> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
+ public <S extends DescriptionElementBase> Pager<S> searchElements(Class<S> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
+ long numberOfResults = descriptionElementDao.count(clazz, queryString);
- List<DescriptionElementBase> results = new ArrayList<DescriptionElementBase>();
+ List<S> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
- results = descriptionElementDao.search(clazz, queryString, pageSize, pageNumber, orderHints, propertyPaths);
+ results = (List<S>)descriptionElementDao.search(clazz, queryString, pageSize, pageNumber, orderHints, propertyPaths);
}
- return new DefaultPagerImpl<DescriptionElementBase>(pageNumber, numberOfResults, pageSize, results);
+ return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
/**
return descriptionElementDao.saveAll(descriptionElements);
}
+ @Override
+ @Transactional(readOnly = false)
+ public List<MergeResult<DescriptionBase>> mergeDescriptionElements(Collection<TaxonDistributionDTO> descriptionElements, boolean returnTransientEntity) {
+ List<MergeResult<DescriptionBase>> mergedObjects = new ArrayList();
+ List<Distribution> toDelete = new ArrayList<>();
+ for(TaxonDistributionDTO obj : descriptionElements) {
+ Iterator<TaxonDescription> iterator = obj.getDescriptionsWrapper().getDescriptions().iterator();
+ while (iterator.hasNext()){
+ TaxonDescription desc = iterator.next();
+ mergedObjects.add(dao.merge(desc, returnTransientEntity));
+ }
+
+
+ }
+
+ return mergedObjects;
+ }
+
/**
* FIXME Candidate for harmonization
* descriptionElementService.delete
@Transactional(readOnly = false)
public DeleteResult deleteDescription(DescriptionBase description) {
DeleteResult deleteResult = new DeleteResult();
+ description = load(description.getId(), Arrays.asList("descriptiveDataSets"));//avoid lazy init exception
if (description instanceof TaxonDescription){
TaxonDescription taxDescription = HibernateProxyHelper.deproxy(description, TaxonDescription.class);
Taxon tax = taxDescription.getTaxon();
tax.removeDescription(taxDescription, true);
- dao.delete(description);
-
deleteResult.addUpdatedObject(tax);
- deleteResult.setCdmEntity(tax);
+ }
+ else if (HibernateProxyHelper.isInstanceOf(description, SpecimenDescription.class)){
+ SpecimenDescription specimenDescription = HibernateProxyHelper.deproxy(description, SpecimenDescription.class);
+ SpecimenOrObservationBase specimen = specimenDescription.getDescribedSpecimenOrObservation();
+ specimen.removeDescription(specimenDescription);
+ deleteResult.addUpdatedObject(specimen);
}
+ Set<DescriptiveDataSet> descriptiveDataSets = description.getDescriptiveDataSets();
+ for (Iterator<DescriptiveDataSet> iterator = descriptiveDataSets.iterator(); iterator.hasNext();) {
+ iterator.next().removeDescription(description);
+ }
+
+ dao.delete(description);
+ deleteResult.addDeletedObject(description);
+ deleteResult.setCdmEntity(description);
+
return deleteResult;
}
descriptionElements = new ArrayList<T>(0);
}
if (logger.isDebugEnabled()){logger.debug(" service - DONE ...");}
- return new DefaultPagerImpl<T>(pageNumber, count.intValue(), pageSize, descriptionElements);
+ return new DefaultPagerImpl<T>(pageNumber, count, pageSize, descriptionElements);
}
}
}
dao.delete(description);
+
}else{
dao.saveOrUpdate(description);
result.addUpdatedObject(description);
}
-
}