1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.impl.responsibility;
17
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.Map;
21
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Convert;
25 import javax.persistence.Entity;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.Id;
28 import javax.persistence.Inheritance;
29 import javax.persistence.InheritanceType;
30 import javax.persistence.JoinColumn;
31 import javax.persistence.ManyToOne;
32 import javax.persistence.NamedQueries;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.OneToMany;
35 import javax.persistence.Table;
36 import javax.persistence.Transient;
37
38 import org.eclipse.persistence.annotations.JoinFetch;
39 import org.eclipse.persistence.annotations.JoinFetchType;
40 import org.kuali.rice.kew.api.KewApiConstants;
41 import org.kuali.rice.kim.api.KimConstants;
42 import org.kuali.rice.kim.api.responsibility.Responsibility;
43 import org.kuali.rice.kim.api.responsibility.ResponsibilityContract;
44 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
45 import org.kuali.rice.kim.api.type.KimType;
46 import org.kuali.rice.kim.api.type.KimTypeAttribute;
47 import org.kuali.rice.kim.api.type.KimTypeInfoService;
48 import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo;
49 import org.kuali.rice.kim.impl.role.RoleResponsibilityBo;
50 import org.kuali.rice.krad.bo.DataObjectBase;
51 import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
52 import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
53 import org.kuali.rice.krad.service.DataDictionaryService;
54 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
55 import org.kuali.rice.krad.util.KRADConstants;
56 import org.springframework.util.AutoPopulatingList;
57
58 @Entity
59 @Table(name = "KRIM_RSP_T")
60 @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
61 @NamedQueries({
62 @NamedQuery(name = "Responsibility.workflowResponsibilities",
63 query = "SELECT r.id FROM ResponsibilityBo r JOIN r.attributeDetails a WHERE " +
64 "a.kimAttribute.attributeName = 'documentTypeName' AND a.attributeValue = :documentTypeName AND " +
65 "r.template.namespaceCode = '" + KRADConstants.KUALI_RICE_WORKFLOW_NAMESPACE + "' AND " +
66 "r.template.name = '" + KewApiConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME + "' AND r.active = true"),
67 @NamedQuery(name = "Responsibility.workflowExceptionResponsibilities",
68 query = "SELECT r.id FROM ResponsibilityBo r JOIN r.attributeDetails a WHERE " +
69 "a.kimAttribute.attributeName = 'documentTypeName' AND a.attributeValue = :documentTypeName AND " +
70 "r.template.namespaceCode = '" + KRADConstants.KUALI_RICE_WORKFLOW_NAMESPACE + "' AND " +
71 "r.template.name = '" + KewApiConstants.EXCEPTION_ROUTING_RESPONSIBILITY_TEMPLATE_NAME + "' AND r.active = true")
72 })
73 public class ResponsibilityBo extends DataObjectBase implements ResponsibilityContract {
74
75 private static final long serialVersionUID = 1L;
76
77 @PortableSequenceGenerator(name = "KRIM_RSP_ID_S")
78 @GeneratedValue(generator = "KRIM_RSP_ID_S")
79 @Id
80 @Column(name = "RSP_ID")
81 String id;
82
83 @Column(name = "NMSPC_CD")
84 String namespaceCode;
85
86 @Column(name = "NM")
87 String name;
88
89 @Column(name = "DESC_TXT")
90 String description;
91
92 @Column(name = "RSP_TMPL_ID")
93 String templateId;
94
95 @Column(name = "ACTV_IND")
96 @Convert(converter = BooleanYNConverter.class)
97 boolean active;
98
99 @JoinFetch(value= JoinFetchType.OUTER)
100 @ManyToOne(targetEntity = ResponsibilityTemplateBo.class, cascade = { CascadeType.REFRESH })
101 @JoinColumn(name = "RSP_TMPL_ID", referencedColumnName = "RSP_TMPL_ID", insertable = false, updatable = false)
102 ResponsibilityTemplateBo template = new ResponsibilityTemplateBo();
103
104 @JoinFetch(value= JoinFetchType.OUTER)
105 @OneToMany(targetEntity = ResponsibilityAttributeBo.class, orphanRemoval = true, cascade = { CascadeType.ALL })
106 @JoinColumn(name = "RSP_ID", referencedColumnName = "RSP_ID")
107 List<ResponsibilityAttributeBo> attributeDetails = new AutoPopulatingList<ResponsibilityAttributeBo>(ResponsibilityAttributeBo.class);
108
109 @JoinFetch(value= JoinFetchType.OUTER)
110 @OneToMany(mappedBy = "kimResponsibility")
111 @JoinColumn(name = "RSP_ID", referencedColumnName = "RSP_ID", insertable = false, updatable = false)
112 List<RoleResponsibilityBo> roleResponsibilities = new AutoPopulatingList<RoleResponsibilityBo>(RoleResponsibilityBo.class);
113
114 @Transient
115 Map<String, String> attributes;
116
117 @Override
118 public Map<String, String> getAttributes() {
119 return attributeDetails != null ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes;
120 }
121
122
123
124
125
126
127
128 public static Responsibility to(ResponsibilityContract bo) {
129 if (bo == null) {
130 return null;
131 }
132 return Responsibility.Builder.create(bo).build();
133 }
134
135
136
137
138
139
140
141 public static ResponsibilityBo from(Responsibility im) {
142 if (im == null) {
143 return null;
144 }
145 ResponsibilityBo bo = new ResponsibilityBo();
146 bo.id = im.getId();
147 bo.namespaceCode = im.getNamespaceCode();
148 bo.name = im.getName();
149 bo.description = im.getDescription();
150 bo.active = im.isActive();
151 bo.templateId = im.getTemplate() != null ? im.getTemplate().getId() : null;
152 bo.template = ResponsibilityTemplateBo.from(im.getTemplate());
153 bo.attributes = im.getAttributes();
154 bo.setVersionNumber(im.getVersionNumber());
155 bo.setObjectId(im.getObjectId());
156 return bo;
157 }
158
159 @Override
160 public ResponsibilityTemplateBo getTemplate() {
161 return template;
162 }
163
164 public String getDetailObjectsValues() {
165 StringBuffer detailObjectsToDisplayBuffer = new StringBuffer();
166 Iterator<ResponsibilityAttributeBo> respIter = attributeDetails.iterator();
167 while (respIter.hasNext()) {
168 ResponsibilityAttributeBo respAttributeData = respIter.next();
169 detailObjectsToDisplayBuffer.append(respAttributeData.getAttributeValue());
170 if (respIter.hasNext()) {
171 detailObjectsToDisplayBuffer.append(KimConstants.KimUIConstants.COMMA_SEPARATOR);
172 }
173 }
174 return detailObjectsToDisplayBuffer.toString();
175 }
176
177 public String getDetailObjectsToDisplay() {
178 final KimType kimType = getTypeInfoService().getKimType(getTemplate().getKimTypeId());
179 StringBuffer detailObjects = new StringBuffer();
180 Iterator<ResponsibilityAttributeBo> respIter = attributeDetails.iterator();
181 while (respIter.hasNext()) {
182 ResponsibilityAttributeBo bo = respIter.next();
183 detailObjects.append(getKimAttributeLabelFromDD(kimType.getAttributeDefinitionById(bo.getKimAttributeId()))).append(":").append(bo.getAttributeValue());
184 if (respIter.hasNext()) {
185 detailObjects.append(KimConstants.KimUIConstants.COMMA_SEPARATOR);
186 }
187 }
188 return detailObjects.toString();
189 }
190
191 private String getKimAttributeLabelFromDD(KimTypeAttribute attribute) {
192 return getDataDictionaryService().getAttributeLabel(attribute.getKimAttribute().getComponentName(), attribute.getKimAttribute().getAttributeName());
193 }
194
195 private DataDictionaryService getDataDictionaryService() {
196 return KRADServiceLocatorWeb.getDataDictionaryService();
197 }
198
199 private KimTypeInfoService getTypeInfoService() {
200 return KimApiServiceLocator.getKimTypeInfoService();
201 }
202
203 @Override
204 public String getId() {
205 return id;
206 }
207
208 public void setId(String id) {
209 this.id = id;
210 }
211
212 @Override
213 public String getNamespaceCode() {
214 return namespaceCode;
215 }
216
217 public void setNamespaceCode(String namespaceCode) {
218 this.namespaceCode = namespaceCode;
219 }
220
221 @Override
222 public String getName() {
223 return name;
224 }
225
226 public void setName(String name) {
227 this.name = name;
228 }
229
230 @Override
231 public String getDescription() {
232 return description;
233 }
234
235 public void setDescription(String description) {
236 this.description = description;
237 }
238
239 public String getTemplateId() {
240 return templateId;
241 }
242
243 public void setTemplateId(String templateId) {
244 this.templateId = templateId;
245 }
246
247 public boolean getActive() {
248 return active;
249 }
250
251 @Override
252 public boolean isActive() {
253 return active;
254 }
255
256 public void setActive(boolean active) {
257 this.active = active;
258 }
259
260 public void setTemplate(ResponsibilityTemplateBo template) {
261 this.template = template;
262 }
263
264 public List<ResponsibilityAttributeBo> getAttributeDetails() {
265 return attributeDetails;
266 }
267
268 public void setAttributeDetails(List<ResponsibilityAttributeBo> attributeDetails) {
269 this.attributeDetails = attributeDetails;
270 }
271
272 public List<RoleResponsibilityBo> getRoleResponsibilities() {
273 return roleResponsibilities;
274 }
275
276 public void setRoleResponsibilities(List<RoleResponsibilityBo> roleResponsibilities) {
277 this.roleResponsibilities = roleResponsibilities;
278 }
279
280 public void setAttributes(Map<String, String> attributes) {
281 this.attributes = attributes;
282 }
283 }