cancel
Showing results for 
Search instead for 
Did you mean: 

Checkout and checkin a file searched by lucene

piski
Champ on-the-rise
Champ on-the-rise
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 !
2 REPLIES 2

mitpatoliya
Star Collaborator
Star Collaborator
One this is is confusing over here.
Actually AFIK search.luceneSearch() It return the array
So, you need to first get the first element from that then apply get the working copy.
Do not know how you are getting that directly in logs.

Try this as well
var workingCopy = pdforiginalcopy[0].checkout();

piski
Champ on-the-rise
Champ on-the-rise
Thanks for your reply,

I've missed that method lucene.search returns an array … OK but now, I have an error (which I don't really understand !)

2012-09-21 13:39:45,556  ERROR [content.cleanup.EagerContentStoreCleaner] [defaultAsyncAction6] Content deletion failed (no exception): 
   URL:    store://2012/9/21/13/39/4213ed6d-43f0-4e97-9675-4b156c679134.bin
   Source: FileContentStore[ root=I:\Alfresco\alf_data\contentstore, allowRandomAccess=true, readOnly=false]
2012-09-21 13:39:45,556  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: 08210245 Failed to execute script 'workspace://SpacesStore/14e1b062-e98e-4ab5-8f08-2125f76b81f5': null
   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.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   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 $Proxy251.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: java.lang.NullPointerException
   at org.alfresco.repo.content.AbstractContentWriter.copyStreams(AbstractContentWriter.java:490)
   at org.alfresco.repo.content.AbstractContentWriter.putContent(AbstractContentWriter.java:436)
   at org.alfresco.repo.jscript.ScriptNode$ScriptContentData.write(ScriptNode.java:3532)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:155)
   at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
   at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
   at org.mozilla.javascript.gen.c34._c0(workspace://SpacesStore/14e1b062-e98e-4ab5-8f08-2125f76b81f5:13)
   at org.mozilla.javascript.gen.c34.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.c34.call(workspace://SpacesStore/14e1b062-e98e-4ab5-8f08-2125f76b81f5)
   at org.mozilla.javascript.gen.c34.exec(workspace://SpacesStore/14e1b062-e98e-4ab5-8f08-2125f76b81f5)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:483)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:241)
   … 35 more

Any guess ?