cancel
Showing results for 
Search instead for 
Did you mean: 

Java backend webscript in background

jamilnour
Star Contributor
Star Contributor
Hello,

I have to run a java back-end webscript in background to do some operation on all the content of a folder.

Right now I have the front end user to wait until the end of the operation to continue using the Share.

Can you please guide me to help me convert my actual working java webscript to run in background like Alfresco is doing with the Folder Rules when they offer the option to run in background?

Is there a way to display a message when the operation is achieved?

Best regards
Jamil
3 REPLIES 3

iblanco
Confirmed Champ
Confirmed Champ
Hi jamilnour,

The easiest thing to do would be encapsulating all your java logic in an Alfresco Action (http://ecmarchitect.com/alfresco-developer-series-tutorials/actions/tutorial/tutorial.html). Then in your Java Backed webscript, or even in a Javascript webscript you can use the ActionService in order to execute the action in the background.

Knowing if the task has already ended is going to be a little bit trickier, I suggest that you mark the folder with an aspect and/or property and just make sure that you update it when the action ends.

Be aware that running actions are stopped and lost when you restart Alfresco so if this is an issue for you you might also have to define some logic in a bean that can check the previous status of the folder and rerun the action accordingly if it was interrupted.

Bye

jamilnour
Star Contributor
Star Contributor
Dear iblanco,

Thank you for the help

Because I already have a working java backed webscript which loop inside the folder files and do the logic on the content depends on a certain request parameters. What is your advise to build the Alfresco Action then call it from the webscript? I mean how to change the class ?
Do I need to read the parameters from the webscript action then pass them to the action-executer? any sample code about passing params to an action-executer from a webscript?

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req,
                                              Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    JSONObject json = null;
    Object jsonO = req.parseContent();
    if (jsonO instanceof JSONObject && jsonO != null)
    {
      //read json params then
      //do the logic on the folder content
      ….
     }


Best regards
Jamil

Ok, I moved the logic from the working webscript to an Alfresco action-executer and call it using ActionService Asynchronously and everything is working fine

Thank you for your help

Best regards
Jamil