1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.rule.bo;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.kew.api.KewApiConstants;
20 import org.kuali.rice.kew.api.extension.ExtensionDefinition;
21 import org.kuali.rice.kew.api.extension.ExtensionDefinitionContract;
22 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
23 import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
24
25 import javax.persistence.Basic;
26 import javax.persistence.CascadeType;
27 import javax.persistence.Column;
28 import javax.persistence.Entity;
29 import javax.persistence.FetchType;
30 import javax.persistence.GeneratedValue;
31 import javax.persistence.Id;
32 import javax.persistence.Lob;
33 import javax.persistence.OneToMany;
34 import javax.persistence.Table;
35 import javax.persistence.Transient;
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40
41
42
43
44
45
46
47
48 @Entity
49 @Table(name="KREW_RULE_ATTR_T")
50 public class RuleAttribute extends PersistableBusinessObjectBase implements ExtensionDefinitionContract {
51
52 private static final long serialVersionUID = 1027673603158346349L;
53
54 @Id
55 @PortableSequenceGenerator(name="KREW_RTE_TMPL_S")
56 @GeneratedValue(generator="KREW_RTE_TMPL_S")
57 @Column(name="RULE_ATTR_ID")
58 private String id;
59 @Column(name="NM")
60 private String name;
61 @Column(name="LBL")
62 private String label;
63 @Column(name="RULE_ATTR_TYP_CD")
64 private String type;
65 @Column(name="CLS_NM")
66 private String resourceDescriptor;
67 @Column(name="DESC_TXT")
68 private String description;
69 @Lob
70 @Basic(fetch=FetchType.LAZY)
71 @Column(name="XML")
72 private String xmlConfigData;
73
74 @Column(name="APPL_ID")
75 private String applicationId;
76
77 @OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE},
78 targetEntity=RuleTemplateAttributeBo.class, mappedBy="ruleAttribute")
79 private List ruleTemplateAttributes;
80 @Transient
81 private List validValues;
82
83
84 @Transient
85 private String returnUrl;
86
87 public RuleAttribute() {
88 ruleTemplateAttributes = new ArrayList();
89 validValues = new ArrayList();
90 }
91
92 public List getValidValues() {
93 return validValues;
94 }
95 public void setValidValues(List ruleAttributeValidValues) {
96 this.validValues = ruleAttributeValidValues;
97 }
98 public List getRuleTemplateAttributes() {
99 return ruleTemplateAttributes;
100 }
101 public void setRuleTemplateAttributes(List ruleTemplateAttributes) {
102 this.ruleTemplateAttributes = ruleTemplateAttributes;
103 }
104 public String getDescription() {
105 return description;
106 }
107 public void setDescription(String description) {
108 this.description = description;
109 }
110 public String getLabel() {
111 return label;
112 }
113 public void setLabel(String label) {
114 this.label = label;
115 }
116
117 public String getName() {
118 return name;
119 }
120 public void setName(String name) {
121 this.name = name;
122 }
123 public String getId() {
124 return id;
125 }
126 public void setId(String id) {
127 this.id = id;
128 }
129 public String getType() {
130 return type;
131 }
132 public void setType(String type) {
133 this.type = type;
134 }
135
136
137
138
139 public String getResourceDescriptor() {
140 return resourceDescriptor;
141 }
142
143
144
145 public void setResourceDescriptor(String resourceDescriptor) {
146 this.resourceDescriptor = resourceDescriptor;
147 }
148
149 public String getRuleAttributeActionsUrl() {
150 return "<a href=\"RuleAttributeReport.do?id="+ id +"\" >report</a>";
151 }
152
153 public String getReturnUrl() {
154 return returnUrl;
155 }
156 public void setReturnUrl(String returnUrl) {
157 this.returnUrl = returnUrl;
158 }
159
160 public String getXmlConfigData() {
161 return xmlConfigData;
162 }
163
164 @Override
165 public Map<String, String> getConfiguration() {
166 Map<String, String> config = new HashMap<String, String>();
167 if (StringUtils.isNotBlank(getXmlConfigData())) {
168 config.put(KewApiConstants.ATTRIBUTE_XML_CONFIG_DATA, getXmlConfigData());
169 }
170 return config;
171 }
172
173 public void setXmlConfigData(String xmlConfigData) {
174 this.xmlConfigData = xmlConfigData;
175 }
176
177 @Override
178 public String getApplicationId() {
179 return applicationId;
180 }
181
182 public void setApplicationId(String applicationId) {
183 this.applicationId = applicationId;
184 }
185
186 public boolean isWorkflowAttribute() {
187 return isWorkflowAttribute(getType());
188 }
189
190 public static boolean isWorkflowAttribute(String type) {
191 return KewApiConstants.RULE_ATTRIBUTE_TYPE.equals(type) ||
192 KewApiConstants.RULE_XML_ATTRIBUTE_TYPE.equals(type);
193 }
194
195 public static ExtensionDefinition to(RuleAttribute ruleAttribute) {
196 if (ruleAttribute == null) {
197 return null;
198 }
199 return ExtensionDefinition.Builder.create(ruleAttribute).build();
200 }
201
202 public static RuleAttribute from(ExtensionDefinition im) {
203 if (im == null) {
204 return null;
205 }
206 RuleAttribute bo = new RuleAttribute();
207 bo.setApplicationId(im.getApplicationId());
208 bo.setDescription(im.getDescription());
209 bo.setResourceDescriptor(im.getResourceDescriptor());
210 bo.setId(im.getId());
211 bo.setLabel(im.getLabel());
212 bo.setType(im.getType());
213 bo.setVersionNumber(im.getVersionNumber());
214 bo.setXmlConfigData(im.getConfiguration().get(KewApiConstants.ATTRIBUTE_XML_CONFIG_DATA));
215
216 return bo;
217 }
218 }