Alfresco:在ftp中覆盖文件时增加文档版本

时间:2013-01-02 07:45:42

标签: ftp alfresco

我想在ftp中覆盖文件时增加次要文档版本。当我跟踪代码时,ContentDiskDriver2.truncateFile()适用于覆盖文件。在此函数中,我使用versionService来增加版本。以下代码用truncateFile()编写 试试{

    NodeRef nodeRef = getNodeForPath(tree, DriverContent.FILE_OPEN_PARAMS.getPath());
    System.out.println("Node Ref: " + nodeRef);

    // Increase minor version to file.
    Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(2, 1.0f);
    versionProperties.put(Version.PROP_DESCRIPTION, "");
    versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);

    VersionService versionService = (VersionService) applicationContext.getBean("versionService");
    versionService.createVersion(nodeRef, versionProperties);
} catch (FileNotFoundException e) {
    e.printStackTrace();
}

但不幸的是我收到了这个错误。

2013-01-02 14:12:31,609  ERROR [org.alfresco.fileserver] [Sess_FTP3_192.168.1.166] Error from JLAN
 org.alfresco.error.AlfrescoRuntimeException: 00020073 Transaction must be active and synchronization is required: Thread[Sess_FTP3_192.168.1.166,5,FTPSessions]
    at org.alfresco.repo.transaction.AlfrescoTransactionSupport.registerSynchronizations(AlfrescoTransactionSupport.java:467)
    at org.alfresco.repo.transaction.AlfrescoTransactionSupport.getSynchronization(AlfrescoTransactionSupport.java:451)
    at org.alfresco.repo.transaction.AlfrescoTransactionSupport.getResource(AlfrescoTransactionSupport.java:244)
    at org.alfresco.repo.transaction.TransactionalResourceHelper.incrementCount(TransactionalResourceHelper.java:71)
    at org.alfresco.repo.policy.BehaviourFilterImpl.disableBehaviour(BehaviourFilterImpl.java:158)
    at org.alfresco.repo.version.Version2ServiceImpl.createVersion(Version2ServiceImpl.java:212)
    at org.alfresco.repo.version.Version2ServiceImpl.createVersion(Version2ServiceImpl.java:140)
    at org.alfresco.filesys.repo.ContentDiskDriver2.increaseVersion(ContentDiskDriver2.java:2937)
    at org.alfresco.filesys.repo.ContentDiskDriver2.truncateFile(ContentDiskDriver2.java:1652)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
    at $Proxy97.truncateFile(Unknown Source)
    at org.alfresco.filesys.repo.NonTransactionalRuleContentDiskDriver.truncateFile(NonTransactionalRuleContentDiskDriver.java:480)
    at org.alfresco.filesys.repo.LegacyFileStateDriver.truncateFile(LegacyFileStateDriver.java:471)
    at org.alfresco.filesys.repo.BufferedContentDiskDriver.truncateFile(BufferedContentDiskDriver.java:532)
    at org.alfresco.jlan.ftp.FTPSrvSession.procStoreFile(FTPSrvSession.java:2262)
    at org.alfresco.jlan.ftp.FTPSrvSession.run(FTPSrvSession.java:4924)
    at java.lang.Thread.run(Thread.java:662)

您能帮助我解决交易必须处于活动状态并且需要同步

我找到了这个链接.. Is the Alfresco repository document version history available via CIFS/FTP?

2 个答案:

答案 0 :(得分:1)

你被“小写字母”与“大字母”Alfresco服务抓住了

“小写字母”服务是原始服务,通常仅在其他Alfresco低级别服务中使用。 “大信”服务是面向服务的包装用户,包括交易,审计,安全等。

对于您的情况,您需要使用大写字母表格,因此请更改行

VersionService versionService = (VersionService) applicationContext.getBean("versionService");

要正确的一个:

VersionService versionService = (VersionService) applicationContext.getBean("VersionService");

您将获得带有事务,安全性等的VersionService副本,这是我认为您需要的情况。 (请注意,bean使用Big First Letter而不是小写字母获取)

答案 1 :(得分:0)

这是我发现的替代解决方案。明确使用交易。

    VersionService versionService = (VersionService) applicationContext.getBean("VersionService");
    TransactionService transactionService = (TransactionService) applicationContext.getBean("transactionService");

    UserTransaction tx = null;
    try {
        tx = transactionService.getUserTransaction();
        tx.begin();
        versionService.createVersion(nodeRef, versionProperties);
        tx.commit();
    } 
    catch (Exception e) 
    {
        if(tx != null)
        {
            try
            {
                tx.rollback();
            } catch (IllegalStateException e1) 
            {
                e1.printStackTrace();
            } catch (SecurityException e2) 
            {
                e2.printStackTrace();
            } catch (SystemException e3) 
            {
                e3.printStackTrace();
            }
        }
    }