cancel
Showing results for 
Search instead for 
Did you mean: 

Invoking JAVA based action from shareUI (and param passing)

annakan
Champ in-the-making
Champ in-the-making
Hello

One day (yesterday) I wrote an action in java, but …

Share does not support adding an action to the document library or document detail context menu.

Thus, I followed http://wiki.alfresco.com/wiki/Custom_Document_Library_Action making the few adjustments because I am in 3.4d and such.

I am to the point where I have my action displayed (troubles with the icon but that's not important right now) and activating a client side javascript (I did not get to that point without crying in horror when I had do deploy things INSIDE the webapp and not under the webextension directory and weeping when I had to copy the whole documentlist.get.config.xml file to add ONE menu item, honestly XML is NOT the right tool for configuration files but I digress, or more hopefully I am wrong on the way to do it right)

Now from THAT client side javascript  (like the backup-action.js at the end of the tutorial) I want to invoke my "classic" java action in the repository.

Is there an equivalent to the modules.actions.genericAction functionality to call a java based action ?

Can modules.actions.genericAction do it with the right parameters ? reading the code in webapps\share\modules\documentlibrary\doclib-actions.js I was not able to find the parameters to do that but I may have missed something.

I have found documentation to have a java based webscript but It means more boiler plate code to in the end call my ten line function and worse it means code duplication, in the Java based action and in the java based webscript.

thanks of lots for your help.
7 REPLIES 7

mikeh
Star Contributor
Star Contributor
Here's the relevant part of the genericAction config, this is case for the "accept-simpleworkflow" action:
webscript:
{
   method: Alfresco.util.Ajax.POST,
   stem: Alfresco.constants.PROXY_URI + "api/",
   name: "actionQueue"
},
config:
{
   requestContentType: Alfresco.util.Ajax.JSON,
   dataObj:
   {
      actionedUponNode: asset.nodeRef,
      actionDefinitionName: "accept-simpleworkflow"
   }
}

Ignoring the ranting parts of your post, we are addressing Share extensibility over the remainder of this year. Which parts of the webapp folder did you have to edit?

What's your suggestion for configuration if not XML?

What other constructive criticism / suggestions do you have for extensions?

Thanks,
Mike

annakan
Champ in-the-making
Champ in-the-making
Thanks for your answer, I will look into it.

<Edited and send in MP>

Thanks a LOT for you help, I'll try to achieve what I set myself to do. Smiley Happy

annakan
Champ in-the-making
Champ in-the-making
Success Smiley Happy

I'll report here the things things I learned from MikeH post

You invoque an action through the actionQueue API
hence the
webscript : {
            method : Alfresco.util.Ajax.POST,
            stem : Alfresco.constants.PROXY_URI + "api/",
            name : "actionQueue"
         },
part.

You pass the name of the action in the actionDefinitionName  entry of the dataObj array of the config array Smiley Wink
You pass the noderef the action is fired upon in the actionedUponNode entry of the same array.

I suppose you can pass other parameters if your action requires it, probably keyed on the name you gave in the addParameterDefinitions method  [paramList.add(new ParameterDefinitionImpl("paramName", …) ], but I did not test this yet.

For reference in 3.4 community I had to use
Alfresco.doclib.Actions.prototype.onMyAction= function DL_onMyAction, rather than Alfresco.DocumentList.prototype.onMyAction = function DL_onMyAction , a bit contrarily to what is said in
http://wiki.alfresco.com/wiki/Custom_Document_Library_Action.

annakan
Champ in-the-making
Champ in-the-making
A subsidiary question :

How do I pass extra parameters to the action ?

For instance my action as 3 parameters, I tried this

config : {
            requestContentType : Alfresco.util.Ajax.JSON,
            dataObj : {
               actionedUponNode : file.nodeRef,
               actionDefinitionName : "change-value-from-field-content",
               Field-To-Get-value-From : "XXX",
               Add-Or-Remove: true,
               Name-Of-Value-To-Change: "YYY"
            }

But nothing happens.
Really nothing. Meaning something breaks inside the script since I do not even have a "failure".

If on the contrary I remove the three last member of the json array, I DO have a failure with the message in the console that the parameter Field-To-Get-value-From is missing. (the exact parameter name inside the Java setParam call).

Commenting the first one and leaving the second one brings me back to the first behavior : silent do-nothing.

It is probably something quite obvious but …

EDIT : maybe not so obvious after all since I noticed that in your above example the "actionedUponNodeRef" of the
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
function was passed as actionedUponNode ….. and changing that to actionedUponNodeRef results in a failure…
So does it mean that there is a mapping of sort between param names in javascript and param names in java ?

annakan
Champ in-the-making
Champ in-the-making
2 days later and none the wiser.

I tried to use the same Smiley Tonguearam structure that is used to pass parameters to server side javascript actions, both as a member of  modules.actions.genericAction.params and modules.actions.genericAction.webscript.params, I also tried to pass them as modules.actions.genericAction.config.params (now  I AM desesperate Smiley Wink ), to no avail.
I traced enough jscript to know that the params where in modules.actions.genericAction.params and are now  expected in modules.actions.genericAction.webscript.params for webscripts but is that the same for java-based actions ?


I don't have an fully source compiled  alfresco, only the sdk but I retrieved the source code and made some search around and I did not find where parameters where marshalled out, I did find
GetMethod getGETMethod(String servicePath, List<WebscriptParam> params)
and
PostMethod getPOSTMethod(String servicePath, List<WebscriptParam> params)
in alfresco-src\HEAD\root\modules\wcmquickstart\wcmquickstartclientapi\source\java\org\alfresco\wcm\client\impl\WebScriptCallerImpl.java but did not get much further.

I changed my param names to be valid javascript identifier to be able to use them as key in the param array and tied both
paramName : "paramvalue" and "paramName":"paramValue" but I always get the same message that my first  parameter, mandatory, is not found …

I am trying at the moment to get further up the un-marshalling code chain (getJsonObject(String servicePath, List<WebscriptParam> params)) to understand what is expected.

Any fresh idea is welcome, and yes it is probably obvious Smiley Sad

mohitshah
Champ in-the-making
Champ in-the-making
Hey Annakan,

Did you find a solution to your problem of passing parameters using the post actionQueue webscript ?

I was trying to do something similar to what you required and stumbled upon the information given here:

http://wiki.alfresco.com/wiki/Rule_REST_API_Design_Notes#Post_Action_Queue

Basically, here's how to do it:

{
   "actionedUponNode" : "workspace://SpacesStore/123-123-abc",
   "actionDefinitionName": "copy",
   "parameterValues":
   {
      "destinationFolder" : "workspace://SpacesStore/123-123-123",
      "deepCopy" : false
   }
}

Hope this helps.

amrutamh
Champ in-the-making
Champ in-the-making
Hi,

On the ongoing discussion, is there a way to analyse different cases of failure from the action (if any) and call appropriate functions?