public boolean isAttachmentValid(String fileId) { try { return (fileId != null && attachmentManager.getAttachment(new Long(fileId)) != null); } catch (Exception e) { return false; } }
boolean isAttachmentsEnabledAndPathSet() { return attachmentManager.attachmentsEnabled(); }
final Attachment attachment = attachmentManager.getAttachment(attachmentId); attachmentManager.streamAttachmentContent(attachment, zipEntryStreamConsumer);
@Override public Promise<Void> apply(@Nullable final Void input) { List<Attachment> attachments = attachmentManager.getAttachments(issue); try { for (Attachment a : attachments) { attachmentManager.deleteAttachment(a); } } catch (RemoveException e) { return Promises.rejected(new AttachmentCleanupException(e)); } return attachmentStore.deleteAttachmentContainerForIssue(issue); } });
for (FilePart filePart : fileParts) ChangeItemBean bean = attachmentManager.createAttachment(getFileFromFilePart(filePart), filePart.getName(), filePart.getContentType(), authContext.getUser(), issue, Collections.<String, Object>emptyMap(), nowTimestamp()); if (idStringValue != null) Attachment attachment = attachmentManager.getAttachment(Long.valueOf(idStringValue)); if (attachment != null)
@Override public ChangeItemBean createAttachment(File file, String filename, String contentType, ApplicationUser author, Issue issue) throws AttachmentException { validateAttachmentLimitSize(file, filename); final ChangeItemBean changeItemBean = attachmentManager.createAttachment(file, filename, contentType, author, issue); if (changeItemBean != null) { monitor.info("Added attachment to issue '" + issue.getKey() + "'"); } return changeItemBean; }
@Override public void consume(@Nonnull final Attachment attachment) { final InputStreamConsumer<Unit> streamConsumer = new InputStreamConsumer<Unit>() { @Override public Unit withInputStream(final InputStream inputStream) throws IOException { final String attachmentFileName = attachment.getFilename(); final ZipArchiveEntry zipEntry = new ZipArchiveEntry(uniqueFileNameGenerator.getUniqueFileName( attachmentFileName)); out.putArchiveEntry(zipEntry); IOUtil.copy(inputStream, out); out.closeArchiveEntry(); return Unit.UNIT; } }; try { attachmentManager.streamAttachmentContent(attachment, streamConsumer); } catch (final IOException e) { LOGGER.info("Streaming operation failed for attachment with Id " + attachment.getId()); } } };
public Collection<Attachment> getAttachments() { if (attachments == null) attachments = attachmentManager.getAttachments(this); return attachments; }
private void cloneAttachmentsIfNeeded(Issue clone) throws CreateException { /* * Note, that Create Attachment permission is not checked, * the same way Link Issue permission is not checked for cloning links. */ if (isCloneAttachments() && attachmentManager.attachmentsEnabled()) { Map<Long, Either<AttachmentError, Attachment>> result = attachmentManager.copyAttachments(originalIssue, getLoggedInUser(), clone.getKey()); for (final Either<AttachmentError, Attachment> either : result.values()) { if (either.isLeft()) { final AttachmentError error = either.left().get(); log.warn(error.getLogMessage(), error.getException().getOrNull()); } } } }
@Override public Either<AttachmentError, ChangeItemBean> apply( @SuppressWarnings ("NullableProblems") final TemporaryWebAttachment tempAttachment) { final Either<AttachmentError, ChangeItemBean> conversionResult = attachmentManager.convertTemporaryAttachment( ConvertTemporaryAttachmentParams.builder() .setAuthor(user) .setIssue(issue) .setTemporaryAttachmentId(tempAttachment.getTemporaryAttachmentId()) .setFilename(tempAttachment.getFilename()) .setContentType(tempAttachment.getContentType()) .setFileSize(tempAttachment.getSize()) .setCreatedTime(tempAttachment.getCreated()) .build() ); return conversionResult.map(new Function<ChangeItemBean, ChangeItemBean>() { @Override public ChangeItemBean apply(@SuppressWarnings ("NullableProblems") final ChangeItemBean changeItemBean) { monitor.removeById(selectedAttachmentId); return changeItemBean; } }); } };
public ChangeItemBean createAttachment(final MultiPartRequestWrapper requestWrapper, final ApplicationUser remoteUser, final GenericValue issue, final String fileParamName, final Map<String, Object> attachmentProperties) throws AttachmentException { final File file = requestWrapper.getFile(fileParamName); if (file == null) //there's not much we can do here. { log.warn(format("Could not create attachment. No file found in MultiPartRequestWrapper. File param name: %s. Request wrapper file names: %s.", fileParamName, CollectionBuilder.list(requestWrapper.getFileNames()))); return null; } final String filename = requestWrapper.getFilesystemName(fileParamName); final String contentType = requestWrapper.getContentType(fileParamName); return attachmentManager.createAttachment(file, filename, contentType, remoteUser, issue, attachmentProperties, UtilDateTime.nowTimestamp()); }
try result = attachmentManager.streamAttachmentContent(attachment, new InputStreamConsumer<Boolean>()
private boolean givenIssueHasAnyAttachment(Issue givenIssue) { return CollectionUtils.isNotEmpty(attachmentManager.getAttachments(givenIssue)); }
/** * Looks up the attachment by reading the id from the query string. * * @param query eg. '/10000/foo.txt' * @return attachment found * @throws AttachmentNotFoundException if no attachment is found after parsing the query string * or if the resulting attachment id does not exist. * @throws DataAccessException if there is a problem accessing the database. */ protected Attachment getAttachment(String query) { int x = query.indexOf('/', 1); final String idStr = query.substring(1, x); Long id; try { id = new Long(idStr); } catch (NumberFormatException e) { throw new AttachmentNotFoundException(idStr); } if (query.indexOf('/', x+1) != -1) { // JRA-14580. only one slash is allowed to prevent infinite recursion by web crawlers. throw new AttachmentNotFoundException(idStr); } return ComponentAccessor.getAttachmentManager().getAttachment(id); }
/** * Attaches files using the method outlined in Fear of attachments at http://www.iseran.com/Steve/papers/fear-of-attachments.pdf * and http://marc.theaimsgroup.com/?l=axis-user&m=109103923030924&w=2 * * @return boolean */ private boolean addAttachmentToIssueFromMimeAttachments(User user, String[] fileNames, Issue issueToAttach) throws RemoteException, RemotePermissionException { String formToken = "issuetoken-" + issueToAttach.getId(); try { File[] files = attachmentHelper.saveFile(fileNames, issueToAttach, formToken); for (int i = 0; i < files.length; i++) { File file = files[i]; attachmentManager.createAttachment(file, fileNames[i], GENERIC_CONTENT_TYPE, user, issueToAttach); } } catch (Exception e) { log.warn("Unable to attach files through the SOAP interface", e); throw new RemoteException("Unable to attach files.", e); } return true; }
private boolean validateAttachmentsEnabled(@Nullable final ApplicationUser user, final ErrorCollection errorCollection) { return processValidationResult(attachmentManager.attachmentsEnabled(), "attachment.service.error.attachments.disabled", user, errorCollection); }
deleteQuietly(thumbnailFile); return attachmentManager.streamAttachmentContent(attachment, new InputStreamConsumer<Thumbnail>()
boolean isAuthorOfAtLeastOneAttachment(Issue issue, ApplicationUser user) { List<Attachment> attachments = attachmentManager.getAttachments(issue); for (final Attachment attachment : attachments) { if (isUserAttachmentAuthor(attachment, user)) { return true; } } return false; }
public boolean apply(GenericValue item) { if (ATTACHMENT.equalsIgnoreCase(item.getString("field"))) { try { return attachmentManager.getAttachment(createLong(item.getString("newvalue"))) != null; } catch (final Exception e) { return false; } } return true; } };
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; } }