![](/img/trans.png)
[英]How can I be able to create a folder node on companyhome in Alfresco?
[英]How to get a companyHome for nodeService.getChildAssocs in Alfresco?
實際上,我正在嘗試從露天的當前任務獲取文件,但是找不到如何獲取當前節點的任何解密信息。 我發現我可以使用以下命令獲取所有需要的子nodeRefs:
List<ChildAssociationRef> children = nodeService.getChildAssocs(companyHome)
但是在這里我只看到我需要NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern
這些至少是3個參數,其中之一也是NodeRef,事實證明我需要一個NodeRef來獲取NodeRef。 據我了解,最后一個nodeRef類似於父文件夾,但是我也不知道如何獲取它。 也可以通過PATH這樣獲取NodeRef:
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
ResultSet rs = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home/app:user_homes/sys:boris/cm:mypics\"");
NodeRef companyHomeNodeRef = null;
try
{
if (rs.length() == 0)
{
throw new AlfrescoRuntimeException("Didn't find Company Home");
}
companyHomeNodeRef = rs.getNodeRef(0);
}
finally
{
rs.close();
}
但是我無法對路徑進行硬編碼,因為Alfresco可以在服務器或其他任何地方運行。 也可以像這樣通過Lucene獲取NodeRef:
SearchParameters sp = new SearchParameters();
sp.addStore(getStoreRef());
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery("TYPE:\"{http://www.alfresco.org/model/content/1.0}content\"");
ResultSet results = null;
try
{
results = serviceRegistry.getSearchService().query(sp);
for(ResultSetRow row : results)
{
NodeRef currentNodeRef = row.getNodeRef();
...
}
}
finally
{
if(results != null)
{
results.close();
}
}
但這將使我返回露天存在的所有節點。 也許可以改進其中一種方法來實現我的願望? 也許還有其他方法?
UPD:這是我想要獲取和使用節點的代碼部分:
NodeService nodeService = getServiceRegistry().getNodeService();
ContentService contentService = getServiceRegistry().getContentService();
List<ChildAssociationRef> children = nodeService.getChildAssocs(companyHome);
if (children.isEmpty()) {
throw new AlfrescoRuntimeException("Workflow bpm_package does not contain any files");
}
for(ChildAssociationRef childAssoc: children){
NodeRef childNodeRef = childAssoc.getChildRef();
FileBinary = getFileBinary(childNodeRef, contentService);
進一步,我將執行文件轉換。 希望這能對情況有所幫助。
嘗試這種方式:
ServiceRegistry serviceRegistry = (ServiceRegistry) context.getBean("ServiceRegistry");
Node rootNode = session.getRootNode();
//obtaining root node company home
Node companyHome = rootNode.getNode("app:company_home");
// getting noderef of company home node
NodeRef companyHomeRef = JCRNodeRef.getNodeRef(companyHome);
List<ChildAssociationRef> children = nodeService.getChildAssocs(companyHomeRef);
for (ChildAssociationRef childAssoc : children) {
NodeRef childNodeRef = childAssoc.getChildRef();
// Use childNodeRef here.
}
這樣,您就可以通過編程方式獲取CompanyHome節點的NodeRef,並通過它獲得了Company Home下的子節點列表。
使用以下導入:
import org.alfresco.jcr.api.JCRNodeRef;
import org.alfresco.service.ServiceRegistry;
import javax.jcr.Node;
import javax.jcr.Session;
import org.springframework.context.ApplicationContext;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.