1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.xml; |
18 | |
|
19 | |
import java.io.IOException; |
20 | |
import java.io.InputStream; |
21 | |
import java.sql.Timestamp; |
22 | |
import java.text.ParseException; |
23 | |
import java.util.ArrayList; |
24 | |
import java.util.Iterator; |
25 | |
import java.util.List; |
26 | |
import java.util.Vector; |
27 | |
|
28 | |
import javax.xml.parsers.ParserConfigurationException; |
29 | |
|
30 | |
import org.apache.commons.lang.BooleanUtils; |
31 | |
import org.apache.commons.lang.StringUtils; |
32 | |
import org.jdom.Attribute; |
33 | |
import org.jdom.Document; |
34 | |
import org.jdom.Element; |
35 | |
import org.jdom.JDOMException; |
36 | |
import org.kuali.rice.core.util.RiceConstants; |
37 | |
import org.kuali.rice.kew.exception.InvalidXmlException; |
38 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
39 | |
import org.kuali.rice.kew.rule.RuleDelegation; |
40 | |
import org.kuali.rice.kew.rule.RuleTemplateOption; |
41 | |
import org.kuali.rice.kew.rule.bo.RuleAttribute; |
42 | |
import org.kuali.rice.kew.rule.bo.RuleTemplate; |
43 | |
import org.kuali.rice.kew.rule.bo.RuleTemplateAttribute; |
44 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
45 | |
import org.kuali.rice.kew.util.KEWConstants; |
46 | |
import org.kuali.rice.kew.util.Utilities; |
47 | |
import org.kuali.rice.kew.util.XmlHelper; |
48 | |
import org.xml.sax.SAXException; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | 0 | public class RuleTemplateXmlParser implements XmlConstants { |
59 | |
|
60 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RuleTemplateXmlParser.class); |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
private static final boolean DEFAULT_ATTRIBUTE_REQUIRED = true; |
66 | |
private static final boolean DEFAULT_ATTRIBUTE_ACTIVE = true; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
private static final String DUMMY_DOCUMENT_TYPE = "dummyDocumentType"; |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | 0 | private int templateAttributeCounter = 0; |
77 | |
|
78 | |
public List<RuleTemplate> parseRuleTemplates(InputStream input) throws IOException, InvalidXmlException { |
79 | |
|
80 | |
try { |
81 | 0 | Document doc = XmlHelper.trimSAXXml(input); |
82 | 0 | Element root = doc.getRootElement(); |
83 | 0 | return parseRuleTemplates(root); |
84 | 0 | } catch (JDOMException e) { |
85 | 0 | throw new InvalidXmlException("Parse error.", e); |
86 | 0 | } catch (SAXException e) { |
87 | 0 | throw new InvalidXmlException("Parse error.", e); |
88 | 0 | } catch (ParserConfigurationException e) { |
89 | 0 | throw new InvalidXmlException("Parse error.", e); |
90 | |
} |
91 | |
} |
92 | |
|
93 | |
public List<RuleTemplate> parseRuleTemplates(Element element) throws InvalidXmlException { |
94 | 0 | List<RuleTemplate> ruleTemplates = new ArrayList<RuleTemplate>(); |
95 | |
|
96 | |
|
97 | 0 | Vector ruleTemplatesElements = XmlHelper.findElements(element, RULE_TEMPLATES); |
98 | 0 | Iterator ruleTemplatesIterator = ruleTemplatesElements.iterator(); |
99 | 0 | while (ruleTemplatesIterator.hasNext()) { |
100 | 0 | Element ruleTemplatesElement = (Element) ruleTemplatesIterator.next(); |
101 | 0 | Vector ruleTemplateElements = XmlHelper.findElements(ruleTemplatesElement, RULE_TEMPLATE); |
102 | 0 | for (Iterator iterator = ruleTemplateElements.iterator(); iterator.hasNext();) { |
103 | 0 | ruleTemplates.add(parseRuleTemplate((Element) iterator.next(), ruleTemplates)); |
104 | |
} |
105 | 0 | } |
106 | 0 | return ruleTemplates; |
107 | |
} |
108 | |
|
109 | |
private RuleTemplate parseRuleTemplate(Element element, List<RuleTemplate> ruleTemplates) throws InvalidXmlException { |
110 | 0 | String name = element.getChildText(NAME, RULE_TEMPLATE_NAMESPACE); |
111 | 0 | String description = element.getChildText(DESCRIPTION, RULE_TEMPLATE_NAMESPACE); |
112 | 0 | Attribute allowOverwriteAttrib = element.getAttribute("allowOverwrite"); |
113 | |
|
114 | 0 | boolean allowOverwrite = false; |
115 | 0 | if (allowOverwriteAttrib != null) { |
116 | 0 | allowOverwrite = Boolean.valueOf(allowOverwriteAttrib.getValue()).booleanValue(); |
117 | |
} |
118 | 0 | if (Utilities.isEmpty(name)) { |
119 | 0 | throw new InvalidXmlException("RuleTemplate must have a name"); |
120 | |
} |
121 | 0 | if (Utilities.isEmpty(description)) { |
122 | 0 | throw new InvalidXmlException("RuleTemplate must have a description"); |
123 | |
} |
124 | |
|
125 | |
|
126 | 0 | RuleTemplate ruleTemplate = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(name); |
127 | |
|
128 | 0 | if (ruleTemplate == null) { |
129 | |
|
130 | 0 | ruleTemplate = new RuleTemplate(); |
131 | |
} else { |
132 | |
|
133 | 0 | if (!allowOverwrite) { |
134 | 0 | throw new RuntimeException("Attempting to overwrite template " + name + " without allowOverwrite set"); |
135 | |
} |
136 | |
|
137 | |
|
138 | 0 | assert(name.equals(ruleTemplate.getName())) : "Existing template definition name does not match incoming definition name"; |
139 | |
} |
140 | |
|
141 | |
|
142 | 0 | ruleTemplate.setName(name); |
143 | 0 | ruleTemplate.setDescription(description); |
144 | |
|
145 | |
|
146 | 0 | updateDelegationTemplate(element, ruleTemplate, ruleTemplates); |
147 | |
|
148 | |
|
149 | 0 | updateRuleTemplateAttributes(element, ruleTemplate); |
150 | |
|
151 | |
|
152 | |
|
153 | 0 | KEWServiceLocator.getRuleTemplateService().save(ruleTemplate); |
154 | |
|
155 | |
|
156 | 0 | updateRuleTemplateDefaultOptions(element, ruleTemplate); |
157 | |
|
158 | 0 | KEWServiceLocator.getRuleTemplateService().save(ruleTemplate); |
159 | |
|
160 | 0 | return ruleTemplate; |
161 | |
} |
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
protected void updateRuleTemplateDefaultOptions(Element ruleTemplateElement, RuleTemplate updatedRuleTemplate) throws InvalidXmlException { |
182 | 0 | Element defaultsElement = ruleTemplateElement.getChild(RULE_DEFAULTS, RULE_TEMPLATE_NAMESPACE); |
183 | |
|
184 | |
|
185 | 0 | boolean isDelegation = updateRuleDefaults(defaultsElement, updatedRuleTemplate); |
186 | |
|
187 | |
|
188 | 0 | updateRuleTemplateOptions(defaultsElement, updatedRuleTemplate, isDelegation); |
189 | |
|
190 | 0 | } |
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
protected void updateRuleTemplateOptions(Element defaultsElement, RuleTemplate updatedRuleTemplate, boolean isDelegation) throws InvalidXmlException { |
198 | |
|
199 | |
|
200 | |
|
201 | 0 | String defaultActionRequested = null; |
202 | 0 | Boolean supportsComplete = null; |
203 | 0 | Boolean supportsApprove = null; |
204 | 0 | Boolean supportsAcknowledge = null; |
205 | 0 | Boolean supportsFYI = null; |
206 | |
|
207 | |
|
208 | |
|
209 | 0 | updatedRuleTemplate.removeNonDefaultOptions(); |
210 | |
|
211 | |
|
212 | 0 | if (defaultsElement != null) { |
213 | |
|
214 | 0 | defaultActionRequested = defaultsElement.getChildText(DEFAULT_ACTION_REQUESTED, RULE_TEMPLATE_NAMESPACE); |
215 | 0 | supportsComplete = BooleanUtils.toBooleanObject(defaultsElement.getChildText(SUPPORTS_COMPLETE, RULE_TEMPLATE_NAMESPACE)); |
216 | 0 | supportsApprove = BooleanUtils.toBooleanObject(defaultsElement.getChildText(SUPPORTS_APPROVE, RULE_TEMPLATE_NAMESPACE)); |
217 | 0 | supportsAcknowledge = BooleanUtils.toBooleanObject(defaultsElement.getChildText(SUPPORTS_ACKNOWLEDGE, RULE_TEMPLATE_NAMESPACE)); |
218 | 0 | supportsFYI = BooleanUtils.toBooleanObject(defaultsElement.getChildText(SUPPORTS_FYI, RULE_TEMPLATE_NAMESPACE)); |
219 | |
} |
220 | |
|
221 | 0 | if (!isDelegation) { |
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | 0 | updateOrDeleteRuleTemplateOption(updatedRuleTemplate, KEWConstants.ACTION_REQUEST_DEFAULT_CD, defaultActionRequested); |
232 | 0 | updateOrDeleteRuleTemplateOption(updatedRuleTemplate, KEWConstants.ACTION_REQUEST_APPROVE_REQ, supportsApprove); |
233 | 0 | updateOrDeleteRuleTemplateOption(updatedRuleTemplate, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, supportsAcknowledge); |
234 | 0 | updateOrDeleteRuleTemplateOption(updatedRuleTemplate, KEWConstants.ACTION_REQUEST_FYI_REQ, supportsFYI); |
235 | 0 | updateOrDeleteRuleTemplateOption(updatedRuleTemplate, KEWConstants.ACTION_REQUEST_COMPLETE_REQ, supportsComplete); |
236 | |
} |
237 | |
|
238 | 0 | } |
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
protected boolean updateRuleDefaults(Element defaultsElement, RuleTemplate updatedRuleTemplate) throws InvalidXmlException { |
248 | |
|
249 | |
|
250 | 0 | if (updatedRuleTemplate.getRuleTemplateId() != null) { |
251 | 0 | RuleBaseValues ruleDefaults = KEWServiceLocator.getRuleService().findDefaultRuleByRuleTemplateId(updatedRuleTemplate.getRuleTemplateId()); |
252 | 0 | if (ruleDefaults != null) { |
253 | 0 | List ruleDelegationDefaults = KEWServiceLocator.getRuleDelegationService().findByDelegateRuleId(ruleDefaults.getRuleBaseValuesId()); |
254 | |
|
255 | 0 | KEWServiceLocator.getRuleService().delete(ruleDefaults.getRuleBaseValuesId()); |
256 | |
|
257 | 0 | for (Iterator iterator = ruleDelegationDefaults.iterator(); iterator.hasNext();) { |
258 | 0 | RuleDelegation ruleDelegation = (RuleDelegation) iterator.next(); |
259 | 0 | KEWServiceLocator.getRuleDelegationService().delete(ruleDelegation.getRuleDelegationId()); |
260 | 0 | } |
261 | |
} |
262 | |
} |
263 | |
|
264 | 0 | boolean isDelegation = false; |
265 | |
|
266 | 0 | if (defaultsElement != null) { |
267 | 0 | String delegationType = defaultsElement.getChildText(DELEGATION_TYPE, RULE_TEMPLATE_NAMESPACE); |
268 | 0 | isDelegation = !Utilities.isEmpty(delegationType); |
269 | |
|
270 | 0 | String description = defaultsElement.getChildText(DESCRIPTION, RULE_TEMPLATE_NAMESPACE); |
271 | |
|
272 | |
|
273 | 0 | if (description == null) { |
274 | 0 | throw new InvalidXmlException("Description must be specified in rule defaults"); |
275 | |
} |
276 | |
|
277 | 0 | String fromDate = defaultsElement.getChildText(FROM_DATE, RULE_TEMPLATE_NAMESPACE); |
278 | 0 | String toDate = defaultsElement.getChildText(TO_DATE, RULE_TEMPLATE_NAMESPACE); |
279 | |
|
280 | 0 | Boolean forceAction = BooleanUtils.toBooleanObject(defaultsElement.getChildText(FORCE_ACTION, RULE_TEMPLATE_NAMESPACE)); |
281 | 0 | Boolean active = BooleanUtils.toBooleanObject(defaultsElement.getChildText(ACTIVE, RULE_TEMPLATE_NAMESPACE)); |
282 | |
|
283 | 0 | if (isDelegation && !KEWConstants.DELEGATION_PRIMARY.equals(delegationType) && !KEWConstants.DELEGATION_SECONDARY.equals(delegationType)) { |
284 | 0 | throw new InvalidXmlException("Invalid delegation type '" + delegationType + "'." + " Expected one of: " |
285 | |
+ KEWConstants.DELEGATION_PRIMARY + "," + KEWConstants.DELEGATION_SECONDARY); |
286 | |
} |
287 | |
|
288 | |
|
289 | 0 | RuleBaseValues ruleDefaults = new RuleBaseValues(); |
290 | |
|
291 | |
|
292 | 0 | ruleDefaults.setRuleTemplate(updatedRuleTemplate); |
293 | 0 | ruleDefaults.setDocTypeName(DUMMY_DOCUMENT_TYPE); |
294 | 0 | ruleDefaults.setTemplateRuleInd(Boolean.TRUE); |
295 | 0 | ruleDefaults.setCurrentInd(Boolean.TRUE); |
296 | 0 | ruleDefaults.setVersionNbr(new Integer(0)); |
297 | 0 | ruleDefaults.setDescription(description); |
298 | |
|
299 | |
|
300 | 0 | ruleDefaults.setForceAction(Boolean.valueOf(BooleanUtils.isTrue(forceAction))); |
301 | 0 | ruleDefaults.setActiveInd(Boolean.valueOf(BooleanUtils.isTrue(active))); |
302 | |
|
303 | 0 | if (ruleDefaults.getActivationDate() == null) { |
304 | 0 | ruleDefaults.setActivationDate(new Timestamp(System.currentTimeMillis())); |
305 | |
} |
306 | |
|
307 | 0 | ruleDefaults.setFromDate(formatDate("fromDate",fromDate)); |
308 | 0 | ruleDefaults.setToDate(formatDate("toDate", toDate)); |
309 | |
|
310 | |
|
311 | |
|
312 | 0 | RuleDelegation ruleDelegationDefaults = null; |
313 | 0 | if (isDelegation) { |
314 | 0 | ruleDelegationDefaults = new RuleDelegation(); |
315 | 0 | ruleDelegationDefaults.setDelegationRuleBaseValues(ruleDefaults); |
316 | 0 | ruleDelegationDefaults.setDelegationType(delegationType); |
317 | 0 | ruleDelegationDefaults.setResponsibilityId(new Long(-1)); |
318 | |
} |
319 | |
|
320 | |
|
321 | 0 | KEWServiceLocator.getRuleTemplateService().saveRuleDefaults(ruleDelegationDefaults, ruleDefaults); |
322 | |
} else { |
323 | |
|
324 | |
} |
325 | |
|
326 | 0 | return isDelegation; |
327 | |
} |
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
protected void updateOrDeleteRuleTemplateOption(RuleTemplate updatedRuleTemplate, String key, Object value) { |
337 | 0 | if (value != null) { |
338 | |
|
339 | 0 | RuleTemplateOption option = updatedRuleTemplate.getRuleTemplateOption(key); |
340 | 0 | if (option != null) { |
341 | 0 | option.setValue(value.toString()); |
342 | |
} else { |
343 | 0 | updatedRuleTemplate.getRuleTemplateOptions().add(new RuleTemplateOption(key, value.toString())); |
344 | |
} |
345 | 0 | } else { |
346 | |
|
347 | 0 | Iterator<RuleTemplateOption> options = updatedRuleTemplate.getRuleTemplateOptions().iterator(); |
348 | 0 | while (options.hasNext()) { |
349 | 0 | RuleTemplateOption opt = options.next(); |
350 | 0 | if (key.equals(opt.getKey())) { |
351 | 0 | options.remove(); |
352 | 0 | break; |
353 | |
} |
354 | 0 | } |
355 | |
} |
356 | 0 | } |
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
protected void updateDelegationTemplate(Element ruleTemplateElement, RuleTemplate updatedRuleTemplate, List<RuleTemplate> parsedRuleTemplates) throws InvalidXmlException { |
366 | 0 | String delegateTemplateName = ruleTemplateElement.getChildText(DELEGATION_TEMPLATE, RULE_TEMPLATE_NAMESPACE); |
367 | |
|
368 | 0 | if (delegateTemplateName != null) { |
369 | |
|
370 | |
|
371 | 0 | RuleTemplate delegateTemplate = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(delegateTemplateName); |
372 | |
|
373 | |
|
374 | 0 | if (delegateTemplate == null) { |
375 | 0 | for (RuleTemplate rt: parsedRuleTemplates) { |
376 | 0 | if (delegateTemplateName.equalsIgnoreCase(rt.getName())) { |
377 | |
|
378 | 0 | Long ruleTemplateId = KEWServiceLocator.getRuleTemplateService().getNextRuleTemplateId(); |
379 | 0 | rt.setRuleTemplateId(ruleTemplateId); |
380 | 0 | delegateTemplate = rt; |
381 | 0 | break; |
382 | |
} |
383 | |
} |
384 | |
} |
385 | |
|
386 | 0 | if (delegateTemplate == null) { |
387 | 0 | throw new InvalidXmlException("Cannot find delegation template " + delegateTemplateName); |
388 | |
} |
389 | |
|
390 | 0 | updatedRuleTemplate.setDelegationTemplateId(delegateTemplate.getDelegationTemplateId()); |
391 | 0 | updatedRuleTemplate.setDelegationTemplate(delegateTemplate); |
392 | |
} else { |
393 | |
|
394 | |
} |
395 | 0 | } |
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | |
protected void updateRuleTemplateAttributes(Element ruleTemplateElement, RuleTemplate updatedRuleTemplate) throws InvalidXmlException { |
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | 0 | Element attributesElement = ruleTemplateElement.getChild(ATTRIBUTES, RULE_TEMPLATE_NAMESPACE); |
410 | 0 | List<RuleTemplateAttribute> incomingAttributes = new ArrayList<RuleTemplateAttribute>(); |
411 | 0 | if (attributesElement != null) { |
412 | 0 | incomingAttributes.addAll(parseRuleTemplateAttributes(attributesElement, updatedRuleTemplate)); |
413 | |
} |
414 | |
|
415 | |
|
416 | 0 | for (RuleTemplateAttribute currentRuleTemplateAttribute: updatedRuleTemplate.getRuleTemplateAttributes()) { |
417 | 0 | String ruleAttributeName = (currentRuleTemplateAttribute.getRuleAttribute() != null) ? currentRuleTemplateAttribute.getRuleAttribute().getName() : "(null)"; |
418 | 0 | LOG.debug("Inactivating rule template attribute with id " + currentRuleTemplateAttribute.getRuleTemplateAttributeId() + " and rule attribute with name " + ruleAttributeName); |
419 | 0 | currentRuleTemplateAttribute.setActive(Boolean.FALSE); |
420 | 0 | } |
421 | |
|
422 | |
|
423 | |
|
424 | 0 | for (RuleTemplateAttribute ruleTemplateAttribute: incomingAttributes) { |
425 | 0 | RuleTemplateAttribute potentialExistingTemplateAttribute = updatedRuleTemplate.getRuleTemplateAttribute(ruleTemplateAttribute); |
426 | 0 | if (potentialExistingTemplateAttribute != null) { |
427 | |
|
428 | 0 | potentialExistingTemplateAttribute.setActive(ruleTemplateAttribute.getActive()); |
429 | 0 | potentialExistingTemplateAttribute.setRequired(ruleTemplateAttribute.getRequired()); |
430 | |
} else { |
431 | |
|
432 | 0 | updatedRuleTemplate.getRuleTemplateAttributes().add(ruleTemplateAttribute); |
433 | |
} |
434 | 0 | } |
435 | 0 | } |
436 | |
|
437 | |
|
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
private List<RuleTemplateAttribute> parseRuleTemplateAttributes(Element attributesElement, RuleTemplate ruleTemplate) throws InvalidXmlException { |
445 | 0 | List<RuleTemplateAttribute> ruleTemplateAttributes = new ArrayList<RuleTemplateAttribute>(); |
446 | 0 | Vector attributeElements = XmlHelper.findElements(attributesElement, ATTRIBUTE); |
447 | 0 | for (Iterator iterator = attributeElements.iterator(); iterator.hasNext();) { |
448 | 0 | ruleTemplateAttributes.add(parseRuleTemplateAttribute((Element) iterator.next(), ruleTemplate)); |
449 | |
} |
450 | 0 | return ruleTemplateAttributes; |
451 | |
} |
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
private RuleTemplateAttribute parseRuleTemplateAttribute(Element element, RuleTemplate ruleTemplate) throws InvalidXmlException { |
461 | 0 | String attributeName = element.getChildText(NAME, RULE_TEMPLATE_NAMESPACE); |
462 | 0 | String requiredValue = element.getChildText(REQUIRED, RULE_TEMPLATE_NAMESPACE); |
463 | 0 | String activeValue = element.getChildText(ACTIVE, RULE_TEMPLATE_NAMESPACE); |
464 | 0 | if (Utilities.isEmpty(attributeName)) { |
465 | 0 | throw new InvalidXmlException("Attribute name must be non-empty"); |
466 | |
} |
467 | 0 | boolean required = DEFAULT_ATTRIBUTE_REQUIRED; |
468 | 0 | if (requiredValue != null) { |
469 | 0 | required = Boolean.parseBoolean(requiredValue); |
470 | |
} |
471 | 0 | boolean active = DEFAULT_ATTRIBUTE_ACTIVE; |
472 | 0 | if (activeValue != null) { |
473 | 0 | active = Boolean.parseBoolean(activeValue); |
474 | |
} |
475 | 0 | RuleAttribute ruleAttribute = KEWServiceLocator.getRuleAttributeService().findByName(attributeName); |
476 | 0 | if (ruleAttribute == null) { |
477 | 0 | throw new InvalidXmlException("Could not locate rule attribute for name '" + attributeName + "'"); |
478 | |
} |
479 | 0 | RuleTemplateAttribute templateAttribute = new RuleTemplateAttribute(); |
480 | 0 | templateAttribute.setRuleAttribute(ruleAttribute); |
481 | 0 | templateAttribute.setRuleAttributeId(ruleAttribute.getRuleAttributeId()); |
482 | 0 | templateAttribute.setRuleTemplate(ruleTemplate); |
483 | 0 | templateAttribute.setRequired(Boolean.valueOf(required)); |
484 | 0 | templateAttribute.setActive(Boolean.valueOf(active)); |
485 | 0 | templateAttribute.setDisplayOrder(new Integer(templateAttributeCounter++)); |
486 | 0 | return templateAttribute; |
487 | |
} |
488 | |
|
489 | |
public Timestamp formatDate(String dateLabel, String dateString) throws InvalidXmlException { |
490 | 0 | if (StringUtils.isBlank(dateString)) { |
491 | 0 | return null; |
492 | |
} |
493 | |
try { |
494 | 0 | return new Timestamp(RiceConstants.getDefaultDateFormat().parse(dateString).getTime()); |
495 | 0 | } catch (ParseException e) { |
496 | 0 | throw new InvalidXmlException(dateLabel + " is not in the proper format. Should have been: " + RiceConstants.DEFAULT_DATE_FORMAT_PATTERN); |
497 | |
} |
498 | |
} |
499 | |
|
500 | |
} |