Coverage Report - org.kuali.rice.kew.export.DataExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
DataExporter
0%
0/31
0%
0/22
4
 
 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.export;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.io.OutputStream;
 20  
 import java.util.ArrayList;
 21  
 import java.util.List;
 22  
 
 23  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 24  
 import org.kuali.rice.kew.edl.bo.EDocLiteAssociation;
 25  
 import org.kuali.rice.kew.edl.bo.EDocLiteStyle;
 26  
 import org.kuali.rice.kew.help.HelpEntry;
 27  
 import org.kuali.rice.kew.rule.RuleBaseValues;
 28  
 import org.kuali.rice.kew.rule.RuleDelegation;
 29  
 import org.kuali.rice.kew.rule.bo.RuleAttribute;
 30  
 import org.kuali.rice.kew.rule.bo.RuleTemplate;
 31  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 32  
 import org.kuali.rice.kim.bo.impl.GroupImpl;
 33  
 import org.kuali.rice.kns.bo.BusinessObject;
 34  
 import org.kuali.rice.kns.bo.Exporter;
 35  
 import org.kuali.rice.kns.exception.ExportNotSupportedException;
 36  
 import org.kuali.rice.kns.util.KNSConstants;
 37  
 
 38  
 /**
 39  
  * The DataExporter allows for exporting of KEW BusinessObjects to various supported
 40  
  * formats.  The current implementation supports only XML export.  This process is initiated
 41  
  * from the KNS screens (lookups and inquiries) and this implementation leverages the
 42  
  * existing XmlExporterService which is part of KEW and which was used to do exports before
 43  
  * KEW was converted to use the KNS.
 44  
  *
 45  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 46  
  */
 47  
 public class DataExporter implements Exporter {
 48  
 
 49  0
         private List<String> supportedFormats = new ArrayList<String>();
 50  
 
 51  0
         public DataExporter() {
 52  0
                 supportedFormats.add(KNSConstants.XML_FORMAT);
 53  0
         }
 54  
 
 55  
         /**
 56  
          * Export the given List of BusinessObjects of the specified type to XML.
 57  
          */
 58  
         public void export(Class<? extends BusinessObject> businessObjectClass, List<BusinessObject> businessObjects, String exportFormat, OutputStream outputStream) throws IOException {
 59  0
                 if (!KNSConstants.XML_FORMAT.equals(exportFormat)) {
 60  0
                         throw new ExportNotSupportedException("The given export format of " + exportFormat + " is not supported by the KEW XML Exporter!");
 61  
                 }
 62  0
                 ExportDataSet dataSet = buildExportDataSet(businessObjectClass, businessObjects);
 63  0
                 outputStream.write(KEWServiceLocator.getXmlExporterService().export(dataSet));
 64  0
         }
 65  
 
 66  
         public List<String> getSupportedFormats(Class<? extends BusinessObject> businessObjectClass) {
 67  0
                 return supportedFormats;
 68  
         }
 69  
 
 70  
         /**
 71  
          * Builds the ExportDataSet based on the BusinessObjects passed in.
 72  
          */
 73  
         protected ExportDataSet buildExportDataSet(Class<? extends BusinessObject> businessObjectClass, List<BusinessObject> businessObjects) {
 74  0
                 ExportDataSet dataSet = new ExportDataSet();
 75  0
                 for (BusinessObject businessObject : businessObjects) {
 76  0
                         if (businessObjectClass.equals(RuleAttribute.class)) {
 77  0
                                 dataSet.getRuleAttributes().add((RuleAttribute)businessObject);
 78  0
                         } else if (businessObjectClass.equals(RuleTemplate.class)) {
 79  0
                                 dataSet.getRuleTemplates().add((RuleTemplate)businessObject);
 80  0
                         } else if (businessObjectClass.equals(DocumentType.class)) {
 81  0
                                 dataSet.getDocumentTypes().add((DocumentType)businessObject);
 82  0
                         } else if (businessObjectClass.equals(EDocLiteAssociation.class)) {
 83  0
                                 dataSet.getEdocLites().add((EDocLiteAssociation)businessObject);
 84  0
                         } else if (businessObjectClass.equals(HelpEntry.class)) {
 85  0
                                 dataSet.getHelp().add((HelpEntry)businessObject);
 86  0
                         } else if (businessObjectClass.equals(RuleBaseValues.class)) {
 87  0
                                 dataSet.getRules().add((RuleBaseValues)businessObject);
 88  0
                         } else if (businessObjectClass.equals(RuleDelegation.class)) {
 89  0
                                 dataSet.getRuleDelegations().add((RuleDelegation)businessObject);
 90  0
                         } else if (businessObjectClass.equals(EDocLiteStyle.class)) {
 91  0
                                 dataSet.getStyles().add((EDocLiteStyle)businessObject);
 92  0
                         } else if (businessObjectClass.equals(GroupImpl.class)) {
 93  0
                                 dataSet.getGroups().add((GroupImpl)businessObject);
 94  
                         }    
 95  
                 }
 96  0
                 return dataSet;
 97  
         }
 98  
 
 99  
 }