如何通过liferay中的编程将标签添加到doc库中的文档?

时间:2012-03-20 05:04:51

标签: liferay document-library

我是liferay的新手。我正在使用liferay 6.0.5 我想通过代码将“Archive”标签添加到doc库文档中,因此我可以使用“Archive”标记获取文档。 怎么做?

以下是正在处理的代码:

private void addArchive(List<DLFileEntry> fileEntryList) {       
    try
    {
        long groupId=0;
        long userId=0;
        String className=null;
        long classPK=0;
        long categoryIds[]=null;
        String tagNames[]=null;
        String newTagNames[] = new String[20];
        long entryId = 0;
        List<AssetTag> TNames = new ArrayList<AssetTag>();
        int i = 0;
        for(DLFileEntry cur:fileEntryList)
        {
            groupId=cur.getGroupId();
            userId=cur.getUserId();
            className=cur.getClass().getName();
            classPK=cur.getPrimaryKey();
            AssetEntry ae=AssetEntryLocalServiceUtil.getEntry(groupId, cur.getUuid());
            categoryIds=ae.getCategoryIds();
            entryId = ae.getEntryId();
            TNames = ae.getTags();
            System.out.println(cur.getTitle());
            i=0;
            for(AssetTag tag : TNames)
            {
                System.out.println(tag.getName());      
                newTagNames[i]=tag.getName().toString();
                i++;
            }
            newTagNames[i]="NameArchive";
            AssetEntryLocalServiceUtil.updateEntry(userId, groupId, className, classPK, categoryIds, newTagNames);
            System.out.println("------------------------------------------------");
        }
        System.out.println("outside for loop"); 
    }
    catch (Exception e) {
        // TODO: handle exception
    }
}

1 个答案:

答案 0 :(得分:0)

首先,您需要使用DLFileEntryLocalServiceUtil类(以及其他相关的DL * LocalServiceUtil类)在文档库中找到文件的“entryId”。

“entryId”与数据库中的assetentry表中的“classPK”字段有关。然后,您可以使用以下方法使用标记“存档”更新AssetEntry:

AssetEntryLocalServiceUtil.updateEntry(userId, groupId, DLFileEntry.class.getName(), fileEntryIdYouJustGot, categoryIds, new String[] {"Archive"});

这将删除任何其他标签,因此您可能希望从资产条目中检索当前标签,然后向其添加“存档”,然后将结果数组传递给方法。

但这是你需要做的事情的基础。

~~编辑~~

修改你的getEntryLine以使用以下内容。你正在传递DLFileEntry UUID,但是如果你看一下源代码,它会要求一个我认为不同的classUuid。还要在异常处理中添加日志记录,以查看是否抛出了异常。

AssetEntry ae=AssetEntryLocalServiceUtil.getEntry(groupId, classPK);