use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.
the class TaxonNodeDaoHibernateImpl method getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification.
@Override
public List<UuidAndTitleCache<TaxonNode>> getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(Classification classification, Integer limit, String pattern, boolean searchForClassifications, boolean includeDoubtful) {
Query query = createQueryForUuidAndTitleCache(limit, classification.getUuid(), pattern, includeDoubtful);
@SuppressWarnings("unchecked") List<SortableTaxonNodeQueryResult> result = query.list();
if (searchForClassifications) {
String queryString = "SELECT new " + SortableTaxonNodeQueryResult.class.getName() + "(" + " node.uuid, node.id, node.classification.titleCache, parent.uuid" + ") " + " FROM TaxonNode AS node " + " LEFT OUTER JOIN node.parent as parent" + " WHERE node.classification.id = " + classification.getId() + " AND node.taxon IS NULL";
if (pattern != null) {
if (pattern.equals("?")) {
limit = null;
} else {
if (!pattern.endsWith("*")) {
pattern += "%";
}
pattern = pattern.replace("*", "%");
pattern = pattern.replace("?", "%");
queryString = queryString + " AND node.classification.titleCache LIKE (:pattern) ";
}
}
query = getSession().createQuery(queryString);
if (limit != null) {
query.setMaxResults(limit);
}
if (pattern != null && !pattern.equals("?")) {
query.setParameter("pattern", pattern);
}
@SuppressWarnings("unchecked") List<SortableTaxonNodeQueryResult> resultClassifications = query.list();
result.addAll(resultClassifications);
}
if (result.size() == 0) {
return null;
} else {
List<UuidAndTitleCache<TaxonNode>> list = new ArrayList<>(result.size());
Collections.sort(result, new SortableTaxonNodeQueryResultComparator());
for (SortableTaxonNodeQueryResult resultDTO : result) {
list.add(new UuidAndTitleCache<>(TaxonNode.class, resultDTO.getTaxonNodeUuid(), resultDTO.getTaxonNodeId(), resultDTO.getTaxonTitleCache()));
}
return list;
}
}
use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.
the class NameServiceImpl method getUuidAndTitleCacheOfSynonymy.
@Override
public List<UuidAndTitleCache> getUuidAndTitleCacheOfSynonymy(Integer limit, UUID taxonUuid) {
List<String> propertyPaths = new ArrayList<>();
propertyPaths.add("synonyms.name.*");
TaxonBase<?> taxonBase = taxonService.load(taxonUuid, propertyPaths);
if (taxonBase instanceof Taxon) {
Taxon taxon = (Taxon) taxonBase;
Set<TaxonName> names = taxon.getSynonymNames();
List<UuidAndTitleCache> uuidAndTitleCacheList = new ArrayList<>();
UuidAndTitleCache<TaxonName> uuidAndTitleCache;
for (TaxonName name : names) {
uuidAndTitleCache = new UuidAndTitleCache<TaxonName>(TaxonName.class, name.getUuid(), name.getId(), name.getTitleCache());
uuidAndTitleCacheList.add(uuidAndTitleCache);
}
}
return null;
}
use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.
the class OccurrenceServiceImpl method findByTitleUuidAndTitleCache.
@Override
public Pager<UuidAndTitleCache<SpecimenOrObservationBase>> findByTitleUuidAndTitleCache(FindOccurrencesConfigurator config) {
List<UuidAndTitleCache<SpecimenOrObservationBase>> occurrences = new ArrayList<>();
Taxon taxon = null;
if (config.getAssociatedTaxonUuid() != null) {
TaxonBase<?> taxonBase = taxonService.load(config.getAssociatedTaxonUuid());
if (taxonBase != null && taxonBase.isInstanceOf(Taxon.class)) {
taxon = CdmBase.deproxy(taxonBase, Taxon.class);
}
}
TaxonName taxonName = null;
if (config.getAssociatedTaxonNameUuid() != null) {
taxonName = nameService.load(config.getAssociatedTaxonNameUuid());
}
occurrences.addAll(dao.findOccurrencesUuidAndTitleCache(config.getClazz(), config.getTitleSearchString(), config.getSignificantIdentifier(), config.getSpecimenType(), taxon, taxonName, config.getMatchMode(), null, null, config.getOrderHints()));
long count = Integer.valueOf(occurrences.size()).longValue();
return new DefaultPagerImpl<>(config.getPageNumber(), count, config.getPageSize(), occurrences);
}
use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.
the class TaxonNodeDaoHibernateImplTest method testGetTaxonNodeUuidAndTitleCacheOfacceptedTaxaByClassificationForNameWithoutRank.
@Test
@DataSet("TaxonNodeDaoHibernateImplTest.findWithoutRank.xml")
public final void testGetTaxonNodeUuidAndTitleCacheOfacceptedTaxaByClassificationForNameWithoutRank() {
// test name without rank
Classification classification = classificationDao.findByUuid(ClassificationUuid);
String pattern = "Acherontia kohlbeckeri*";
List<UuidAndTitleCache<TaxonNode>> result = taxonNodeDao.getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(classification, null, pattern, true);
assertNotNull(result);
assertEquals(1, result.size());
// titleCache:Acherontia kohlbeckeri rank: Unknown Rank
assertEquals("4f73adcc-a535-4fbe-a97a-c05ee8b12191", result.get(0).getUuid().toString());
}
use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.
the class TermServiceImpl method getUuidAndTitleCacheNamedAreaByAbbrev.
@Override
@Transactional(readOnly = true)
public List<UuidAndTitleCache<NamedArea>> getUuidAndTitleCacheNamedAreaByAbbrev(List<TermVocabulary> vocs, Integer limit, String pattern, Language lang, TermSearchField type) {
List<NamedArea> areas = dao.listByAbbrev(NamedArea.class, vocs, limit, pattern, type);
List<UuidAndTitleCache<NamedArea>> result = new ArrayList<>();
UuidAndTitleCache<NamedArea> uuidAndTitleCache;
for (NamedArea area : areas) {
if (type.equals(TermSearchField.NoAbbrev)) {
uuidAndTitleCache = new UuidAndTitleCache<>(area.getUuid(), area.getId(), area.labelWithLevel(area, lang));
} else {
String display = area.labelWithLevel(area, lang);
if (type.equals(TermSearchField.IDInVocabulary)) {
display += " - " + area.getIdInVocabulary();
} else if (type.equals(TermSearchField.Symbol1)) {
display += " - " + area.getSymbol();
} else if (type.equals(TermSearchField.Symbol2)) {
display += " - " + area.getSymbol2();
}
uuidAndTitleCache = new UuidAndTitleCache<>(area.getUuid(), area.getId(), display);
}
result.add(uuidAndTitleCache);
}
return result;
}
Aggregations