import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
+import eu.etaxonomy.cdm.api.service.dto.DNASampleDTO;
import eu.etaxonomy.cdm.api.service.dto.DerivateDTO;
import eu.etaxonomy.cdm.api.service.dto.DerivateDataDTO;
import eu.etaxonomy.cdm.api.service.dto.DerivateDataDTO.ContigFile;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.location.Country;
import eu.etaxonomy.cdm.model.location.NamedArea;
+import eu.etaxonomy.cdm.model.location.Point;
import eu.etaxonomy.cdm.model.media.Media;
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
import eu.etaxonomy.cdm.persistence.dao.initializer.AbstractBeanInitializer;
-import eu.etaxonomy.cdm.persistence.dao.molecular.ISingleReadDao;
import eu.etaxonomy.cdm.persistence.dao.occurrence.IOccurrenceDao;
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
/**
* @author a.babadshanjan
- * @created 01.09.2008
+ * @since 01.09.2008
*/
@Service
@Transactional(readOnly = true)
@Autowired
private ISequenceService sequenceService;
- @Autowired
- private ISingleReadDao singleReadDao;
-
@Autowired
private AbstractBeanInitializer beanInitializer;
private static final String SEPARATOR_STRING = ", ";
+ private static final List<String> DERIVED_UNIT_INIT_STRATEGY = Arrays.asList(new String []{
+ "derivedFrom.derivatives",
+ "derivedFrom.originals",
+ "specimenTypeDesignations.*",
+ "specimenTypeDesignations.citation.*",
+ "specimenTypeDesignations.homotypicalGroup.*",
+ "specimenTypeDesignations.typifiedNames",
+ "collection.$"
+ });
+
public OccurrenceServiceImpl() {
logger.debug("Load OccurrenceService Bean");
}
*/
@Override
public List<Country> getCountryByName(String name) {
- List<? extends DefinedTermBase> terms = this.definedTermDao.findByTitle(Country.class, name, null, null, null, null, null, null);
+ List<? extends DefinedTermBase> terms = this.definedTermDao.findByTitleWithRestrictions(Country.class, name, null, null, null, null, null, null);
List<Country> countries = new ArrayList<>();
for (int i = 0; i < terms.size(); i++) {
countries.add((Country) terms.get(i));
@Override
public Pager<DerivationEvent> getDerivationEvents(SpecimenOrObservationBase occurence, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
- Integer numberOfResults = dao.countDerivationEvents(occurence);
+ long numberOfResults = dao.countDerivationEvents(occurence);
List<DerivationEvent> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
}
@Override
- public int countDeterminations(SpecimenOrObservationBase occurence, TaxonBase taxonbase) {
+ public long countDeterminations(SpecimenOrObservationBase occurence, TaxonBase taxonbase) {
return dao.countDeterminations(occurence, taxonbase);
}
@Override
- public Pager<DeterminationEvent> getDeterminations(SpecimenOrObservationBase occurrence, TaxonBase taxonBase, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
- Integer numberOfResults = dao.countDeterminations(occurrence, taxonBase);
+ public Pager<DeterminationEvent> getDeterminations(SpecimenOrObservationBase occurrence, TaxonBase taxonBase,
+ Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
+ long numberOfResults = dao.countDeterminations(occurrence, taxonBase);
List<DeterminationEvent> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
results = dao.getDeterminations(occurrence, taxonBase, pageSize, pageNumber, propertyPaths);
}
- return new DefaultPagerImpl<DeterminationEvent>(pageNumber, numberOfResults, pageSize, results);
+ return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
@Override
public Pager<Media> getMedia(SpecimenOrObservationBase occurence, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
- Integer numberOfResults = dao.countMedia(occurence);
+ long numberOfResults = dao.countMedia(occurence);
List<Media> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
}
}
}
- return new DefaultPagerImpl<Media>(pageNumber, media.size(), pageSize, media);
+ return new DefaultPagerImpl<Media>(pageNumber, Long.valueOf(media.size()), pageSize, media);
}
@Override
- public Pager<SpecimenOrObservationBase> list(Class<? extends SpecimenOrObservationBase> type, TaxonName determinedAs, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
- Integer numberOfResults = dao.count(type, determinedAs);
+ public Pager<SpecimenOrObservationBase> list(Class<? extends SpecimenOrObservationBase> type, TaxonName determinedAs,
+ Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
+ long numberOfResults = dao.count(type, determinedAs);
+ @SuppressWarnings("rawtypes")
List<SpecimenOrObservationBase> results = new ArrayList<>();
- pageNumber = pageNumber == null ? 0 : pageNumber;
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
- Integer start = pageSize == null ? 0 : pageSize * pageNumber;
- results = dao.list(type, determinedAs, pageSize, start, orderHints, propertyPaths);
+ results = dao.list(type, determinedAs, pageSize, pageNumber, orderHints, propertyPaths);
}
- return new DefaultPagerImpl<SpecimenOrObservationBase>(pageNumber, numberOfResults, pageSize, results);
+ return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
@Override
- public Pager<SpecimenOrObservationBase> list(Class<? extends SpecimenOrObservationBase> type, TaxonBase determinedAs, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
- Integer numberOfResults = dao.count(type, determinedAs);
+ public Pager<SpecimenOrObservationBase> list(Class<? extends SpecimenOrObservationBase> type, TaxonBase determinedAs,
+ Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
+ long numberOfResults = dao.count(type, determinedAs);
+ @SuppressWarnings("rawtypes")
List<SpecimenOrObservationBase> results = new ArrayList<>();
- pageNumber = pageNumber == null ? 0 : pageNumber;
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
- Integer start = pageSize == null ? 0 : pageSize * pageNumber;
- results = dao.list(type, determinedAs, pageSize, start, orderHints, propertyPaths);
+ results = dao.list(type, determinedAs, pageSize, pageNumber, orderHints, propertyPaths);
}
- return new DefaultPagerImpl<SpecimenOrObservationBase>(pageNumber, numberOfResults, pageSize, results);
+ return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
@Override
}
@Override
- public List<SpecimenNodeWrapper> listUuidAndTitleCacheByAssociatedTaxon(List<UUID> taxonNodeUuids,
- Integer limit, Integer start, List<OrderHint> orderHints) {
- return dao.listUuidAndTitleCacheByAssociatedTaxon(taxonNodeUuids, limit, start, orderHints);
+ public Collection<SpecimenNodeWrapper> listUuidAndTitleCacheByAssociatedTaxon(List<UUID> taxonNodeUuids,
+ Integer limit, Integer start) {
+ return dao.listUuidAndTitleCacheByAssociatedTaxon(taxonNodeUuids, limit, start);
}
@Override
Set<UUID> fieldUnitUuids = new HashSet<>();
List<SpecimenOrObservationBase> records = listByAssociatedTaxon(null, includeRelationships, associatedTaxon, maxDepth, null, null, orderHints, propertyPaths);
for (SpecimenOrObservationBase<?> specimen : records) {
- for (FieldUnit fieldUnit : getFieldUnits(specimen.getUuid(), null)) {
+ for (FieldUnit fieldUnit : findFieldUnits(specimen.getUuid(), null)) {
fieldUnitUuids.add(fieldUnit.getUuid());
}
}
//dao.list() does the paging of the field units. Passing the field units directly to the Pager would not work
List<SpecimenOrObservationBase> fieldUnits = dao.list(fieldUnitUuids, pageSize, pageNumber, orderHints, propertyPaths);
- return new DefaultPagerImpl<SpecimenOrObservationBase>(pageNumber, fieldUnitUuids.size(), pageSize, fieldUnits);
+ return new DefaultPagerImpl<>(pageNumber, fieldUnitUuids.size(), pageSize, fieldUnits);
}
@Override
- public FieldUnitDTO assembleFieldUnitDTO(FieldUnit fieldUnit, UUID associatedTaxonUuid) {
+ public FieldUnitDTO assembleFieldUnitDTO(FieldUnit fieldUnit) {
if (!getSession().contains(fieldUnit)) {
fieldUnit = (FieldUnit) load(fieldUnit.getUuid());
}
- TaxonBase associatedTaxon = taxonService.load(associatedTaxonUuid);
- FieldUnitDTO fieldUnitDTO = new FieldUnitDTO();
+ FieldUnitDTO fieldUnitDTO = new FieldUnitDTO(fieldUnit);
if (fieldUnit.getGatheringEvent() != null) {
GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
fieldUnitDTO.setDate(dateString);
}
- // Taxon Name
- fieldUnitDTO.setTaxonName(associatedTaxon.getName().getTitleCache());
-
// Herbaria map
Map<eu.etaxonomy.cdm.model.occurrence.Collection, Integer> collectionToCountMap = new HashMap<>();
// List of accession numbers for citation
continue;
}
// collect accession numbers for citation
- String mostSignificantIdentifier = getMostSignificantIdentifier(derivedUnit);
- if (mostSignificantIdentifier != null) {
- preservedSpecimenAccessionNumbers.add(mostSignificantIdentifier);
- }
+ String identifier = getMostSignificantIdentifier(derivedUnit);
// collect collections for herbaria column
- if (derivedUnit.getCollection() != null) {
- Integer herbariumCount = collectionToCountMap.get(derivedUnit.getCollection());
+ eu.etaxonomy.cdm.model.occurrence.Collection collection = derivedUnit.getCollection();
+ if (collection != null) {
+ //combine collection with identifier
+ if (identifier != null) {
+ if(collection.getCode()!=null){
+ identifier = (collection.getCode()!=null?collection.getCode():"[no collection]")+" "+identifier;
+ }
+ preservedSpecimenAccessionNumbers.add(identifier);
+ }
+
+ Integer herbariumCount = collectionToCountMap.get(collection);
if (herbariumCount == null) {
herbariumCount = 0;
}
- collectionToCountMap.put(derivedUnit.getCollection(), herbariumCount + 1);
+ collectionToCountMap.put(collection, herbariumCount + 1);
}
if (derivedUnit.getRecordBasis().equals(SpecimenOrObservationType.PreservedSpecimen)) {
PreservedSpecimenDTO preservedSpecimenDTO = assemblePreservedSpecimenDTO(derivedUnit, fieldUnitDTO);
- fieldUnitDTO.addPreservedSpecimenDTO(preservedSpecimenDTO);
+ fieldUnitDTO.addDerivate(preservedSpecimenDTO);
fieldUnitDTO.setHasCharacterData(fieldUnitDTO.isHasCharacterData() || preservedSpecimenDTO.isHasCharacterData());
fieldUnitDTO.setHasDetailImage(fieldUnitDTO.isHasDetailImage() || preservedSpecimenDTO.isHasDetailImage());
fieldUnitDTO.setHasDna(fieldUnitDTO.isHasDna() || preservedSpecimenDTO.isHasDna());
herbariaString += SEPARATOR_STRING;
}
herbariaString = removeTail(herbariaString, SEPARATOR_STRING);
- fieldUnitDTO.setHerbarium(herbariaString);
+ fieldUnitDTO.setCollection(herbariaString);
return fieldUnitDTO;
}
if (!getSession().contains(derivedUnit)) {
derivedUnit = (DerivedUnit) load(derivedUnit.getUuid());
}
- PreservedSpecimenDTO preservedSpecimenDTO = new PreservedSpecimenDTO();
+ PreservedSpecimenDTO preservedSpecimenDTO = new PreservedSpecimenDTO(derivedUnit);
//specimen identifier
FormatKey collectionKey = FormatKey.COLLECTION_CODE;
specimenIdentifier = CdmFormatterFactory.format(derivedUnit, new FormatKey[] {
collectionKey, FormatKey.SPACE,
FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE });
+ if(CdmUtils.isBlank(specimenIdentifier)){
+ specimenIdentifier = derivedUnit.getTitleCache();
+ }
if(CdmUtils.isBlank(specimenIdentifier)){
specimenIdentifier = derivedUnit.getUuid().toString();
}
preservedSpecimenDTO.setAccessionNumber(specimenIdentifier);
- preservedSpecimenDTO.setUuid(derivedUnit.getUuid().toString());
+
//preferred stable URI
preservedSpecimenDTO.setPreferredStableUri(derivedUnit.getPreferredStableUri());
fieldUnitDTO.setHasType(true);
}
TypeDesignationStatusBase<?> typeStatus = specimenTypeDesignation.getTypeStatus();
- if (typeStatus != null) {
- List<String> typedTaxaNames = new ArrayList<>();
- String label = typeStatus.getLabel();
- Set<TaxonName> typifiedNames = specimenTypeDesignation.getTypifiedNames();
- for (TaxonName taxonName : typifiedNames) {
- typedTaxaNames.add(taxonName.getFullTitleCache());
- }
- preservedSpecimenDTO.addTypes(label, typedTaxaNames);
+ Set<TaxonName> typifiedNames = specimenTypeDesignation.getTypifiedNames();
+ List<String> typedTaxaNames = new ArrayList<>();
+ for (TaxonName taxonName : typifiedNames) {
+ typedTaxaNames.add(taxonName.getTitleCache());
}
+ preservedSpecimenDTO.addTypes(typeStatus!=null?typeStatus.getLabel():"", typedTaxaNames);
}
// individuals associations
return derivedUnits;
}
+ private Set<DerivateDTO> getDerivedUnitDTOsFor(DerivateDTO specimenDto, DerivedUnit specimen, HashMap<UUID, DerivateDTO> alreadyCollectedSpecimen) {
+ Set<DerivateDTO> derivedUnits = new HashSet<>();
+// load
+ for (DerivationEvent derivationEvent : specimen.getDerivationEvents()) {
+ for (DerivedUnit derivative : derivationEvent.getDerivatives()) {
+ if (!alreadyCollectedSpecimen.containsKey(specimenDto.getUuid())){
+ PreservedSpecimenDTO dto;
+ if (derivative instanceof DnaSample) {
+ dto = new DNASampleDTO(derivative);
+ } else {
+ dto = new PreservedSpecimenDTO(derivative);
+ }
+ alreadyCollectedSpecimen.put(dto.getUuid(), dto);
+ dto.addAllDerivates(getDerivedUnitDTOsFor(dto, derivative, alreadyCollectedSpecimen));
+ derivedUnits.add(dto);
+ }
+ }
+ }
+ return derivedUnits;
+ }
+
+// private Set<DerivateDTO> getDerivedUnitDTOsFor(DerivateDTO specimenDto, DerivedUnit specimen, HashMap<UUID, DerivateDTO> alreadyCollectedSpecimen) {
+// Set<DerivateDTO> derivedUnits = new HashSet<>();
+//// load
+// for (DerivationEvent derivationEvent : specimen.getDerivationEvents()) {
+// for (DerivedUnit derivative : derivationEvent.getDerivatives()) {
+// if (!alreadyCollectedSpecimen.containsKey(specimenDto.getUuid())){
+// PreservedSpecimenDTO dto;
+// if (derivative instanceof DnaSample){
+// dto = DNASampleDTO.newInstance(derivative);
+// }else{
+// dto = PreservedSpecimenDTO.newInstance(derivative);
+// }
+// alreadyCollectedSpecimen.put(dto.getUuid(), dto);
+// dto.addAllDerivates(getDerivedUnitDTOsFor(dto, derivative, alreadyCollectedSpecimen));
+// derivedUnits.add(dto);
+// }
+// }
+// }
+// return derivedUnits;
+// }
+
@SuppressWarnings("unchecked")
@Override
- public <T extends SpecimenOrObservationBase> Pager<T> pageByAssociatedTaxon(Class<T> type, Set<TaxonRelationshipEdge> includeRelationships,
+ public <T extends SpecimenOrObservationBase> Pager<T> pageByAssociatedTaxon(Class<T> type, Set<TaxonRelationshipEdge> includedRelationships,
Taxon associatedTaxon, Integer maxDepth, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
Set<Taxon> taxa = new HashSet<>();
Set<Integer> occurrenceIds = new HashSet<>();
List<T> occurrences = new ArrayList<>();
+ boolean includeUnpublished = INCLUDE_UNPUBLISHED;
// Integer limit = PagerUtils.limitFor(pageSize);
// Integer start = PagerUtils.startFor(pageSize, pageNumber);
associatedTaxon = (Taxon) taxonService.load(associatedTaxon.getUuid());
}
- if (includeRelationships != null) {
- taxa = taxonService.listRelatedTaxa(associatedTaxon, includeRelationships, maxDepth, null, null, propertyPaths);
+ if (includedRelationships != null) {
+ taxa = taxonService.listRelatedTaxa(associatedTaxon, includedRelationships, maxDepth, includeUnpublished, null, null, propertyPaths);
}
taxa.add(associatedTaxon);
for (Taxon taxon : taxa) {
List<T> perTaxonOccurrences = dao.listByAssociatedTaxon(type, taxon, null, null, orderHints, propertyPaths);
- for (SpecimenOrObservationBase o : perTaxonOccurrences) {
+ for (SpecimenOrObservationBase<?> o : perTaxonOccurrences) {
occurrenceIds.add(o.getId());
}
}
occurrences = (List<T>) dao.loadList(occurrenceIds, propertyPaths);
- return new DefaultPagerImpl<T>(pageNumber, occurrenceIds.size(), pageSize, occurrences);
+ return new DefaultPagerImpl<T>(pageNumber, Long.valueOf(occurrences.size()), pageSize, occurrences);
}
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<FieldUnitDTO> findFieldUnitDTOByAssociatedTaxon(Set<TaxonRelationshipEdge> includedRelationships,
+ UUID associatedTaxonUuid) {
+
+ Set<Taxon> taxa = new HashSet<>();
+ Set<Integer> occurrenceIds = new HashSet<>();
+ List<FieldUnitDTO> fieldUnitDTOs = new ArrayList<>();
+ HashMap<UUID, DerivateDTO> alreadyCollectedSpecimen = new HashMap<>();
+ List<SpecimenOrObservationBase> occurrences = new ArrayList<>();
+ boolean includeUnpublished = INCLUDE_UNPUBLISHED;
+
+ // Integer limit = PagerUtils.limitFor(pageSize);
+ // Integer start = PagerUtils.startFor(pageSize, pageNumber);
+
+ Taxon associatedTaxon = (Taxon) taxonService.load(associatedTaxonUuid);
+
+
+ if (includedRelationships != null) {
+ taxa = taxonService.listRelatedTaxa(associatedTaxon, includedRelationships, null, includeUnpublished, null, null, null);
+ }
+
+ taxa.add(associatedTaxon);
+
+ for (Taxon taxon : taxa) {
+ List<SpecimenOrObservationBase> perTaxonOccurrences = dao.listByAssociatedTaxon(null,taxon, null, null, null, DERIVED_UNIT_INIT_STRATEGY);
+ for (SpecimenOrObservationBase<?> o : perTaxonOccurrences) {
+ if (o.isInstanceOf(DerivedUnit.class)){
+ DerivedUnit derivedUnit;
+ DerivateDTO derivedUnitDTO;
+ if (o.isInstanceOf(DnaSample.class)) {
+ derivedUnit = HibernateProxyHelper.deproxy(o, DnaSample.class);
+ derivedUnitDTO = new DNASampleDTO(derivedUnit);
+ } else {
+ derivedUnit = HibernateProxyHelper.deproxy(o, DerivedUnit.class);
+ derivedUnitDTO = new PreservedSpecimenDTO(derivedUnit);
+ }
+ if (alreadyCollectedSpecimen.get(derivedUnitDTO.getUuid()) == null){
+ alreadyCollectedSpecimen.put(derivedUnitDTO.getUuid(), derivedUnitDTO);
+ }
+ derivedUnitDTO.addAllDerivates(getDerivedUnitDTOsFor(derivedUnitDTO, derivedUnit, alreadyCollectedSpecimen));
+ this.findFieldUnitDTO(derivedUnitDTO, fieldUnitDTOs, alreadyCollectedSpecimen);
+ }
+ }
+
+ }
+
+ return fieldUnitDTOs;
+
+ }
+
+
+
+ @Override
+ public List<DerivedUnit> findByAccessionNumber(
+ String accessionNumberString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
+ List<String> propertyPaths) {
+
+ List<DerivedUnit> records = new ArrayList<>();
+ records = dao.findByGeneticAccessionNumber(accessionNumberString, propertyPaths);
+
+ return records;
+
+ }
+
@Override
public Pager<SearchResult<SpecimenOrObservationBase>> findByFullText(
Class<? extends SpecimenOrObservationBase> clazz, String queryString, Rectangle boundingBox, List<Language> languages,
int totalHits = topDocsResultSet != null ? topDocsResultSet.totalGroupCount : 0;
- return new DefaultPagerImpl<SearchResult<SpecimenOrObservationBase>>(pageNumber, totalHits, pageSize,
- searchResults);
+ return new DefaultPagerImpl<>(pageNumber, Long.valueOf(totalHits), pageSize, searchResults);
}
@Override
- public Collection<FieldUnit> getFieldUnits(UUID derivedUnitUuid, List<String> propertyPaths) {
+ public Collection<FieldUnit> findFieldUnits(UUID derivedUnitUuid, List<String> propertyPaths) {
//It will search recursively over all {@link DerivationEvent}s and get the "originals" ({@link SpecimenOrObservationBase})
//from which this DerivedUnit was derived until all FieldUnits are found.
return fieldUnits;
}
+
+
+ @Override
+ public FieldUnitDTO findFieldUnitDTO(DerivateDTO derivedUnitDTO, Collection<FieldUnitDTO> fieldUnits, HashMap<UUID, DerivateDTO> alreadyCollectedSpecimen) {
+ //It will search recursively over all {@link DerivationEvent}s and get the "originals" ({@link SpecimenOrObservationBase})
+ //from which this DerivedUnit was derived until all FieldUnits are found.
+ List<SpecimenOrObservationBase> specimens = new ArrayList<>();
+ List<String> propertyPaths = new ArrayList<>();
+
+ propertyPaths.add("descriptions.elements.media.title");
+ propertyPaths.add("kindOfUnit");
+
+ specimens = dao.findOriginalsForDerivedUnit(derivedUnitDTO.getUuid(), propertyPaths);
+
+ if (specimens.size() > 1){
+ logger.debug("The derived unit with uuid " + derivedUnitDTO.getUuid() + "has more than one orginal");
+ }
+ // for (SpecimenOrObservationBase specimen: specimens){
+ SpecimenOrObservationBase specimen = null;
+ if (specimens.size() > 0){
+ specimen = specimens.get(0);
+ }else{
+ return null;
+ }
+ FieldUnitDTO fieldUnitDto = null;
+ if (alreadyCollectedSpecimen.get(specimen.getUuid()) != null){
+ alreadyCollectedSpecimen.get(specimen.getUuid()).addDerivate(derivedUnitDTO);
+ if ( alreadyCollectedSpecimen.get(specimen.getUuid()) instanceof FieldUnitDTO){
+ ((FieldUnitDTO)alreadyCollectedSpecimen.get(specimen.getUuid())).getTaxonRelatedDerivedUnits().add(derivedUnitDTO.getUuid());
+ }
+ }else{
+ if (specimen.isInstanceOf(FieldUnit.class)){
+ fieldUnitDto = FieldUnitDTO.newInstance((FieldUnit)specimen);
+ fieldUnitDto.addDerivate(derivedUnitDTO);
+ fieldUnits.add(fieldUnitDto);
+ }else{
+ DerivateDTO originalDTO;
+ if (specimen instanceof DnaSample){
+ originalDTO = new DNASampleDTO((DnaSample)specimen);
+ } else {
+ originalDTO = new PreservedSpecimenDTO((DerivedUnit)specimen);
+ }
+ originalDTO.addDerivate(derivedUnitDTO);
+ fieldUnitDto = findFieldUnitDTO(originalDTO, fieldUnits, alreadyCollectedSpecimen);
+ }
+
+ }
+ // }
+ alreadyCollectedSpecimen.put(derivedUnitDTO.getUuid(), derivedUnitDTO);
+ if (fieldUnitDto != null){
+ fieldUnitDto.addTaxonRelatedDerivedUnits(derivedUnitDTO);
+ }
+ return fieldUnitDto;
+
+ }
+
@Override
@Transactional(readOnly = false)
public UpdateResult moveSequence(DnaSample from, DnaSample to, Sequence sequence) {
return dao.listIndividualsAssociations(specimen, limit, start, orderHints, propertyPaths);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
- public Collection<TaxonBase<?>> listAssociatedTaxa(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start,
- List<OrderHint> orderHints, List<String> propertyPaths) {
+ public Collection<TaxonBase<?>> listAssociatedTaxa(SpecimenOrObservationBase<?> specimen, Integer limit,
+ Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
+ return listAssociatedTaxa(specimen, INCLUDE_UNPUBLISHED, limit, start, orderHints, propertyPaths);
+ }
+ @Override
+ public Collection<TaxonBase<?>> listAssociatedTaxa(SpecimenOrObservationBase<?> specimen, boolean includeUnpublished,
+ Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
Collection<TaxonBase<?>> associatedTaxa = new HashSet<>();
//individuals associations
- associatedTaxa.addAll(listIndividualsAssociationTaxa(specimen, limit, start, orderHints, propertyPaths));
+ associatedTaxa.addAll(listIndividualsAssociationTaxa(specimen, includeUnpublished, limit, start, orderHints, propertyPaths));
//type designation
if(specimen.isInstanceOf(DerivedUnit.class)){
- associatedTaxa.addAll(listTypeDesignationTaxa(HibernateProxyHelper.deproxy(specimen, DerivedUnit.class), limit, start, orderHints, propertyPaths));
+ associatedTaxa.addAll(listTypeDesignationTaxa(HibernateProxyHelper.deproxy(specimen, DerivedUnit.class),
+ includeUnpublished, limit, start, orderHints, propertyPaths));
}
//determinations
- associatedTaxa.addAll(listDeterminedTaxa(specimen, limit, start, orderHints, propertyPaths));
+ associatedTaxa.addAll(listDeterminedTaxa(specimen, includeUnpublished, limit, start, orderHints, propertyPaths));
return associatedTaxa;
}
+
+ /**
+ * {@inheritDoc}
+ */
@Override
- public Collection<TaxonBase<?>> listDeterminedTaxa(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start,
+ public Collection<TaxonBase<?>> listDeterminedTaxa(SpecimenOrObservationBase<?> specimen, Integer limit,
+ Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
+ return listDeterminedTaxa(specimen, INCLUDE_UNPUBLISHED, limit, start, orderHints, propertyPaths);
+ }
+ @Override
+ public Collection<TaxonBase<?>> listDeterminedTaxa(SpecimenOrObservationBase<?> specimen, boolean includeUnpublished, Integer limit, Integer start,
List<OrderHint> orderHints, List<String> propertyPaths) {
Collection<TaxonBase<?>> associatedTaxa = new HashSet<>();
for (DeterminationEvent determinationEvent : listDeterminationEvents(specimen, limit, start, orderHints, propertyPaths)) {
if(determinationEvent.getIdentifiedUnit().equals(specimen)){
if(determinationEvent.getTaxon()!=null){
- associatedTaxa.add(taxonService.load(determinationEvent.getTaxon().getUuid(), propertyPaths));
+ associatedTaxa.add(taxonService.load(determinationEvent.getTaxon().getUuid(), includeUnpublished, propertyPaths));
}
if(determinationEvent.getTaxonName()!=null){
Collection<TaxonBase> taxonBases = determinationEvent.getTaxonName().getTaxonBases();
for (TaxonBase taxonBase : taxonBases) {
- associatedTaxa.add(taxonService.load(taxonBase.getUuid(), propertyPaths));
+ associatedTaxa.add(taxonService.load(taxonBase.getUuid(), includeUnpublished, propertyPaths));
}
}
}
return associatedTaxa;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public Collection<TaxonBase<?>> listTypeDesignationTaxa(DerivedUnit specimen, Integer limit, Integer start,
List<OrderHint> orderHints, List<String> propertyPaths) {
+ return listTypeDesignationTaxa(specimen, INCLUDE_UNPUBLISHED, limit, start, orderHints, propertyPaths);
+ }
+ @Override
+ public Collection<TaxonBase<?>> listTypeDesignationTaxa(DerivedUnit specimen, boolean includeUnpublished,
+ Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
Collection<TaxonBase<?>> associatedTaxa = new HashSet<>();
for (SpecimenTypeDesignation typeDesignation : listTypeDesignations(specimen, limit, start, orderHints, propertyPaths)) {
if(typeDesignation.getTypeSpecimen().equals(specimen)){
for (TaxonName taxonName : typifiedNames) {
Set<Taxon> taxa = taxonName.getTaxa();
for (Taxon taxon : taxa) {
- associatedTaxa.add(taxonService.load(taxon.getUuid(), propertyPaths));
+ associatedTaxa.add(taxonService.load(taxon.getUuid(), includeUnpublished, propertyPaths));
}
}
}
return associatedTaxa;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
- public Collection<TaxonBase<?>> listIndividualsAssociationTaxa(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start,
- List<OrderHint> orderHints, List<String> propertyPaths) {
+ public Collection<TaxonBase<?>> listIndividualsAssociationTaxa(SpecimenOrObservationBase<?> specimen, Integer limit,
+ Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
+ return listIndividualsAssociationTaxa(specimen, INCLUDE_UNPUBLISHED, limit, start, orderHints, propertyPaths);
+ }
+
+ @Override
+ public Collection<TaxonBase<?>> listIndividualsAssociationTaxa(SpecimenOrObservationBase<?> specimen, boolean includeUnpublished,
+ Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
Collection<TaxonBase<?>> associatedTaxa = new HashSet<>();
for (IndividualsAssociation individualsAssociation : listIndividualsAssociations(specimen, null, null, null, null)) {
if(individualsAssociation.getInDescription().isInstanceOf(TaxonDescription.class)){
TaxonDescription taxonDescription = HibernateProxyHelper.deproxy(individualsAssociation.getInDescription(), TaxonDescription.class);
if(taxonDescription.getTaxon()!=null){
- associatedTaxa.add(taxonService.load(taxonDescription.getTaxon().getUuid(), propertyPaths));
+ associatedTaxa.add(taxonService.load(taxonDescription.getTaxon().getUuid(), includeUnpublished, propertyPaths));
}
}
}
@Override
- public Integer countByTitle(IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase> config){
+ public long countByTitle(IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase> config){
if (config instanceof FindOccurrencesConfigurator) {
FindOccurrencesConfigurator occurrenceConfig = (FindOccurrencesConfigurator) config;
Taxon taxon = null;
if(occurrenceConfig.getAssociatedTaxonUuid()!=null){
- TaxonBase taxonBase = taxonService.load(occurrenceConfig.getAssociatedTaxonUuid());
+ TaxonBase<?> taxonBase = taxonService.load(occurrenceConfig.getAssociatedTaxonUuid());
if(taxonBase.isInstanceOf(Taxon.class)){
taxon = HibernateProxyHelper.deproxy(taxonBase, Taxon.class);
}
if(occurrenceConfig.isRetrieveIndirectlyAssociatedSpecimens() || !occurrenceConfig.getAssignmentStatus().equals(AssignmentStatus.ALL_SPECIMENS)){
List<SpecimenOrObservationBase> occurrences = new ArrayList<>();
occurrences.addAll(dao.findOccurrences(occurrenceConfig.getClazz(),
- occurrenceConfig.getTitleSearchString(), occurrenceConfig.getSignificantIdentifier(),
+ occurrenceConfig.getTitleSearchStringSqlized(), occurrenceConfig.getSignificantIdentifier(),
occurrenceConfig.getSpecimenType(), taxon, taxonName, occurrenceConfig.getMatchMode(), null, null,
occurrenceConfig.getOrderHints(), occurrenceConfig.getPropertyPaths()));
occurrences = filterOccurencesByAssignmentAndHierarchy(occurrenceConfig, occurrences, taxon, taxonName);
}
return dao.countOccurrences(occurrenceConfig.getClazz(),
- occurrenceConfig.getTitleSearchString(), occurrenceConfig.getSignificantIdentifier(),
+ occurrenceConfig.getTitleSearchStringSqlized(), occurrenceConfig.getSignificantIdentifier(),
occurrenceConfig.getSpecimenType(), taxon, taxonName, occurrenceConfig.getMatchMode(), null, null,
occurrenceConfig.getOrderHints(), occurrenceConfig.getPropertyPaths());
}
else{
- return dao.countByTitle(config.getTitleSearchString());
+ return super.countByTitle(config);
}
}
List<UuidAndTitleCache<SpecimenOrObservationBase>> occurrences = new ArrayList<>();
Taxon taxon = null;
if(config.getAssociatedTaxonUuid()!=null){
- TaxonBase taxonBase = taxonService.load(config.getAssociatedTaxonUuid());
+ TaxonBase<?> taxonBase = taxonService.load(config.getAssociatedTaxonUuid());
if(taxonBase.isInstanceOf(Taxon.class)){
- taxon = HibernateProxyHelper.deproxy(taxonBase, Taxon.class);
+ taxon = CdmBase.deproxy(taxonBase, Taxon.class);
}
}
TaxonName taxonName = null;
config.getSpecimenType(), taxon, taxonName, config.getMatchMode(), null, null,
config.getOrderHints()));
- return new DefaultPagerImpl<UuidAndTitleCache<SpecimenOrObservationBase>>(config.getPageNumber(), occurrences.size(), config.getPageSize(), occurrences);
+ return new DefaultPagerImpl<>(config.getPageNumber(), occurrences.size(), config.getPageSize(), occurrences);
}
@Override
- public Pager<SpecimenOrObservationBase> findByTitle(
- IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase> config) {
+ public <S extends SpecimenOrObservationBase> Pager<S> findByTitle(
+ IIdentifiableEntityServiceConfigurator<S> config) {
if (config instanceof FindOccurrencesConfigurator) {
FindOccurrencesConfigurator occurrenceConfig = (FindOccurrencesConfigurator) config;
List<SpecimenOrObservationBase> occurrences = new ArrayList<>();
Taxon taxon = null;
if(occurrenceConfig.getAssociatedTaxonUuid()!=null){
- TaxonBase taxonBase = taxonService.load(occurrenceConfig.getAssociatedTaxonUuid());
+ TaxonBase<?> taxonBase = taxonService.load(occurrenceConfig.getAssociatedTaxonUuid());
if(taxonBase.isInstanceOf(Taxon.class)){
taxon = HibernateProxyHelper.deproxy(taxonBase, Taxon.class);
}
if(occurrenceConfig.getAssociatedTaxonNameUuid()!=null){
taxonName = nameService.load(occurrenceConfig.getAssociatedTaxonNameUuid());
}
- occurrences.addAll(dao.findOccurrences(occurrenceConfig.getClazz(),
+ List<? extends SpecimenOrObservationBase> foundOccurrences = dao.findOccurrences(occurrenceConfig.getClazz(),
occurrenceConfig.getTitleSearchString(), occurrenceConfig.getSignificantIdentifier(),
occurrenceConfig.getSpecimenType(), taxon, taxonName, occurrenceConfig.getMatchMode(), null, null,
- occurrenceConfig.getOrderHints(), occurrenceConfig.getPropertyPaths()));
+ occurrenceConfig.getOrderHints(), occurrenceConfig.getPropertyPaths());
+ occurrences.addAll(foundOccurrences);
occurrences = filterOccurencesByAssignmentAndHierarchy(occurrenceConfig, occurrences, taxon, taxonName);
- return new DefaultPagerImpl<SpecimenOrObservationBase>(config.getPageNumber(), occurrences.size(), config.getPageSize(), occurrences);
+ return new DefaultPagerImpl<>(config.getPageNumber(), occurrences.size(), config.getPageSize(), (List<S>)occurrences);
}
return super.findByTitle(config);
}
//filter out (un-)assigned specimens
if(taxon==null && taxonName==null){
AssignmentStatus assignmentStatus = occurrenceConfig.getAssignmentStatus();
- List<SpecimenOrObservationBase<?>> specimenWithAssociations = new ArrayList<>();
+ List<SpecimenOrObservationBase> specimenWithAssociations = new ArrayList<>();
if(!assignmentStatus.equals(AssignmentStatus.ALL_SPECIMENS)){
for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) {
- Collection<TaxonBase<?>> associatedTaxa = listAssociatedTaxa(specimenOrObservationBase, null, null, null, null);
+ boolean includeUnpublished = true; //TODO not sure if this is correct, maybe we have to propagate publish flag to higher methods.
+ Collection<TaxonBase<?>> associatedTaxa = listAssociatedTaxa(specimenOrObservationBase,
+ includeUnpublished, null, null, null, null);
if(!associatedTaxa.isEmpty()){
specimenWithAssociations.add(specimenOrObservationBase);
}
// indirectly associated specimens
if(occurrenceConfig.isRetrieveIndirectlyAssociatedSpecimens()){
List<SpecimenOrObservationBase> indirectlyAssociatedOccurrences = new ArrayList<>(occurrences);
- for (SpecimenOrObservationBase specimen : occurrences) {
+ for (SpecimenOrObservationBase<?> specimen : occurrences) {
List<SpecimenOrObservationBase<?>> allHierarchyDerivates = getAllHierarchyDerivatives(specimen);
for (SpecimenOrObservationBase<?> specimenOrObservationBase : allHierarchyDerivates) {
if(!occurrences.contains(specimenOrObservationBase)){
@Override
public List<SpecimenOrObservationBase<?>> getAllHierarchyDerivatives(SpecimenOrObservationBase<?> specimen){
List<SpecimenOrObservationBase<?>> allHierarchyDerivatives = new ArrayList<>();
- Collection<FieldUnit> fieldUnits = getFieldUnits(specimen.getUuid(), null);
+ Collection<FieldUnit> fieldUnits = findFieldUnits(specimen.getUuid(), null);
if(fieldUnits.isEmpty()){
allHierarchyDerivatives.add(specimen);
allHierarchyDerivatives.addAll(getAllChildDerivatives(specimen));
}
@Override
- public int countOccurrences(IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase> config){
+ public long countOccurrences(IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase> config){
return countByTitle(config);
}
* {@inheritDoc}
*/
@Override
- public List<FieldUnit> getFieldUnitsForGatheringEvent(UUID gatheringEventUuid) {
- return dao.getFieldUnitsForGatheringEvent(gatheringEventUuid, null, null, null, null);
+ public List<FieldUnit> findFieldUnitsForGatheringEvent(UUID gatheringEventUuid) {
+ return dao.findFieldUnitsForGatheringEvent(gatheringEventUuid, null, null, null, null);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<Point> findPointsForFieldUnitList(List<UUID> fieldUnitUuids) {
+
+ return dao.findPointsForFieldUnitList(fieldUnitUuids);
+ }
}