use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.
the class RightsDaoImpl method getUuidAndTitleCache.
@Override
public List<UuidAndTitleCache<Rights>> getUuidAndTitleCache(Integer limit, String pattern) {
List<UuidAndTitleCache<Rights>> list = new ArrayList<UuidAndTitleCache<Rights>>();
Session session = getSession();
String queryString = "SELECT " + "r.uuid, r.id, r.text, r.abbreviatedText, r.uri, agent.titleCache, type.titleCache FROM " + type.getSimpleName() + " AS r LEFT OUTER JOIN r.agent AS agent LEFT OUTER JOIN r.type as type";
if (pattern != null) {
queryString += " WHERE ";
queryString += " r.text LIKE :pattern";
queryString += " OR agent.titleCache LIKE :pattern";
queryString += " OR r.abbreviatedText LIKE :pattern";
// queryString += " OR r.uri LIKE :pattern";
// queryString += " OR type.titleCache 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);
}
@SuppressWarnings("unchecked") List<Object[]> result = query.list();
for (Object[] object : result) {
if (object[2] == null && object[3] == null && object[4] == null && object[5] == null && object[6] == null) {
continue;
}
String rightsText = "";
String text = (String) object[2];
String abbrev = (String) object[3];
String uri = object[4] != null ? ((URI) object[4]).toString() : null;
String agentTitle = (String) object[5];
String typeLabel = (String) object[6];
boolean isFirst = true;
if (StringUtils.isNotBlank(text)) {
rightsText = text;
}
if (StringUtils.isNotBlank(agentTitle)) {
rightsText = rightsText + (StringUtils.isBlank(rightsText) ? "" : " - ") + agentTitle;
}
if (StringUtils.isNotBlank(typeLabel)) {
rightsText = rightsText + (StringUtils.isBlank(rightsText) ? "" : " - ") + typeLabel;
}
if (StringUtils.isNotBlank(abbrev)) {
rightsText = rightsText + (StringUtils.isBlank(rightsText) ? "" : " - ") + abbrev;
}
if (StringUtils.isNotBlank(uri)) {
rightsText = rightsText + (StringUtils.isBlank(rightsText) ? "" : " - ") + uri;
}
list.add(new UuidAndTitleCache<Rights>(Rights.class, (UUID) object[0], (Integer) object[1], rightsText));
}
return list;
}
use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.
the class IdentifiableDaoBase method getUuidAndTitleCacheByMarker.
@Override
public List<UuidAndTitleCache<T>> getUuidAndTitleCacheByMarker(Integer limit, String pattern, MarkerType markerType) {
if (markerType == null) {
return new ArrayList<>();
}
String queryString = "SELECT c.uuid, c.titleCache FROM %s as c " + " INNER JOIN c.markers as mks " + " WHERE (1=1) ";
queryString = String.format(queryString, type.getSimpleName());
queryString += " AND mks.markerType = :type";
if (pattern != null) {
queryString += " AND c.titleCache like :pattern";
pattern = pattern.replace("*", "%");
pattern = pattern.replace("?", "_");
pattern = pattern + "%";
}
Query query = getSession().createQuery(queryString);
if (pattern != null) {
query.setParameter("pattern", pattern);
}
// parameters
query.setEntity("type", markerType);
query.setMaxResults(limit);
@SuppressWarnings("unchecked") List<Object[]> results = query.list();
List<UuidAndTitleCache<T>> uuidAndTitleCacheResult = new ArrayList<>();
for (Object[] result : results) {
uuidAndTitleCacheResult.add(new UuidAndTitleCache<>((UUID) result[0], (String) result[1]));
}
return uuidAndTitleCacheResult;
}
use of eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache in project cdmlib by cybertaxonomy.
the class TaxonServiceSearchTaxaAndNamesTest method testfindTaxaAndNamesForEditor.
/**
* Test method for
* {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#searchByName(java.lang.String, eu.etaxonomy.cdm.model.reference.Reference)}
* .
*/
@Test
@DataSet
public final void testfindTaxaAndNamesForEditor() {
IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
configurator.setTitleSearchString("Abies bor*");
configurator.setMatchMode(MatchMode.BEGINNING);
configurator.setDoTaxa(true);
configurator.setDoSynonyms(false);
configurator.setDoNamesWithoutTaxa(true);
configurator.setDoTaxaByCommonNames(false);
@SuppressWarnings("rawtypes") List<UuidAndTitleCache<? extends IdentifiableEntity>> list = taxonService.findTaxaAndNamesForEditor(configurator);
Assert.assertEquals("Expecting one entity", 1, list.size());
configurator.setTitleSearchString("silver fir");
configurator.setMatchMode(MatchMode.BEGINNING);
configurator.setDoTaxa(false);
configurator.setDoSynonyms(false);
configurator.setDoNamesWithoutTaxa(true);
configurator.setDoTaxaByCommonNames(true);
list = taxonService.findTaxaAndNamesForEditor(configurator);
Assert.assertEquals("Expecting one entity", 1, list.size());
}
Aggregations