1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
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 | |
|
47 | |
|
48 | |
@Override |
49 | |
public PersistableBusinessObject getDocumentBusinessObject() { |
50 | 0 | return (PersistableBusinessObject) super.getDocumentDataObject(); |
51 | |
} |
52 | |
|
53 | |
|
54 | |
|
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 | |
|
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 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | 0 | } |
113 | |
} |