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 java.util.Iterator; |
19 | |
|
20 | |
import org.jdom.Element; |
21 | |
import org.kuali.rice.kew.export.ExportDataSet; |
22 | |
import org.kuali.rice.kew.xml.XmlConstants; |
23 | |
import org.kuali.rice.kew.xml.XmlRenderer; |
24 | |
import org.kuali.rice.kim.bo.Group; |
25 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeInfo; |
26 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 0 | public class GroupXmlExporter implements XmlExporter, XmlConstants { |
35 | 0 | protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass()); |
36 | |
|
37 | 0 | private XmlRenderer renderer = new XmlRenderer(GROUP_NAMESPACE); |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public Element export(ExportDataSet dataSet) { |
45 | 0 | if (!dataSet.getGroups().isEmpty()) { |
46 | 0 | Element rootElement = renderer.renderElement(null, GROUPS); |
47 | 0 | rootElement.setAttribute(SCHEMA_LOCATION_ATTR, GROUP_SCHEMA_LOCATION, SCHEMA_NAMESPACE); |
48 | 0 | for (Iterator iterator = dataSet.getGroups().iterator(); iterator.hasNext();) { |
49 | 0 | Group group = (Group) iterator.next(); |
50 | 0 | exportGroup(rootElement, group); |
51 | 0 | } |
52 | 0 | return rootElement; |
53 | |
} |
54 | |
|
55 | 0 | return null; |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
private void exportGroup(Element parent, Group group) { |
66 | 0 | Element groupElement = renderer.renderElement(parent, GROUP); |
67 | 0 | if (group.getGroupName() != null) { |
68 | 0 | renderer.renderTextElement(groupElement, NAME, group.getGroupName()); |
69 | |
} |
70 | 0 | if (group.getNamespaceCode() != null) { |
71 | 0 | renderer.renderTextElement(groupElement, NAMESPACE, group.getNamespaceCode()); |
72 | |
} |
73 | |
|
74 | 0 | if (group.getGroupDescription() != null && !group.getGroupDescription().trim().equals("")) { |
75 | 0 | renderer.renderTextElement(groupElement, DESCRIPTION, group.getGroupDescription()); |
76 | |
} |
77 | |
|
78 | 0 | renderer.renderTextElement(groupElement, ACTIVE, new Boolean(group.isActive()).toString()); |
79 | |
|
80 | 0 | if (group.getKimTypeId() != null) { |
81 | 0 | Element typeElement = renderer.renderElement(groupElement, TYPE); |
82 | 0 | KimTypeInfo kimType = KIMServiceLocator.getTypeInfoService().getKimType(group.getKimTypeId()); |
83 | 0 | renderer.renderTextElement(typeElement, NAMESPACE, kimType.getNamespaceCode()); |
84 | 0 | renderer.renderTextElement(typeElement, NAME, kimType.getName()); |
85 | |
} |
86 | |
|
87 | 0 | if (group.getAttributes().size() > 0) { |
88 | 0 | Element attributesElement = renderer.renderElement(groupElement, ATTRIBUTES); |
89 | 0 | for (String key : group.getAttributes().keySet()) { |
90 | 0 | Element attributeElement = renderer.renderElement(attributesElement, ATTRIBUTE); |
91 | 0 | attributeElement.setAttribute(KEY, key); |
92 | 0 | attributeElement.setAttribute(VALUE, group.getAttributes().get(key)); |
93 | 0 | } |
94 | |
} |
95 | |
|
96 | 0 | java.util.List<String> memberGroupIds = KIMServiceLocator.getIdentityManagementService().getDirectMemberGroupIds(group.getGroupId()); |
97 | |
|
98 | 0 | java.util.List<String> memberPrincipalIds = KIMServiceLocator.getIdentityManagementService().getDirectGroupMemberPrincipalIds(group.getGroupId()); |
99 | |
|
100 | 0 | if (memberGroupIds.size() > 0 || memberPrincipalIds.size() > 0) { |
101 | 0 | Element membersElement = renderer.renderElement(groupElement, MEMBERS); |
102 | 0 | for (String memberGroupId : memberGroupIds) { |
103 | 0 | Group memberGroup = KIMServiceLocator.getIdentityManagementService().getGroup(memberGroupId); |
104 | 0 | Element groupNameElement = renderer.renderElement(membersElement, GROUP_NAME); |
105 | 0 | renderer.renderTextElement(groupNameElement, NAME, memberGroup.getGroupName()); |
106 | 0 | renderer.renderTextElement(groupNameElement, NAMESPACE, memberGroup.getNamespaceCode()); |
107 | 0 | } |
108 | 0 | for (String memberPrincipalId : memberPrincipalIds) { |
109 | 0 | renderer.renderTextElement(membersElement, PRINCIPAL_NAME, KIMServiceLocator.getIdentityManagementService().getPrincipal(memberPrincipalId).getPrincipalName()); |
110 | |
} |
111 | |
} |
112 | 0 | } |
113 | |
|
114 | |
} |