1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.xml.export; |
17 | |
|
18 | |
import org.jdom.Element; |
19 | |
import org.kuali.rice.core.api.impex.ExportDataSet; |
20 | |
import org.kuali.rice.core.framework.impex.xml.XmlExporter; |
21 | |
import org.kuali.rice.core.util.xml.XmlRenderer; |
22 | |
import org.kuali.rice.kew.export.KewExportDataSet; |
23 | |
import org.kuali.rice.kim.api.group.Group; |
24 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
25 | |
import org.kuali.rice.kim.api.type.KimType; |
26 | |
|
27 | |
import java.util.Iterator; |
28 | |
|
29 | |
import static org.kuali.rice.core.api.impex.xml.XmlConstants.*; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class GroupXmlExporter implements XmlExporter { |
38 | 0 | protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass()); |
39 | |
|
40 | 0 | private XmlRenderer renderer = new XmlRenderer(GROUP_NAMESPACE); |
41 | |
|
42 | |
@Override |
43 | |
public boolean supportPrettyPrint() { |
44 | 0 | return true; |
45 | |
} |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public Element export(ExportDataSet exportDataSet) { |
53 | 0 | KewExportDataSet dataSet = KewExportDataSet.fromExportDataSet(exportDataSet); |
54 | 0 | if (!dataSet.getGroups().isEmpty()) { |
55 | 0 | Element rootElement = renderer.renderElement(null, GROUPS); |
56 | 0 | rootElement.setAttribute(SCHEMA_LOCATION_ATTR, GROUP_SCHEMA_LOCATION, SCHEMA_NAMESPACE); |
57 | 0 | for (Iterator iterator = dataSet.getGroups().iterator(); iterator.hasNext();) { |
58 | 0 | Group group = (Group) iterator.next(); |
59 | 0 | exportGroup(rootElement, group); |
60 | 0 | } |
61 | 0 | return rootElement; |
62 | |
} |
63 | |
|
64 | 0 | return null; |
65 | |
} |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
private void exportGroup(Element parent, Group group) { |
75 | 0 | Element groupElement = renderer.renderElement(parent, GROUP); |
76 | 0 | if (group.getName() != null) { |
77 | 0 | renderer.renderTextElement(groupElement, NAME, group.getName()); |
78 | |
} |
79 | 0 | if (group.getNamespaceCode() != null) { |
80 | 0 | renderer.renderTextElement(groupElement, NAMESPACE, group.getNamespaceCode()); |
81 | |
} |
82 | |
|
83 | 0 | if (group.getDescription() != null && !group.getDescription().trim().equals("")) { |
84 | 0 | renderer.renderTextElement(groupElement, DESCRIPTION, group.getDescription()); |
85 | |
} |
86 | |
|
87 | 0 | renderer.renderTextElement(groupElement, ACTIVE, new Boolean(group.isActive()).toString()); |
88 | |
|
89 | 0 | if (group.getKimTypeId() != null) { |
90 | 0 | Element typeElement = renderer.renderElement(groupElement, TYPE); |
91 | 0 | KimType kimType = KimApiServiceLocator.getKimTypeInfoService().getKimType(group.getKimTypeId()); |
92 | 0 | renderer.renderTextElement(typeElement, NAMESPACE, kimType.getNamespaceCode()); |
93 | 0 | renderer.renderTextElement(typeElement, NAME, kimType.getName()); |
94 | |
} |
95 | |
|
96 | 0 | if (group.getAttributes().size() > 0) { |
97 | 0 | Element attributesElement = renderer.renderElement(groupElement, ATTRIBUTES); |
98 | 0 | for (String key : group.getAttributes().keySet()) { |
99 | 0 | Element attributeElement = renderer.renderElement(attributesElement, ATTRIBUTE); |
100 | 0 | attributeElement.setAttribute(KEY, key); |
101 | 0 | attributeElement.setAttribute(VALUE, group.getAttributes().get(key)); |
102 | 0 | } |
103 | |
} |
104 | |
|
105 | 0 | java.util.List<String> memberGroupIds = KimApiServiceLocator.getGroupService().getDirectMemberGroupIds(group.getId()); |
106 | |
|
107 | 0 | java.util.List<String> memberPrincipalIds = KimApiServiceLocator.getGroupService().getDirectMemberPrincipalIds( |
108 | |
group.getId()); |
109 | |
|
110 | 0 | if (memberGroupIds.size() > 0 || memberPrincipalIds.size() > 0) { |
111 | 0 | Element membersElement = renderer.renderElement(groupElement, MEMBERS); |
112 | 0 | for (String memberGroupId : memberGroupIds) { |
113 | 0 | Group memberGroup = KimApiServiceLocator.getGroupService().getGroup(memberGroupId); |
114 | 0 | Element groupNameElement = renderer.renderElement(membersElement, GROUP_NAME); |
115 | 0 | renderer.renderTextElement(groupNameElement, NAME, memberGroup.getName()); |
116 | 0 | renderer.renderTextElement(groupNameElement, NAMESPACE, memberGroup.getNamespaceCode()); |
117 | 0 | } |
118 | 0 | for (String memberPrincipalId : memberPrincipalIds) { |
119 | 0 | renderer.renderTextElement(membersElement, PRINCIPAL_NAME, KimApiServiceLocator.getIdentityService().getPrincipal(memberPrincipalId).getPrincipalName()); |
120 | |
} |
121 | |
} |
122 | 0 | } |
123 | |
|
124 | |
} |