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