1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.repository;
17
18 import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
19 import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
20 import org.kuali.rice.krms.api.repository.category.CategoryDefinition;
21 import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
22 import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinitionContract;
23
24 import javax.persistence.CascadeType;
25 import javax.persistence.Column;
26 import javax.persistence.Convert;
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.Id;
30 import javax.persistence.JoinColumn;
31 import javax.persistence.JoinTable;
32 import javax.persistence.ManyToMany;
33 import javax.persistence.OneToMany;
34 import javax.persistence.Table;
35 import javax.persistence.Transient;
36 import javax.persistence.Version;
37 import java.io.Serializable;
38 import java.util.ArrayList;
39 import java.util.List;
40
41 @Entity
42 @Table(name = "KRMS_TERM_SPEC_T")
43 public class TermSpecificationBo implements TermSpecificationDefinitionContract, Serializable {
44
45 private static final long serialVersionUID = 1l;
46
47 @PortableSequenceGenerator(name = "KRMS_TERM_SPEC_S")
48 @GeneratedValue(generator = "KRMS_TERM_SPEC_S")
49 @Id
50 @Column(name = "TERM_SPEC_ID")
51 private String id;
52
53 @Column(name = "NM")
54 private String name;
55
56 @Column(name = "NMSPC_CD")
57 private String namespace;
58
59 @Column(name = "TYP")
60 private String type;
61
62 @Column(name = "DESC_TXT")
63 private String description;
64
65 @Column(name = "ACTV")
66 @Convert(converter = BooleanYNConverter.class)
67 private boolean active = true;
68
69 @Column(name = "VER_NBR")
70 @Version
71 private Long versionNumber;
72
73 @ManyToMany(targetEntity = CategoryBo.class, cascade = { CascadeType.REFRESH })
74 @JoinTable(name = "KRMS_TERM_SPEC_CTGRY_T",
75 joinColumns = { @JoinColumn(name = "TERM_SPEC_ID", referencedColumnName = "TERM_SPEC_ID") },
76 inverseJoinColumns = { @JoinColumn(name = "CTGRY_ID", referencedColumnName = "CTGRY_ID") })
77 private List<CategoryBo> categories = new ArrayList<CategoryBo>();
78
79 @OneToMany(orphanRemoval = true, mappedBy = "termSpecification")
80 private List<ContextValidTermBo> contextValidTerms = new ArrayList<ContextValidTermBo>();
81
82 @Transient
83 private List<String> contextIds = new ArrayList<String>();
84
85 @Transient
86 private List<ContextBo> contexts = new ArrayList<ContextBo>();
87
88
89
90
91
92
93
94 public static TermSpecificationDefinition to(TermSpecificationBo bo) {
95 if (bo == null) {
96 return null;
97 }
98
99 return TermSpecificationDefinition.Builder.create(bo).build();
100 }
101
102
103
104
105
106
107
108 public static TermSpecificationBo from(TermSpecificationDefinition im) {
109 if (im == null) {
110 return null;
111 }
112
113 TermSpecificationBo bo = new TermSpecificationBo();
114 bo.id = im.getId();
115 bo.namespace = im.getNamespace();
116 bo.name = im.getName();
117 bo.type = im.getType();
118 bo.description = im.getDescription();
119 bo.categories = new ArrayList<CategoryBo>();
120
121 for (CategoryDefinition category : im.getCategories()) {
122 bo.categories.add(CategoryBo.from(category));
123 }
124
125 bo.contextIds.addAll(im.getContextIds());
126 bo.active = im.isActive();
127 bo.setVersionNumber(im.getVersionNumber());
128
129 return bo;
130 }
131
132 public String getId() {
133 return id;
134 }
135
136 public void setId(String id) {
137 this.id = id;
138 }
139
140 public String getName() {
141 return name;
142 }
143
144 public void setName(String name) {
145 this.name = name;
146 }
147
148 public String getNamespace() {
149 return namespace;
150 }
151
152 public void setNamespace(String namespace) {
153 this.namespace = namespace;
154 }
155
156 public String getType() {
157 return type;
158 }
159
160 public void setType(String type) {
161 this.type = type;
162 }
163
164 public String getDescription() {
165 return description;
166 }
167
168 public void setDescription(String description) {
169 this.description = description;
170 }
171
172 public boolean getActive() {
173 return active;
174 }
175
176 public boolean isActive() {
177 return active;
178 }
179
180 public void setActive(boolean active) {
181 this.active = active;
182 }
183
184 public Long getVersionNumber() {
185 return versionNumber;
186 }
187
188 public void setVersionNumber(Long versionNumber) {
189 this.versionNumber = versionNumber;
190 }
191
192 public List<CategoryBo> getCategories() {
193 return categories;
194 }
195
196 public void setCategories(List<CategoryBo> categories) {
197 this.categories = categories;
198 }
199
200 public List<String> getContextIds() {
201 return contextIds;
202 }
203
204 public void setContextIds(List<String> contextIds) {
205 this.contextIds = contextIds;
206 }
207
208 public List<ContextBo> getContexts() {
209 return contexts;
210 }
211
212 public void setContexts(List<ContextBo> contexts) {
213 this.contexts = contexts;
214 }
215
216 public List<ContextValidTermBo> getContextValidTerms() {
217 return contextValidTerms;
218 }
219
220 public void setContextValidTerms(List<ContextValidTermBo> contextValidTerms) {
221 this.contextValidTerms = contextValidTerms;
222 }
223 }