java API 中的 CompanyHome 引用
CompanyHome reference in java API
我配置了一个调度程序作业,并通过扩展 org.quartz.StatefulJob
创建了一个操作 class
在 Action Class 的执行方法中(如下所示),在执行方法中获取对 CompanyHome 的引用的最佳方法是什么?
我的目标是在调用操作时在公司主目录中创建一个文件。有什么建议吗?
您尝试过使用 NodeLocatorService
吗?
https://docs.alfresco.com/4.0/concepts/node-locator-available.html。
例如:
NodeRef companyHomeNodeRef = registry.getNodeLocatorService().getNode(CompanyHomeNodeLocator.NAME, null, null);
请实现这样的方法
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);
在服务中添加这个 bean-context.xml
<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
}
希望这会有所帮助。
我配置了一个调度程序作业,并通过扩展 org.quartz.StatefulJob
创建了一个操作 class在 Action Class 的执行方法中(如下所示),在执行方法中获取对 CompanyHome 的引用的最佳方法是什么?
我的目标是在调用操作时在公司主目录中创建一个文件。有什么建议吗?
您尝试过使用 NodeLocatorService
吗?
https://docs.alfresco.com/4.0/concepts/node-locator-available.html。
例如:
NodeRef companyHomeNodeRef = registry.getNodeLocatorService().getNode(CompanyHomeNodeLocator.NAME, null, null);
请实现这样的方法
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);
在服务中添加这个 bean-context.xml
<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
}
希望这会有所帮助。