使用FileNet API

时间:2017-10-30 12:43:48

标签: java filenet-p8 filenet filenet-content-engine

我有这段代码:

Folder fold = Factory.Folder.fetchInstance(os, folderPath, null);
DocumentSet docs = fold.get_ContainedDocuments();
Iterator it = docs.iterator();

Document retr;
try {
    while (it.hasNext()) {
        retr = (Document)it.next();
        String name = retr.get_Name();
        System.out.println(name);

        if(name.equals(fileName)) {
            System.out.println("Match Found");
            System.out.println("Document Name : " + retr.get_Name());
            return retr;
        }
    }
} catch (Exception e) {
    e.printStackTrace();
}

目前,此代码适用于检索具有特定文件名的文档。我想添加到此,以便它还可以选择具有该名称的文件的最新版本。我该怎么办?

我考虑在现有的内部添加一个额外的,但我害怕影响性能。

2 个答案:

答案 0 :(得分:0)

如果您要提交文档(或文档的子类),则包含的文档将是当前文档版本。在这种情况下,当前文档版本是(按使用顺序):

  • 发布的版本(如果有的话),否则
  • 当前版本(如果有),否则
  • 预订版。

您无法使用Folder.file方法将特定文档版本归档到该文件夹​​中,因此您将始终在文件夹中包含DocumentSet最新版本

答案 1 :(得分:0)

这是你可以做的,以获得最新版本的文件

    Folder fold = Factory.Folder.fetchInstance(os, folderPath, null);
        DocumentSet docs = fold.get_ContainedDocuments();
        Iterator it = docs.iterator();

        Document retr;
        try {
            while (it.hasNext()) {
                retr = (Document)it.next();
                String name = retr.get_Name();
                System.out.println(name);

                if(name.equals(fileName)) {

                    System.out.println("Match Found");
                    System.out.println("Document Name : " + retr.get_Name());
//here you are checking the document for the name. It also can happen that, this document might have more than version but the title remained same for each version. You can get the latest version like

                    return retr.get_CurrentVersion();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }