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.krms.api.repository.term.TermDefinition;
20 import org.kuali.rice.krms.api.repository.term.TermDefinitionContract;
21 import org.kuali.rice.krms.api.repository.term.TermParameterDefinition;
22
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.ManyToOne;
30 import javax.persistence.OneToMany;
31 import javax.persistence.Table;
32 import javax.persistence.Transient;
33 import javax.persistence.Version;
34 import java.io.Serializable;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Map;
39 import java.util.Map.Entry;
40
41 @Entity
42 @Table(name = "KRMS_TERM_T")
43 public class TermBo implements TermDefinitionContract, Serializable {
44
45 private static final long serialVersionUID = 1l;
46
47 public static final String TERM_SEQ_NAME = "KRMS_TERM_S";
48
49 @PortableSequenceGenerator(name = TERM_SEQ_NAME) @GeneratedValue(generator = TERM_SEQ_NAME) @Id @Column(
50 name = "TERM_ID")
51 private String id;
52
53 @Column(name = "TERM_SPEC_ID")
54 private String specificationId;
55
56 @Column(name = "DESC_TXT")
57 private String description;
58
59 @Version @Column(name = "VER_NBR", length = 8)
60 protected Long versionNumber;
61
62
63 @ManyToOne(targetEntity = TermSpecificationBo.class, cascade = {CascadeType.REFRESH})
64 @JoinColumn(name = "TERM_SPEC_ID", referencedColumnName = "TERM_SPEC_ID", insertable = false, updatable = false)
65 private TermSpecificationBo specification = new TermSpecificationBo();
66
67 @OneToMany(targetEntity = TermParameterBo.class, orphanRemoval = true,
68 cascade = {CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST},
69 mappedBy = "term"
70 )
71 private List<TermParameterBo> parameters;
72
73 @Transient
74 private Map<String, String> parametersMap = new HashMap<String, String>();
75
76
77
78
79
80
81
82 public static TermDefinition to(TermBo bo) {
83 if (bo == null) {
84 return null;
85 }
86
87 return org.kuali.rice.krms.api.repository.term.TermDefinition.Builder.create(bo).build();
88 }
89
90
91
92
93
94
95
96 public static TermBo from(TermDefinition im) {
97 if (im == null) {
98 return null;
99 }
100
101 TermBo bo = new TermBo();
102 bo.id = im.getId();
103 bo.specificationId = im.getSpecification().getId();
104 bo.description = im.getDescription();
105 bo.specification = TermSpecificationBo.from(im.getSpecification());
106 bo.parameters = new ArrayList<TermParameterBo>();
107
108 for (TermParameterDefinition parm : im.getParameters()) {
109 TermParameterBo termParmBo = TermParameterBo.from(parm);
110 bo.parameters.add(termParmBo);
111 termParmBo.setTerm(bo);
112 }
113
114 bo.versionNumber = im.getVersionNumber();
115
116 return bo;
117 }
118
119 public TermSpecificationBo getSpecification() {
120 return specification;
121 }
122
123 public void setSpecification(TermSpecificationBo specification) {
124 this.specification = specification;
125 }
126
127 public List<TermParameterBo> getParameters() {
128 return parameters;
129 }
130
131 public Map<String, String> getParametersMap() {
132 return parametersMap;
133 }
134
135 public void setParameters(List<TermParameterBo> parameters) {
136 this.parameters = parameters;
137 }
138
139 public void exportToParametersMap() {
140
141 if (parameters != null) {
142 for (TermParameterBo param : parameters) {
143 parametersMap.put(param.getName(), param.getValue());
144 }
145 }
146 }
147
148 public void importFromParametersMap() {
149 if (parameters == null) {
150 parameters = new ArrayList<TermParameterBo>();
151 } else {
152 parameters.clear();
153 }
154
155 for (Entry<String, String> paramEntry : parametersMap.entrySet()) {
156 TermParameterDefinition termDef = TermParameterDefinition.Builder.create(null, id, paramEntry.getKey(),
157 paramEntry.getValue()).build();
158 parameters.add(TermParameterBo.from(termDef));
159 }
160 }
161
162 public String getDescription() {
163 return description;
164 }
165
166 public void setDescription(String description) {
167 this.description = description;
168 }
169
170 public String getSpecificationId() {
171 return specificationId;
172 }
173
174 public void setSpecificationId(String specificationId) {
175 this.specificationId = specificationId;
176 }
177
178 public String getId() {
179 return id;
180 }
181
182 public void setId(String id) {
183 this.id = id;
184 }
185
186 public Long getVersionNumber() {
187 return versionNumber;
188 }
189
190 public void setVersionNumber(Long versionNumber) {
191 this.versionNumber = versionNumber;
192 }
193 }