cancel
Showing results for 
Search instead for 
Did you mean: 

custom move action

nancyaggarwal
Champ in-the-making
Champ in-the-making
Hi All,

I am making a custom action in which when i click on the action the document gets move to another folder in company home.Till now i am able to see the action in document library but when i click on it, it says it can't be moved.

I am using a simpleRepoAction for client-side javascript and from which i am calling a webscript for moving the document.

I am getting the following error:

15:52:47,333 ERROR [org.springframework.extensions.webscripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: 09070001 Failed to convert request to JSON
org.springframework.extensions.webscripts.WebScriptException: 09070001 Failed to convert request to JSON
   at org.springframework.extensions.webscripts.json.JSONReader.read(JSONReader.java:82)
   at org.springframework.extensions.webscripts.json.JSONReader.createScriptParameters(JSONReader.java:93)
   at org.springframework.extensions.webscripts.AbstractWebScript.createScriptParameters(AbstractWebScript.java:663)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:81)
   at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:429)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:433)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:491)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:529)
   at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:345)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:377)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
   at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
   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:61)
   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.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
   at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
   at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
   at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760)
   at java.lang.Thread.run(Thread.java:722)
Caused by: org.json.JSONException: A JSONObject text must begin with '{' at character 0
   at org.json.JSONTokener.syntaxError(JSONTokener.java:413)
   at org.json.JSONObject.<init>(JSONObject.java:180)
   at org.json.JSONObject.<init>(JSONObject.java:420)
   at org.springframework.extensions.webscripts.json.JSONReader.read(JSONReader.java:77)
   … 28 more



Below are my files which i am using for this action


onActionSimpleRepoAction: function dlA_onActionSimpleRepoAction(record, owner)
      {
         // Get action params
         var params = this.getAction(record, owner).params,
            displayName = record.displayName,
            namedParams = ["function", "action", "success", "successMessage", "failure", "failureMessage"],
            repoActionParams = {};

         for (var name in params)
         {
            if (params.hasOwnProperty(name) && !Alfresco.util.arrayContains(namedParams, name))
            {
               repoActionParams[name] = params[name];
            }
         }

         // Prepare genericAction config
         var config =
         {
            success:
            {
               event:
               {
                  name: "metadataRefresh",
                  obj: record
               }
            },
            failure:
            {
               message: this.msg(params.failureMessage, displayName)
            },
            webscript:
            {
               method: Alfresco.util.Ajax.GET,
               stem: Alfresco.constants.PROXY_URI + "slingshot/doclib/action/",
               name: "archive/site/{site}/{container}",
            },
            params:
            {
               site: this.options.siteId,
                container: this.options.containerId,
               nodeRef: record.jsNode.nodeRef.uri,
            },
            config:
            {
               requestContentType: Alfresco.util.Ajax.JSON,
               dataObj:
               {
                  actionedUponNode: record.nodeRef,
                  actionDefinitionName: params.action,
                  parameterValues: repoActionParams,
               }
            }
         };

         // Add configured success callbacks and messages if provided
         if (YAHOO.lang.isFunction(this[params.success]))
         {
            config.success.callback =
            {
               fn: this[params.success],
               obj: record,
               scope: this
            };
         }
         if (params.successMessage)
         {
            config.success.message = this.msg(params.successMessage, displayName);
         }

         // Acd configured failure callback and message if provided
         if (YAHOO.lang.isFunction(this[params.failure]))
         {
            config.failure.callback =
            {
               fn: this[params.failure],
               obj: record,
               scope: this
            };
         }
         if (params.failureMessage)
         {
            config.failure.message = this.msg(params.failureMessage, displayName);
         }

         // Execute the repo action
         this.modules.actions.genericAction(config);
      },



my move.get.json.js


<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/action.lib.js">

/*//**
* Move multiple files action
* @method POST
*//*

*//**
* Entrypoint required by action.lib.js
*
* @method runAction
* @param p_params {object} Object literal containing files array
* @return {object|null} object representation of action results
*//*
*/
function runAction(p_params)
{
   var results = [],
      destNode = move_store,
      files = p_params.files,
      parent = null,
      file, fileNode, result, nodeRef,
      fromSite;

  
// Find destination node
   var destNode = p_params.rootNode.childByNamePath("/move_store");
   if (destNode == null)
   {
      destNode = p_params.rootNode.createFolder("move_store");
   }
   // Must have array of files
   if (!files || files.length == 0)
   {
      status.setCode(status.STATUS_BAD_REQUEST, "No files.");
      return;
   }
  
   for (file in files)
   {
      nodeRef = files[file];
      result =
      {
         nodeRef: nodeRef,
         action: "moveFile",
         success: false
      };
     
      try
      {
         fileNode = search.findNode(nodeRef);
         if (fileNode == null)
         {
            result.id = file;
            result.nodeRef = nodeRef;
            result.success = false;
         }
         else
         {
            if (p_params.parent && p_params.parent != null)
            {
               parent = search.findNode(p_params.parent);
            }
            result.id = fileNode.name;
            result.type = fileNode.isContainer ? "folder" : "document";
           
            // Retain the name of the site the node is currently in. Null if it's not in a site.
            fromSite = fileNode.siteShortName;
           
            // move the node
            result.success = fileNode.move(parent, destNode);
           
            if (result.success)
            {
               // If this was an inter-site move, we'll need to clean up the permissions on the node
               if (String(fromSite) !== String(fileNode.siteShortName))
               {
                  siteService.cleanSitePermissions(fileNode);
               }
            }
         }
      }
      catch (e)
      {
         result.id = file;
         result.nodeRef = nodeRef;
         result.success = false;
      }
     
      results.push(result);
   }

   return results;
}

/* Bootstrap action script */
main();




my move.get.desc.xml

<webscript>
  <shortname>archive</shortname>
  <description>Document List Action -archive multiple files</description>
<url>/slingshot/doclib/action/archive/site/{site}/{container}/{path}</url>
  <url>/slingshot/doclib/action/archive/site/{site}/{container}</url>
  <url>/slingshot/doclib/action/archive/node/{store_type}/{store_id}/{id}/{path}</url>
  <url>/slingshot/doclib/action/archive/node/{store_type}/{store_id}/{id}</url>
  <format default="json">argument</format>
  <authentication>user</authentication>
<transaction>required</transaction>
  <lifecycle>internal</lifecycle>
</webscript>


my move.get.json.ftl

<#import "action.lib.ftl" as actionLib />
<@actionLib.resultsJSON results=results />




Please help


Nancy

4 REPLIES 4

yogeshpj
Star Contributor
Star Contributor
Hello Nancy,

You may be passing the STRING to JSONObject with leading spaces. Try trimming.

Thanks,
Yogesh Prajapati

Hello Yogesh,

I tried trimming buut no success.


Thanks
Nancy

Can you please log the json object in Logger and then try to validate json object on http://jsonlint.com/?

rjohnson
Star Contributor
Star Contributor
Nancy

I do't think that your client side code is creating JSON.


         for (var name in params)

         {

            if (params.hasOwnProperty(name) && !Alfresco.util.arrayContains(namedParams, name))

            {

               repoActionParams[name] = params[name];

            }

         }


I think will create an array, not a JSON structure

You can use a client side JSON library or jQuery if its already loaded.