Search in sources :

Example 36 with UuidAndTitleCache

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;
}
Also used : Query(org.hibernate.Query) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) Rights(eu.etaxonomy.cdm.model.media.Rights) UUID(java.util.UUID) Session(org.hibernate.Session)

Example 37 with UuidAndTitleCache

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

Example 38 with UuidAndTitleCache

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());
}
Also used : IFindTaxaAndNamesConfigurator(eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator) IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

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