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.MERGE, 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 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 if (parametersMap == null || parametersMap.isEmpty()) {
153 for (TermParameterBo param : parameters) {
154 parametersMap.put(param.getName(), param.getValue());
155 }
156 }
157 parameters.clear();
158 }
159
160 for (Entry<String, String> paramEntry : parametersMap.entrySet()) {
161 TermParameterDefinition termDef = TermParameterDefinition.Builder.create(null, id, paramEntry.getKey(),
162 paramEntry.getValue()).build();
163 parameters.add(TermParameterBo.from(termDef));
164 }
165 }
166
167 public String getDescription() {
168 return description;
169 }
170
171 public void setDescription(String description) {
172 this.description = description;
173 }
174
175 public String getSpecificationId() {
176 return specificationId;
177 }
178
179 public void setSpecificationId(String specificationId) {
180 this.specificationId = specificationId;
181 }
182
183 public String getId() {
184 return id;
185 }
186
187 public void setId(String id) {
188 this.id = id;
189 }
190
191 public Long getVersionNumber() {
192 return versionNumber;
193 }
194
195 public void setVersionNumber(Long versionNumber) {
196 this.versionNumber = versionNumber;
197 }
198 }