Search in sources :

Example 1 with PersistableAttachmentList

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;
}
Also used : PersistableAttachment(org.kuali.kfs.krad.bo.PersistableAttachment) PersistableAttachmentList(org.kuali.kfs.krad.bo.PersistableAttachmentList) BusinessObject(org.kuali.kfs.krad.bo.BusinessObject) InquiryForm(org.kuali.kfs.kns.web.struts.form.InquiryForm)

Aggregations

InquiryForm (org.kuali.kfs.kns.web.struts.form.InquiryForm)1 BusinessObject (org.kuali.kfs.krad.bo.BusinessObject)1 PersistableAttachment (org.kuali.kfs.krad.bo.PersistableAttachment)1 PersistableAttachmentList (org.kuali.kfs.krad.bo.PersistableAttachmentList)1