1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.xml.export;
18
19 import java.util.Iterator;
20
21 import org.jdom.Element;
22 import org.kuali.rice.core.exception.RiceRuntimeException;
23 import org.kuali.rice.kew.export.ExportDataSet;
24 import org.kuali.rice.kew.rule.RuleBaseValues;
25 import org.kuali.rice.kew.rule.RuleDelegation;
26 import org.kuali.rice.kew.rule.RuleResponsibility;
27 import org.kuali.rice.kew.service.KEWServiceLocator;
28 import org.kuali.rice.kew.xml.XmlConstants;
29 import org.kuali.rice.kew.xml.XmlRenderer;
30 import org.kuali.rice.kim.bo.Group;
31 import org.kuali.rice.kim.bo.entity.KimPrincipal;
32
33
34
35
36
37
38
39
40
41 public class RuleDelegationXmlExporter implements XmlExporter, XmlConstants {
42
43 protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass());
44
45 private XmlRenderer renderer = new XmlRenderer(RULE_NAMESPACE);
46 private RuleXmlExporter ruleExporter = new RuleXmlExporter(RULE_NAMESPACE);
47
48 public Element export(ExportDataSet dataSet) {
49 if (!dataSet.getRuleDelegations().isEmpty()) {
50 Element rootElement = renderer.renderElement(null, RULE_DELEGATIONS);
51 rootElement.setAttribute(SCHEMA_LOCATION_ATTR, RULE_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
52 for (Iterator iterator = dataSet.getRuleDelegations().iterator(); iterator.hasNext();) {
53 RuleDelegation ruleDelegation = (RuleDelegation) iterator.next();
54 exportRuleDelegation(rootElement, ruleDelegation);
55 }
56 return rootElement;
57 }
58 return null;
59 }
60
61 private void exportRuleDelegation(Element parent, RuleDelegation ruleDelegation) {
62 Element ruleDelegationElement = renderer.renderElement(parent, RULE_DELEGATION);
63 exportParentResponsibility(ruleDelegationElement, ruleDelegation);
64 renderer.renderTextElement(ruleDelegationElement, DELEGATION_TYPE, ruleDelegation.getDelegationType());
65 ruleExporter.exportRule(ruleDelegationElement, ruleDelegation.getDelegationRuleBaseValues());
66 }
67
68 private void exportParentResponsibility(Element parent, RuleDelegation delegation) {
69 Element parentResponsibilityElement = renderer.renderElement(parent, PARENT_RESPONSIBILITY);
70 RuleResponsibility ruleResponsibility = KEWServiceLocator.getRuleService().findRuleResponsibility(delegation.getResponsibilityId());
71 renderer.renderTextElement(parentResponsibilityElement, PARENT_RULE_NAME, ruleResponsibility.getRuleBaseValues().getName());
72 if (ruleResponsibility.isUsingWorkflowUser()) {
73 KimPrincipal principal = ruleResponsibility.getPrincipal();
74 renderer.renderTextElement(parentResponsibilityElement, PRINCIPAL_NAME, principal.getPrincipalName());
75 } else if (ruleResponsibility.isUsingGroup()) {
76 Group group = ruleResponsibility.getGroup();
77 Element groupElement = renderer.renderElement(parentResponsibilityElement, GROUP_NAME);
78 groupElement.setText(group.getGroupName());
79 groupElement.setAttribute(NAMESPACE, group.getNamespaceCode());
80 } else if (ruleResponsibility.isUsingRole()) {
81 renderer.renderTextElement(parentResponsibilityElement, ROLE, ruleResponsibility.getRuleResponsibilityName());
82 } else {
83 throw new RiceRuntimeException("Encountered a rule responsibility when exporting with an invalid type of '" + ruleResponsibility.getRuleResponsibilityType());
84 }
85 }
86
87 }