001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package edu.sampleu.travel.bo;
017    
018    import java.util.ArrayList;
019    import java.util.LinkedHashMap;
020    import java.util.List;
021    
022    import org.apache.struts.upload.FormFile;
023    import org.kuali.rice.krad.bo.MultiDocumentAttachment;
024    import org.kuali.rice.krad.bo.PersistableAttachment;
025    import org.kuali.rice.krad.bo.PersistableAttachmentList;
026    import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
027    
028    public class AttachmentSample extends PersistableBusinessObjectBase implements PersistableAttachment, PersistableAttachmentList<MultiAttachmentSample> {
029        
030        private String id;
031        private String description;
032        
033        private String fileName;
034        private String contentType;
035        private byte[] attachmentContent;
036        private transient FormFile attachmentFile;
037        
038        private List<MultiAttachmentSample> attachments;
039        
040        public AttachmentSample() {
041            this.attachments = new ArrayList<MultiAttachmentSample>();
042        }
043    
044        public String getId() {
045            return this.id;
046        }
047    
048        public void setId(String id) {
049            this.id = id;
050        }
051    
052        public String getDescription() {
053            return this.description;
054        }
055    
056        public void setDescription(String description) {
057            this.description = description;
058        }
059    
060        public String getFileName() {
061            return this.fileName;
062        }
063    
064        public void setFileName(String fileName) {
065            this.fileName = fileName;
066        }
067    
068        public String getContentType() {
069            return this.contentType;
070        }
071    
072        public void setContentType(String contentType) {
073            this.contentType = contentType;
074        }
075    
076        public byte[] getAttachmentContent() {
077            return this.attachmentContent;
078        }
079    
080        public void setAttachmentContent(byte[] attachmentContent) {
081            this.attachmentContent = attachmentContent;
082        }
083    
084        public FormFile getAttachmentFile() {
085            return this.attachmentFile;
086        }
087    
088        public void setAttachmentFile(FormFile attachmentFile) {
089            this.attachmentFile = attachmentFile;
090        }
091    
092        @Override
093        public List<MultiAttachmentSample> getAttachments() {
094            return this.attachments;
095        }
096    
097        @Override
098        public void setAttachments(List<MultiAttachmentSample> attachments) {
099            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    }