001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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 org.kuali.core.bo;
017:
018: import java.io.IOException;
019: import java.io.InputStream;
020: import java.util.LinkedHashMap;
021:
022: import org.apache.commons.lang.StringUtils;
023: import org.kuali.rice.KNSServiceLocator;
024:
025: /**
026: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
027: */
028: public class Attachment extends PersistableBusinessObjectBase {
029:
030: private Long noteIdentifier;
031: private String attachmentMimeTypeCode;
032: private String attachmentFileName;
033: private String attachmentIdentifier;
034: private Long attachmentFileSize;
035: private String attachmentTypeCode;
036:
037: private Note note;
038:
039: /**
040: * Default constructor.
041: */
042: public Attachment() {
043:
044: }
045:
046: /**
047: * Gets the noteIdentifier attribute.
048: *
049: * @return Returns the noteIdentifier
050: *
051: */
052: public Long getNoteIdentifier() {
053: return noteIdentifier;
054: }
055:
056: /**
057: * Sets the noteIdentifier attribute.
058: *
059: * @param noteIdentifier The noteIdentifier to set.
060: *
061: */
062: public void setNoteIdentifier(Long noteIdentifier) {
063: this .noteIdentifier = noteIdentifier;
064: }
065:
066: /**
067: * Gets the attachmentMimeTypeCode attribute.
068: *
069: * @return Returns the attachmentMimeTypeCode
070: *
071: */
072: public String getAttachmentMimeTypeCode() {
073: return attachmentMimeTypeCode;
074: }
075:
076: /**
077: * Sets the attachmentMimeTypeCode attribute.
078: *
079: * @param attachmentMimeTypeCode The attachmentMimeTypeCode to set.
080: *
081: */
082: public void setAttachmentMimeTypeCode(String attachmentMimeTypeCode) {
083: this .attachmentMimeTypeCode = attachmentMimeTypeCode;
084: }
085:
086: /**
087: * Gets the attachmentFileName attribute.
088: *
089: * @return Returns the attachmentFileName
090: *
091: */
092: public String getAttachmentFileName() {
093: return attachmentFileName;
094: }
095:
096: /**
097: * Sets the attachmentFileName attribute.
098: *
099: * @param attachmentFileName The attachmentFileName to set.
100: *
101: */
102: public void setAttachmentFileName(String attachmentFileName) {
103: this .attachmentFileName = attachmentFileName;
104: }
105:
106: /**
107: * Gets the attachmentIdentifier attribute.
108: *
109: * @return Returns the attachmentIdentifier
110: *
111: */
112: public String getAttachmentIdentifier() {
113: return attachmentIdentifier;
114: }
115:
116: /**
117: * Sets the attachmentIdentifier attribute.
118: *
119: * @param attachmentIdentifier The attachmentIdentifier to set.
120: *
121: */
122: public void setAttachmentIdentifier(String attachmentIdentifier) {
123: this .attachmentIdentifier = attachmentIdentifier;
124: }
125:
126: /**
127: * Gets the attachmentFileSize attribute.
128: *
129: * @return Returns the attachmentFileSize
130: *
131: */
132: public Long getAttachmentFileSize() {
133: return attachmentFileSize;
134: }
135:
136: /**
137: * Sets the attachmentFileSize attribute.
138: *
139: * @param attachmentFileSize The attachmentFileSize to set.
140: *
141: */
142: public void setAttachmentFileSize(Long attachmentFileSize) {
143: this .attachmentFileSize = attachmentFileSize;
144: }
145:
146: /**
147: * Gets the attachmentTypeCode attribute.
148: *
149: * @return Returns the attachmentTypeCode
150: *
151: */
152: public String getAttachmentTypeCode() {
153: return attachmentTypeCode;
154: }
155:
156: /**
157: * Sets the attachmentTypeCode attribute.
158: *
159: * @param attachmentTypeCode The attachmentTypeCode to set.
160: *
161: */
162: public void setAttachmentTypeCode(String attachmentTypeCode) {
163: this .attachmentTypeCode = attachmentTypeCode;
164: }
165:
166: /**
167: * Gets the note attribute.
168: * @return Returns the note.
169: */
170: public Note getNote() {
171: return note;
172: }
173:
174: /**
175: * Sets the note attribute value.
176: * @param note The note to set.
177: */
178: public void setNote(Note note) {
179: this .note = note;
180: }
181:
182: /**
183: * @return false if any of the required fields (attachmentId, fileName, fileSize, and mimeType) are blank
184: */
185: public boolean isComplete() {
186: return (StringUtils.isNotBlank(attachmentIdentifier)
187: && StringUtils.isNotBlank(attachmentFileName)
188: && (attachmentFileSize != null) && StringUtils
189: .isNotBlank(attachmentMimeTypeCode));
190: }
191:
192: /**
193: * (non-Javadoc)
194: *
195: * @see org.kuali.core.service.DocumentAttachmentService#retrieveAttachmentContents(org.kuali.core.document.DocumentAttachment)
196: */
197: public InputStream getAttachmentContents() throws IOException {
198: return KNSServiceLocator.getAttachmentService()
199: .retrieveAttachmentContents(this );
200: }
201:
202: /**
203: * @see org.kuali.core.bo.BusinessObjectBase#toStringMapper()
204: */
205: protected LinkedHashMap toStringMapper() {
206: LinkedHashMap m = new LinkedHashMap();
207: m.put("noteIdentifier", this.noteIdentifier);
208: return m;
209: }
210: }
|