文件网批量搜索和更新



我有一个要求,其中,我必须更新对象存储中数百万个文档的文档元数据。所以我用下面的方法独立编写了一个简单的 java

SearchSQL documentSearchSQL = new SearchSQL();
String selectQuery = "Id ";
String classSymbolicName="Document_Class_Name";
String myAlias1 = "r";
String whereClause="r.Document_Type_Code='DIRMKTGDOC'and VersionStatus=1"
boolean subClassesToo=false;
documentSearchSQL.setSelectList(selectQuery);
documentSearchSQL.setFromClauseInitialValue(classSymbolicName, myAlias1, subClassesToo);
documentSearchSQL.setWhereClause(whereClause);
UpdatingBatch updatingBatch =null;
SearchScope searchScope = new SearchScope(p8ObjectStore);
RepositoryRowSet rowSet = searchScope.fetchRows(documentSearchSQL, new Integer(10000), null, new Boolean(true));
PageIterator pageIterator = rowSet.pageIterator();
RepositoryRow row;
Document document = null;
while(pageIterator.nextPage()){
Object[] rowArray = pageIterator.getCurrentPage();
updatingBatch = UpdatingBatch.createUpdatingBatchInstance(p8ObjectStore.get_Domain(),RefreshMode.NO_REFRESH); 
for (int i = 0; i < rowArray.length; i++) {
row= (RepositoryRow)rowArray[i];
Properties documentProps = row.getProperties();
document = Factory.Document.fetchInstance(p8ObjectStore, documentProps.getIdValue("Id"), null);
// I have the metadata symbolic name and its values within HashMap. So iterating Map to set the values
for(Map.Entry<String, ArrayList<String>> documentMetadata : documentMetadataValues.entrySet()){
document.getProperties().putObjectValue(documentMetadata.getKey(), documentMetadata.getValue().get(1));
}
updatingBatch.add(document, null);
}
updatingBatch.updateBatch();

当我在docVersion上运行查询时,我发现大约70万个文档符合标准,并期望所有文档都得到更新。当我运行该程序时,它更新了大约 390k 个文档,然后给出了错误

com.filenet.api.exception.EngineRuntimeException: FNRCA0031E: API_UNABLE_TO_USE_CONNECTION: The URI for server communication cannot be determined from the connection object http://server:port/wsi/FNCEWS40MTOM. Message was: Connection refused: connect

有没有更好的方法来实现这一目标?另外,我将使用组件队列在生产中运行此工具。

实际上,您有 2 个更好的选择来执行此操作,要么使用基于脚本的批量操作,要么使用扫描。


批量操作

您可以将批量操作应用于查询的搜索结果。这些操作的应用在查询运行时或查询运行之后发生。

  1. 在管理控制台中访问对象存储搜索
  2. 在">SQL 视图"选项卡上,输入相应的查询。
  3. 在">批量操作"选项卡上,选择"启用"。
  4. 在"脚本"部分中,选择">运行脚本"。
  5. 在脚本字段中输入您的 JavaScript 代码。有关更多信息,请参阅下面的示例。
  6. 单击运行。管理控制台运行查询和 JavaScript 操作。

importClass(Packages.com.filenet.api.property.Properties);
importClass(Packages.com.filenet.api.constants.RefreshMode);
function OnCustomProcess(CEObject) {
CEObject.refresh();
CEObject.getProperties().putValue("DocumentTitle", "Test1");
CEObject.save(RefreshMode.REFRESH);
}

有关这方面的更多信息,您可以在此处查看知识中心


自定义扫描作业

或者,您可以使用自定义扫描作业。扫描是配置为处理数据库表中对象的后台服务的实例。 如果对象满足配置的条件,则扫描将对对象执行操作。 扫描由扫描操作扫描作业组成

  1. 在域导航窗格中,单击对象存储。在对象中 商店导航窗格中,右键单击扫描管理>扫描操作文件夹,然后单击新建扫描操作
  2. 选择操作类型。对于此示例,让我们选择 Java 脚本(下面列出了一个示例),然后完成向导。
  3. 在域导航窗格中,选择对象存储。 在对象存储导航窗格中,选择">扫描管理">"作业扫描>自定义作业"文件夹,然后单击新建,参考我们刚刚创建的操作,然后完成向导。 现在一切就绪!运行扫描作业

importPackage(Packages.com.filenet.api.core);
importPackage(Packages.com.filenet.api.constants);
importPackage(Packages.com.filenet.api.exception);
importPackage(Packages.com.filenet.api.sweep);
importPackage(Packages.com.filenet.api.engine);
// Implement for custom job and queue sweeps.
function onSweep(sweepObject, sweepItems) {
var hcc = HandlerCallContext.getInstance();
hcc.traceDetail("Entering CustomSweepHandler.onSweep");
hcc.traceDetail("sweepObject = " +
sweepObject.getProperties().getIdValue(PropertyNames.ID) +
"sweepItems.length = " + sweepItems.length);
// Iterate the sweepItems and change the class.
idx = 0;
for (idx = 0; idx < sweepItems.length; idx++) {
// At the top of your loop, always check to make sure 
// that the server is not shutting down. 
// If it is, clean up and return control to the server.
if (hcc != null && hcc.isShuttingDown()) {
throw new EngineRuntimeException(ExceptionCode.E_BACKGROUND_TASK_TERMINATED,
this.constructor.name + " is terminating prematurely because the server is shutting down");
}
var item = sweepItems[idx].getTarget();
String msg = "sweepItems[" + idx + "]= " + item.getProperties().getIdValue("ID");
hcc.traceDetail(msg);
try {
var CEObject = Document(item);
CEObject.getProperties().putValue("DocumentTitle", "Test1");
CEObject.save(RefreshMode.NO_REFRESH);
// Set outcome to PROCESSED if item processed successfully.
sweepItems[idx].setOutcome(SweepItemOutcome.PROCESSED,
"item processed by " + this.constructor.name);
}
// Set failure status on objects that fail to process.
catch (ioe) {
sweepItems[idx].setOutcome(SweepItemOutcome.FAILED, "CustomSweepHandler: " +
ioe.rhinoException.getMessage());
}
}
hcc.traceDetail("Exiting CustomSweepHandler.onSweep");
}
/* 
* Called automatically when the handler is invoked by a custom sweep job 
* or sweep policy. Specify properties required by the handler, if any.
* If you return an empty array, then all properties are fetched.
*/
function getRequiredProperties() {
var pnames = ['Id', 'DocumentTitle'];
return pnames.toString();
}

有关扫描工作的更多信息,请查看此处的链接

相关内容

最新更新