Project

General

Profile

Revision 969dbe3e

ID969dbe3e3d4772bc34a4b68a3e87fb1c672a3fa1
Parent 794708a7
Child ec3ff238

Added by Katja Luther over 5 years ago

#5678: fix deletion of FeatureNodes and minor changes

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/FeatureNode.java
41 41
import org.hibernate.annotations.Table;
42 42
import org.hibernate.envers.Audited;
43 43

  
44
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util;
44 45
import eu.etaxonomy.cdm.model.common.ITreeNode;
45 46
import eu.etaxonomy.cdm.model.common.VersionableEntity;
46 47

  
......
236 237
	 */
237 238
	@Override
238 239
    public List<FeatureNode> getChildNodes() {
240
	    HHH_9751_Util.removeAllNull(children);
241
	    updateSortIndex();
239 242
		return children;
240 243
	}
241 244

  
......
298 301
	 * @see				#removeChild(int)
299 302
	 */
300 303
	public void removeChild(FeatureNode child){
304
	    HHH_9751_Util.removeAllNull(children);
305
	    updateSortIndex();
301 306
		int index = children.indexOf(child);
302 307
		if (index >= 0){
303 308
			removeChild(index);
......
316 321
	 * @see				#removeChild(FeatureNode)
317 322
	 */
318 323
	public void removeChild(int index){
324
	    HHH_9751_Util.removeAllNull(children);
325
    	updateSortIndex();
319 326
		FeatureNode child = children.get(index);
320 327
		if (child != null){
321 328
			children.remove(index);
......
341 348
	 * @see					#removeChild(int)
342 349
	 */
343 350
	public FeatureNode getChildAt(int childIndex) {
344
			return children.get(childIndex);
351
	    HHH_9751_Util.removeAllNull(children);
352
	    updateSortIndex();
353
		return children.get(childIndex);
345 354
	}
346 355

  
347 356
	/**
......
364 373
	 * @see			#removeChild(int)
365 374
	 */
366 375
	public int getIndex(FeatureNode node) {
376
	    HHH_9751_Util.removeAllNull(children);
377
	    updateSortIndex();
378

  
367 379
		if (! children.contains(node)){
368 380
			return -1;
369 381
		}else{
......
603 615
		}
604 616
	}
605 617

  
618
	private void updateSortIndex(){
619
	 // TODO workaround (see sortIndex doc)
620
        for (int i = 0; i < children.size(); i++) {
621
            children.get(i).setSortIndex(i);
622
        }
623
	}
624

  
606 625

  
607 626
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/PolytomousKeyNode.java
426 426
	 */
427 427
	public List<PolytomousKeyNode> getChildren() {
428 428
	    HHH_9751_Util.removeAllNull(children);
429
	    updateSortIndex();
429 430
		return children;
430 431
	}
431 432

  
......
466 467
			throw new IndexOutOfBoundsException("Wrong index: " + index);
467 468
		}
468 469
		HHH_9751_Util.removeAllNull(children);
470
		updateSortIndex();
469 471

  
470 472
		if(nodeNumber == null) {
471 473
            	nodeNumber = getMaxNodeNumberFromRoot() + 1;
......
475 477
		children.add(index, child);
476 478
		child.setKey(this.getKey());
477 479

  
478
		// TODO workaround (see sortIndex doc)
479
		for (int i = 0; i < children.size(); i++) {
480
			children.get(i).setSortIndex(i);
481
		}
480
		updateSortIndex();
482 481
		child.setSortIndex(index);
483 482
		child.setParent(this);
484 483
	}
......
498 497
	 */
499 498
	public void removeChild(PolytomousKeyNode child) {
500 499
		HHH_9751_Util.removeAllNull(children);
500
		updateSortIndex();
501 501
		int index = children.indexOf(child);
502 502
		if (index >= 0) {
503 503
			removeChild(index);
......
592 592
			newNodeN++;
593 593
			List<PolytomousKeyNode> children = node.getChildren();
594 594
			HHH_9751_Util.removeAllNull(children);
595
			updateSortIndex();
595 596
			for (PolytomousKeyNode child : children) {
596 597
				if (node == child){
597 598
					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.");
......
887 888

  
888 889
    }
889 890

  
891
    private void updateSortIndex(){
892
        // TODO workaround (see sortIndex doc)
893
        for (int i = 0; i < children.size(); i++) {
894
            children.get(i).setSortIndex(i);
895
        }
896
    }
897

  
890 898

  
891 899
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImpl.java
27 27
import org.springframework.transaction.annotation.Transactional;
28 28

  
29 29
import eu.etaxonomy.cdm.api.service.config.CreateHierarchyForClassificationConfigurator;
30
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
31
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
30 32
import eu.etaxonomy.cdm.api.service.pager.Pager;
31 33
import eu.etaxonomy.cdm.api.service.pager.PagerUtils;
32 34
import eu.etaxonomy.cdm.api.service.pager.impl.AbstractPagerImpl;
......
586 588
       return dao.classificationLookup(classification);
587 589
   }
588 590

  
591

  
592
    public DeleteResult delete(UUID classificationUuid, TaxonDeletionConfigurator config){
593
        DeleteResult result = new DeleteResult();
594
        Classification classification = dao.findByUuid(classificationUuid);
595
        if (classification == null){
596
            result.addException(new IllegalArgumentException("The classification does not exist in database."));
597
            result.setAbort();
598
            return result;
599
        }
600
        if (!classification.hasChildNodes()){
601
            dao.delete(classification);
602
        }
603
        if (config.getTaxonNodeConfig().getChildHandling().equals(ChildHandling.DELETE) ){
604
            TaxonNode root = classification.getRootNode();
605
            taxonNodeDao.delete(root, true);
606
            dao.delete(classification);
607
        }
608

  
609

  
610
        return result;
611
    }
612

  
589 613
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IClassificationService.java
16 16
import java.util.UUID;
17 17

  
18 18
import eu.etaxonomy.cdm.api.service.config.CreateHierarchyForClassificationConfigurator;
19
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
19 20
import eu.etaxonomy.cdm.api.service.pager.Pager;
20 21
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
21 22
import eu.etaxonomy.cdm.model.name.Rank;
......
309 310
     */
310 311
    ClassificationLookupDTO classificationLookup(Classification classification);
311 312

  
313
    DeleteResult delete(UUID classificationUuid, TaxonDeletionConfigurator config);
314

  
312 315

  
313 316
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)