Revision 4d68581f
Added by Katja Luther over 3 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/CharacterNodeDto.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.persistence.dto; |
10 | 10 |
|
11 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
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; |
|
12 | 20 |
|
13 | 21 |
/** |
14 | 22 |
* @author k.luther |
15 | 23 |
* @since Oct 9, 2020 |
16 | 24 |
*/ |
17 |
public class CharacterNodeDto extends TermNodeDto<Feature> {
|
|
25 |
public class CharacterNodeDto extends TermNodeDto { |
|
18 | 26 |
|
19 | 27 |
private static final long serialVersionUID = 7635704848569122836L; |
20 | 28 |
|
... | ... | |
23 | 31 |
* @param parent |
24 | 32 |
* @param position |
25 | 33 |
*/ |
26 |
public CharacterNodeDto(CharacterDto characterDto, TermNodeDto parent, int position, TermTreeDto treeDto) { |
|
27 |
super(characterDto, parent, position, treeDto); |
|
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) { |
|
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, TermTreeDto.fromTree(child.getGraph()), 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)); |
|
54 |
}else{ |
|
55 |
children.add(TermNodeDto.fromNode(childNode)); |
|
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 |
|
|
28 | 69 |
} |
29 | 70 |
|
30 | 71 |
|
Also available in: Unified diff
ref #8774: further implementations for using term dtos in editor