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