AnsweredAssumed Answered

Permission to move file from source to destination location

Question asked by ankurkhandelwal on Dec 12, 2012
Latest reply on Dec 13, 2012 by ankurkhandelwal
Hi All.

I am working on ALfresco 3.4 version.

We are working on a customization where user posts the document in a temporary folder in Alfresco repository.When user fills in required information for the document in share and posts it,it moves from that temporary folder to another location in repository.

My temporary source folder is named as MailTempFolder and is residing inside comapny home.

My destination folder is Comapny Home>Sites>icici>documentLibrary>Active>Customer>Retail>Direct.

Now when I am trying to move any file from MailTempFolder to destination folder using this webscript

function main()
      {
         logger.log("\n=================================~CREATE MAIL-WEBSCIPT-CALLED~~~ILKMMMMMMMMMMMMMM~~~~~~~~~~");         
         var  aspects = ["kb:icicilombard"];         
         var destNode = null;      
         var level1 = json.get("level1").toString();
         var level2 = json.get("level2").toString();
         var level3 = json.get("level3").toString();
         var level3 = json.get("level3").toString();      
         var siteId = json.get("siteId").toString();
         var tags = json.get("tags").toString();         
         var   description = json.get("description").toString();
         var   band = json.get("band").toString();
         var   vertical = json.get("vertical").toString();
         var   userid = json.get("userid").toString();
         var   refuserid = json.get("refuserid").toString();
         var   visibility = json.get("visibility").toString();
         var   printableflag = json.get("printableflag").toString();
         var   declaration = json.get("declaration").toString();
         var   date = json.get("date").toString();   
         var   newfilename = json.get("newfilename").toString();            
         var   ref2 = json.get("ref").toString();
         var mailContentNodeRef = json.get("mailContentNodeRef").toString();         
         var   ref = "";var ref3 = "";   
         logger.log("================>"+ref2);         
         var nodelist = ref2.split(",");            
         for ( var x = 0; x < nodelist.length; x++ )
         {         
            var checkref = nodelist[x].toString();         
         }
         
         var mailAttachments = "";
         var mailContent = "|";
         
         var gefileName = newfilename.split(",");
         for ( var g = 0; g < nodelist.length; g++ )
         {   
            ref3 = nodelist[g].toString();
            
            if(ref3.indexOf(mailContentNodeRef) == -1){
            if(g == 0){         
               mailAttachments +=gefileName[g].toString()+"|"+ref3;
               
            }else{               
               mailAttachments += ","+gefileName[g].toString()+"|"+ref3;
               
            }
            }
            else{            
               mailContent = gefileName[g].toString()+"|"+ref3;
            }            
         }
         
      
      
   for ( var i = 0; i < nodelist.length; i++ )
   {            
      ref = nodelist[i].toString();
      var existingFileNodes = new Array();
      var searchQuery = "PATH:\"/app:company_home/st:sites/cm:"+siteId+"/cm:documentLibrary/cm:Active"+"/cm:"+level1+"/cm:"+level2+"/cm:"+level3+"\" AND TYPE:\"cm:folder\"";         
      var folder = search.luceneSearch(searchQuery);
      var node = search.findNode(ref);            
      if (!node.hasAspect("kb:icicilombard"))
      {      
      node.addAspect("kb:icicilombard");
      }
      else{   }      
            
      if (aspects.length > 0)
        {
               
         var props = new Array(20);
         var today = new Date();
         var category = "";
         var currentUserName = person.properties.userName;            
         var creatorvertical = person.properties[ "kb:vertical"];         
         props["kb:CreatorVertical"] = creatorvertical;   
         props["kb:ilDescription"] = description;      
         props["kb:ilTagWords"] = tags;      
         if(date != null && date != "" )
         {      
            props["kb:ilExpiryDate"] = new Date(date);            
         }
         else
         {
            var blankDate = null;
            props["kb:ilExpiryDate"] = blankDate;            
         }         
         props["kb:docuementAcceptedBy"] = currentUserName;
         props["kb:docuementAcceptedOn"] =  today;            
         props["kb:ilLevelOne"] = level1;
         props["kb:ilLevelTwo"] = level2;
         props["kb:ilLevelThree"] = level3;         
         props["kb:ilBand"] = band;
         props["kb:ilVertical"] = vertical;
         props["kb:ilUserId"] = userid;   
         props["kb:ilUserIdRefer"] = refuserid;
         props["kb:ilInternalAndExternal"] = visibility;            
         props["kb:ilDeclaration"] = declaration;         
         
         var gefileName = newfilename.split(",");
         logger.log("———–FILE—-"+gefileName[i].toString());
         node.properties["name"]= gefileName[i].toString();
         node.save();
         
         
         
         var todayPublished = new Date();
         props["kb:isPublished"] = true;
         props["kb:PublishedDate"] = todayPublished;
         props["kb:PublishedBy"] = currentUserName;         
         props["kb:ilNonPrintableNonSaveable"] = printableflag;
         node.save();
         
         if(node.hasAspect("cm:ownable")){
         node.properties["cm:owner"] = currentUserName;
         node.save();

         }else{
         node.addAspect("cm:ownable");
         node.properties["cm:owner"] = currentUserName;
         node.save();
         }



         
         var filename =  node.properties["cm:name"];         
         /*var existingFile = folder[0].childByNamePath(filename);            
         if (existingFile !== null)
         {
            logger.log("———–FILE-ALREADY-EXIST——————————");
            return ;
         }*/               
         logger.log("——–NEW FILE NAME—————"+filename);
         for (var j = 0; j < aspects.length; j++)
            {
               node.addAspect(aspects[j],props);
            }
         node.save();
      }
      
         //props["kb:ilMailContent"] = mailContent ;
         //props["kb:ilMailAttachmentNew"] = mailAttachments;
         //node.save();
      
      if (node.hasAspect("kb:MailKM"))
         {
            logger.log("MailKM aspect already applied-mail-start");
            
            node.properties["kb:ilMailContent"] = mailContent ;
            node.properties["kb:ilMailAttachments"] = mailAttachments;
            node.save();
            
            logger.log("MailKM aspect already applied–end");
         }

         else{   

            logger.log("Applying MailKM Aspect on Doc-mail-start");         

            node.addAspect("kb:MailKM");
            node.save();

            node.properties["kb:ilMailContent"] = mailContent ;
            node.properties["kb:ilMailAttachments"] = mailAttachments;
            node.save();
            
            logger.log("Applying MailKM Aspect on Doc–end");

         }
      
         
      if (node.hasAspect("kb:Archived"))
      {   
         node.properties["kb:isArchived"] = "None";
         node.save();                     
      }
      else{                     
         node.addAspect("kb:Archived");
         node.save();
         node.properties["kb:isArchived"] = "None";
         node.save();            
      }
    
      var currentTagTokens = tags.split( "," );   
      for ( var k = 0; k < currentTagTokens.length; k++ )
      {
         var currentTags = currentTagTokens[k] ;               
         addTag(node,currentTags);   
      }
                  
      getFirstFewLines(node);      
      node.save();         
      node.move(folder[0]);   
      node.save();         
   }
      logger.log("———–COMPLETE::::————————–");
}


function addTag(node,tagName)
{   
      var resultString = "Action failed";
      var resultCode = false;
      var newTag = null;
      var newTagNodeRef = "";

   if ((tagName != "") && (tagName != null))
   {
      tagName = tagName.toLowerCase();
      tagName = tagName.trim();
      newTag = createTag(tagName);
      if (newTag != null)
      {            
         resultString = "Tag added";
         resultCode = true;
         newTagNodeRef = newTag.nodeRef.toString();
      }
      else
      {         
         resultString = "Tag '" + tagName + "' not indexed";

      }
      
   
      if (newTag != null)
      {
               
         resultString = "Already tagged with '" + tagName + "'";   
         var tags = node.properties["cm:taggable"];   
         if (tags == null)
         {         
            tags = new Array();      
         }
      
      
       // Check node doesn't already have this tag
         var hasTag = false;
         for each (tag in tags)
         {      
            if (tag != null)
            {      
               if (tag.name == tagName)
               {       
                 hasTag = true;
                 break;
               }
            }
         }
         if (!hasTag)
         {
               
            // Add it to our node
            tags.push(newTag);
            tagsArray = new Array();
            tagsArray["cm:taggable"] = tags;
            node.addAspect("cm:taggable", tagsArray);   
            resultString = "Document tagged";
            resultCode = true;
         }
      }          
   }
}

function createTag(tagName)
{
    //logger.log("inside create tag");
   var existingTags = classification.getRootCategories("cm:taggable");

   for each (existingTag in existingTags)
   {
   if (existingTag.name == tagName)
      {
       logger.log("got classification:::::::222222::EXITING TAG:::"+existingTag);
         return existingTag;
      }
     if (existingTag.name.equals(tagName))
      {
       logger.log("got classification:::after triming::"+existingTag);
         return existingTag;
      }    
   }
   
   var tagNode = classification.createRootCategory("cm:taggable", tagName); 
   return tagNode;
}


function addCategory(node,category)
{   
   var resultString = "Action failed";
   var resultCode = false;
   var newCategory = null;
   var newTagNodeRef = "";
   var categories = node.properties["cm:generalclassifiable"];  
    newCategory = getCategory(category);   
   if(newCategory != null)
   {   
    if( categories == null){
      categories = new Array();
   }
  
      categories.push(newCategory);
   categoryArray = new Array();
   categoryArray["cm:categories"] = categories;
   node.addAspect("cm:generalclassifiable", categoryArray);   
   resultString = "category  tagged";
   resultCode = true;

  }
}

function getCategory(documentcategory)
{
   var existingCategories = classification.getRootCategories("cm:generalclassifiable");

   for each (existingCategory in existingCategories)
   {   
     if (existingCategory.name.equals(documentcategory))
      {      
         return existingCategory;
      }    
   }

   return null;
}

function getFirstFewLines(newFile)
{

   
      var myDoc = search.findNode(newFile.nodeRef);      
      var trans1 = null;
      var subString = null;
      var charSize = 250;
      var isFewLinesCaptured = false;      

            if(myDoc.mimetype == "text/plain")
            {            
               if(myDoc.size > charSize)
               {
               subString =  myDoc.content.substring(0,charSize);
               }
               else
               {
               subString =  myDoc.content.substring(0);
               }
               isFewLinesCaptured = true;
                  
            }
            else if ((myDoc.mimetype == "application/pdf") || (myDoc.mimetype == "text/html") || (myDoc.mimetype == "application/msword"))
            {
               
               trans1 = myDoc.transformDocument("text/plain");
            
               if((trans1 != null) && (trans1.mimetype == "text/plain"))
               {
                  
                  if(trans1.size > charSize)
                  {
                  subString =  trans1.content.substring(0,charSize);
                  }
                  else
                  {
                  subString =  trans1.content.substring(0);
                  }
                  trans1.remove();
               }
               isFewLinesCaptured = true;
            }
         if(isFewLinesCaptured)
         {
               
            while(subString.indexOf('\n')!=-1)
            {
               subString = subString.replace('\n',' ');
            }
               
            while(subString.indexOf("  ")!=-1)
            {
               subString = subString.replace("  "," ");
            }   

            if(null != subString)
            {
               myDoc.properties["cm:description"] = subString.trim();               
               myDoc.save();
            }
         }               

      }

main();


I am getting the error log attached below saying I do not have rights to perform the operation.



20:10:47,807  ERROR [extensions.webscripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: 11060006 Wrapped Exception (with status template): 11060910 Failed to execute script 'classpath*:alfresco/extension/templates/webscripts/com/ilkm/CreateMailContent/createmailContent.post.json.js': 11060909 Access Denied.  You do not have the appropriate permissions to perform this operation.
org.springframework.extensions.webscripts.WebScriptException: 11060006 Wrapped Exception (with status template): 11060910 Failed to execute script 'classpath*:alfresco/extension/templates/webscripts/com/ilkm/CreateMailContent/createmailContent.post.json.js': 11060909 Access Denied.  You do not have the appropriate permissions to perform this operation.
   at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:759)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
   at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:400)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:381)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:453)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:491)
   at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:316)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:352)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:189)
   at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
   at java.lang.Thread.run(Thread.java:662)
Caused by: org.alfresco.scripts.ScriptException: 11060910 Failed to execute script 'classpath*:alfresco/extension/templates/webscripts/com/ilkm/CreateMailContent/createmailContent.post.json.js': 11060909 Access Denied.  You do not have the appropriate permissions to perform this operation.
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:194)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:282)
   at org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:102)
   at org.springframework.extensions.webscripts.AbstractWebScript.executeScript(AbstractWebScript.java:982)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:86)
   … 24 more
Caused by: org.alfresco.repo.security.permissions.AccessDeniedException: 11060909 Access Denied.  You do not have the appropriate permissions to perform this operation.
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:48)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:146)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy7.createNode(Unknown Source)
   at org.alfresco.repo.copy.CopyServiceImpl.recursiveCopy(CopyServiceImpl.java:542)
   at org.alfresco.repo.copy.CopyServiceImpl.copyImpl(CopyServiceImpl.java:447)
   at org.alfresco.repo.copy.CopyServiceImpl.copy(CopyServiceImpl.java:242)
   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:307)
   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:44)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:146)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy50.copy(Unknown Source)
   at org.alfresco.repo.jscript.ScriptNode.transformNode(ScriptNode.java:2326)
   at org.alfresco.repo.jscript.ScriptNode.transformDocument(ScriptNode.java:2300)
   at org.alfresco.repo.jscript.ScriptNode.transformDocument(ScriptNode.java:2262)
   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.c40._c6(file:/KMAPPDATA/apache-tomcat-6.0.26/shared/classes/alfresco/extension/templates/webscripts/com/ilkm/CreateMailContent/createmailContent.post.json.js:355)
   at org.mozilla.javascript.gen.c40.call(file:/KMAPPDATA/apache-tomcat-6.0.26/shared/classes/alfresco/extension/templates/webscripts/com/ilkm/CreateMailContent/createmailContent.post.json.js)
   at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
   at org.mozilla.javascript.gen.c40._c1(file:/KMAPPDATA/apache-tomcat-6.0.26/shared/classes/alfresco/extension/templates/webscripts/com/ilkm/CreateMailContent/createmailContent.post.json.js:193)
   at org.mozilla.javascript.gen.c40.call(file:/KMAPPDATA/apache-tomcat-6.0.26/shared/classes/alfresco/extension/templates/webscripts/com/ilkm/CreateMailContent/createmailContent.post.json.js)
   at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:108)
   at org.mozilla.javascript.gen.c40._c0(file:/KMAPPDATA/apache-tomcat-6.0.26/shared/classes/alfresco/extension/templates/webscripts/com/ilkm/CreateMailContent/createmailContent.post.json.js:394)
   at org.mozilla.javascript.gen.c40.call(file:/KMAPPDATA/apache-tomcat-6.0.26/shared/classes/alfresco/extension/templates/webscripts/com/ilkm/CreateMailContent/createmailContent.post.json.js)
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
   at org.mozilla.javascript.gen.c40.call(file:/KMAPPDATA/apache-tomcat-6.0.26/shared/classes/alfresco/extension/templates/webscripts/com/ilkm/CreateMailContent/createmailContent.post.json.js)
   at org.mozilla.javascript.gen.c40.exec(file:/KMAPPDATA/apache-tomcat-6.0.26/shared/classes/alfresco/extension/templates/webscripts/com/ilkm/CreateMailContent/createmailContent.post.json.js)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:472)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:190)
   … 28 more
Caused by: net.sf.acegisecurity.AccessDeniedException: Access is denied.
   at net.sf.acegisecurity.vote.AffirmativeBased.decide(AffirmativeBased.java:86)
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:394)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:44)
   … 81 more
In the else part
20:11:14,484  DEBUG [content.transform.ContentTransformerRegistry] Searched for transformer:
   source mimetype: application/octet-stream
   target mimetype: text/plain
   transformers: []
In the else part
20:11:14,865  DEBUG [content.transform.ContentTransformerRegistry] Searched for transformer:
   source mimetype: application/octet-stream
   target mimetype: text/plain
   transformers: []



If the user has admin permission in Alfresco he is able to move the content from source folder to destination folder but if he is not a member of admin group he is not able to move the document from source to destination folder.

Can you please guide us as how can we move the document from source folder to destination folder when user is not a member of admin group.


Regards,

Ankur Khandelwal

Outcomes