Coverage Report - org.kuali.rice.kew.export.DataExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
DataExporter
0%
0/30
0%
0/18
3.5
 
 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.core.api.impex.ExportDataSet;
 24  
 import org.kuali.rice.core.api.services.CoreApiServiceLocator;
 25  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 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.kim.api.group.Group;
 32  
 import org.kuali.rice.kim.impl.group.GroupBo;
 33  
 import org.kuali.rice.kns.bo.Exporter;
 34  
 import org.kuali.rice.kns.exception.ExportNotSupportedException;
 35  
 import org.kuali.rice.kns.util.KNSConstants;
 36  
 
 37  
 /**
 38  
  * The DataExporter allows for exporting of KEW BusinessObjects to various
 39  
  * supported formats. The current implementation supports only XML export. This
 40  
  * process is initiated from the KNS screens (lookups and inquiries) and this
 41  
  * implementation leverages the existing XmlExporterService which is part of KEW
 42  
  * and which was used to do exports before KEW was converted to use the KNS.
 43  
  * 
 44  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 45  
  */
 46  
 public class DataExporter implements Exporter {
 47  
 
 48  0
         private List<String> supportedFormats = new ArrayList<String>();
 49  
 
 50  0
         public DataExporter() {
 51  0
                 supportedFormats.add(KNSConstants.XML_FORMAT);
 52  0
         }
 53  
 
 54  
         /**
 55  
          * @see org.kuali.rice.kns.bo.Exporter#getSupportedFormats(java.lang.Class)
 56  
          */
 57  
         @Override
 58  
         public List<String> getSupportedFormats(Class<?> dataObjectClass) {
 59  0
                 return supportedFormats;
 60  
         }
 61  
 
 62  
         /**
 63  
          * Builds the ExportDataSet based on the BusinessObjects passed in.
 64  
          */
 65  
         protected ExportDataSet buildExportDataSet(Class<?> dataObjectClass, List<? extends Object> dataObjects) {
 66  0
                 KewExportDataSet dataSet = new KewExportDataSet();
 67  0
                 for (Object dataObject : dataObjects) {
 68  0
                         if (dataObjectClass.equals(RuleAttribute.class)) {
 69  0
                                 dataSet.getRuleAttributes().add((RuleAttribute)dataObject);
 70  0
                         } else if (dataObjectClass.equals(RuleTemplate.class)) {
 71  0
                                 dataSet.getRuleTemplates().add((RuleTemplate)dataObject);
 72  0
                         } else if (dataObjectClass.equals(DocumentType.class)) {
 73  0
                                 dataSet.getDocumentTypes().add((DocumentType)dataObject);
 74  0
                         } else if (dataObjectClass.equals(HelpEntry.class)) {
 75  0
                                 dataSet.getHelp().add((HelpEntry)dataObject);
 76  0
                         } else if (dataObjectClass.equals(RuleBaseValues.class)) {
 77  0
                                 dataSet.getRules().add((RuleBaseValues)dataObject);
 78  0
                         } else if (dataObjectClass.equals(RuleDelegation.class)) {
 79  0
                                 dataSet.getRuleDelegations().add((RuleDelegation)dataObject);
 80  0
                         } else if (dataObjectClass.equals(GroupBo.class)) {
 81  0
                                 dataSet.getGroups().add((Group)dataObject);
 82  
                         }
 83  
                 }
 84  
 
 85  0
                 ExportDataSet exportDataSet = new ExportDataSet();
 86  0
                 dataSet.populateExportDataSet(exportDataSet);
 87  0
                 return exportDataSet;
 88  
         }
 89  
 
 90  
         /**
 91  
          * Export the given List of Objects of the specified type to XML.
 92  
          * 
 93  
          * @see org.kuali.rice.kns.bo.Exporter#export(java.lang.Class, java.util.List, java.lang.String, java.io.OutputStream)
 94  
          */
 95  
         @Override
 96  
         public void export(Class<?> dataObjectClass, List<? extends Object> dataObjects, String exportFormat, OutputStream outputStream) throws IOException,
 97  
                         ExportNotSupportedException {
 98  0
                 if (!KNSConstants.XML_FORMAT.equals(exportFormat)) {
 99  0
                         throw new ExportNotSupportedException("The given export format of "
 100  
                                         + exportFormat
 101  
                                         + " is not supported by the KEW XML Exporter!");
 102  
                 }
 103  0
                 ExportDataSet dataSet = buildExportDataSet(dataObjectClass, dataObjects);
 104  0
                 outputStream.write(CoreApiServiceLocator.getXmlExporterService()
 105  
                                 .export(dataSet));
 106  0
                 outputStream.flush();
 107  
                 
 108  0
         }
 109  
 }