Coverage Report - org.kuali.rice.kns.document.MaintenanceDocumentBase
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceDocumentBase
0%
0/35
0%
0/12
2.111
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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.kns.document;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.apache.struts.upload.FormFile;
 20  
 import org.kuali.rice.kns.maintenance.Maintainable;
 21  
 import org.kuali.rice.krad.bo.DocumentAttachment;
 22  
 import org.kuali.rice.krad.bo.PersistableBusinessObject;
 23  
 
 24  
 import javax.persistence.Transient;
 25  
 import java.io.FileNotFoundException;
 26  
 import java.io.IOException;
 27  
 
 28  
 /**
 29  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 30  
  */
 31  0
 public class MaintenanceDocumentBase extends org.kuali.rice.krad.document.MaintenanceDocumentBase implements MaintenanceDocument {
 32  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceDocumentBase.class);
 33  
 
 34  
     @Transient
 35  
     protected transient FormFile fileAttachment;
 36  
 
 37  
     public MaintenanceDocumentBase() {
 38  0
         super();
 39  0
     }
 40  
 
 41  
     public MaintenanceDocumentBase(String documentTypeName) {
 42  0
         super(documentTypeName);
 43  0
     }
 44  
 
 45  
     /**
 46  
      * @see org.kuali.rice.krad.document.DocumentBase#getDocumentBusinessObject()
 47  
      */
 48  
     @Override
 49  
     public PersistableBusinessObject getDocumentBusinessObject() {
 50  0
         return (PersistableBusinessObject) super.getDocumentDataObject();
 51  
     }
 52  
 
 53  
     /**
 54  
      * Checks old maintainable bo has key values
 55  
      */
 56  
     public boolean isOldBusinessObjectInDocument() {
 57  0
         boolean isOldBusinessObjectInExistence = false;
 58  0
         if (getOldMaintainableObject() == null || getOldMaintainableObject().getBusinessObject() == null) {
 59  0
             isOldBusinessObjectInExistence = false;
 60  
         } else {
 61  0
             isOldBusinessObjectInExistence = getOldMaintainableObject().isOldBusinessObjectInDocument();
 62  
         }
 63  0
         return isOldBusinessObjectInExistence;
 64  
     }
 65  
 
 66  
     public Maintainable getNewMaintainableObject() {
 67  0
         return (Maintainable) newMaintainableObject;
 68  
     }
 69  
 
 70  
     public Maintainable getOldMaintainableObject() {
 71  0
         return (Maintainable) oldMaintainableObject;
 72  
     }
 73  
 
 74  
     public FormFile getFileAttachment() {
 75  0
         return this.fileAttachment;
 76  
     }
 77  
 
 78  
     public void setFileAttachment(FormFile fileAttachment) {
 79  0
         this.fileAttachment = fileAttachment;
 80  0
     }
 81  
 
 82  
     public void populateDocumentAttachment() {
 83  0
         refreshAttachment();
 84  
 
 85  0
         if (fileAttachment != null && StringUtils.isNotEmpty(fileAttachment.getFileName())) {
 86  
             //Populate DocumentAttachment BO
 87  0
             if (attachment == null) {
 88  0
                 attachment = new DocumentAttachment();
 89  
             }
 90  
 
 91  
             byte[] fileContents;
 92  
             try {
 93  0
                 fileContents = fileAttachment.getFileData();
 94  0
                 if (fileContents.length > 0) {
 95  0
                     attachment.setFileName(fileAttachment.getFileName());
 96  0
                     attachment.setContentType(fileAttachment.getContentType());
 97  0
                     attachment.setAttachmentContent(fileAttachment.getFileData());
 98  0
                     attachment.setDocumentNumber(getDocumentNumber());
 99  
                 }
 100  0
             } catch (FileNotFoundException e) {
 101  0
                 LOG.error("Error while populating the Document Attachment", e);
 102  0
                 throw new RuntimeException("Could not populate DocumentAttachment object", e);
 103  0
             } catch (IOException e) {
 104  0
                 LOG.error("Error while populating the Document Attachment", e);
 105  0
                 throw new RuntimeException("Could not populate DocumentAttachment object", e);
 106  0
             }
 107  
         }
 108  
 //        else if(attachment != null) {
 109  
 //            //Attachment has been deleted - Need to delete the Attachment Reference Object
 110  
 //            deleteAttachment();
 111  
 //        }
 112  0
     }
 113  
 }