Revision 5c45a99a
Added by Andreas Müller over 1 year ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/PolytomousKeyNode.java | ||
---|---|---|
38 | 38 |
import org.hibernate.annotations.CascadeType; |
39 | 39 |
import org.hibernate.envers.Audited; |
40 | 40 |
|
41 |
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util; |
|
42 | 41 |
import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter; |
43 | 42 |
import eu.etaxonomy.cdm.model.common.IMultiLanguageTextHolder; |
44 | 43 |
import eu.etaxonomy.cdm.model.common.Language; |
... | ... | |
473 | 472 |
if (index < 0 || index > children.size() + 1) { |
474 | 473 |
throw new IndexOutOfBoundsException("Wrong index: " + index); |
475 | 474 |
} |
476 |
if (children.contains(null)){ |
|
477 |
HHH_9751_Util.removeAllNull(children); |
|
478 |
updateSortIndex(); |
|
479 |
} |
|
475 |
|
|
480 | 476 |
if(nodeNumber == null) { |
481 | 477 |
nodeNumber = getMaxNodeNumberFromRoot() + 1; |
482 | 478 |
} |
... | ... | |
484 | 480 |
children.add(index, child); |
485 | 481 |
child.setKey(this.getKey()); |
486 | 482 |
|
487 |
updateSortIndex(); |
|
488 |
child.setSortIndex(index); |
|
489 | 483 |
child.setParent(this); |
490 |
//this.removeNullValueFromChildren(); |
|
491 | 484 |
} |
492 | 485 |
|
493 | 486 |
/** |
... | ... | |
547 | 540 |
PolytomousKeyNode rootKeyNode = this.getKey().getRoot(); |
548 | 541 |
int rootNumber = this.getKey().getStartNumber(); |
549 | 542 |
|
550 |
rootKeyNode.updateSortIndex(); |
|
551 | 543 |
return getMaxNodeNumber(rootNumber, rootKeyNode); |
552 | 544 |
} |
553 | 545 |
|
... | ... | |
560 | 552 |
private int getMaxNodeNumber(int maxNumber, PolytomousKeyNode parent) { |
561 | 553 |
if (parent.getNodeNumber() != null) { |
562 | 554 |
maxNumber = (maxNumber < parent.getNodeNumber()) ? parent.getNodeNumber() : maxNumber; |
563 |
parent.removeNullValueFromChildren(); |
|
564 | 555 |
for (PolytomousKeyNode child : parent.getChildren()) { |
565 | 556 |
if (parent == child){ |
566 | 557 |
throw new RuntimeException("Parent and child are the same for the given key node. This will lead to an infinite loop when updating the max node number."); |
... | ... | |
593 | 584 |
} else { |
594 | 585 |
node.setNodeNumber(nodeN); |
595 | 586 |
newNodeN++; |
596 |
List<PolytomousKeyNode> children = node.getChildren(); |
|
597 |
HHH_9751_Util.removeAllNull(children); |
|
598 |
updateSortIndex(); |
|
587 |
List<PolytomousKeyNode> children = node.getChildren();; |
|
599 | 588 |
for (PolytomousKeyNode child : children) { |
600 | 589 |
if (node == child){ |
601 | 590 |
throw new RuntimeException("Parent and child are the same for the given key node. This will lead to an infinite loop when updating node numbers."); |
... | ... | |
891 | 880 |
return result; |
892 | 881 |
} |
893 | 882 |
|
894 |
private void updateSortIndex(){ |
|
895 |
HHH_9751_Util.removeAllNull(children); |
|
896 |
for (int i = 0; i < children.size(); i++) { |
|
897 |
children.get(i).setSortIndex(i); |
|
898 |
} |
|
899 |
} |
|
900 |
|
|
901 |
public void removeNullValueFromChildren(){ |
|
902 |
updateSortIndex(); |
|
903 |
} |
|
904 | 883 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/PostMergeEntityListener.java | ||
---|---|---|
84 | 84 |
if (TaxonNode.class.isAssignableFrom(entityClazz)){ |
85 | 85 |
//do nothing (remove if #8127/#3722 is fully solved |
86 | 86 |
} else if (PolytomousKeyNode.class.isAssignableFrom(entityClazz)){ |
87 |
PolytomousKeyNode node = (PolytomousKeyNode) entity; |
|
88 |
if (node.getChildren() != null && Hibernate.isInitialized(node.getChildren()) ){ |
|
89 |
node.removeNullValueFromChildren(); |
|
90 |
for (PolytomousKeyNode childNode: node.getChildren()){ |
|
91 |
removeNullFromCollections(childNode); |
|
92 |
} |
|
93 |
} |
|
87 |
// PolytomousKeyNode node = (PolytomousKeyNode) entity; |
|
88 |
// if (node.getChildren() != null && Hibernate.isInitialized(node.getChildren()) ){ |
|
89 |
// node.removeNullValueFromChildren(); |
|
90 |
// for (PolytomousKeyNode childNode: node.getChildren()){ |
|
91 |
// removeNullFromCollections(childNode); |
|
92 |
// } |
|
93 |
// } |
|
94 |
//do nothing (remove if #8127/#3722 is fully solved |
|
94 | 95 |
}else if (PolytomousKey.class.isAssignableFrom(entityClazz)){ |
95 |
PolytomousKey key = (PolytomousKey) entity; |
|
96 |
PolytomousKeyNode node = key.getRoot(); |
|
97 |
if (node != null && node.getChildren() != null && Hibernate.isInitialized(node.getChildren()) ){ |
|
98 |
node.removeNullValueFromChildren(); |
|
99 |
for (PolytomousKeyNode childNode: node.getChildren()){ |
|
100 |
removeNullFromCollections(childNode); |
|
101 |
} |
|
102 |
} |
|
96 |
// PolytomousKey key = (PolytomousKey) entity; |
|
97 |
// PolytomousKeyNode node = key.getRoot(); |
|
98 |
// if (node != null && node.getChildren() != null && Hibernate.isInitialized(node.getChildren()) ){ |
|
99 |
//// node.removeNullValueFromChildren(); |
|
100 |
// for (PolytomousKeyNode childNode: node.getChildren()){ |
|
101 |
// removeNullFromCollections(childNode); |
|
102 |
// } |
|
103 |
// } |
|
104 |
//do nothing (remove if #8127/#3722 is fully solved |
|
103 | 105 |
}else if(TermTree.class.isAssignableFrom(entityClazz)){ |
104 | 106 |
//do nothing (remove if #8127/#3722 is fully solved |
105 | 107 |
} else if (TermNode.class.isAssignableFrom(entityClazz)){ |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceImpl.java | ||
---|---|---|
16 | 16 |
import org.springframework.stereotype.Service; |
17 | 17 |
import org.springframework.transaction.annotation.Transactional; |
18 | 18 |
|
19 |
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util; |
|
20 | 19 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
21 | 20 |
import eu.etaxonomy.cdm.model.description.PolytomousKey; |
22 | 21 |
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode; |
... | ... | |
53 | 52 |
} |
54 | 53 |
List<PolytomousKeyNode> children = new ArrayList<>(); |
55 | 54 |
|
56 |
node.removeNullValueFromChildren(); |
|
57 | 55 |
for (PolytomousKeyNode child: node.getChildren()){ |
58 | 56 |
children.add(child); |
59 | 57 |
} |
... | ... | |
81 | 79 |
result.addUpdatedObject(node); |
82 | 80 |
} |
83 | 81 |
if (parent!= null){ |
84 |
if (parent.getChildren().contains(null)){ |
|
85 |
List<PolytomousKeyNode> parentChildren = parent.getChildren(); |
|
86 |
HHH_9751_Util.removeAllNull(parentChildren); |
|
87 |
} |
|
88 | 82 |
parent.removeChild(node); |
89 | 83 |
dao.saveOrUpdate(parent); |
90 | 84 |
} |
Also available in: Unified diff
ref #10067, ref #3722, ref #8127 remove all manual sortindex and null value handling from polytomous key (node)