Coverage Report - org.kuali.rice.kim.impl.jaxb.KimImporterAndExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
KimImporterAndExporter
0%
0/13
0%
0/6
2.667
 
 1  
 /*
 2  
  * Copyright 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/ecl1.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.kim.impl.jaxb;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.io.InputStream;
 20  
 import java.io.OutputStream;
 21  
 import java.util.Collections;
 22  
 import java.util.List;
 23  
 
 24  
 import org.kuali.rice.core.framework.impex.xml.XmlLoader;
 25  
 import org.kuali.rice.kim.api.permission.PermissionContract;
 26  
 import org.kuali.rice.kim.api.role.RoleContract;
 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  
 /**
 32  
  * Imports and exports roles and permissions from/to XML via JAXB.
 33  
  * 
 34  
  * <p>TODO: Do we need to restrict XML additions or updates based on which user is performing the ingestion?
 35  
  * 
 36  
  * <p>TODO: It may be best to make this class into a "service" instead.
 37  
  * 
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 39  
  */
 40  0
 public class KimImporterAndExporter implements XmlLoader, Exporter {
 41  
 
 42  0
     private final List<String> supportedFormats = Collections.singletonList(KRADConstants.XML_FORMAT);
 43  
     
 44  
     /**
 45  
      * @see org.kuali.rice.core.framework.impex.xml.XmlLoader#loadXml(java.io.InputStream, java.lang.String)
 46  
      */
 47  
     @Override
 48  
     public void loadXml(InputStream inputStream, String principalId) {
 49  0
         KimXmlUtil.parseKimXml(inputStream);
 50  0
     }
 51  
 
 52  
     /**
 53  
      * @see org.kuali.rice.krad.bo.Exporter#export(java.lang.Class, java.util.List, java.lang.String, java.io.OutputStream)
 54  
      */
 55  
     @Override
 56  
     public void export(Class<?> dataObjectClass, List<? extends Object> dataObjects, String exportFormat,
 57  
             OutputStream outputStream) throws IOException, ExportNotSupportedException {
 58  0
         if (!supportedFormats.contains(exportFormat)) {
 59  0
             throw new ExportNotSupportedException("The KimImporterAndExporter does not support the \"" + exportFormat + "\" export format");
 60  
         }
 61  
         
 62  0
         if (PermissionContract.class.isAssignableFrom(dataObjectClass)) {
 63  0
             KimXmlUtil.exportKimXml(outputStream, dataObjects, null);
 64  0
         } else if (RoleContract.class.isAssignableFrom(dataObjectClass)) {
 65  0
             KimXmlUtil.exportKimXml(outputStream, null, dataObjects);
 66  
         } else {
 67  0
             throw new ExportNotSupportedException("The KimImporterAndExporter cannot export non-permission and non-role objects");
 68  
         }
 69  
         
 70  0
     }
 71  
 
 72  
     /**
 73  
      * @see org.kuali.rice.krad.bo.Exporter#getSupportedFormats(java.lang.Class)
 74  
      */
 75  
     @Override
 76  
     public List<String> getSupportedFormats(Class<?> dataObjectClass) {
 77  0
         return supportedFormats;
 78  
     }
 79  
 }