Coverage Report - org.kuali.rice.kew.xml.export.GroupXmlExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
GroupXmlExporter
0%
0/45
0%
0/26
8
 
 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  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  
      * 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  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  
         // TODO jjhanso - THIS METHOD NEEDS JAVADOCS
 55  0
         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  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  
 }