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 static org.kuali.rice.core.api.impex.xml.XmlConstants.DELEGATION_TYPE; |
20 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.GROUP_NAME; |
21 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.NAMESPACE; |
22 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.PARENT_RESPONSIBILITY; |
23 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.PARENT_RULE_NAME; |
24 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.PRINCIPAL_NAME; |
25 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.ROLE; |
26 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.RULE_DELEGATION; |
27 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.RULE_DELEGATIONS; |
28 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.RULE_NAMESPACE; |
29 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.RULE_SCHEMA_LOCATION; |
30 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.SCHEMA_LOCATION_ATTR; |
31 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.SCHEMA_NAMESPACE; |
32 | |
|
33 | |
import java.util.Iterator; |
34 | |
|
35 | |
import org.jdom.Element; |
36 | |
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
37 | |
import org.kuali.rice.core.api.impex.ExportDataSet; |
38 | |
import org.kuali.rice.core.framework.impex.xml.XmlExporter; |
39 | |
import org.kuali.rice.core.util.xml.XmlRenderer; |
40 | |
import org.kuali.rice.kew.export.KewExportDataSet; |
41 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
42 | |
import org.kuali.rice.kew.rule.RuleDelegation; |
43 | |
import org.kuali.rice.kew.rule.RuleResponsibility; |
44 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
45 | |
import org.kuali.rice.kim.api.entity.principal.Principal; |
46 | |
import org.kuali.rice.kim.api.group.Group; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | public class RuleDelegationXmlExporter implements XmlExporter { |
56 | |
|
57 | 0 | protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass()); |
58 | |
|
59 | 0 | private XmlRenderer renderer = new XmlRenderer(RULE_NAMESPACE); |
60 | 0 | private RuleXmlExporter ruleExporter = new RuleXmlExporter(RULE_NAMESPACE); |
61 | |
|
62 | |
@Override |
63 | |
public boolean supportPrettyPrint() { |
64 | 0 | return true; |
65 | |
} |
66 | |
|
67 | |
public Element export(ExportDataSet exportDataSet) { |
68 | 0 | KewExportDataSet dataSet = KewExportDataSet.fromExportDataSet(exportDataSet); |
69 | 0 | if (!dataSet.getRuleDelegations().isEmpty()) { |
70 | 0 | Element rootElement = renderer.renderElement(null, RULE_DELEGATIONS); |
71 | 0 | rootElement.setAttribute(SCHEMA_LOCATION_ATTR, RULE_SCHEMA_LOCATION, SCHEMA_NAMESPACE); |
72 | 0 | for (Iterator iterator = dataSet.getRuleDelegations().iterator(); iterator.hasNext();) { |
73 | 0 | RuleDelegation ruleDelegation = (RuleDelegation) iterator.next(); |
74 | 0 | exportRuleDelegation(rootElement, ruleDelegation); |
75 | 0 | } |
76 | 0 | return rootElement; |
77 | |
} |
78 | 0 | return null; |
79 | |
} |
80 | |
|
81 | |
private void exportRuleDelegation(Element parent, RuleDelegation ruleDelegation) { |
82 | 0 | Element ruleDelegationElement = renderer.renderElement(parent, RULE_DELEGATION); |
83 | 0 | exportParentResponsibility(ruleDelegationElement, ruleDelegation); |
84 | 0 | renderer.renderTextElement(ruleDelegationElement, DELEGATION_TYPE, ruleDelegation.getDelegationType()); |
85 | 0 | ruleExporter.exportRule(ruleDelegationElement, ruleDelegation.getDelegationRuleBaseValues()); |
86 | 0 | } |
87 | |
|
88 | |
private void exportParentResponsibility(Element parent, RuleDelegation delegation) { |
89 | 0 | Element parentResponsibilityElement = renderer.renderElement(parent, PARENT_RESPONSIBILITY); |
90 | 0 | RuleResponsibility ruleResponsibility = KEWServiceLocator.getRuleService().findRuleResponsibility(delegation.getResponsibilityId()); |
91 | 0 | renderer.renderTextElement(parentResponsibilityElement, PARENT_RULE_NAME, ruleResponsibility.getRuleBaseValues().getName()); |
92 | 0 | if (ruleResponsibility.isUsingWorkflowUser()) { |
93 | 0 | Principal principal = ruleResponsibility.getPrincipal(); |
94 | 0 | renderer.renderTextElement(parentResponsibilityElement, PRINCIPAL_NAME, principal.getPrincipalName()); |
95 | 0 | } else if (ruleResponsibility.isUsingGroup()) { |
96 | 0 | Group group = ruleResponsibility.getGroup(); |
97 | 0 | Element groupElement = renderer.renderElement(parentResponsibilityElement, GROUP_NAME); |
98 | 0 | groupElement.setText(group.getName()); |
99 | 0 | groupElement.setAttribute(NAMESPACE, group.getNamespaceCode()); |
100 | 0 | } else if (ruleResponsibility.isUsingRole()) { |
101 | 0 | renderer.renderTextElement(parentResponsibilityElement, ROLE, ruleResponsibility.getRuleResponsibilityName()); |
102 | |
} else { |
103 | 0 | throw new RiceRuntimeException("Encountered a rule responsibility when exporting with an invalid type of '" + ruleResponsibility.getRuleResponsibilityType()); |
104 | |
} |
105 | 0 | } |
106 | |
|
107 | |
} |