@BeforeClass
 public static void initFactories() {
   ProcessBuilderFactory.setProcessBuilderFactoryService(new ProcessBuilderFactoryServiceImpl());
   ProcessMarshallerFactory.setProcessMarshallerFactoryService(
       new ProcessMarshallerFactoryServiceImpl());
   ProcessRuntimeFactory.setProcessRuntimeFactoryService(new ProcessRuntimeFactoryServiceImpl());
 }
 private static void loadProvider() {
   ServiceRegistryImpl.getInstance()
       .addDefault(
           ProcessRuntimeFactoryService.class,
           "org.jbpm.process.instance.ProcessRuntimeFactoryServiceImpl");
   setProcessRuntimeFactoryService(
       ServiceRegistryImpl.getInstance().get(ProcessRuntimeFactoryService.class));
 }
Esempio n. 3
0
  public DiagramInfo getDiagramInfo(String processId) {
    if (kbase == null) {
      GuvnorConnectionUtils guvnorUtils = new GuvnorConnectionUtils();
      if (guvnorUtils.guvnorExists()) {
        try {
          KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("Guvnor default");
          kagent.applyChangeSet(ResourceFactory.newReaderResource(guvnorUtils.createChangeSet()));
          kagent.monitorResourceChangeEvents(false);
          kbase = kagent.getKnowledgeBase();
        } catch (Throwable t) {
          logger.error("Could not build kbase from Guvnor assets: " + t.getMessage());
        }
      } else {
        logger.warn("Could not connect to Guvnor.");
      }
      if (kbase == null) {
        kbase = KnowledgeBaseFactory.newKnowledgeBase();
      }
      String directory = System.getProperty("jbpm.console.directory");
      if (directory == null) {
        logger.error("jbpm.console.directory property not found");
      } else {
        File file = new File(directory);
        if (!file.exists()) {
          throw new IllegalArgumentException("Could not find " + directory);
        }
        if (!file.isDirectory()) {
          throw new IllegalArgumentException(directory + " is not a directory");
        }
        ProcessBuilderFactory.setProcessBuilderFactoryService(
            new ProcessBuilderFactoryServiceImpl());
        ProcessMarshallerFactory.setProcessMarshallerFactoryService(
            new ProcessMarshallerFactoryServiceImpl());
        ProcessRuntimeFactory.setProcessRuntimeFactoryService(
            new ProcessRuntimeFactoryServiceImpl());
        BPMN2ProcessFactory.setBPMN2ProcessProvider(new BPMN2ProcessProviderImpl());
        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        for (File subfile :
            file.listFiles(
                new FilenameFilter() {
                  public boolean accept(File dir, String name) {
                    return name.endsWith(".bpmn") || name.endsWith("bpmn2");
                  }
                })) {
          kbuilder.add(ResourceFactory.newFileResource(subfile), ResourceType.BPMN2);
        }
        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
      }
    }
    Process process = kbase.getProcess(processId);
    if (process == null) {
      return null;
    }

    DiagramInfo result = new DiagramInfo();
    // TODO: diagram width and height?
    result.setWidth(932);
    result.setHeight(541);
    List<DiagramNodeInfo> nodeList = new ArrayList<DiagramNodeInfo>();
    if (process instanceof WorkflowProcess) {
      addNodesInfo(nodeList, ((WorkflowProcess) process).getNodes(), "id=");
    }
    result.setNodeList(nodeList);
    return result;
  }