cancel
Showing results for 
Search instead for 
Did you mean: 

Getting all deployed Workflow Definitions

amiramira
Champ in-the-making
Champ in-the-making
Hi, I am sorry for my English
I want to get all deployed Workflow Definition this is what i did


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.alfresco.repo.workflow.BPMEngineRegistry;
import org.alfresco.repo.workflow.WorkflowComponent;
import org.alfresco.service.cmr.workflow.WorkflowAdminService;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;

public class WorkflowManag {

   private WorkflowAdminService workflowAdminService;
   BPMEngineRegistry registry = new BPMEngineRegistry();

   public void setBPMEngineRegistry(BPMEngineRegistry registry) {
      this.registry = registry;
   }
   
   public void setWorkflowAdminService(
         WorkflowAdminService workflowAdminService) {
      this.workflowAdminService = workflowAdminService;
   }

   public WorkflowManag(){
   }
 
   
   public List<WorkflowDefinition> getAllDefinitions() {
      List<WorkflowDefinition> definitions = new ArrayList<WorkflowDefinition>();
      String[] ids = registry.getWorkflowComponents();
      
      System.out.println(ids);

      for (String id : ids) {
         if (workflowAdminService.isEngineVisible(id)) {
            WorkflowComponent component = registry.getWorkflowComponent(id);
            definitions.addAll(component.getAllDefinitions());
         }
      
      }
      System.out.println("11111");
      return Collections.unmodifiableList(definitions);

and this is the class test

WorkflowManag wf=new WorkflowManag();
         List<WorkflowDefinition> l=wf.getAllDefinitions();
          System.out.println("aaaaaaaaa"+l.size());
          
          BPMEngineRegistry registry = new BPMEngineRegistry();
         if (registry.getWorkflowComponents().length==0) {
            System.out.println("your reg is empty ");
         }else {
            System.out.println(registry.getWorkflowComponents());
         }


when i execute i get this

[Ljava.lang.String;@1192410
11111
aaaaaaaaa0
your reg is empty

why the registry is empty!!

Thanks



2 REPLIES 2

s_palyukh
Star Contributor
Star Contributor
You should use WorkflowService



List<WorkflowDefinition> allDefinitions = workflowService.getAllDefinitions();



    /**
     * Gets latest deployed Workflow Definitions
     *
     * @return  the latest deployed workflow definitions
     */
    @Auditable
    public List<WorkflowDefinition> getDefinitions();
   
    /**
     * Gets all deployed Workflow Definitions (with all previous versions)
     *
     * @return  the deployed (and previous) workflow definitions
     */
    @Auditable
    public List<WorkflowDefinition> getAllDefinitions();

amiramira
Champ in-the-making
Champ in-the-making
Tank's for your help