0

以下是我们的要求

其中一个应用程序(比如 ABC)仅使用 FileNet 来存储文档。现在,其中一些引用已在 ABC 中清除(但清除的文档 ID 存储在 ABC 的 DB 中),并且不再需要存储在 FileNet 中的那些文档,需要删​​除以清理空间。

为了实现上述目的,我们有以下逻辑:

  1. 从 ABS 的数据库中获取文档 ID
  2. 在 CE 中运行 delete 方法

问题是如何连接到 CE 之外的不同数据库以及

  1. 搜索中的脚本会是不错的选择吗?
  2. 使用批量删除但问题是,如果一个文件失败,那么整个过程都会失败,我们必须返回
  3. 这些可以使用自定义事件和订阅吗?
4

2 回答 2

0

一个简单的自定义批处理 Java/.NET 程序可以达到这个目的。如果您计划每月/每季度安排一次此活动,它还将有助于定期运行它。

您可以使用下面的代码片段作为参考。当然,它不是最佳的,但只是草草写下。

String query = "select DOCID from ......."; //appropriate query to return document ids.
try{
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(query);

    while(rs.next()){
        Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id(<<doc Id in the loop>>));
        doc.delete();
        doc.save(RefreshMode.NO_REFRESH);
    }
} catch (SQLException e)
{
   //something went wrong with the sql
}

关于自定义事件,我不确定您会将触发器与哪个自定义事件关联?

于 2015-12-30T19:54:54.367 回答
0

我有一个自定义数据库,我可以从中获取 GUID,然后从 CE 中删除该文档(如果可用)。与 GUID 关联的所有记录都将从表中删除。

此外,该方法是同步的,以使多个线程能够加速该过程。随着记录数量的增加,批量删除肯定需要时间。输出消息仍需整理。

/**
 * This method "HARD" deletes the document from CE in <B>BATCH</B>.
 * @param filenetDocGUID
 * @throws Exception
 */
public static synchronized String batchDeleteDocumentFromCE_DB(List<String> filenetDocGUID, String QUERY) throws Exception {
    System.out.println("Start of batchDeleteDocumentFromCE_DB() method");
    System.out.println("Input Parameter filenetDocGUID is : " + filenetDocGUID);
    long startTime = System.currentTimeMillis();

    Document document = null;
    UserContext uc = null;
    ObjectStore os = null;
    Subject subject = null;
    VersionSeries vs = null;
    UpdatingBatch ub = null;

    int deletedRecordsFromDB [] = null ;
    List<String> deletedRecordsFromCE = null;
    PreparedStatement preparedStatement = null;
    Connection dbConnection = null;
    String messageBody = "<table border=\"1\" align=\"center\"><tr><td>GUID</td><td>DB Records</td><td>CE Records</td></tr>";
    List<String> processedfilenetDocGUID = null;

    try {
        if (filenetDocGUID != null) {

            getCESession(); // This will get CE Session

            os = ceSessionData.getObjectStore(); 
            System.out.println("Domain fetched from CESession static reference is : " + ceSessionData.getDomain());

            // The RefreshMode parameter indicates that the property cache for this instance is to be 
            // refreshed with the updated data.
            ub = UpdatingBatch.createUpdatingBatchInstance(ceSessionData.getDomain(), RefreshMode.NO_REFRESH);
            System.out.println("Batch update object created");

            subject = ceSessionData.getSubject();
            System.out.println("Subject fetched from CESession static reference.");

            uc = UserContext.get();
            uc.pushSubject(subject);

            dbConnection = getDataBaseConnection();
            dbConnection.setAutoCommit(false); // auto commit is set to false so that DB is not committed before deleting the records
            preparedStatement = dbConnection.prepareStatement(QUERY);
            //QUERY will be for the db from where you need to remove the data
            deletedRecordsFromCE = new ArrayList<String>();

            if (os != null) 
            {
                processedfilenetDocGUID = new ArrayList<String>();
                for(String GUID : filenetDocGUID)
                {
                    try
                    {
                        //get document versions from CE
                        document = Factory.Document.fetchInstance(os, GUID.trim(), null);
                        vs = document.get_VersionSeries();
                        vs.delete();
                        ub.add(vs, null);// add documents to the batch

                        //prepare statement for deleting records from DB with the GUID
                        preparedStatement.setString(1, GUID.trim());
                        preparedStatement.addBatch();   // add records to dB batch for deletion
                        deletedRecordsFromCE.add("1");

                        processedfilenetDocGUID.add(GUID);
                    }
                    catch(Exception exp)
                    {
                        if(exp.getMessage().contains("The requested item was not found.")||exp.getMessage().contains("E_OBJECT_NOT_FOUND"))
                        {
                            log.error("The requested item with GUID : "+GUID.trim()+" was not found in CE.");
                            //If document is not available in CE, then delete all records associated with it from DB
                            //document not present in CE but available in DB so delete all the DB records referring to this GUID
                            //prepare statement for deleting records from DB with the GUID

                            preparedStatement.setString(1, GUID.trim());
                            preparedStatement.addBatch();
                            deletedRecordsFromCE.add("The requested item was not found.");

                            processedfilenetDocGUID.add(GUID);
                        }
                        else
                        {
                            log.error("Exception occurred while fetching Document Version Series from DB");
                        }
                    }
                }

                deletedRecordsFromDB =  preparedStatement.executeBatch();
                System.out.println("Batch Records deleted from DB >>>>>>>>>>>>>>>>>>>>");
                if(ub.hasPendingExecute())
                {
                    //execute the batch only if there are records in the batch
                    ub.updateBatch();
                    System.out.println("Batch Records deleted from CE>>>>>>>>>>>>>>>>>>>>>>>>>>");
                }
                else
                {
                    System.out.println("No records to be deleted from CE>>>>>>>>>>>>>>>>>>>>>>>>>>");
                }

                dbConnection.commit();
                System.out.println("DB delete records commit successful");

                //below will create a html to view the report for deletion
                for(int i=0; i<processedfilenetDocGUID.size(); i++)
                {
                    messageBody = messageBody+("<tr><td>"+processedfilenetDocGUID.get(i)+"</td>");
                    if(deletedRecordsFromCE.get(i)!=null)
                    {
                        //only if document was present in CE or document version series was not obtained from CE
                        messageBody = messageBody+("<td>"+deletedRecordsFromDB[i]+"</td><td>"+deletedRecordsFromCE.get(i)+"</td>");
                    }
                    else
                    {
                        //if any other exception occurs then neglect the record and proceed with others
                        messageBody = messageBody+("<td>"+deletedRecordsFromDB[i]+"</td><td>Exception occured while deleting from CE.</td>");
                    }
                    messageBody = messageBody+(messageBody + "</tr>");
                }
            }
        }
    }
    catch (Exception e) 
    {
        System.out.println("Exception in deleteDocumentFromCE() Method of CEManager.class");

        dbConnection.rollback(); // rollback from dB in case of issues
        log.error(e.getMessage());
        throw new Exception("System Error occurred while deleting the document in CE.. "+e.getMessage());
    }
    finally 
    {
        messageBody = messageBody+("<tr><td colspan=\"3\">Time taken for Batch in msec : "+(System.currentTimeMillis()-startTime)+"</td></tr>");
        messageBody = messageBody+("<tr><td colspan=\"3\">Records deleted : "+processedfilenetDocGUID.size()+" from input "+filenetDocGUID.size()+"</td></tr>");
        messageBody = messageBody+("</table>");

        System.out.println("Message : "+messageBody);
        document = null;
        vs = null;
        ub = null;
        deletedRecordsFromCE = null;
        closeDBResources(dbConnection, preparedStatement, null);
        if (uc != null)
            uc.popSubject();
    }

    System.out.println("End of batchDeleteDocumentFromCE_DB() method.");
    return messageBody;
}
于 2016-05-04T08:18:38.313 回答