import javax.xml.bind.annotation.XmlType;
import org.apache.log4j.Logger;
+import org.hibernate.LazyInitializationException;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Index;
// ************************* GETTER / SETTER *******************************/
+ @Transient
public Integer getSortIndex() {
+ TaxonNode parent = HibernateProxyHelper.deproxy(this.parent, TaxonNode.class);
+ parent.removeNullValueFromChildren();
+
return sortIndex;
}
/**
@Override
public List<TaxonNode> getChildNodes() {
+
return childNodes;
}
protected void setChildNodes(List<TaxonNode> childNodes) {
@Override
public TaxonNode addChildTaxon(Taxon taxon, int index, Reference citation, String microCitation) {
+ Classification classification = HibernateProxyHelper.deproxy(this.getClassification(), Classification.class);
+ taxon = HibernateProxyHelper.deproxy(taxon, Taxon.class);
if (this.getClassification().isTaxonInTree(taxon)){
throw new IllegalArgumentException(String.format("Taxon may not be in a classification twice: %s", taxon.getTitleCache()));
}
*/
protected boolean removeChildNode(TaxonNode childNode){
boolean result = true;
- while (childNodes.contains(null)){
- childNodes.remove(null);
- }
+ removeNullValueFromChildren();
if(childNode == null){
throw new IllegalArgumentException("TaxonNode may not be null");
}
parent = HibernateProxyHelper.deproxy(parent, TaxonNode.class);
List<TaxonNode> parentChildren = parent.getChildNodes();
//TODO: Only as a workaround. We have to find out why merge creates null entries.
+
while (parentChildren.contains(null)){
parentChildren.remove(null);
}
parent.updateSortIndex(0);
+ if (index > parent.getChildNodes().size()){
+ index = parent.getChildNodes().size();
+ }
if (parentChildren.contains(this)){
//avoid duplicates
if (parentChildren.indexOf(this) < index){
return hasTaxon() ? getTaxon().getNullSafeRank() : null;
}
+ private void removeNullValueFromChildren(){
+ try {
+ if (childNodes.contains(null)){
+ while(childNodes.contains(null)){
+ childNodes.remove(null);
+ }
+ }
+ this.updateSortIndex(0);
+ } catch (LazyInitializationException e) {
+ logger.info("Cannot clean up uninitialized children without a session, skipping.");
+ }
+ }
+
//*********************** CLONE ********************************************************/