/** * {@inheritDoc} */ @Override public boolean detach(Attachment attachment) { boolean found=this.attachments.containsValue(attachment); if(found) { AttachmentId remove = this.attachmentsById.remove(attachment.id()); this.attachmentsByResourceId.remove(attachment.resourceId()); this.attachments.remove(remove); } return found; }
@Override public final Map<String,PublicResource> attachments() { Map<String,PublicResource> result=new HashMap<String, PublicResource>(); for(Attachment attachment:resolveAs(Resource.class).attachments()) { result.put(attachment.id(), createResource(attachment.resourceId())); } return result; }
static AttachmentSnapshotCollection createFromResource(Resource resource, DelegatedWriteSession session) { AttachmentSnapshotCollection repository=new AttachmentSnapshotCollection(); for(Attachment attachment:resource.attachments()) { DelegatedResourceSnapshot snapshot = session.resolveResource(attachment.resourceId()); checkState(snapshot!=null,"Could not resolve attached resource of attachment %s of resource %s",attachment,resource.id()); DelegatedAttachmentSnapshot newAttachment=new DelegatedAttachmentSnapshot(attachment.id(),snapshot); repository.safeAttach(newAttachment); } return repository; }