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