1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.datamodel.classifications2.model;
20
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.stream.Collectors;
24
25 import org.mycore.datamodel.classifications2.MCRCategory;
26 import org.mycore.datamodel.classifications2.MCRCategoryID;
27 import org.mycore.datamodel.classifications2.MCRLabel;
28
29 import com.fasterxml.jackson.annotation.JsonGetter;
30 import com.fasterxml.jackson.annotation.JsonInclude;
31 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
32
33 import jakarta.xml.bind.annotation.XmlAccessType;
34 import jakarta.xml.bind.annotation.XmlAccessorType;
35 import jakarta.xml.bind.annotation.XmlAttribute;
36 import jakarta.xml.bind.annotation.XmlElement;
37 import jakarta.xml.bind.annotation.XmlRootElement;
38 import jakarta.xml.bind.annotation.XmlSeeAlso;
39 import jakarta.xml.bind.annotation.XmlType;
40 import jakarta.xml.bind.annotation.adapters.NormalizedStringAdapter;
41 import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
42
43 @XmlAccessorType(XmlAccessType.FIELD)
44 @XmlType(name = "MCRClassCategory",
45 propOrder = {
46 "label",
47 "url",
48 "category"
49 })
50 @XmlSeeAlso({ MCRLabel.class, MCRClassURL.class })
51 @XmlRootElement(name = "category")
52 @JsonInclude(value = JsonInclude.Include.NON_EMPTY)
53 @JsonPropertyOrder({ "ID", "url", "labels", "categories" })
54 public class MCRClassCategory {
55
56 @XmlElement(required = true)
57 protected List<MCRLabel> label;
58
59 protected MCRClassURL url;
60
61 protected List<MCRClassCategory> category;
62
63 @XmlAttribute(name = "ID", required = true)
64 @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
65 protected String id;
66
67 @JsonGetter("labels")
68 public List<MCRLabel> getLabel() {
69 if (label == null) {
70 label = new ArrayList<>();
71 }
72 return this.label;
73 }
74
75 public MCRClassURL getUrl() {
76 return url;
77 }
78
79 public void setUrl(MCRClassURL value) {
80 this.url = value;
81 }
82
83 @JsonGetter("categories")
84 public List<MCRClassCategory> getCategory() {
85 if (category == null) {
86 category = new ArrayList<>();
87 }
88 return this.category;
89 }
90
91 @JsonGetter
92 public String getID() {
93 return id;
94 }
95
96 public void setID(String value) {
97 this.id = value;
98 }
99
100 public static MCRClassCategory getInstance(MCRCategory from) {
101 MCRClassCategory categ = new MCRClassCategory();
102 MCRCategoryID categoryID = from.getId();
103 categ.setID(categoryID.isRootID() ? categoryID.getRootID() : categoryID.getID());
104 categ.setUrl(MCRClassURL.getInstance(from.getURI()));
105 categ.getCategory()
106 .addAll(getInstance(from.getChildren()));
107 categ.getLabel()
108 .addAll(
109 from.getLabels()
110 .stream()
111 .map(MCRLabel::clone)
112 .collect(Collectors.toList()));
113 return categ;
114 }
115
116 public static List<MCRClassCategory> getInstance(List<MCRCategory> children) {
117 return children
118 .stream()
119 .map(MCRClassCategory::getInstance)
120 .collect(Collectors.toList());
121 }
122
123 }