Search in sources :

Example 6 with GroupedTaxonDTO

use of eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO in project cdmlib by cybertaxonomy.

the class ClassificationServiceImpl method groupTaxaByMarkedParents.

@Override
public List<GroupedTaxonDTO> groupTaxaByMarkedParents(List<UUID> originalTaxonUuids, UUID classificationUuid, MarkerType markerType, Boolean flag) {
    List<GroupedTaxonDTO> result = new ArrayList<>();
    // get treeindex for each taxonUUID
    Map<UUID, TreeIndex> taxonIdTreeIndexMap = dao.treeIndexForTaxonUuids(classificationUuid, originalTaxonUuids);
    // get all marked tree indexes
    Set<TreeIndex> markedTreeIndexes = dao.getMarkedTreeIndexes(markerType, flag);
    Map<TreeIndex, TreeIndex> groupedMap = TreeIndex.group(markedTreeIndexes, taxonIdTreeIndexMap.values());
    Set<TreeIndex> notNullGroups = new HashSet<>(groupedMap.values());
    notNullGroups.remove(null);
    // get taxonInfo for treeIndexes
    Map<TreeIndex, UuidAndTitleCache<?>> treeIndexTaxonIdMap = taxonNodeDao.taxonUuidsForTreeIndexes(notNullGroups);
    // fill result list
    for (UUID originalTaxonUuid : originalTaxonUuids) {
        GroupedTaxonDTO item = new GroupedTaxonDTO();
        result.add(item);
        item.setTaxonUuid(originalTaxonUuid);
        TreeIndex toBeGroupedTreeIndex = taxonIdTreeIndexMap.get(originalTaxonUuid);
        TreeIndex groupTreeIndex = groupedMap.get(toBeGroupedTreeIndex);
        UuidAndTitleCache<?> uuidAndLabel = treeIndexTaxonIdMap.get(groupTreeIndex);
        if (uuidAndLabel != null) {
            item.setGroupTaxonUuid(uuidAndLabel.getUuid());
            item.setGroupTaxonName(uuidAndLabel.getTitleCache());
        }
    }
    return result;
}
Also used : TreeIndex(eu.etaxonomy.cdm.model.common.TreeIndex) GroupedTaxonDTO(eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO) ArrayList(java.util.ArrayList) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) UUID(java.util.UUID) HashSet(java.util.HashSet)

Aggregations

GroupedTaxonDTO (eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO)6 UUID (java.util.UUID)4 Rank (eu.etaxonomy.cdm.model.name.Rank)3 ArrayList (java.util.ArrayList)3 TreeIndex (eu.etaxonomy.cdm.model.common.TreeIndex)2 Classification (eu.etaxonomy.cdm.model.taxon.Classification)2 UuidAndTitleCache (eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 MarkerType (eu.etaxonomy.cdm.model.common.MarkerType)1 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 DataSet (org.unitils.dbunit.annotation.DataSet)1