View Javadoc

1   /**
2    * Copyright 2005-2012 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 edu.sampleu.travel.bo;
17  
18  import java.util.ArrayList;
19  import java.util.LinkedHashMap;
20  import java.util.List;
21  
22  import org.apache.struts.upload.FormFile;
23  import org.kuali.rice.krad.bo.MultiDocumentAttachment;
24  import org.kuali.rice.krad.bo.PersistableAttachment;
25  import org.kuali.rice.krad.bo.PersistableAttachmentList;
26  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
27  
28  public class AttachmentSample extends PersistableBusinessObjectBase implements PersistableAttachment, PersistableAttachmentList<MultiAttachmentSample> {
29      
30      private String id;
31      private String description;
32      
33      private String fileName;
34      private String contentType;
35      private byte[] attachmentContent;
36      private transient FormFile attachmentFile;
37      
38      private List<MultiAttachmentSample> attachments;
39      
40      public AttachmentSample() {
41          this.attachments = new ArrayList<MultiAttachmentSample>();
42      }
43  
44      public String getId() {
45          return this.id;
46      }
47  
48      public void setId(String id) {
49          this.id = id;
50      }
51  
52      public String getDescription() {
53          return this.description;
54      }
55  
56      public void setDescription(String description) {
57          this.description = description;
58      }
59  
60      public String getFileName() {
61          return this.fileName;
62      }
63  
64      public void setFileName(String fileName) {
65          this.fileName = fileName;
66      }
67  
68      public String getContentType() {
69          return this.contentType;
70      }
71  
72      public void setContentType(String contentType) {
73          this.contentType = contentType;
74      }
75  
76      public byte[] getAttachmentContent() {
77          return this.attachmentContent;
78      }
79  
80      public void setAttachmentContent(byte[] attachmentContent) {
81          this.attachmentContent = attachmentContent;
82      }
83  
84      public FormFile getAttachmentFile() {
85          return this.attachmentFile;
86      }
87  
88      public void setAttachmentFile(FormFile attachmentFile) {
89          this.attachmentFile = attachmentFile;
90      }
91  
92      @Override
93      public List<MultiAttachmentSample> getAttachments() {
94          return this.attachments;
95      }
96  
97      @Override
98      public void setAttachments(List<MultiAttachmentSample> attachments) {
99          List<MultiAttachmentSample> list = new ArrayList<MultiAttachmentSample>();
100         for (MultiAttachmentSample multiAttachment : attachments) {
101             MultiAttachmentSample attachment = new MultiAttachmentSample();
102             attachment.setId(multiAttachment.getId());
103             attachment.setAttachmentContent(multiAttachment.getAttachmentContent());
104             attachment.setFileName(multiAttachment.getFileName());
105             attachment.setContentType(multiAttachment.getContentType());
106             list.add(attachment);
107         }
108         this.attachments = list;
109     }
110 
111     protected LinkedHashMap toStringMapper() {
112         LinkedHashMap<String, Object> toStringMap = new LinkedHashMap<String, Object>();
113         toStringMap.put("id", id);
114         return toStringMap;
115     }
116 
117     @Override
118     public List buildListOfDeletionAwareLists() {
119         List managedLists = super.buildListOfDeletionAwareLists();
120         managedLists.add(this.attachments);
121         return managedLists;
122     }
123 }