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