Search in sources :

Example 16 with UuidAndTitleCache

use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.

the class TaxonNodeDaoHibernateImplTest method testGetTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification.

@Test
@DataSet("TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
public final void testGetTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification() {
    Classification classification = classificationDao.findByUuid(classificationUuid);
    List<UuidAndTitleCache<TaxonNode>> result = taxonNodeDao.getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(classification, null, null, true);
    assertNotNull(result);
    assertEquals(7, result.size());
    // test exclude
    UUID excludeUUID = UUID.fromString("a9f42927-e507-4fda-9629-62073a908aae");
    List<UUID> excludeUUids = new ArrayList<>();
    excludeUUids.add(excludeUUID);
    result = taxonNodeDao.getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(classification, null, null, false);
    assertEquals(6, result.size());
    // test limit
    int limit = 2;
    result = taxonNodeDao.getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(classification, limit, null, false);
    assertEquals(2, result.size());
    // test pattern
    String pattern = "*Rothschi*";
    result = taxonNodeDao.getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(classification, 2, pattern, true);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals("0b5846e5-b8d2-4ca9-ac51-099286ea4adc", result.get(0).getUuid().toString());
    // test pattern
    pattern = "*TestBaum*";
    result = taxonNodeDao.getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(classification, null, pattern, true);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals("6d6b43aa-3a77-4be5-91d0-00b702fc5d6e", result.get(0).getUuid().toString());
}
Also used : Classification(eu.etaxonomy.cdm.model.taxon.Classification) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 17 with UuidAndTitleCache

use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.

the class DescriptiveDataSetDao method getTaxonFeatureDescriptionElementMap.

@Override
public <T extends DescriptionElementBase> Map<UuidAndTitleCache, Map<UUID, Set<T>>> getTaxonFeatureDescriptionElementMap(Class<T> clazz, UUID descriptiveDataSetUuid, DescriptiveSystemRole role) {
    checkNotInPriorView("DescriptiveDataSetDao.getTaxonFeatureDescriptionElementMap(DescriptiveDataSet descriptiveDataSet, Set<Feature> features, Integer pageSize,Integer pageNumber, List<OrderHint> orderHints,	List<String> propertyPaths)");
    Map<UuidAndTitleCache, Map<UUID, Set<T>>> result = new HashMap<>();
    try {
        // for maps see
        // http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html
        // Elements of indexed collections (arrays, lists, and maps) can be referred to by index in a where clause only:
        // 
        // Example: from Order order where order.items[0].id = 1234
        // feature
        String strQueryTreeId = "SELECT ws.descriptiveSystem.id FROM DescriptiveDataSet dds join dds.descriptiveSystem tree WHERE dds.uuid = :descriptiveDataSetUuid ";
        Query queryTree = getSession().createQuery(strQueryTreeId);
        queryTree.setParameter("descriptiveDataSetUuid", descriptiveDataSetUuid);
        List<?> trees = queryTree.list();
        String ftSelect = "SELECT feature.id FROM TermNode node join node.feature as feature " + " WHERE node.featureTree.id in (:trees) ";
        Query ftQuery = getSession().createQuery(ftSelect);
        ftQuery.setParameterList("trees", trees);
        List<?> features = ftQuery.list();
        String strClass = (clazz == null) ? "DescriptionElementBase" : clazz.getSimpleName();
        String fetch = "";
        if (clazz.equals(CategoricalData.class)) {
            fetch = " left join fetch el.states stateList join fetch stateList.state ";
        } else if (clazz.equals(QuantitativeData.class)) {
            fetch = " left join fetch el.statisticalValues valueList join fetch valueList.type ";
        }
        String strQuery = " select taxon.uuid, taxon.id, taxon.titleCache, feature.uuid, el " + " from " + strClass + " el " + " join el.feature feature " + " join el.inDescription d " + " join d.taxon taxon " + " join d.descriptiveDataSets ws " + " join ws.descriptiveSystem ftree " + fetch + " where ws.uuid = :descriptiveDataSetUuid " + " and el.class = :clazz " + " and feature.id in (:features)  " + " order by taxon.uuid asc, feature.uuid asc";
        Query query = getSession().createQuery(strQuery);
        query.setParameter("descriptiveDataSetUuid", descriptiveDataSetUuid);
        query.setParameter("clazz", clazz.getSimpleName());
        query.setParameterList("features", features);
        // NOTE: Paging does not work with fetch
        // fill result
        @SuppressWarnings("unchecked") List<Object[]> list = query.list();
        for (Object[] listEntry : list) {
            UUID taxonUuid = (UUID) listEntry[0];
            Integer id = (Integer) listEntry[1];
            String titleCache = (String) listEntry[2];
            UuidAndTitleCache taxon = new UuidAndTitleCache(taxonUuid, id, titleCache);
            UUID featureUuid = (UUID) listEntry[3];
            T data = (T) listEntry[4];
            Map<UUID, Set<T>> taxonMap = result.get(taxon);
            if (taxonMap == null) {
                taxonMap = new HashMap<>();
                result.put(taxon, taxonMap);
            }
            Set<T> featureSet = taxonMap.get(featureUuid);
            if (featureSet == null) {
                featureSet = new HashSet<>();
                taxonMap.put(featureUuid, featureSet);
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("feature set already exists");
                }
            }
            featureSet.add(data);
        }
        return result;
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : HashSet(java.util.HashSet) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) Set(java.util.Set) Query(org.hibernate.Query) HashMap(java.util.HashMap) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with UuidAndTitleCache

use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.

the class TaxonNameDaoHibernateImpl method getUuidAndTitleCacheOfNames.

@Override
public List<UuidAndTitleCache> getUuidAndTitleCacheOfNames(Integer limit, String pattern) {
    String queryString = "SELECT uuid, id, fullTitleCache FROM TaxonName LIMIT " + limit;
    @SuppressWarnings("unchecked") List<Object[]> result = getSession().createSQLQuery(queryString).list();
    if (result.size() == 0) {
        return null;
    } else {
        List<UuidAndTitleCache> list = new ArrayList<>(result.size());
        for (Object object : result) {
            Object[] objectArray = (Object[]) object;
            UUID uuid = UUID.fromString((String) objectArray[0]);
            Integer id = (Integer) objectArray[1];
            String titleCache = (String) objectArray[2];
            list.add(new UuidAndTitleCache(type, uuid, id, titleCache));
        }
        return list;
    }
}
Also used : ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) UUID(java.util.UUID)

Example 19 with UuidAndTitleCache

use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.

the class OccurrenceDaoHibernateImpl method findOccurrencesUuidAndTitleCache.

@Override
public <T extends SpecimenOrObservationBase> List<UuidAndTitleCache<SpecimenOrObservationBase>> findOccurrencesUuidAndTitleCache(Class<T> clazz, String queryString, String significantIdentifier, SpecimenOrObservationType recordBasis, Taxon associatedTaxon, TaxonName associatedTaxonName, MatchMode matchmode, Integer limit, Integer start, List<OrderHint> orderHints) {
    Criteria criteria = createFindOccurrenceCriteria(clazz, queryString, significantIdentifier, recordBasis, associatedTaxon, associatedTaxonName, matchmode, limit, start, orderHints, null);
    if (criteria != null) {
        ProjectionList projectionList = Projections.projectionList();
        projectionList.add(Projections.property("uuid"));
        projectionList.add(Projections.property("id"));
        projectionList.add(Projections.property("titleCache"));
        criteria.setProjection(projectionList);
        @SuppressWarnings("unchecked") List<Object[]> result = criteria.list();
        List<UuidAndTitleCache<SpecimenOrObservationBase>> uuidAndTitleCacheList = new ArrayList<>();
        for (Object[] object : result) {
            uuidAndTitleCacheList.add(new UuidAndTitleCache<>((UUID) object[0], (Integer) object[1], (String) object[2]));
        }
        return uuidAndTitleCacheList;
    } else {
        return Collections.emptyList();
    }
}
Also used : ArrayList(java.util.ArrayList) Criteria(org.hibernate.Criteria) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) ProjectionList(org.hibernate.criterion.ProjectionList) UUID(java.util.UUID)

Example 20 with UuidAndTitleCache

use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.

the class OccurrenceDaoHibernateImpl method listUuidAndTitleCacheByAssociatedTaxon.

@Override
public <T extends SpecimenOrObservationBase> List<UuidAndTitleCache<SpecimenOrObservationBase>> listUuidAndTitleCacheByAssociatedTaxon(Class<T> clazz, Taxon associatedTaxon, Integer limit, Integer start, List<OrderHint> orderHints) {
    Query query = createSpecimenQuery("sob.uuid, sob.id, sob.titleCache", clazz, associatedTaxon, limit, start, orderHints);
    if (query == null) {
        return Collections.emptyList();
    }
    List<UuidAndTitleCache<SpecimenOrObservationBase>> list = new ArrayList<>();
    @SuppressWarnings("unchecked") List<Object[]> result = query.list();
    for (Object[] object : result) {
        list.add(new UuidAndTitleCache<>((UUID) object[0], (Integer) object[1], (String) object[2]));
    }
    return list;
}
Also used : Query(org.hibernate.Query) AuditQuery(org.hibernate.envers.query.AuditQuery) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) UUID(java.util.UUID)

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