Coverage Report - org.kuali.rice.kew.xml.export.GroupXmlExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
GroupXmlExporter
0%
0/47
0%
0/26
5.667
 
 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 org.jdom.Element;
 19  
 import org.kuali.rice.core.api.impex.ExportDataSet;
 20  
 import org.kuali.rice.core.framework.impex.xml.XmlExporter;
 21  
 import org.kuali.rice.core.util.xml.XmlRenderer;
 22  
 import org.kuali.rice.kew.export.KewExportDataSet;
 23  
 import org.kuali.rice.kim.api.common.attribute.KimAttributeData;
 24  
 import org.kuali.rice.kim.api.group.Group;
 25  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 26  
 import org.kuali.rice.kim.api.type.KimType;
 27  
 
 28  
 import java.util.Iterator;
 29  
 
 30  
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.*;
 31  
 
 32  
 /**
 33  
  * This is a description of what this class does - jjhanso don't forget to fill this in.
 34  
  *
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  *
 37  
  */
 38  0
 public class GroupXmlExporter implements XmlExporter {
 39  0
     protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass());
 40  
 
 41  0
     private XmlRenderer renderer = new XmlRenderer(GROUP_NAMESPACE);
 42  
 
 43  
         @Override
 44  
         public boolean supportPrettyPrint() {
 45  0
                 return true;
 46  
         }
 47  
     
 48  
     /**
 49  
      * This overridden method ...
 50  
      *
 51  
      * @see org.kuali.rice.core.framework.impex.xml.XmlExporter#export(org.kuali.rice.core.api.impex.ExportDataSet)
 52  
      */
 53  
     public Element export(ExportDataSet exportDataSet) {
 54  0
             KewExportDataSet dataSet = KewExportDataSet.fromExportDataSet(exportDataSet);
 55  0
         if (!dataSet.getGroups().isEmpty()) {
 56  0
             Element rootElement = renderer.renderElement(null, GROUPS);
 57  0
             rootElement.setAttribute(SCHEMA_LOCATION_ATTR, GROUP_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
 58  0
             for (Iterator iterator = dataSet.getGroups().iterator(); iterator.hasNext();) {
 59  0
                 Group group = (Group) iterator.next();
 60  0
                 exportGroup(rootElement, group);
 61  0
             }
 62  0
             return rootElement;
 63  
         }
 64  
         // TODO jjhanso - THIS METHOD NEEDS JAVADOCS
 65  0
         return null;
 66  
     }
 67  
 
 68  
     /**
 69  
      * This method ...
 70  
      *
 71  
      * @param rootElement
 72  
      * @param group
 73  
      * @param object
 74  
      */
 75  
     private void exportGroup(Element parent, Group group) {
 76  0
         Element groupElement = renderer.renderElement(parent, GROUP);
 77  0
         if (group.getName() != null) {
 78  0
             renderer.renderTextElement(groupElement, NAME, group.getName());
 79  
         }
 80  0
         if (group.getNamespaceCode() != null) {
 81  0
             renderer.renderTextElement(groupElement, NAMESPACE, group.getNamespaceCode());
 82  
         }
 83  
 
 84  0
         if (group.getDescription() != null && !group.getDescription().trim().equals("")) {
 85  0
             renderer.renderTextElement(groupElement, DESCRIPTION, group.getDescription());
 86  
         }
 87  
 
 88  0
         renderer.renderTextElement(groupElement, ACTIVE, new Boolean(group.isActive()).toString());
 89  
 
 90  0
         if (group.getKimTypeId() != null) {
 91  0
             Element typeElement = renderer.renderElement(groupElement, TYPE);
 92  0
             KimType kimType = KimApiServiceLocator.getKimTypeInfoService().getKimType(group.getKimTypeId());
 93  0
             renderer.renderTextElement(typeElement, NAMESPACE, kimType.getNamespaceCode());
 94  0
             renderer.renderTextElement(typeElement, NAME, kimType.getName());
 95  
         }
 96  
 
 97  0
         if (group.getAttributes().size() > 0) {
 98  0
             Element attributesElement = renderer.renderElement(groupElement, ATTRIBUTES);
 99  0
             for (String key : group.getAttributes().keySet()) {
 100  0
                 Element attributeElement = renderer.renderElement(attributesElement, ATTRIBUTE);
 101  0
                 attributeElement.setAttribute(KEY, key);
 102  0
                 attributeElement.setAttribute(VALUE, group.getAttributes().get(key));
 103  0
             }
 104  
         }
 105  
 
 106  0
         java.util.List<String> memberGroupIds = KimApiServiceLocator.getIdentityManagementService().getDirectMemberGroupIds(group.getId());
 107  
 
 108  0
         java.util.List<String> memberPrincipalIds = KimApiServiceLocator.getIdentityManagementService().getDirectGroupMemberPrincipalIds(group.getId());
 109  
 
 110  0
         if (memberGroupIds.size() > 0 || memberPrincipalIds.size() > 0) {
 111  0
             Element membersElement = renderer.renderElement(groupElement, MEMBERS);
 112  0
             for (String memberGroupId : memberGroupIds) {
 113  0
                 Group memberGroup = KimApiServiceLocator.getIdentityManagementService().getGroup(memberGroupId);
 114  0
                 Element groupNameElement = renderer.renderElement(membersElement, GROUP_NAME);
 115  0
                 renderer.renderTextElement(groupNameElement, NAME, memberGroup.getName());
 116  0
                 renderer.renderTextElement(groupNameElement, NAMESPACE, memberGroup.getNamespaceCode());
 117  0
             }
 118  0
             for (String memberPrincipalId : memberPrincipalIds) {
 119  0
                 renderer.renderTextElement(membersElement, PRINCIPAL_NAME, KimApiServiceLocator.getIdentityManagementService().getPrincipal(memberPrincipalId).getPrincipalName());
 120  
             }
 121  
         }
 122  0
     }
 123  
 
 124  
 }