Search in sources :

Example 26 with UuidAndTitleCache

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

the class PrimerServiceTest method testGetPrimerUuidAndTitleCache.

@Test
public void testGetPrimerUuidAndTitleCache() {
    String primerLabel = "MatK";
    Primer primer = Primer.NewInstance(primerLabel);
    UUID uuid = primerService.save(primer).getUuid();
    List<UuidAndTitleCache<Primer>> primerUuidAndTitleCache = primerService.getPrimerUuidAndTitleCache();
    assertEquals("Number of Primers in DB is incorrect.", 1, primerUuidAndTitleCache.size());
    UuidAndTitleCache<Primer> uuidAndTitleCache = primerUuidAndTitleCache.iterator().next();
    assertEquals("UUID is incorrect.", uuid, uuidAndTitleCache.getUuid());
    assertEquals("Label is incorrect.", primerLabel, uuidAndTitleCache.getTitleCache());
}
Also used : Primer(eu.etaxonomy.cdm.model.molecular.Primer) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test)

Example 27 with UuidAndTitleCache

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

the class TaxonDaoHibernateImpl method getUuidAndTitleCache.

@Override
protected List<UuidAndTitleCache<TaxonBase>> getUuidAndTitleCache(Query query) {
    List<UuidAndTitleCache<TaxonBase>> list = new ArrayList<>();
    List<SortableTaxonNodeQueryResult> result = query.list();
    if (!result.isEmpty()) {
        Collections.sort(result, new SortableTaxonNodeQueryResultComparator());
    }
    for (SortableTaxonNodeQueryResult stnqr : result) {
        list.add(new UuidAndTitleCache<TaxonBase>(stnqr.getTaxonNodeUuid(), stnqr.getTaxonNodeId(), stnqr.getTaxonTitleCache()));
    }
    return list;
}
Also used : TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) SortableTaxonNodeQueryResultComparator(eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResultComparator) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) SortableTaxonNodeQueryResult(eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResult)

Example 28 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 29 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 30 with UuidAndTitleCache

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

the class ReferenceDaoHibernateImpl method getUuidAndTitleCache.

@Override
public List<UuidAndTitleCache<Reference>> getUuidAndTitleCache(Integer limit, String pattern, ReferenceType refType) {
    List<UuidAndTitleCache<Reference>> list = new ArrayList<>();
    Session session = getSession();
    String queryString = "SELECT " + "r.uuid, r.id, r.titleCache, ab.titleCache " + " FROM " + type.getSimpleName() + " AS r LEFT OUTER JOIN r.authorship AS ab ";
    if (refType != null || pattern != null) {
        queryString += " WHERE (1=1) ";
        if (refType != null) {
            // OR r.type = :genericType) " ;
            queryString += " AND (r.type = :type) ";
        }
        if (pattern != null) {
            queryString += " AND (r.titleCache LIKE :pattern) OR (r.abbrevTitleCache LIKE :pattern) ";
        }
    }
    Query query;
    // if (pattern != null){
    query = session.createQuery(queryString);
    if (limit != null) {
        query.setMaxResults(limit);
    }
    if (pattern != null) {
        pattern = pattern.replace("*", "%");
        pattern = pattern.replace("?", "_");
        pattern = pattern + "%";
        query.setParameter("pattern", pattern);
    }
    if (refType != null) {
        query.setParameter("type", refType);
    // query.setParameter("genericType", ReferenceType.Generic);
    }
    @SuppressWarnings("unchecked") List<Object[]> result = query.list();
    for (Object[] object : result) {
        String referenceTitle = (String) object[2];
        if (referenceTitle != null) {
            String teamTitle = (String) object[3];
            referenceTitle = ReferenceDefaultCacheStrategy.putAuthorToEndOfString(referenceTitle, teamTitle);
            list.add(new UuidAndTitleCache<Reference>(Reference.class, (UUID) object[0], (Integer) object[1], referenceTitle));
        } else {
            logger.warn("Title cache of reference is null. This should not happen. Please fix data. UUID: " + object[0]);
        }
    }
    return list;
}
Also used : Query(org.hibernate.Query) Reference(eu.etaxonomy.cdm.model.reference.Reference) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) UUID(java.util.UUID) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

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