cancel
Showing results for 
Search instead for 
Did you mean: 

Add a new workflow with Java

ventus85
Champ in-the-making
Champ in-the-making
Hi!
The list of workflows is the page http://localhost:8080/alfresco/s/api/workflow-definitions.
I would like to create a Java class that will allow me, through an interface (client), enter a new workflow.
I have a web page. This page is a list of workflow and an "add" button.
If I click, a window is displayed. In this window, I enter the data for the workflow (title, description etc). Then I click on a button "save" and the listener must add the new workflow.
I do not know how to do this last part, ie the addition of workflow in Alfresco.
How it works?
I have seen that there is a class Workflow Service (http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/service/cmr/workflow/WorkflowServ...) and I've read this thread http://forums.alfresco.com/en/index.php?t=16989 but I did not understand.

thank you
12 REPLIES 12

ventus85
Champ in-the-making
Champ in-the-making
If I want to insert a new workflow (not a new type as in the previous post) I noticed that the node is in workspace://SpaceStore–>System–>workflow–>Package.
In this case the creation of a new node from the website is easier.
The node has some properties, such as name, workflowDefinitionId, workflowDefinitionName, created, creator, etc. etc.. But where I find the assignee?

Thank you

mitpatoliya
Star Collaborator
Star Collaborator
Yes in order to create the new workflow you need to fist create one workflow node set all that related properties in that.
For assignee you need to create start task and then set assignee as its parameter. than you need to update the start task.
So it will trigger the workflow.

ventus85
Champ in-the-making
Champ in-the-making
Yes in order to create the new workflow you need to fist create one workflow node set all that related properties in that.
For assignee you need to create start task and then set assignee as its parameter. than you need to update the start task.
So it will trigger the workflow.

I know what you mean, but I did not understand one thing: what is the Java class that I must use? WorkflowTask?

I'm sorry because I had not previously specified that use Java.

Thank you

alarocca
Champ in-the-making
Champ in-the-making
There is an action called "start-workflow". You should call it providing the expected parameters.

http://wiki.alfresco.com/wiki/WorkflowAdministration#Step_7:_Integration_with_Rules_.28Optional.29

ventus85
Champ in-the-making
Champ in-the-making
Searching the Internet and reading the documentation, I found this example:

WorkflowService workflowService = serviceRegistry.getWorkflowService();
   NodeRef workflowNodeRef = workflowService.createPackage(null);

   Map<QName, Serializable> properties = new HashMap<QName, Serializable>();

   Date date = new Date(System.currentTimeMillis());

   properties.put(WorkflowModel.ASSOC_PACKAGE, workflowNodeRef);
    
   NodeRef personNodeId =  personService.getPerson("USER_TEST");

   properties.put(WorkflowModel.ASSOC_ASSIGNEE,personNodeId );
   properties.put(WorkflowModel.PROP_DUE_DATE, date);
   properties.put(WorkflowModel.PROP_DESCRIPTION, "PROP_DESCRIPTION");
   properties.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, date);
   properties.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "PROP_WORKFLOW_DESCRIPTION");
     
   WorkflowPath path = workflowService.startWorkflow(wid, parameters);

   WorkflowTaskQuery query = new WorkflowTaskQuery();

   query.setTaskState(WorkflowTaskState.COMPLETED);
   query.setTaskState(WorkflowTaskState.IN_PROGRESS);

   
      

where these classes and interfaces are used:
  • Interface WorkflowModel: http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/repo/workflow/WorkflowModel.html

  • Interface WorkflowService: Workflow Service. Client facing API for interacting with Alfresco Workflows and Tasks.

  • Interface ServiceRegistry: This interface represents the registry of public Repository Services. The registry provides meta-data about each service and provides access to the service interface.

  • Class NodeRef

  • Class QName: QName represents the qualified name of a Repository item. Each QName consists of a local name qualified by a namespace.

  • Class WorkflowTaskQuery: Workflow Task Query Provides support for setting predicates and order by.
My idea was to use "properties" and start the workflow:
WorkflowPath path = workflowService.startWorkflow(wid,, properties);


Edit: While I was writing, you said…  Smiley Very Happy
Your last post made ​​me confused…
Now I will use the code I posted, but I do not know if that's okay…

alarocca
Champ in-the-making
Champ in-the-making
If you need to start the workflow from an external application, then the webservice does not provide an interface to the workflow sevice, and calling the action is the solution. Instead if your piece of code runs "inside" Alfresco (eg, a bean) you can use directly the workflowService class like your example do.

ventus85
Champ in-the-making
Champ in-the-making
I have a web page with a form. This form is similar to that of Alfresco Share (http://localhost:8080/share/page/my-workflows –> add workflow). The user enters the data and click on "Save." My Java class has to receive the data and create the child node package.
For this reason I thought of using that example.
But the problem is for properties that are not present in the node.

What do you mean by "calling the action"?

Thank you.

alarocca
Champ in-the-making
Champ in-the-making

ventus85
Champ in-the-making
Champ in-the-making
I'm sorry, but I do not understand.  :cry:

Why the solutions as written here or in the thread are not going well?
What I did not understand?

Add an action makes it more difficult, but maybe I'm wrong, I do not know these classes.