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());
}
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;
}
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);
}
}
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();
}
}
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;
}
Aggregations