Search in sources :

Example 21 with UuidAndTitleCache

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;
    }
}
Also used : SortableTaxonNodeQueryResultComparator(eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResultComparator) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Query(org.hibernate.Query) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) SortableTaxonNodeQueryResult(eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResult)

Example 22 with UuidAndTitleCache

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;
}
Also used : Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) ArrayList(java.util.ArrayList) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache)

Example 23 with UuidAndTitleCache

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);
}
Also used : DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) ArrayList(java.util.ArrayList) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache)

Example 24 with UuidAndTitleCache

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());
}
Also used : Classification(eu.etaxonomy.cdm.model.taxon.Classification) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 25 with UuidAndTitleCache

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;
}
Also used : ArrayList(java.util.ArrayList) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UuidAndTitleCache (eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache)38 ArrayList (java.util.ArrayList)31 UUID (java.util.UUID)27 Query (org.hibernate.Query)17 Session (org.hibernate.Session)10 AuditQuery (org.hibernate.envers.query.AuditQuery)7 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)5 Test (org.junit.Test)5 IdentifiableEntity (eu.etaxonomy.cdm.model.common.IdentifiableEntity)4 Reference (eu.etaxonomy.cdm.model.reference.Reference)4 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)4 SortableTaxonNodeQueryResult (eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResult)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 FullTextSession (org.hibernate.search.FullTextSession)4 DataSet (org.unitils.dbunit.annotation.DataSet)4 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 TreeIndex (eu.etaxonomy.cdm.model.common.TreeIndex)3 Primer (eu.etaxonomy.cdm.model.molecular.Primer)3 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)3