问题描述
我正在尝试在我的 Java 类中调用操作: public void execute() {
System.out.println("ScheduledJobExecuter_imapWF se poslusne hlasi");
//potrebuju nejaky noderef
ResultSet resSet = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACEsstORE,SearchService.LANGUAGE_FTS_ALFRESCO,"PATH:\" /app:company_home/st:sites/cm:sparta/cm:documentLibrary\"");
if(resSet.length() != 1){
throw new AlfrescoRuntimeException("Nasel jsem spatny pocet veci...resSet.length() != 1 (Error n420)");
}
NodeRef actionedUponNoderef = resSet.getNodeRef(0);
//volam akci
Action a = actionService.createAction("get_mail_imap");
//actionService.executeAction(a,actionedUponNoderef);
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {
public Object doWork() throws Exception {
actionService.executeAction(a,actionedUponNoderef);
return null;
}
},AuthenticationUtil.getAdminUserName());
}
但突出显示的行:actionService.executeAction(a,actionedUponNoderef);
抛出错误:
sparta-acs_1 | 2021-01-11 11:26:00,089 ERROR [quartz.core.JobRunShell] [DefaultScheduler_Worker-2] Job DEFAULT.org.springframework.scheduling.quartz.JobDetailfactorybean#46bdcf89 threw an unhandled Exception:
sparta-acs_1 | java.lang.IllegalStateException: Actions invariably access the repository. Doing so without a transaction is not recommended.
sparta-acs_1 | at org.alfresco.repo.action.executer.ActionExecuterabstractBase.execute(ActionExecuterabstractBase.java:251)
sparta-acs_1 | at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:856)
sparta-acs_1 | at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:757)
sparta-acs_1 | at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:581)
sparta-acs_1 | at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:567)
sparta-acs_1 | at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:865)
sparta-acs_1 | at cz.signia.sparta.jobs.ScheduledJobExecuter_imapWF$1.doWork(ScheduledJobExecuter_imapWF.java:57)
sparta-acs_1 | at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:602)
sparta-acs_1 | at cz.signia.sparta.jobs.ScheduledJobExecuter_imapWF.execute(ScheduledJobExecuter_imapWF.java:55)
sparta-acs_1 | at cz.signia.sparta.jobs.ScheduledJob_imapWF$1.doWork(ScheduledJob_imapWF.java:35)
sparta-acs_1 | at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:602)
sparta-acs_1 | at cz.signia.sparta.jobs.ScheduledJob_imapWF.execute(ScheduledJob_imapWF.java:33)
sparta-acs_1 | at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
sparta-acs_1 | at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
你知道如何解决这个问题吗?
谢谢
解决方法
希望您将 webscript 交易值设为 readwrite,
<webscript>
<shortname>{}</shortname>
<description>{}</description>
<url>/{name}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction allow="readwrite" buffersize="0">required</transaction>
</webscript>
,
以给定用户的身份执行工作单元。调用后线程的认证用户会恢复到正常状态。
final Context cx = Context.getCurrentContext();
final Scriptable scope = getScope();
RunAsWork<Object> raw = new RunAsWork<Object>() {
public Object doWork() throws Exception {
func.call(cx,scope,new Object[] {});
return null;
}
};
AuthenticationUtil.runAs(raw,AuthenticationUtil.getAdminUserName());
}