/** * This will delete an asset and all its attachments * * @param assetId The id of the asset * @return <code>true</code> if the asset and all its attachments are deleted. Note this is not * atomic so some attachments may be deleted and <code>false</code> returned. * @throws IOException * @throws RequestFailureException */ public void deleteAssetAndAttachments(String assetId) throws IOException, RequestFailureException { Asset ass = getUnverifiedAsset(assetId); List<Attachment> attachments = ass.getAttachments(); if (attachments != null) { for (Attachment attachment : attachments) { deleteAttachment(assetId, attachment.get_id()); } } // Now delete the asset deleteAsset(assetId); }
/** * Returns the meta data about an attachment * * @param assetId The ID of the asset owning the attachment * @param attachmentId The ID of the attachment * @return The attachment meta data * @throws IOException * @throws RequestFailureException */ public Attachment getAttachmentMetaData(String assetId, String attachmentId) throws IOException, BadVersionException, RequestFailureException { // At the moment can only get all attachments Asset ass = getAsset(assetId); List<Attachment> allAttachments = ass.getAttachments(); for (Attachment attachment : allAttachments) { if (attachmentId.equals(attachment.get_id())) { return attachment; } } // Didn't find it so just return null return null; }
/** * This method will update an existing attachment on an asset. Note that Massive currently doesn't * support update attachment so this will do a delete and an add. * * @param assetId The ID of the asset that the attachment is attached to * @param name The name of the attachment to update * @param file The file to attach * @param attach Attachment metadata * @return * @throws IOException * @throws RequestFailureException */ public Attachment updateAttachment(String assetId, AttachmentSummary summary) throws IOException, BadVersionException, RequestFailureException { // First find the attachment to update // TODO update when massive supports proper updates to attachments Asset ass = getAsset(assetId); List<Attachment> attachments = ass.getAttachments(); if (attachments != null) { for (Attachment attachment : attachments) { if (attachment.getName().equals(summary.getName())) { this.deleteAttachment(assetId, attachment.get_id()); break; } } } return this.addAttachment(assetId, summary); }