View Javadoc

1   /*
2    * Copyright 2007-2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * This is a description of what this class does - jjhanso don't forget to fill this in.
30   *
31   * @author Kuali Rice Team (rice.collab@kuali.org)
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       * This overridden method ...
41       *
42       * @see org.kuali.rice.kew.xml.export.XmlExporter#export(org.kuali.rice.kew.export.ExportDataSet)
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          // TODO jjhanso - THIS METHOD NEEDS JAVADOCS
55          return null;
56      }
57  
58      /**
59       * This method ...
60       *
61       * @param rootElement
62       * @param group
63       * @param object
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 }