use of org.kuali.kfs.krad.bo.PersistableAttachmentList in project cu-kfs by CU-CommunityApps.
the class KualiInquiryAction method downloadAttachment.
/**
* Downloads the attachment to the user's browser
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward downloadAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
InquiryForm inquiryForm = (InquiryForm) form;
int line = getSelectedLine(request);
BusinessObject bo = retrieveBOFromInquirable(inquiryForm);
if (line < 0) {
if (bo instanceof PersistableAttachment) {
PersistableAttachment attachment = (PersistableAttachment) bo;
if (StringUtils.isNotBlank(attachment.getFileName()) && attachment.getAttachmentContent() != null) {
streamToResponse(attachment.getAttachmentContent(), attachment.getFileName(), attachment.getContentType(), response);
}
}
} else {
if (bo instanceof PersistableAttachmentList) {
PersistableAttachmentList<PersistableAttachment> attachmentsBo = (PersistableAttachmentList<PersistableAttachment>) bo;
if (CollectionUtils.isEmpty(attachmentsBo.getAttachments())) {
return null;
}
List<? extends PersistableAttachment> attachments = attachmentsBo.getAttachments();
if (CollectionUtils.isNotEmpty(attachments) && attachments.size() > line) {
PersistableAttachment attachment = attachmentsBo.getAttachments().get(line);
streamToResponse(attachment.getAttachmentContent(), attachment.getFileName(), attachment.getContentType(), response);
}
}
}
return null;
}
Aggregations