Project

General

Profile

Revision a6035e28

IDa6035e281f7266cc77bc0ae78fad429fd4c3d6f7
Parent 65149714
Child ae79876f

Added by Katja Luther over 5 years ago

#5536

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionBase.java
39 39
import org.hibernate.search.annotations.ContainedIn;
40 40
import org.hibernate.search.annotations.FieldBridge;
41 41

  
42
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util;
42 43
import eu.etaxonomy.cdm.hibernate.search.DescriptionBaseClassBridge;
43 44
import eu.etaxonomy.cdm.hibernate.search.GroupByTaxonClassBridge;
44 45
import eu.etaxonomy.cdm.hibernate.search.NotNullAwareIdBridge;
......
221 222
     * @see    	   		#getDescriptionSources()
222 223
     */
223 224
    public void addElement(DescriptionElementBase element) {
224
        removeNullValue();
225
        HHH_9751_Util.removeAllNull(this.descriptionElements);
225 226
        if (element.getInDescription() != null){
226 227
            element.getInDescription().removeElement(element);
227 228
        }
......
234 235
     * @param elements
235 236
     */
236 237
    public void addElements(DescriptionElementBase ... elements) {
237
        removeNullValue();
238
        HHH_9751_Util.removeAllNull(this.descriptionElements);
238 239
        for (DescriptionElementBase element : elements){
239 240
    		addElement(element);
240 241
    	}
......
249 250
     * @see     		#addElement(DescriptionElementBase)
250 251
     */
251 252
    public void removeElement(DescriptionElementBase element) {
252
        removeNullValue();
253
        HHH_9751_Util.removeAllNull(this.descriptionElements);
253 254
        this.descriptionElements.remove(element);
254 255
        element.setInDescription(null);
255 256
    }
256 257

  
257
    private void removeNullValue(){
258
        while(this.descriptionElements.contains(null)){
259
            this.descriptionElements.remove(null);
260
        }
261
    }
258

  
262 259

  
263 260
    /**
264 261
     * Returns the number of {@link DescriptionElementBase elementary description data} which constitute
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/PolytomousKeyNode.java
34 34
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
35 35

  
36 36
import org.apache.log4j.Logger;
37
import org.hibernate.LazyInitializationException;
38 37
import org.hibernate.annotations.Cascade;
39 38
import org.hibernate.annotations.CascadeType;
40 39
import org.hibernate.envers.Audited;
41 40

  
41
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util;
42 42
import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter;
43 43
import eu.etaxonomy.cdm.model.common.IMultiLanguageTextHolder;
44 44
import eu.etaxonomy.cdm.model.common.Language;
......
425 425
	 * <i>this</i> feature node.
426 426
	 */
427 427
	public List<PolytomousKeyNode> getChildren() {
428
	    removeNullValueFromChildren();
428
	    HHH_9751_Util.removeAllNull(children);
429 429
		return children;
430 430
	}
431 431

  
......
465 465
		if (index < 0 || index > children.size() + 1) {
466 466
			throw new IndexOutOfBoundsException("Wrong index: " + index);
467 467
		}
468
		removeNullValueFromChildren();
468
		HHH_9751_Util.removeAllNull(children);
469 469

  
470 470
		if(nodeNumber == null) {
471 471
            	nodeNumber = getMaxNodeNumberFromRoot() + 1;
......
497 497
	 * @see #removeChild(int)
498 498
	 */
499 499
	public void removeChild(PolytomousKeyNode child) {
500
		HHH_9751_Util.removeAllNull(children);
500 501
		int index = children.indexOf(child);
501
		removeNullValueFromChildren();
502 502
		if (index >= 0) {
503 503
			removeChild(index);
504 504
		}
505 505
	}
506 506

  
507 507

  
508
	private void removeNullValueFromChildren(){
509
	    try {
510
    	    if (children.contains(null)){
511
                while(children.contains(null)){
512
                    children.remove(null);
513
                }
514
            }
515
	    } catch (LazyInitializationException e) {
516
	        logger.info("Cannot clean up uninitialized children without a session, skipping.");
517
	    }
518
	}
508

  
519 509
	/**
520 510
	 * Removes the feature node placed at the given (index + 1) position from
521 511
	 * the list of {@link #getChildren() children} of <i>this</i> feature node.
......
601 591
			node.setNodeNumber(nodeN);
602 592
			newNodeN++;
603 593
			List<PolytomousKeyNode> children = node.getChildren();
604
			 while (children.contains(null)){
605
			     children.remove(null);
606
		       }
607

  
594
			HHH_9751_Util.removeAllNull(children);
608 595
			for (PolytomousKeyNode child : children) {
609 596
				if (node == child){
610 597
					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.");
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonNode.java
626 626
        List<TaxonNode> parentChildren = parent.getChildNodes();
627 627
       //TODO: Only as a workaround. We have to find out why merge creates null entries.
628 628

  
629
        while (parentChildren.contains(null)){
630
            parentChildren.remove(null);
631
        }
629
        HHH_9751_Util.removeAllNull(parentChildren);
632 630
        parent.updateSortIndex(0);
633 631
        if (index > parent.getChildNodes().size()){
634 632
            index = parent.getChildNodes().size();
......
739 737
        Set<TaxonNode> nodeSet = new HashSet<TaxonNode>();
740 738
       // nodeSet.add(this);
741 739
        TaxonBase taxon = HibernateProxyHelper.deproxy(this.getTaxon(), Taxon.class);
742
        try{
743
            TaxonNameBase name = HibernateProxyHelper.deproxy(taxon.getName(), TaxonNameBase.class);
744
            if (name.getRank().isHigher(rank)){
745
            	return null;
746
            }
747
            if (name.getRank().equals(rank)){
748
            	return this;
749
            }
750
        }catch (NullPointerException e){
751
            System.err.println(taxon.getTitleCache() +  " " + e.getMessage());
740
        if (taxon == null){
741
            return null;
752 742
        }
753
        if(this.getParent() != null ){
743
        TaxonNameBase name = HibernateProxyHelper.deproxy(taxon.getName(), TaxonNameBase.class);
744
        if (name.getRank().isHigher(rank)){
745
        	return null;
746
        }
747
        if (name.getRank().equals(rank)){
748
        	return this;
749
        }
750

  
751
        if(this.getParent() != null){
754 752
        	TaxonNode parent =  CdmBase.deproxy(this.getParent(), TaxonNode.class);
755 753
            return parent.getAncestorOfRank(rank);
756 754
        }
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceImpl.java
17 17
import org.springframework.stereotype.Service;
18 18
import org.springframework.transaction.annotation.Transactional;
19 19

  
20
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util;
20 21
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
21 22
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
22 23
import eu.etaxonomy.cdm.persistence.dao.description.IPolytomousKeyNodeDao;
......
70 71
        if (parent!= null){
71 72
            if (parent.getChildren().contains(null)){
72 73
                List<PolytomousKeyNode> parentChildren = parent.getChildren();
73
                while (parent.getChildren().contains(null)){
74
                    parentChildren.remove(null);
75
                }
74
                HHH_9751_Util.removeAllNull(parentChildren);
76 75
            }
77 76
            parent.removeChild(node);
78 77
            dao.saveOrUpdate(parent);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)