package eu.etaxonomy.cdm.api.service;\r
\r
import java.util.ArrayList;\r
+import java.util.Arrays;\r
import java.util.List;\r
\r
import org.apache.log4j.Logger;\r
+import org.hibernate.Hibernate;\r
import org.springframework.beans.factory.annotation.Autowired;\r
import org.springframework.stereotype.Service;\r
import org.springframework.transaction.annotation.Propagation;\r
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;\r
import eu.etaxonomy.cdm.api.service.pager.Pager;\r
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;\r
+import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;\r
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;\r
import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;\r
+import eu.etaxonomy.cdm.model.description.DescriptionBase;\r
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
+import eu.etaxonomy.cdm.model.description.IndividualsAssociation;\r
+import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;\r
import eu.etaxonomy.cdm.model.media.Media;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
+import eu.etaxonomy.cdm.model.name.HomotypicalGroup;\r
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;\r
import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;\r
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;\r
import eu.etaxonomy.cdm.model.occurrence.FieldObservation;\r
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;\r
+import eu.etaxonomy.cdm.model.taxon.Taxon;\r
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
+import eu.etaxonomy.cdm.persistence.dao.AbstractBeanInitializer;\r
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;\r
+import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao;\r
import eu.etaxonomy.cdm.persistence.dao.occurrence.IOccurrenceDao;\r
+import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;\r
import eu.etaxonomy.cdm.persistence.query.OrderHint;\r
+import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;\r
\r
/**\r
* @author a.babadshanjan\r
\r
@Autowired\r
private IDefinedTermDao definedTermDao; \r
+ \r
+ @Autowired\r
+ private IDescriptionService descriptionService; \r
+ \r
+ @Autowired\r
+ private AbstractBeanInitializer beanInitializer;\r
+ \r
+ @Autowired\r
+ private ITaxonDao taxonDao;\r
+ \r
+ \r
\r
public OccurrenceServiceImpl() {\r
logger.debug("Load OccurrenceService Bean");\r
}\r
\r
+\r
/* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#generateTitleCache()\r
+ * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)\r
*/\r
- public void generateTitleCache() {\r
- // TODO Auto-generated method stub\r
- logger.warn("Not yet implemented");\r
+ @Override\r
+ @Transactional(readOnly = false)\r
+ public void updateTitleCache(Class<? extends SpecimenOrObservationBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<SpecimenOrObservationBase> cacheStrategy, IProgressMonitor monitor) {\r
+ if (clazz == null){\r
+ clazz = SpecimenOrObservationBase.class;\r
+ }\r
+ super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);\r
}\r
\r
+\r
/**\r
* FIXME Candidate for harmonization\r
* move to termService\r
* move to termService\r
*/\r
public List<WaterbodyOrCountry> getWaterbodyOrCountryByName(String name) {\r
- List<? extends DefinedTermBase> terms = this.definedTermDao.getDefinedTermByRepresentationText(name, WaterbodyOrCountry.class);\r
+ List<? extends DefinedTermBase> terms = this.definedTermDao.findByTitle(WaterbodyOrCountry.class, name, null, null, null, null, null, null) ;\r
List<WaterbodyOrCountry> countries = new ArrayList<WaterbodyOrCountry>();\r
for (int i=0;i<terms.size();i++){\r
countries.add((WaterbodyOrCountry)terms.get(i));\r
Integer numberOfResults = dao.countDerivationEvents(occurence);\r
\r
List<DerivationEvent> results = new ArrayList<DerivationEvent>();\r
- if(numberOfResults > 0) { // no point checking again\r
+ if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)\r
results = dao.getDerivationEvents(occurence, pageSize, pageNumber,propertyPaths); \r
}\r
\r
Integer numberOfResults = dao.countDeterminations(occurrence, taxonBase);\r
\r
List<DeterminationEvent> results = new ArrayList<DeterminationEvent>();\r
- if(numberOfResults > 0) { // no point checking again\r
+ if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)\r
results = dao.getDeterminations(occurrence,taxonBase, pageSize, pageNumber, propertyPaths); \r
}\r
\r
Integer numberOfResults = dao.countMedia(occurence);\r
\r
List<Media> results = new ArrayList<Media>();\r
- if(numberOfResults > 0) { // no point checking again\r
+ if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)\r
results = dao.getMedia(occurence, pageSize, pageNumber, propertyPaths); \r
}\r
\r
return new DefaultPagerImpl<Media>(pageNumber, numberOfResults, pageSize, results);\r
}\r
\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.api.service.IOccurrenceService#list(java.lang.Class, eu.etaxonomy.cdm.model.taxon.TaxonBase, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)\r
+ */\r
public Pager<SpecimenOrObservationBase> list(Class<? extends SpecimenOrObservationBase> type, TaxonBase determinedAs, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {\r
Integer numberOfResults = dao.count(type,determinedAs);\r
List<SpecimenOrObservationBase> results = new ArrayList<SpecimenOrObservationBase>();\r
pageNumber = pageNumber == null ? 0 : pageNumber;\r
- if(numberOfResults > 0) { // no point checking again\r
+ if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)\r
Integer start = pageSize == null ? 0 : pageSize * pageNumber;\r
results = dao.list(type,determinedAs, pageSize, start, orderHints,propertyPaths);\r
}\r
- return new DefaultPagerImpl<SpecimenOrObservationBase>(pageNumber, numberOfResults, pageSize, results); }\r
+ return new DefaultPagerImpl<SpecimenOrObservationBase>(pageNumber, numberOfResults, pageSize, results); \r
+ }\r
\r
@Override\r
public List<UuidAndTitleCache<DerivedUnitBase>> getDerivedUnitBaseUuidAndTitleCache() {\r
public DerivedUnitFacade getDerivedUnitFacade(DerivedUnitBase derivedUnit, List<String> propertyPaths) throws DerivedUnitFacadeNotSupportedException {\r
derivedUnit = (DerivedUnitBase<?>)dao.load(derivedUnit.getUuid(), null);\r
DerivedUnitFacadeConfigurator config = DerivedUnitFacadeConfigurator.NewInstance();\r
+ config.setThrowExceptionForNonSpecimenPreservationMethodRequest(false);\r
DerivedUnitFacade derivedUnitFacade = DerivedUnitFacade.NewInstance(derivedUnit, config);\r
+ beanInitializer.initialize(derivedUnitFacade, propertyPaths);\r
return derivedUnitFacade;\r
}\r
+\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.api.service.IOccurrenceService#listDerivedUnitFacades(eu.etaxonomy.cdm.model.description.DescriptionBase, java.util.List)\r
+ */\r
+ @Override\r
+ public List<DerivedUnitFacade> listDerivedUnitFacades(\r
+ DescriptionBase description, List<String> propertyPaths) {\r
+ \r
+ List<DerivedUnitFacade> derivedUnitFacadeList = new ArrayList<DerivedUnitFacade>();\r
+ IndividualsAssociation tempIndividualsAssociation;\r
+ SpecimenOrObservationBase tempSpecimenOrObservationBase;\r
+ List<DescriptionElementBase> elements = descriptionService.listDescriptionElements(description, null, IndividualsAssociation.class, null, 0, Arrays.asList(new String []{"associatedSpecimenOrObservation"}));\r
+ for(DescriptionElementBase element : elements){\r
+ if(element instanceof IndividualsAssociation){\r
+ tempIndividualsAssociation = (IndividualsAssociation)element;\r
+ if(tempIndividualsAssociation.getAssociatedSpecimenOrObservation() != null){\r
+ tempSpecimenOrObservationBase = HibernateProxyHelper.deproxy(tempIndividualsAssociation.getAssociatedSpecimenOrObservation(), SpecimenOrObservationBase.class);\r
+ if(tempSpecimenOrObservationBase instanceof DerivedUnitBase){\r
+ try {\r
+ derivedUnitFacadeList.add(DerivedUnitFacade.NewInstance((DerivedUnitBase)tempSpecimenOrObservationBase));\r
+ } catch (DerivedUnitFacadeNotSupportedException e) {\r
+ logger.warn(tempIndividualsAssociation.getAssociatedSpecimenOrObservation().getTitleCache() + " : " +e.getMessage());\r
+ }\r
+ }\r
+ }\r
+ \r
+ }\r
+ }\r
+ \r
+ beanInitializer.initializeAll(derivedUnitFacadeList, propertyPaths);\r
+ \r
+ return derivedUnitFacadeList;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.api.service.IOccurrenceService#listSpecimenOrObservationsFor(java.lang.Class, eu.etaxonomy.cdm.model.taxon.Taxon, java.util.List)\r
+ */\r
+ @Override\r
+ public <T extends SpecimenOrObservationBase> List<T> listByAnyAssociation(Class<T> type,\r
+ Taxon associatedTaxon, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths)\r
+ {\r
+ \r
+ associatedTaxon = (Taxon) taxonDao.load(associatedTaxon.getUuid());\r
+ return dao.listByAnyAssociation(type, associatedTaxon, limit, start, orderHints, propertyPaths);\r
+ \r
+ }\r
+ \r
+ \r
}\r