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