cancel
Showing results for 
Search instead for 
Did you mean: 

executing simple-workflow with web services

alexcocia
Champ in-the-making
Champ in-the-making
I have a Folder with a simple-workflow rule on it so, for each document inside this folder, on execution of the workflow, it will be moved to another folder.
I'm trying to execute this with the web services, but it doesn't move the content of the file, (even if it changes its modification's date)
Have the following code, having the uuid of the file under the mentioned folder.


Reference reference = new Reference(STORE, uuid, null);
Rule[] rules = actionService.getRules(reference, null);
if (rules != null) {
  for (Rule rule : rules) {
    ActionExecutionResult[] resultado = actionService.executeActions( new Predicate(new Reference[]{reference}, STORE, null), rule.getAction().getActions());
  }
}


Any idea? Help will be appreciated
5 REPLIES 5

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

If all you want to do is execute an action on an object then it is not necessary to use rules.

Have a look at the ActionsUtils class.  It has the method 'executeAction' which encapsulates the execution of an action upon a Reference.  You can either use this directly, or take a peek at the code and extract the relevant parts to help achieve your objective.

Cheers,
Roy

alexcocia
Champ in-the-making
Champ in-the-making
Hi rwetherall,

Sorry for the delay… but it still doesn't work.
What I want to execute is the rule (simple workflow rule) that I've made on my folder. I have a reference to a file on this folder, and want to execute the rule…

I've seen rules have actions inside,… do I have to execute all actions inside rules to do so?

mimi_mircea
Champ in-the-making
Champ in-the-making
I have one rule witch is a simple workflow and has only approve and reject actions. I want to execute this rule on a specific content on that space.

The rule is defined via the UI, and i wat to run it via web services…

My code is this :

                    Reference refe = new Reference(store,rows[4].getNode().getId(),null);
                    Predicate pred = new Predicate(new Reference[]{refe},store,null);
                        ActionExecutionResult[] resultado = actionService.executeActions(pred,rules[0].getAction().getActions());

rows[4] is the content on witch i want to execute the rule, and rules[0] is the rule.

If the rule has an action like "remove an aspect ", or anything different of a workflow, this code runs ok, but when i want to approve or reject [or a rule with only approve action] it doesn't work. It changes my modified date, but it doesn't move the content to a specific space.

This is the rule "Move item to 'User Homes' if 'Accept' action is taken. Move item to 'INTRANET' if 'deny' action is taken."

I looked verry hard on google and on this forum, but i didn't find anything.

My rule has an action witch is a composite-action… and it contains an array of actions. in this array i have an action witch has this 6 parameters:
0 : name "approve-move" value "true"
1 :  name "approve-step" value "Accept"
2 :  name "reject-move" value "true"
3 :  name "reject-step" value "deny"
4 :  name "approve-folder" value "workspace://SpacesStore/bd6a37c8-0389-11dc-93af-e1b360d3eec0"
5: : name "reject-folder" value "workspace://SpacesStore/0c175ace-0489-11dc-bc81-8dcef503d25d"

[img]http://img171.imageshack.us/img171/7579/problemeo0.png[/img]


This is a little odd because i expected one action for approve and another action for reject, so can i choose witch action should run.

But in this way, it's only one action and i don't know how to run it for approve or for reject but this is the way alfresco implements actions for rules, please add code or something to make this work because i had ran out of ideeas.

So a web service client can execute the rule action for a specific need… approve or reject…?

Thank you verry much

salvatore_bagli
Champ in-the-making
Champ in-the-making
I have the same problem.

I have liferay+alfresco
[img]http://files.digital2b.net/webscripts_alfresco.GIF[/img]

And I want to add two scripts with Approve and Reject actions.

How can I build the webscripts? Where can i find it?

I modified
liferay/webapps/alfresco/WEB-INF/classes/alfresco/templates/client/myspaces_preview_panel.ftl
by adding

            <tr>
               <td class="spaceAction docActionUpdate" onclick="event.cancelBubble=true;MySpaces.updateItem(this, '${node.nodeRef}');">Approva</td>
               <td class="spaceAction docActionUpdate" onclick="event.cancelBubble=true;MySpaces.updateItem(this, '${node.nodeRef}');">Rifiuta</td>
            </tr>

updateItem is a function in a javascript file:

digital2b:/srv/digital_disk/liferay/webapps# grep -R 'updateItem' *
alfresco/scripts/ajax/myspaces.js:   updateItem: function(actionEl, nodeRef)

i took a look to that function (and similar), but I don't understand how I can build an approve/reject function.

Thanks in advance
Salvatore Baglieri

mimi_mircea
Champ in-the-making
Champ in-the-making
ok.. i've done this by implementing the approve or reject step… in my application…
basically it does read the space for a workflow…. and reads the approve_folder and reject_folder for that workflow…
after that i move the documents, or i copy them accordingly to these folders…


        private void readWorkflow(){  // it reads the approve_folder and reject_folder from that space
            relogin(); // this is a function witch checkes if the ticket is still valid. if not it relogins :)…. many problems may occur without it

            RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
        try{
            String username = AuthenticationUtils.getAuthenticationDetails().getUserName();
            String userhome = username + "_home";
            String referinta = "/app:company_home/app:user_homes/sys:" + userhome;  // the reference to the space…. in this case i read the workflow from the user_home of the current user
            Store store= new Store(Constants.WORKSPACE_STORE,"SpacesStore");  
            Reference ref=new Reference(store,null,referinta);
            ActionServiceSoapBindingStub actionService=WebServiceFactory.getActionService();
            Rule[] reguli = actionService.getRules(ref,new RuleFilter());   // reads the rules
            Rule reg_workflow = null;
            approve_folder = "";   //
            reject_folder = "";      // these fields are private in this class…
            int nr = 0;
                        if (reguli!=null)
              {
                  nr=reguli.length;
              }
              for (int i=0;i<nr;i++)
              {
                  if (reguli[i].getTitle().equalsIgnoreCase("workflow_simplu"))   // if the rule is named "workflow_simplu" then it store-s it
                  {
                      reg_workflow=reguli[i];
                  }
              }
              if (reg_workflow!=null)
              {
                  NamedValue[] nm=reg_workflow.getAction().getActions(0).getParameters();
                  for (int i=0;i<nm.length;i++)
                  {
                      if (nm[i].getName().equalsIgnoreCase("approve-folder"))   // and then is reads the parameters "approve-folder" and "reject-folder" …. witch contains values with the id's for the approve folder and reject folder
                          approve_folder=nm[i].getValue().substring(24);
                      if (nm[i].getName().equalsIgnoreCase("reject-folder"))
                          reject_folder=nm[i].getValue().substring(24);
                  }
              }
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

and then i move the file


    public void move_file(String unde, String nume, String id){  // unde = where…. nume = name
        relogin();
            RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
            try {
                Store store= new Store(Constants.WORKSPACE_STORE,"SpacesStore");  
                ParentReference dossierDestinationParentRef = new ParentReference();
                dossierDestinationParentRef.setStore(store);
                String IDElemDestination = unde; // spatiul INDEXATE
                dossierDestinationParentRef.setUuid(IDElemDestination);
                dossierDestinationParentRef.setAssociationType(Constants.ASSOC_CONTAINS);
                String nomElementADeplacer = nume; // numele fisierului
                dossierDestinationParentRef.setChildName(nomElementADeplacer);
                /** Create the ref of the element to move */
                Reference sourceRef = new Reference();
                sourceRef.setStore(store);
                String iDElementADeplacer = id;
                sourceRef.setUuid(iDElementADeplacer);
                /** Move */
                CMLMove deplacer = new CMLMove();
                /** destination folder : */
                deplacer.setTo(dossierDestinationParentRef);
                /** element to move */
                deplacer.setWhere(new Predicate(new Reference[]{sourceRef}, null, null));
                /** Execute command */
                CML cmlDeplacer = new CML();
                cmlDeplacer.setMove(new CMLMove[]{deplacer});
                UpdateResult[] results;
                results = repositoryService.update(cmlDeplacer);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
    }


this is the only way i have found… but works perfectly