Project

General

Profile

Download (2.33 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2020 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.persistence.dto;
10

    
11
import java.util.ArrayList;
12
import java.util.List;
13
import java.util.UUID;
14

    
15
import org.springframework.util.Assert;
16

    
17
import eu.etaxonomy.cdm.model.description.Character;
18
import eu.etaxonomy.cdm.model.term.TermNode;
19
import eu.etaxonomy.cdm.model.term.TermType;
20

    
21
/**
22
 * @author k.luther
23
 * @since Oct 9, 2020
24
 */
25
public class CharacterNodeDto extends TermNodeDto {
26

    
27
    private static final long serialVersionUID = 7635704848569122836L;
28

    
29
    /**
30
     * @param termDto
31
     * @param parent
32
     * @param position
33
     */
34
    public CharacterNodeDto(CharacterDto characterDto, TermNodeDto parent, int position, TermTreeDto treeDto, UUID uuid, String treeIndex, String path) {
35
        super(characterDto, parent, position, treeDto, uuid, treeIndex, path);
36
    }
37

    
38
    public static CharacterNodeDto fromTermNode(TermNode<Character> child, TermTreeDto treeDto) {
39
        Assert.notNull(child, "Node should not be null");
40
        CharacterNodeDto dto = new CharacterNodeDto(child.getTerm() != null?CharacterDto.fromCharacter(child.getTerm()): null, null, child.getParent() != null?child.getParent().getIndex(child): 0, treeDto, child.getUuid(), child.treeIndex(), child.getPath());
41

    
42
        if (child.getParent() != null){
43
            dto.setParentUuid(child.getParent().getUuid());
44
        }
45

    
46
        List<TermNodeDto> children = new ArrayList();
47
        for (Object o: child.getChildNodes()){
48
            if (o instanceof TermNode){
49
                TermNode childNode = (TermNode)o;
50

    
51
                if (childNode != null){
52
                    if(childNode.getTermType().equals(TermType.Character)){
53
                        children.add(CharacterNodeDto.fromTermNode(childNode, treeDto));
54
                    }else{
55
                        children.add(TermNodeDto.fromNode(childNode, treeDto));
56
                    }
57
                }
58
            }
59
        }
60
        dto.setChildren(children);
61
        dto.setOnlyApplicableIf(child.getOnlyApplicableIf());
62
        dto.setInapplicableIf(child.getInapplicableIf());
63

    
64
        dto.setTermType(child.getTermType());
65

    
66
        return dto;
67
    }
68
}
(4-4/29)