我如何在Atlassian Confluence与Java API更新(不添加其他)附件



我们有一个自定义插件,允许人们通过GUI上传文档,并在我们的插件中添加有关这些文档的元数据。另外,插件的另一个功能是,我们通过Confluence SOAP服务将XML文件推向我们。该XML文件每天通过SOAP服务在插件空间内附加到特定文件。

我们现在被指控扭转过程。现在,我们将进行自己的肥皂调用以获取相同的XML文件并将其连接到同一页面。

我可以成功地将一个新文件附加到页面上,但是当我尝试更新(替换)XML文件使用较新版本时,我最终将另一个文件上传到另一个文件,因此我将带有多个文件的副本同名,这不是我们想要的。

这是我添加新附件的内容,但不会更新(替换)附件:

page = pageManager.getPage(spaceKey, pageTitle);
attachment = attachmentManager.getAttachment(page, attachmentFilename);
Attachment currentAttachment = null;
currentAttachment = (Attachment) attachment.clone();
attachment = new Attachment();
attachment.setFileName(attachmentFilename);
attachment.setContent(page);
attachment.setFileSize(fileSize);
attachment.setContentType(newAttachmentContentType);
attachment.setCreator(page.getCreator());
attachment.setCreationDate(date);
attachment.setComment(attachmentComment);
attachmentManager.saveAttachment(attachment, currentAttachment, dplAsStream);

再次,我想要的是用更新的filename.xml替换filename.xml,但是我得到的是filename.xml,filename.xml,filename.xml,等等。

据我所知,没有简单的updateAttachment,因为文件存储遵循基于版本的方法。同一文件的每一个上传(通过文件名)将是已经存在的文件的较新版本,而无需删除较旧的文件。

要实现您的更新功能,可能有必要执行多个步骤:

  1. 检查要上传的文件是否已经存在(= update)
  2. 使用AttachmentManager删除给定版本或所有以前的版本
  3. 上传文件

也许CLI实现提供了更多细节,因为您可以在这里运行更新命令。

最新更新