Search in sources :

Example 1 with UuidAndTitleCache

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

the class AgentDaoImpl method getTeamUuidAndNomenclaturalTitle.

@Override
public List<UuidAndTitleCache<Team>> getTeamUuidAndNomenclaturalTitle() {
    List<UuidAndTitleCache<Team>> list = new ArrayList<>();
    Session session = getSession();
    Query query = session.createQuery("select uuid, id, nomenclaturalTitleCache from " + type.getSimpleName() + " where dtype = 'Team'");
    @SuppressWarnings("unchecked") List<Object[]> result = query.list();
    for (Object[] object : result) {
        list.add(new UuidAndTitleCache<>(Team.class, (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) TeamOrPersonUuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.TeamOrPersonUuidAndTitleCache) Team(eu.etaxonomy.cdm.model.agent.Team) UUID(java.util.UUID) Session(org.hibernate.Session)

Example 2 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 3 with UuidAndTitleCache

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

the class TaxonDaoHibernateImplTest method testGetTaxaByNameForEditor.

@Test
@DataSet
public void testGetTaxaByNameForEditor() {
    TaxonNode subtree = null;
    Reference sec = referenceDao.findById(1);
    assert sec != null : "sec must exist";
    @SuppressWarnings("rawtypes") List<UuidAndTitleCache<? extends IdentifiableEntity>> results;
    results = taxonDao.getTaxaByNameForEditor(doTaxa, doSynonyms, noMisapplied, noCommonNames, false, includeUnpublished, noAuthors, "Acher", null, subtree, MatchMode.BEGINNING, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertFalse("The list should not be empty", results.isEmpty());
    assertEquals(4, results.size());
    results = taxonDao.getTaxaByNameForEditor(doTaxa, doSynonyms, noMisapplied, noCommonNames, false, includeUnpublished, noAuthors, "A", null, subtree, MatchMode.BEGINNING, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals(7, results.size());
    results = taxonDao.getTaxaByNameForEditor(doTaxa, noSynonyms, noMisapplied, noCommonNames, false, includeUnpublished, noAuthors, "A", null, subtree, MatchMode.BEGINNING, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals(5, results.size());
    assertEquals(results.get(0).getType(), Taxon.class);
    results = taxonDao.getTaxaByNameForEditor(noTaxa, doSynonyms, noMisapplied, noCommonNames, false, includeUnpublished, noAuthors, "A", null, subtree, MatchMode.BEGINNING, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals(2, results.size());
    assertEquals(results.get(0).getType(), Synonym.class);
    results = taxonDao.getTaxaByNameForEditor(doTaxa, doSynonyms, noMisapplied, noCommonNames, false, includeUnpublished, noAuthors, "Aus", null, subtree, MatchMode.EXACT, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals("Results list should contain one entity", 1, results.size());
    results = taxonDao.getTaxaByNameForEditor(doTaxa, doSynonyms, doMisapplied, noCommonNames, false, includeUnpublished, noAuthors, "A", null, subtree, MatchMode.BEGINNING, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals("Results list should contain 8 entities", 8, results.size());
    results = taxonDao.getTaxaByNameForEditor(doTaxa, doSynonyms, doMisapplied, noCommonNames, false, includeUnpublished, doAuthors, "Brachyglossa Boisduval", null, subtree, MatchMode.BEGINNING, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals("Results list should contain 1 entity", 1, results.size());
    results = taxonDao.getTaxaByNameForEditor(doTaxa, doSynonyms, doMisapplied, noCommonNames, false, includeUnpublished, noAuthors, "Brachyglossa Boisduval", null, subtree, MatchMode.BEGINNING, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals("Results list should contain no entities", 0, results.size());
    results = taxonDao.getTaxaByNameForEditor(doTaxa, doSynonyms, doMisapplied, noCommonNames, false, includeUnpublished, noAuthors, "Orphaned", null, subtree, MatchMode.BEGINNING, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals("Results list should contain one entity, the orphaned synonym", 1, results.size());
// TODO: test the search for misapplied names
}
Also used : IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Reference(eu.etaxonomy.cdm.model.reference.Reference) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 4 with UuidAndTitleCache

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

the class ClassificationServiceImpl method groupTaxaByHigherTaxon.

@Override
public List<GroupedTaxonDTO> groupTaxaByHigherTaxon(List<UUID> originalTaxonUuids, UUID classificationUuid, Rank minRank, Rank maxRank) {
    List<GroupedTaxonDTO> result = new ArrayList<>();
    // get treeindex for each taxonUUID
    Map<UUID, TreeIndex> taxonIdTreeIndexMap = dao.treeIndexForTaxonUuids(classificationUuid, originalTaxonUuids);
    // build treeindex list (or tree)
    // TODO make it work with TreeIndex or move there
    List<String> treeIndexClosureStr = new ArrayList<>();
    for (TreeIndex treeIndex : taxonIdTreeIndexMap.values()) {
        String[] splits = treeIndex.toString().substring(1).split(ITreeNode.separator);
        String currentIndex = ITreeNode.separator;
        for (String split : splits) {
            if (split.equals("")) {
                continue;
            }
            currentIndex += split + ITreeNode.separator;
            if (!treeIndexClosureStr.contains(currentIndex) && !split.startsWith(ITreeNode.treePrefix)) {
                treeIndexClosureStr.add(currentIndex);
            }
        }
    }
    // get rank sortindex for all parent taxa with sortindex <= minRank and sortIndex >= maxRank (if available)
    Integer minRankOrderIndex = minRank == null ? null : minRank.getOrderIndex();
    Integer maxRankOrderIndex = maxRank == null ? null : maxRank.getOrderIndex();
    List<TreeIndex> treeIndexClosure = TreeIndex.NewListInstance(treeIndexClosureStr);
    Map<TreeIndex, Integer> treeIndexSortIndexMapTmp = taxonNodeDao.rankOrderIndexForTreeIndex(treeIndexClosure, minRankOrderIndex, maxRankOrderIndex);
    // remove all treeindex with "exists child in above map(and child.sortindex > xxx)
    List<TreeIndex> treeIndexList = TreeIndex.sort(treeIndexSortIndexMapTmp.keySet());
    Map<TreeIndex, Integer> treeIndexSortIndexMap = new HashMap<>();
    TreeIndex lastTreeIndex = null;
    for (TreeIndex treeIndex : treeIndexList) {
        if (lastTreeIndex != null && lastTreeIndex.hasChild(treeIndex)) {
            treeIndexSortIndexMap.remove(lastTreeIndex);
        }
        treeIndexSortIndexMap.put(treeIndex, treeIndexSortIndexMapTmp.get(treeIndex));
        lastTreeIndex = treeIndex;
    }
    // get taxonID for treeIndexes
    Map<TreeIndex, UuidAndTitleCache<?>> treeIndexTaxonIdMap = taxonNodeDao.taxonUuidsForTreeIndexes(treeIndexSortIndexMap.keySet());
    // fill result list
    for (UUID originalTaxonUuid : originalTaxonUuids) {
        GroupedTaxonDTO item = new GroupedTaxonDTO();
        result.add(item);
        item.setTaxonUuid(originalTaxonUuid);
        TreeIndex groupTreeIndex = taxonIdTreeIndexMap.get(originalTaxonUuid);
        String groupIndexX = TreeIndex.toString(groupTreeIndex);
        while (groupTreeIndex != null) {
            if (treeIndexTaxonIdMap.get(groupTreeIndex) != null) {
                UuidAndTitleCache<?> uuidAndLabel = treeIndexTaxonIdMap.get(groupTreeIndex);
                item.setGroupTaxonUuid(uuidAndLabel.getUuid());
                item.setGroupTaxonName(uuidAndLabel.getTitleCache());
                break;
            } else {
                groupTreeIndex = groupTreeIndex.parent();
            // int index = groupIndex.substring(0, groupIndex.length()-1).lastIndexOf(ITreeNode.separator);
            // groupIndex = index < 0 ? null : groupIndex.substring(0, index+1);
            }
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) GroupedTaxonDTO(eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) TreeIndex(eu.etaxonomy.cdm.model.common.TreeIndex) UUID(java.util.UUID)

Example 5 with UuidAndTitleCache

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

the class CommonServiceImpl method getReferencingObjectTarget.

private UuidAndTitleCache<CdmBase> getReferencingObjectTarget(CdmBase entity) {
    CdmBase targetEntity;
    entity = CdmBase.deproxy(entity);
    if (entity instanceof SecundumSource) {
        targetEntity = ((SecundumSource) entity).getSourcedTaxon();
    } else if (entity instanceof NomenclaturalSource) {
        targetEntity = ((NomenclaturalSource) entity).getSourcedName();
    } else if (entity instanceof DescriptionElementSource) {
        DescriptionElementBase element = ((DescriptionElementSource) entity).getSourcedElement();
        targetEntity = getTarget(element);
    } else if (entity instanceof DescriptionElementBase) {
        targetEntity = getTarget((DescriptionElementBase) entity);
    } else if (entity instanceof IdentifiableSource) {
        IdentifiableSource source = (IdentifiableSource) entity;
        targetEntity = originalSourceDao.findIdentifiableBySourceId(IdentifiableEntity.class, source.getId());
    } else if (entity instanceof NamedSource) {
        NamedSource source = (NamedSource) entity;
        SingleSourcedEntityBase singleSourced = originalSourceDao.findSingleSourceBySourceId(SingleSourcedEntityBase.class, source.getId());
        if (singleSourced != null) {
            targetEntity = singleSourced;
        } else {
            // TODO
            targetEntity = entity;
        }
    } else if (entity instanceof DescriptionBase) {
        targetEntity = getTarget((DescriptionBase<?>) entity);
    } else {
        targetEntity = entity;
    }
    targetEntity = CdmBase.deproxy(targetEntity);
    if (targetEntity == null) {
        targetEntity = entity;
    }
    String targetLabel = targetEntity instanceof IdentifiableEntity ? ((IdentifiableEntity<?>) targetEntity).getTitleCache() : null;
    UuidAndTitleCache<CdmBase> result = new UuidAndTitleCache<>(targetEntity.getClass(), targetEntity.getUuid(), targetEntity.getId(), targetLabel);
    return result;
}
Also used : DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) SecundumSource(eu.etaxonomy.cdm.model.taxon.SecundumSource) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) NamedSource(eu.etaxonomy.cdm.model.reference.NamedSource) NomenclaturalSource(eu.etaxonomy.cdm.model.name.NomenclaturalSource) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) DescriptionElementSource(eu.etaxonomy.cdm.model.description.DescriptionElementSource) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) SingleSourcedEntityBase(eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase)

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