Alfresco应用类别与js文件

Alfresco apply category with js to doc

本文关键字:js 文件 应用 Alfresco      更新时间:2023-09-26

如何在Alfresco中使用javascript应用类别文档?

尝试如下:

document.properties["cm:categories"] = "testCat";
更新:

像这样,我可以得到"根类别",但不能得到"子类别":

var rootCats =  classification.getRootCategories("cm:generalclassifiable");
document. properties["cm:categories"] = rootCats[3];

这个行不通:

document. properties["cm:categories"] = rootCats[3][1];

我发现了,如果有人需要这就是它的方法

获取所有根目录[音频,视频,图像,…]

var rootCats =  classification.getRootCategories("cm:generalclassifiable");

从所需的根类别中获取子类别->从"视频"[恐怖,喜剧,…]中获取子类别

var singleCat = rootCats[1].subCategories; 

apply category to document -> apply "horror" to document

doc. properties["cm:categories"] = singleCat[0]; //app

保存它

doc.save();

首先确保文档具有可分类的方面(即具有cm:generalClassifiable方面)。

然后查找要添加的类别(如:

)

UPDATE:查找某个名称的类别类型节点的示例查询:

像这样搜索你的类别,例如,你也可以添加一个PATH子句,以确保你在正确的层次结构。

var nodes = var categories= search.luceneSearch('+TYPE:"http://www.alfresco.org/model/content/1.0}category" +@name:testCat');

然后从返回的数组中取出元素…

获取节点的现有类别:

categories= document.properties["cm:categories"];

将新类别压入数组:

categories.push(categoryToAdd);

赋值给文档:

document.properties["cm:categories"] = categories;

document.save();

我们有一个类似的需求,尽管与OP问题略有不同,但我们认为它足以保证在这里包含。

我们偶尔需要批量应用类别。例如:获得新业务,迁移所有文档,添加类别以匹配现有内容。

在界面中为大量文档添加类别是乏味的。它需要启用方面(可分类的),然后编辑属性以选择所需的类别。为每个文档单独设置。更糟糕的是,添加方面对共享中的资源管理器视图中的文档不可用,因此需要输入预览。对于大型文档,进入预览本身就是几秒钟的延迟。

因此,我们构建了一个简单的脚本,将父文件夹的类别应用于其下的所有内容。然后我们只需要设置该文件夹的类别,并开始在其中移动内容(即:移动内容以获得类别/ies,然后移动回原来的位置,但现在所有的方面和类别/ies都应用了)。

实际上我们现在有2个:

  1. 第一个文件夹/规则覆盖对象拥有和的任何类别将它们替换为父文件夹中的那些—我们将此文件夹命名为BulkCategorise
  2. 第二个是累积的,所以它保留现有的类别,只添加来自父文件夹的目录,我们将其命名为AccumulateCategories

我们将创建第三个,以便在时间允许的情况下选择性地删除它们。

注意事项:

  • 实际上不需要添加可分类方面手动或在代码中,它"只是工作"-至少在5.1。
  • 这可能不是最好的方法
  • 累积一个已经应用的类别似乎不会引起任何问题,它们似乎会自动合并/合并

要使用这些脚本,创建2个文件夹,并对每个文件夹应用一个规则来运行相关的脚本。

第一个脚本完全将对象的类别替换为父文件夹的类别,并且非常简单[设置@name和SITE以匹配您的安装]:

var inheritFromDir = search.luceneSearch('TYPE:"http://www.alfresco.org/model/content/1.0}folder" +@name:BulkCategorise +SITE:YOUR_SITE_NAME');
// We need to deref the array of noderefs result using inheritFromDir[0]
document.properties["cm:categories"] = inheritFromDir[0].properties["cm:categories"];
document.save();

第二个脚本有点复杂——我们留下了日志代码(注释掉了)作为一个例子,看看如何做到这一点,因为它也花了一些时间来弄清楚(这是一个非常有用的功能)。如前所述,更新第一行的@name和SITE以匹配您的系统。

var inheritFromDir = search.luceneSearch('TYPE:"http://www.alfresco.org/model/content/1.0}folder" +@name:AccumulateCategories +SITE:YOUR_SITE_NAME');
// We need to deref the single array result using inheritFromDir[0] to get categories from topmost parent (folder) node
var parentCatArray = inheritFromDir[0].properties["cm:categories"];
//and any existing categories of the doc, or null if none exist
var thisCatArray = document.properties["cm:categories"];
var thisLen = 0;
if (thisCatArray != null) {
   thisLen = thisCatArray.length;
} else {
   thisCatArray = new Array();
}
// Some logging to find out what  is going on...
//var logFile = space.childByNamePath("log.txt");
// If the log file does not already exist, create it in current folder.
//if (logFile == null) {
//    logFile = space.createFile("log.txt");
//}
//if (logFile != null) {
//    logFile.content += new Date().toGMTString() + "'tRun started. Length of existing array is: " + thisLen + "'r'n";
//    logFile.content += new Date().toGMTString() + "'tFound parent node categories:'r'n";
      for (var i=0; i < parentCatArray.length; i++)
      {
         thisCatArray[thisLen]=parentCatArray[i];
         thisLen += 1;
      }
//}
// Push the new array of categories to the document
thisCatArray.push(document);
// apply and save the doc
document.properties["cm:categories"] = thisCatArray;
document.save();

等。瞧!我们以类似的方式实现了BulkTag和BulkAccumulateTags。现在,添加任意类别就像将它们应用到文件夹并通过拖放移动内容一样简单。