0

我通过扩展 org.quartz.StatefulJob 配置了一个调度程序作业并创建了一个动作类

在 Action 类的执行方法中(如下所示),在执行方法中获取 CompanyHome 引用的最佳方法是什么?

我的目标是在操作调用时在公司主目录中创建一个文件。有什么建议吗?

在此处输入图像描述

4

2 回答 2

3

你试过使用NodeLocatorService吗? https://docs.alfresco.com/4.0/concepts/node-locator-available.html。例如:

NodeRef companyHomeNodeRef = registry.getNodeLocatorService().getNode(CompanyHomeNodeLocator.NAME, null, null);
于 2020-02-13T18:13:59.237 回答
1

请实现这样的方法

public NodeRef getCompanyHomeNodeReference() {
        NodeRef companyHomeNodeRef = null;
        companyHomeNodeRef = (NodeRef)AuthenticationUtil.runAsSystem(new AuthenticationUtil.RunAsWork<Object>() {
            public Object doWork() throws Exception {
                StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"));
                ResultSet rs = serviceRegistry.getSearchService().query(storeRef, SearchService.LANGUAGE_XPATH,
                        "/app:company_home"); 
                Object companyHome = null;
                try {
                    if (rs.length() == 0) {
                        LOG.error("Didn't find Company Home ");
                        throw new AlfrescoRuntimeException("Didn't find Company Home");
                    }
                    final NodeRef companyHomeNodeRef1 = rs.getNodeRef(0);
                    if(companyHomeNodeRef1 == null) {
                        LOG.info("Didn't find Company Homes");
                    }else {
                        companyHome = companyHomeNodeRef1;
                    }
                } finally {
                    rs.close();
                }
                return companyHome;
            }

        });
        return companyHomeNodeRef;
    }

导入如下:

import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.repository.StoreRef;

请查看关键代码如何放置在 AuthenticationUtil 中(这非常重要)。

然后使用下面的代码创建一个文件:

fileFolderService.create(companyNodeRef, "yourfilename", ContentModel.TYPE_CONTENT);

在 service-context.xml 中添加这个 bean

<bean id="yourObj" class="MoveMonthlyDataAction">
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry" />
        </property> 
</bean>

并在MoveMonthlyDataAction . java下面提到,

public class MoveMonthlyDataAction {
    ServiceRegistry serviceRegistry;

    public void execute(){
        // your code
    }
    // getter and setter
}

希望这会有所帮助。

于 2020-02-14T10:32:36.950 回答