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