AnsweredAssumed Answered

Checkout and checkin a file searched by lucene

Question asked by piski on Sep 21, 2012
Latest reply on Sep 21, 2012 by piski
Hi All,

I've made a small script that searches a file (it works) … but when I try to check it out the pdf "image", I have an error :

 2012-09-21 10:52:29,318  DEBUG [repo.jscript.ScriptLogger] [defaultAsyncAction6] Fichier original : G-12-082-Formulaire_commentaires
2012-09-21 10:52:29,318  DEBUG [repo.jscript.ScriptLogger] [defaultAsyncAction6] Fichier pdf : Node Type: {http://www.alfresco.org/model/content/1.0}content, Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/content/1.0}titled, {http://www.alfresco.org/model/content/1.0}copiedfrom, {http://www.alfresco.org/model/rendition/1.0}renditioned, {http://www.alfresco.org/model/content/1.0}author, {http://www.alfresco.org/model/content/1.0}taggable, {http://www.alfresco.org/model/system/1.0}localized]
2012-09-21 10:52:29,318  DEBUG [repo.jscript.RhinoScriptProcessor] [defaultAsyncAction6] Time to execute script: 4.509791ms
2012-09-21 10:52:29,318  ERROR [repo.action.AsynchronousActionExecutionQueueImpl] [defaultAsyncAction6] Failed to execute asynchronous action: Action[ id=c7f85951-f0b9-4209-8eb7-e8c4a7a98f61, node=workspace://SpacesStore/c7f85951-f0b9-4209-8eb7-e8c4a7a98f61 ]
org.alfresco.scripts.ScriptException: 08212648 Failed to execute script 'workspace://SpacesStore/14e1b062-e98e-4ab5-8f08-2125f76b81f5': 08212647 TypeError: Cannot find function checkout. (workspace://SpacesStore/14e1b062-e98e-4ab5-8f08-2125f76b81f5#12)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:245)
   at org.alfresco.repo.processor.ScriptServiceImpl.execute(ScriptServiceImpl.java:237)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:143)
   at sun.reflect.GeneratedMethodAccessor1171.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:147)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy270.executeScript(Unknown Source)
   at org.alfresco.repo.action.executer.ScriptActionExecuter.executeImpl(ScriptActionExecuter.java:164)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:196)
   at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:780)
   at org.alfresco.repo.action.executer.CompositeActionExecuter.executeImpl(CompositeActionExecuter.java:66)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:196)
   at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:780)
   at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:700)
   at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper$1$1.execute(AsynchronousActionExecutionQueueImpl.java:403)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:388)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:259)
   at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper$1.doWork(AsynchronousActionExecutionQueueImpl.java:412)
   at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:519)
   at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper.run(AsynchronousActionExecutionQueueImpl.java:415)
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
   at java.lang.Thread.run(Thread.java:662)
Caused by: org.alfresco.error.AlfrescoRuntimeException: 08212647 TypeError: Cannot find function checkout. (workspace://SpacesStore/14e1b062-e98e-4ab5-8f08-2125f76b81f5#12)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:499)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:241)
   … 34 more
Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot find function checkout. (workspace://SpacesStore/14e1b062-e98e-4ab5-8f08-2125f76b81f5#12)
   at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3350)
   at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3340)
   at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3356)
   at org.mozilla.javascript.ScriptRuntime.typeError1(ScriptRuntime.java:3368)
   at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3428)
   at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2052)
   at org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:117)
   at org.mozilla.javascript.gen.c132._c0(workspace://SpacesStore/14e1b062-e98e-4ab5-8f08-2125f76b81f5:12)
   at org.mozilla.javascript.gen.c132.call(workspace://SpacesStore/14e1b062-e98e-4ab5-8f08-2125f76b81f5)
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
   at org.mozilla.javascript.gen.c132.call(workspace://SpacesStore/14e1b062-e98e-4ab5-8f08-2125f76b81f5)
   at org.mozilla.javascript.gen.c132.exec(workspace://SpacesStore/14e1b062-e98e-4ab5-8f08-2125f76b81f5)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:483)
   … 35 more

My script (fired by a rule) :
// Main purpose : update the pdf "image" of an xls file being updated
// Name of current document being updated (xls file … tmp of xls file in this case !)
var documentxls = document.name.substr(0, document.name.indexOf('.'));
logger.log("Fichier original : " + documentxls);

// Search always returns 1 row (I know it can be a weakness but it works for now …)
var pdforiginalcopy = search.luceneSearch("@cm\\:name:\"" + documentxls + ".pdf\"");
logger.log("Fichier pdf : " + pdforiginalcopy);

// Check it out and update content on the working copy - "pdf" is the current version
var workingCopy = pdforiginalcopy.checkout(); -> THE ERROR !
workingCopy.properties.content.write(document.properties.content);

// Check it back in
workingCopy.checkin("Document updated", true);

Any help would be appreciated,
Thanks !

Outcomes