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

alarocca
Champ in-the-making
Champ in-the-making
Sorry for confusing you. Your code works well.

Only if you develop an external application (but it's not your case) and, using webservices, the action "start-workflow" is the only way to do that because webservice api does not provide any access to the workflowService.

ventus85
Champ in-the-making
Champ in-the-making
Can you give me an example of external application?

I will try to explain better.  Smiley Happy
Suppose I have an Alfresco Service and a method "CreateNode", which takes as input:
-the parent reference;
-node type;
-the properties; (ex. Map <String, object>);
-a callback.

If the child of the package had all the properties included in the form there are no problems.
But in my case the node has some properties, for example the node has no properties "priority" and "due date".
What do you do?
You create a new type which also has the missing properties or those properties are stored somewhere else?

Thank you.

ventus85
Champ in-the-making
Champ in-the-making
This is my code (similar to the code of the page http://forums.alfresco.com/en/viewtopic.php?f=34&t=16989)

Button save;
this.addButton( save = new Button("Save) );
      save.addListener(Events.Select, new Listener<ButtonEvent>() {

         @Override
         public void handleEvent(ButtonEvent be) {
                  addWorkflow();
            };   
         }
            
      });

   public void addWorkflow() {
      
      WorkflowService workflowService = null;
      NodeRef nodeRef;
      Date date = new Date();
      
      NodeRef wfPackage = workflowService.createPackage(null);
      
      Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
      properties.put(WorkflowModel.PROP_TASK_ID, 3);
      properties.put(WorkflowModel.PROP_DUE_DATE, new Date());
      properties.put(WorkflowModel.PROP_PRIORITY, 1);  // task instance field
      properties.put(WorkflowModel.PROP_PERCENT_COMPLETE, 10);  // context variable
      properties.put(WorkflowModel.PROP_START_DATE, date.getTime());
      properties.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "Prova aggiunta workflow");
      
      workflowService.createPackage(wfPackage);
      
      WorkflowDefinition wfDefinition = workflowService.getDefinitionByName(WorkflowModelModeratedInvitation.WORKFLOW_DEFINITION_NAME);
      if (wfDefinition == null) {
         Object objs[] = { WorkflowModelModeratedInvitation.WORKFLOW_DEFINITION_NAME };
      throw new InvitationException("invitation.error.noworkflow", objs);
      }
      
      WorkflowPath wfPath = workflowService.startWorkflow(wfDefinition.getId(), properties);
   }

If I run the code, the new workflow is not created.
Why? What's wrong?

Thank you