【发布时间】:2019-08-13 10:53:36
【问题描述】:
工作流程完成后,如何在 Alfresco 存储库中创建 xml 文件?
我创建了一个 ServiceTask,但从那里我只能访问 DelegateExecution、ProcessEngine 和各种服务,但不能访问 NodeService.
问候,
迈克
编辑。 很难相信对于像从正在进行的工作流创建新文件这样的基本事情没有简单的解决方案。 (在这种情况下,REST API 似乎要好很多)
首先,需要在bpmn文件中创建ServiceTask:
<serviceTask id="myServiceTask" activiti:class="com.example.myClass"></serviceTask>
其次,在myClass中:
Map<Object, Object> registeredBeans = Context.getProcessEngineConfiguration().getBeans();
ServiceRegistry registry = (ServiceRegistry)registeredBeans.get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
NodeService nodeService = registry.getNodeService();
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
ResultSet rs = registry.getSearchService().query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home/app:shared\"");
NodeRef companyHomeNodeRef = null;
try
{
if (rs.length() == 0)
{
throw new AlfrescoRuntimeException("Bad Lucene Search!");
}
companyHomeNodeRef = rs.getNodeRef(0);
// Create a map to contain the values of the properties of the node
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NAME, "NewFile.txt");
// use the node service to create a new node
NodeRef node = nodeService.createNode(
companyHomeNodeRef,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "TEST"),
ContentModel.TYPE_CONTENT,
props).getChildRef();
// Use the content service to set the content onto the newly created node
ContentWriter writer = registry.getContentService().getWriter(node, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent("Message inside new content");
}
finally
{
rs.close();
}
我必须获得 NodeSerivce,然后使用 Lucene 搜索 SharedFolder/Userhome(不应该在某处声明公共文件夹的“路径”吗?)最后使用 ContentWriter em>,我可以将内容放到他的 Alfresco Repository 中。
【问题讨论】: