/** * Removes all temporary attachments for the given formToken. Form token may not be null; * * @param formToken The formToken of the form to remove entries for. May not be null. */ public void clearEntriesForFormToken(String formToken) { final Collection<TemporaryAttachment> attachmentsForFormToken = getByFormToken(formToken); for (TemporaryAttachment temporaryAttachment : attachmentsForFormToken) { temporaryAttachment.getFile().delete(); temporaryAttachments.remove(temporaryAttachment.getId()); } }
public int compareTo(final TemporaryAttachment other) { return this.created.compareTo(other.getCreated()); }
String getFormToken(final Issue issue, final Project project) { final Either<Issue, Project> entity = Either.<Issue, Project>cond(issue == null, project, issue); return TemporaryAttachment.getEntityToken(entity); }
private Either<AttachmentError, ChangeItemBean> transformTemporaryAttachment(final Long selectedAttachment, final TemporaryAttachmentsMonitor temporaryAttachmentsMonitor, @Nullable final ApplicationUser user, final Issue issue) { final TemporaryAttachment tempAttachment = temporaryAttachmentsMonitor.getById(selectedAttachment); if (tempAttachment == null) { final String errorMessage = getI18n(user).getText("attachfile.error.temp.file.not.exists"); return attachmentError( "Temporary attachment missing: " + selectedAttachment, errorMessage, "#" + selectedAttachment, VALIDATION_FAILED ); } else { return tryCreateAttachment(new CreateAttachmentParamsBean.Builder( tempAttachment.getFile(), tempAttachment.getFilename(), tempAttachment.getContentType(), user, issue).build()); } }
private List<ChangeItemBean> convertTemporaryAttachments(final ApplicationUser user, final Issue issue, final List<Long> selectedAttachments, final TemporaryAttachmentsMonitor temporaryAttachmentsMonitor, final String attachScreenshotFileName) throws AttachmentException { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // NOTE: this method has been copied from attachment manager and changed to accept fileName specified in Screenshot Attachment Dialog ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// notNull("issue", issue); notNull("attachScreenshotFileName", attachScreenshotFileName); notNull("selectedAttachments", selectedAttachments); notNull("temporaryAttachmentsMonitor", temporaryAttachmentsMonitor); final List<ChangeItemBean> ret = new ArrayList<ChangeItemBean>(); for (final Long selectedAttachment : selectedAttachments) { final TemporaryAttachment tempAttachment = temporaryAttachmentsMonitor.getById(selectedAttachment); final ChangeItemBean cib = attachmentManager.createAttachment(tempAttachment.getFile(), attachScreenshotFileName, tempAttachment.getContentType(), user, issue, Collections.<String, Object>emptyMap(), UtilDateTime.nowTimestamp()); if (cib != null) { ret.add(cib); } } //finally clear any other remaining temp attachments for give form token temporaryAttachmentsMonitor.clearEntriesForFormToken(formToken); return ret; } }
void addToMonitor(TemporaryAttachment temporaryAttachment) throws AttachmentException { final TemporaryAttachmentsMonitor attachmentsMonitor = locator.get(true); if (attachmentsMonitor != null) { attachmentsMonitor.add(temporaryAttachment); } else { deleteFileIfExists(temporaryAttachment.getFile()); throw new AttachmentException(getI18n().getText("attachfile.error.session.error", temporaryAttachment.getFilename())); } }
/** * Adds temporary attachments to the interally maintained list of temporary attachements * * @param temporaryAttachment the attachment to add */ public void add(final TemporaryAttachment temporaryAttachment) { temporaryAttachments.put(temporaryAttachment.getId(), temporaryAttachment); }
createTemporaryAttachmentOnDisk(file, uniqueFile.getFile()); final TemporaryAttachment temporaryAttachment = new TemporaryAttachment(uniqueFile.getId(), uniqueFile.getFile(), filename, contentType, formToken); addToMonitor(temporaryAttachment); return temporaryAttachment;
/** * When this object is unbount from the HttpSession, it's responsible for cleanup. Any * temporary attachments not converted to real attachments by now should be deleted to save * disk space! * * @param httpSessionBindingEvent */ public void valueUnbound(final HttpSessionBindingEvent httpSessionBindingEvent) { //delete any temporary attachments left over. for (TemporaryAttachment temporaryAttachment : temporaryAttachments.values()) { temporaryAttachment.getFile().delete(); } temporaryAttachments.clear(); } }
validationResult.getContentType(), validationResult.getSize(), issue, project, formToken); return Response.status(Response.Status.CREATED) .entity(new AttachTemporaryFileGoodResultBean(attach.getId().toString(), filename)).cacheControl(never()).build();
final TemporaryAttachment temporaryAttachment = new TemporaryAttachment(uniqueFile.getId(), uniqueFile.getFile(), fileName, contentType, formToken); addToMonitor(temporaryAttachment); return temporaryAttachment;