use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.
the class TaxonNodeDaoHibernateImplTest method testGetTaxonNodeUuidAndTitleCache.
@Test
@DataSet("TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
public final void testGetTaxonNodeUuidAndTitleCache() {
String pattern = "";
List<TaxonNodeDto> result = taxonNodeDao.getUuidAndTitleCache(100, pattern, classificationUuid, true);
assertNotNull(result);
assertEquals(6, result.size());
// test limit
int limit = 2;
result = taxonNodeDao.getUuidAndTitleCache(limit, pattern, classificationUuid, true);
assertEquals(2, result.size());
// test pattern & classification
pattern = "*Rothschi*";
result = taxonNodeDao.getUuidAndTitleCache(100, pattern, classificationUuid, true);
assertNotNull(result);
assertEquals(1, result.size());
assertEquals("0b5846e5-b8d2-4ca9-ac51-099286ea4adc", result.get(0).getUuid().toString());
// test pattern without classification
pattern = "*Rothschi*";
result = taxonNodeDao.getUuidAndTitleCache(100, pattern, null, true);
assertNotNull(result);
assertEquals(2, result.size());
// test doubtful & pattern
pattern = "Aus*";
result = taxonNodeDao.getUuidAndTitleCache(100, pattern, classificationUuid, true);
assertNotNull(result);
assertEquals(1, result.size());
assertEquals("ebf8ea46-9f24-47be-8fb5-02bd67f90348", result.get(0).getUuid().toString());
}
use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.
the class DescriptiveDataSetService method createSpecimenRowWrapper.
private SpecimenRowWrapperDTO createSpecimenRowWrapper(DescriptionBaseDto description, UUID taxonNodeUuid, UUID datasetUuid) {
TaxonNodeDto taxonNode = taxonNodeService.dto(taxonNodeUuid);
DescriptiveDataSetBaseDto descriptiveDataSet = getDescriptiveDataSetDtoByUuid(datasetUuid);
// UuidAndTitleCache<SpecimenOrObservationBase> specimen = description.getSpecimenDto();
SpecimenOrObservationBase specimen = occurrenceService.find(description.getSpecimenDto().getUuid());
// supplemental information
if (taxonNode == null) {
taxonNode = findTaxonNodeForDescription(description, descriptiveDataSet);
}
FieldUnit fieldUnit = null;
String identifier = null;
NamedArea country = null;
if (taxonNode == null) {
return null;
}
// taxon node was found
// get field unit
Collection<FieldUnit> fieldUnits = occurrenceService.findFieldUnits(specimen.getUuid(), Arrays.asList(new String[] { "gatheringEvent", "gatheringEvent.country" }));
if (fieldUnits.size() > 1) {
// $NON-NLS-1$
logger.error("More than one or no field unit found for specimen");
return null;
} else {
if (fieldUnits.size() > 0) {
fieldUnit = fieldUnits.iterator().next();
}
}
// get identifier
identifier = occurrenceService.getMostSignificantIdentifier(specimen.getUuid());
// get country
if (fieldUnit != null && fieldUnit.getGatheringEvent() != null) {
country = fieldUnit.getGatheringEvent().getCountry();
}
// get default taxon description
// TaxonDescription defaultTaxonDescription = findDefaultDescription(description.getUuid(), descriptiveDataSet.getUuid());
DescriptionBaseDto defaultTaxonDescription = recurseDefaultDescription(taxonNode, descriptiveDataSet);
TaxonRowWrapperDTO taxonRowWrapper = defaultTaxonDescription != null ? createTaxonRowWrapper(defaultTaxonDescription.getDescriptionUuid(), descriptiveDataSet.getUuid()) : null;
// use description not specimen for specimenRow
SpecimenRowWrapperDTO specimenRowWrapperDTO = new SpecimenRowWrapperDTO(description, SpecimenOrObservationDTOFactory.fromEntity(specimen), specimen.getRecordBasis(), taxonNode, fieldUnit, identifier, country);
specimenRowWrapperDTO.setDefaultDescription(taxonRowWrapper);
return specimenRowWrapperDTO;
}
use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.
the class DescriptiveDataSetService method findDefaultDescription.
@Override
public DescriptionBaseDto findDefaultDescription(UUID specimenDescriptionUuid, UUID dataSetUuid) {
DescriptionBaseDto specimenDescription = descriptionService.loadDto(specimenDescriptionUuid);
DescriptiveDataSetBaseDto dataSet = dao.getDescriptiveDataSetDtoByUuid(dataSetUuid);
TaxonNodeDto node = findTaxonNodeForDescription(specimenDescription, dataSet);
return recurseDefaultDescription(node, dataSet);
}
use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.
the class ClassificationServiceImpl method getTaxonInContext.
@Override
public TaxonInContextDTO getTaxonInContext(UUID classificationUuid, UUID taxonBaseUuid, Boolean doChildren, Boolean doSynonyms, boolean includeUnpublished, List<UUID> ancestorMarkers, TaxonNodeSortMode sortMode) {
TaxonInContextDTO result = new TaxonInContextDTO();
TaxonBase<?> taxonBase = taxonDao.load(taxonBaseUuid);
if (taxonBase == null) {
throw new EntityNotFoundException("Taxon with uuid " + taxonBaseUuid + " not found in datasource");
}
boolean isSynonym = false;
Taxon acceptedTaxon;
if (taxonBase.isInstanceOf(Synonym.class)) {
isSynonym = true;
Synonym synonym = CdmBase.deproxy(taxonBase, Synonym.class);
acceptedTaxon = synonym.getAcceptedTaxon();
if (acceptedTaxon == null) {
throw new EntityNotFoundException("Accepted taxon not found for synonym");
}
TaxonStatus taxonStatus = TaxonStatus.Synonym;
if (synonym.getName() != null && acceptedTaxon.getName() != null && synonym.getName().getHomotypicalGroup().equals(acceptedTaxon.getName().getHomotypicalGroup())) {
taxonStatus = TaxonStatus.SynonymObjective;
}
result.setTaxonStatus(taxonStatus);
} else {
acceptedTaxon = CdmBase.deproxy(taxonBase, Taxon.class);
result.setTaxonStatus(TaxonStatus.Accepted);
}
UUID acceptedTaxonUuid = acceptedTaxon.getUuid();
UUID taxonNodeUuid = getTaxonNodeUuidByTaxonUuid(classificationUuid, acceptedTaxonUuid);
if (taxonNodeUuid == null) {
throw new EntityNotFoundException("Taxon not found in classficiation with uuid " + classificationUuid + ". Either classification does not exist or does not contain taxon/synonym with uuid " + taxonBaseUuid);
}
result.setTaxonNodeUuid(taxonNodeUuid);
// TODO make it a dao call
Taxon parentTaxon = getParentTaxon(classificationUuid, acceptedTaxon);
if (parentTaxon != null) {
result.setParentTaxonUuid(parentTaxon.getUuid());
result.setParentTaxonLabel(parentTaxon.getTitleCache());
if (parentTaxon.getName() != null) {
result.setParentNameLabel(parentTaxon.getName().getTitleCache());
}
}
result.setTaxonUuid(taxonBaseUuid);
result.setClassificationUuid(classificationUuid);
if (taxonBase.getSec() != null) {
result.setSecundumUuid(taxonBase.getSec().getUuid());
result.setSecundumLabel(taxonBase.getSec().getTitleCache());
}
result.setTaxonLabel(taxonBase.getTitleCache());
TaxonName name = taxonBase.getName();
result.setNameUuid(name.getUuid());
result.setNameLabel(name.getTitleCache());
result.setNameWithoutAuthor(name.getNameCache());
result.setGenusOrUninomial(name.getGenusOrUninomial());
result.setInfraGenericEpithet(name.getInfraGenericEpithet());
result.setSpeciesEpithet(name.getSpecificEpithet());
result.setInfraSpecificEpithet(name.getInfraSpecificEpithet());
result.setAuthorship(name.getAuthorshipCache());
Rank rank = name.getRank();
if (rank != null) {
result.setRankUuid(rank.getUuid());
String rankLabel = rank.getAbbreviation();
if (StringUtils.isBlank(rankLabel)) {
rankLabel = rank.getLabel();
}
result.setRankLabel(rankLabel);
}
boolean recursive = false;
Integer pageSize = null;
Integer pageIndex = null;
Pager<TaxonNodeDto> children = taxonNodeService.pageChildNodesDTOs(taxonNodeUuid, recursive, includeUnpublished, doSynonyms, sortMode, pageSize, pageIndex);
// children
if (!isSynonym) {
for (TaxonNodeDto childDto : children.getRecords()) {
if (doChildren && childDto.getTaxonStatus().equals(TaxonStatus.Accepted)) {
EntityDTO<Taxon> child = new EntityDTO<Taxon>(childDto.getTaxonUuid(), childDto.getTitleCache());
result.addChild(child);
} else if (doSynonyms && childDto.getTaxonStatus().isSynonym()) {
EntityDTO<Synonym> child = new EntityDTO<>(childDto.getTaxonUuid(), childDto.getTitleCache());
result.addSynonym(child);
}
}
} else {
result.setAcceptedTaxonUuid(acceptedTaxonUuid);
String nameTitel = acceptedTaxon.getName() == null ? null : acceptedTaxon.getName().getTitleCache();
result.setAcceptedTaxonLabel(acceptedTaxon.getTitleCache());
result.setAcceptedNameLabel(nameTitel);
}
// marked ancestors
if (ancestorMarkers != null && !ancestorMarkers.isEmpty()) {
@SuppressWarnings("rawtypes") List<DefinedTermBase> markerTypesTerms = termDao.list(ancestorMarkers, pageSize, null, null, null);
List<MarkerType> markerTypes = new ArrayList<>();
for (DefinedTermBase<?> term : markerTypesTerms) {
if (term.isInstanceOf(MarkerType.class)) {
markerTypes.add(CdmBase.deproxy(term, MarkerType.class));
}
}
if (!markerTypes.isEmpty()) {
TaxonNode node = taxonNodeDao.findByUuid(taxonNodeUuid);
handleAncestorsForMarkersRecursive(result, markerTypes, node);
}
}
return result;
}
use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.
the class ClassificationServiceImpl method listChildNodeDtosOfTaxon.
@Override
public List<TaxonNodeDto> listChildNodeDtosOfTaxon(UUID taxonUuid, UUID classificationUuid, UUID subtreeUuid, boolean includeUnpublished, Integer pageSize, Integer pageIndex, TaxonNodeDtoSortMode sortMode, List<String> propertyPaths) throws FilterException {
Classification classification = dao.load(classificationUuid);
Taxon taxon = (Taxon) taxonDao.load(taxonUuid);
TaxonNode subtree = taxonNodeDao.load(subtreeUuid);
if (subtreeUuid != null && subtree == null) {
throw new FilterException("Taxon node for subtree filter can not be found in database", true);
}
List<TaxonNode> results = dao.listChildrenOf(taxon, classification, subtree, includeUnpublished, pageSize, pageIndex, propertyPaths);
Comparator<TaxonNodeDto> comparator = sortMode.comparator();
// TODO order during the hibernate query in the dao?
List<TaxonNodeDto> dtos = results.stream().map(e -> new TaxonNodeDto(e)).sorted(comparator).collect(Collectors.toList());
return dtos;
}
Aggregations