Search in sources :

Example 16 with TaxonNodeDto

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

the class CdmLightClassificationExport method doInvoke.

@Override
protected void doInvoke(CdmLightExportState state) {
    try {
        IProgressMonitor monitor = state.getConfig().getProgressMonitor();
        CdmLightExportConfigurator config = state.getConfig();
        if (config.getTaxonNodeFilter().hasClassificationFilter()) {
            Classification classification = getClassificationService().load(config.getTaxonNodeFilter().getClassificationFilter().get(0).getUuid());
            state.setRootId(classification.getRootNode().getUuid());
        } else if (config.getTaxonNodeFilter().hasSubtreeFilter()) {
            state.setRootId(config.getTaxonNodeFilter().getSubtreeFilter().get(0).getUuid());
        }
        @SuppressWarnings("unchecked") TaxonNodeOutStreamPartitioner<XmlExportState> partitioner = TaxonNodeOutStreamPartitioner.NewInstance(this, state, state.getConfig().getTaxonNodeFilter(), 100, monitor, null);
        handleMetaData(state);
        monitor.subTask("Start partitioning");
        TaxonNode node = partitioner.next();
        while (node != null) {
            handleTaxonNode(state, node);
            node = partitioner.next();
        }
        // get rootNode and create helperObjects
        if (state.getRootId() != null) {
            List<TaxonNodeDto> childrenOfRoot = state.getNodeChildrenMap().get(state.getRootId());
            Comparator<TaxonNodeDto> comp = state.getConfig().getComparator();
            if (comp == null) {
                comp = new TaxonNodeDtoByRankAndNameComparator();
            }
            if (childrenOfRoot != null) {
                Collections.sort(childrenOfRoot, comp);
                OrderHelper helper = new OrderHelper(state.getRootId());
                helper.setOrderIndex(state.getActualOrderIndexAndUpdate());
                state.getOrderHelperMap().put(state.getRootId(), helper);
                for (TaxonNodeDto child : childrenOfRoot) {
                    OrderHelper childHelper = new OrderHelper(child.getTaxonUuid());
                    helper.addChild(childHelper);
                    childHelper.setOrderIndex(state.getActualOrderIndexAndUpdate());
                    childHelper.addChildren(createOrderHelper(state.getNodeChildrenMap().get(child.getUuid()), state));
                }
            }
            state.getNodeChildrenMap().clear();
            for (OrderHelper order : state.getOrderHelperMap().values()) {
                setOrderIndex(state, order);
            }
        }
        state.getProcessor().createFinalResult(state);
    } catch (Exception e) {
        state.getResult().addException(e, "An unexpected error occurred in main method doInvoke() " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) IProgressMonitor(eu.etaxonomy.cdm.common.monitor.IProgressMonitor) Classification(eu.etaxonomy.cdm.model.taxon.Classification) TaxonNodeDtoByRankAndNameComparator(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoByRankAndNameComparator) XmlExportState(eu.etaxonomy.cdm.io.common.XmlExportState) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 17 with TaxonNodeDto

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

the class CdmLightClassificationExport method createOrderHelper.

private List<OrderHelper> createOrderHelper(List<TaxonNodeDto> nodes, CdmLightExportState state) {
    List<TaxonNodeDto> children = nodes;
    // alreadySortedNodes.add(parentUuid);
    if (children == null) {
        return null;
    }
    Comparator<TaxonNodeDto> comp = state.getConfig().getComparator();
    if (comp == null) {
        comp = new TaxonNodeDtoByRankAndNameComparator();
    }
    Collections.sort(children, comp);
    // TODO: nochmal checken!!!
    OrderHelper helperChild;
    List<OrderHelper> childrenHelper = new ArrayList<>();
    for (TaxonNodeDto child : children) {
        helperChild = new OrderHelper(child.getTaxonUuid());
        helperChild.setOrderIndex(state.getActualOrderIndexAndUpdate());
        if (state.getNodeChildrenMap().get(child.getUuid()) != null) {
            children = state.getNodeChildrenMap().get(child.getUuid());
            helperChild.addChildren(createOrderHelper(children, state));
        }
        childrenHelper.add(helperChild);
    }
    return childrenHelper;
}
Also used : TaxonNodeDtoByRankAndNameComparator(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoByRankAndNameComparator) ArrayList(java.util.ArrayList) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 18 with TaxonNodeDto

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

the class CdmLightClassificationExport method handleTaxonNode.

private void handleTaxonNode(CdmLightExportState state, TaxonNode taxonNode) {
    if (taxonNode == null) {
        String message = "TaxonNode for given taxon node UUID not found. ";
        // TODO
        state.getResult().addWarning(message);
    } else {
        try {
            TaxonNode root = taxonNode;
            List<TaxonNodeDto> childNodes;
            if (root.hasChildNodes()) {
                childNodes = new ArrayList<>();
                for (TaxonNode child : root.getChildNodes()) {
                    if (child != null) {
                        childNodes.add(new TaxonNodeDto(child));
                    }
                }
                state.getNodeChildrenMap().put(root.getUuid(), childNodes);
            // add root to node map
            }
            TaxonNodeDto rootDto = new TaxonNodeDto(root);
            UUID parentUuid = root.getParent() != null ? root.getParent().getUuid() : state.getClassificationUUID(root);
            List<TaxonNodeDto> children = state.getNodeChildrenMap().get(parentUuid);
            if (children != null && !children.contains(rootDto)) {
                state.getNodeChildrenMap().get(parentUuid).add(rootDto);
            } else if (state.getNodeChildrenMap().get(parentUuid) == null) {
                List<TaxonNodeDto> rootList = new ArrayList<>();
                rootList.add(rootDto);
                state.getNodeChildrenMap().put(parentUuid, rootList);
            }
            if (root.hasTaxon()) {
                handleTaxon(state, root);
            }
        } catch (Exception e) {
            state.getResult().addException(e, "An unexpected error occurred when handling taxonNode " + taxonNode.getUuid() + ": " + e.getMessage() + e.getStackTrace());
        }
    }
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) List(java.util.List) ArrayList(java.util.ArrayList) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) UUID(java.util.UUID) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 19 with TaxonNodeDto

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

the class TaxonNodeDaoHibernateImpl method getTaxonNodeDto.

@Override
public List<TaxonNodeDto> getTaxonNodeDto(Integer limit, String pattern, UUID classificationUuid) {
    String queryString = getTaxonNodeDtoQuery();
    queryString += "   INNER JOIN tn.classification AS cls " + " WHERE t.titleCache LIKE :pattern ";
    if (classificationUuid != null) {
        queryString += "AND cls.uuid = :classificationUuid";
    }
    Query query = getSession().createQuery(queryString);
    query.setParameter("pattern", pattern.toLowerCase() + "%");
    if (classificationUuid != null) {
        query.setParameter("classificationUuid", classificationUuid);
    }
    @SuppressWarnings("unchecked") List<SortableTaxonNodeQueryResult> result = query.list();
    List<TaxonNodeDto> list = createNodeDtos(result);
    return list;
}
Also used : Query(org.hibernate.Query) SortableTaxonNodeQueryResult(eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResult) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 20 with TaxonNodeDto

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

the class TaxonNodeDaoHibernateImpl method getTaxonNodeDtos.

@Override
public List<TaxonNodeDto> getTaxonNodeDtos(List<UUID> nodeUuids) {
    String queryString = getTaxonNodeDtoQuery();
    queryString = queryString + " WHERE tn.uuid IN (:uuid) ";
    Query query = getSession().createQuery(queryString);
    query.setParameterList("uuid", nodeUuids);
    @SuppressWarnings("unchecked") List<SortableTaxonNodeQueryResult> result = query.list();
    List<TaxonNodeDto> list = createNodeDtos(result);
    return list;
}
Also used : Query(org.hibernate.Query) SortableTaxonNodeQueryResult(eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResult) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Aggregations

TaxonNodeDto (eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)34 ArrayList (java.util.ArrayList)16 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)15 UUID (java.util.UUID)11 Query (org.hibernate.Query)10 Classification (eu.etaxonomy.cdm.model.taxon.Classification)8 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)8 SortableTaxonNodeQueryResult (eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResult)6 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)4 DescriptiveDataSetBaseDto (eu.etaxonomy.cdm.persistence.dto.DescriptiveDataSetBaseDto)4 Test (org.junit.Test)4 DescriptionBaseDto (eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto)3 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)3 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)3 BigInteger (java.math.BigInteger)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 DataSet (org.unitils.dbunit.annotation.DataSet)3 SpecimenRowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO)2 TaxonRowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO)2 IProgressMonitor (eu.etaxonomy.cdm.common.monitor.IProgressMonitor)2