/**
   * Fills combobox with branches of given repository fork
   *
   * @param repoName
   * @param fork
   * @return
   */
  public ComboBoxModel doFillBranchItems(@QueryParameter String name, @QueryParameter String fork) {
    ComboBoxModel aux = new ComboBoxModel();

    if (this.githubClient.getUser() == null) {
      setGithubConfig();
    }

    if (fork.length() == 0) {
      return aux;
    }

    try {
      RepositoryId repoId = new RepositoryId(fork, name);
      RepositoryService githubRepoSrv = new RepositoryService(this.githubClient);
      List<RepositoryBranch> branches = githubRepoSrv.getBranches(repoId);

      for (RepositoryBranch branch : branches) {
        aux.add(branch.getName());
      }

    } catch (Exception e) {
      // TODO: handle exception
    }
    Collections.sort(aux);
    return this.branchItems = aux;
  }
  /**
   * 查看流程定义图
   *
   * @param request
   * @param processDefId 流程定义id
   * @return
   */
  @RequestMapping(value = "/viewprocessDefImage.do")
  public String viewprocessDefImage(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam("processDefId") String processDefId)
      throws Exception {
    // 根据流程定义id查询流程定义
    ProcessDefinition processDefinition =
        repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionId(processDefId)
            .singleResult();

    InputStream inputStream =
        repositoryService.getResourceAsStream(
            processDefinition.getDeploymentId(), processDefinition.getDiagramResourceName());

    //        // 输出资源内容到相应对象
    //        byte[] b = new byte[1024];
    //        int len;
    //        while ((len = inputStream.read(b, 0, 1024)) != -1) {
    //        	response.getOutputStream().write(b, 0, len);
    //        }

    response.getOutputStream().write(IoUtil.readInputStream(inputStream, "processDefInputStream"));

    return null;
  }
  /** Fill combobox with forks of repository */
  public ComboBoxModel doFillForkItems(@QueryParameter String value, @QueryParameter String name) {
    ComboBoxModel aux = new ComboBoxModel();

    if (this.githubClient.getUser() == null) {
      setGithubConfig();
    }

    try {
      RepositoryService githubRepoSrv = new RepositoryService(this.githubClient);
      List<org.eclipse.egit.github.core.Repository> forks;

      try {
        // get parent repository if repository itself is forked
        org.eclipse.egit.github.core.Repository parent =
            githubRepoSrv.getRepository(value, name).getParent();

        if (parent != null) {
          // get fork of parent repository
          forks = githubRepoSrv.getForks(parent);
          for (org.eclipse.egit.github.core.Repository fork : forks) {
            org.eclipse.egit.github.core.User user = fork.getOwner();
            aux.add(user.getLogin());
          }
        }

        if (aux.isEmpty()) {
          // add forks of repository
          forks = githubRepoSrv.getForks(new RepositoryId(value, name));
          for (org.eclipse.egit.github.core.Repository fork : forks) {
            org.eclipse.egit.github.core.User user = fork.getOwner();
            aux.add(user.getLogin());
          }
        }
        aux.add(0, value);
      } catch (Exception ex) {
      }

      try {
        // try to use global githubLogin, find repository and add forks
        forks = githubRepoSrv.getForks(new RepositoryId(this.githubLogin, name));
        for (org.eclipse.egit.github.core.Repository fork : forks) {
          org.eclipse.egit.github.core.User user = fork.getOwner();
          if (!aux.contains(user.getLogin())) {
            aux.add(user.getLogin());
          }
        }
      } catch (Exception ex) {
      }

    } catch (Exception ex) {
      // TODO: handle exception
    }
    Collections.sort(aux);
    return this.forkItems = aux;
  }
  /**
   * 删除执行流程
   *
   * @param request
   * @param processDefId
   * @return
   */
  @RequestMapping(value = "/remove.do")
  public String remove(
      HttpServletRequest request, @RequestParam("processDefId") String processDefId) {

    repositoryService.deleteDeployment(processDefId);
    return "redirect:/simple/index.do";
  }
예제 #5
0
 @Test
 public void test() {
   ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
   RepositoryService repositoryService = engine.getRepositoryService();
   RuntimeService runtimeService = engine.getRuntimeService();
   TaskService taskService = engine.getTaskService();
   repositoryService.createDeployment().addClasspathResource("bpmn/first.bpmn").deploy();
   runtimeService.startProcessInstanceByKey("process1");
   Task task = taskService.createTaskQuery().singleResult();
   System.out.println("第一个任务完成前,当前任务名称:" + task.getName());
   taskService.complete(task.getId());
   task = taskService.createTaskQuery().singleResult();
   System.out.println("第二个任务完成前,当前任务名称:" + task.getName());
   taskService.complete(task.getId());
   task = taskService.createTaskQuery().singleResult();
   System.out.println("流程结束后,查找任务:" + task);
 }
예제 #6
0
 /**
  * 查询流程定义
  *
  * @param processDefinitionId
  * @return
  */
 @Override
 public ProcessDefinition getProcessDefinition(String processDefinitionId) {
   ProcessDefinition processDefinition =
       repositoryService
           .createProcessDefinitionQuery()
           .processDefinitionId(processDefinitionId)
           .singleResult();
   return processDefinition;
 }
  @Override
  public synchronized void start(StartContext context) throws StartException {
    ServiceController<?> controller = context.getController();
    LOGGER.tracef("Starting: %s in mode %s", controller.getName(), controller.getMode());
    try {
      ServiceContainer serviceContainer = context.getController().getServiceContainer();

      // Setup the OSGi {@link Framework} properties
      SubsystemState subsystemState = injectedSubsystemState.getValue();
      Map<String, Object> props = new HashMap<String, Object>(subsystemState.getProperties());
      setupIntegrationProperties(context, props);

      // Register the URLStreamHandlerFactory
      Module coreFrameworkModule =
          ((ModuleClassLoader) FrameworkBuilder.class.getClassLoader()).getModule();
      Module.registerURLStreamHandlerFactoryModule(coreFrameworkModule);
      Module.registerContentHandlerFactoryModule(coreFrameworkModule);

      ServiceTarget serviceTarget = context.getChildTarget();
      JAXPServiceProvider.addService(serviceTarget);
      ResolverService.addService(serviceTarget);
      RepositoryService.addService(serviceTarget);

      Activation activation = subsystemState.getActivationPolicy();
      Mode initialMode = (activation == Activation.EAGER ? Mode.ACTIVE : Mode.LAZY);

      // Configure the {@link Framework} builder
      FrameworkBuilder builder = FrameworkBuilderFactory.create(props, initialMode);
      builder.setServiceContainer(serviceContainer);
      builder.setServiceTarget(serviceTarget);

      builder.createFrameworkServices(serviceContainer, true);
      builder.registerIntegrationService(FrameworkPhase.CREATE, new BundleLifecycleIntegration());
      builder.registerIntegrationService(
          FrameworkPhase.CREATE, new FrameworkModuleIntegration(props));
      builder.registerIntegrationService(FrameworkPhase.CREATE, new ModuleLoaderIntegration());
      builder.registerIntegrationService(
          FrameworkPhase.CREATE, new SystemServicesIntegration(resource, extensions));
      builder.registerIntegrationService(FrameworkPhase.INIT, new BootstrapBundlesIntegration());
      builder.registerIntegrationService(
          FrameworkPhase.INIT, new PersistentBundlesIntegration(deploymentTracker));

      // Install the services to create the framework
      builder.installServices(FrameworkPhase.CREATE, serviceTarget, verificationHandler);

      if (activation == Activation.EAGER) {
        builder.installServices(FrameworkPhase.INIT, serviceTarget, verificationHandler);
        builder.installServices(FrameworkPhase.ACTIVE, serviceTarget, verificationHandler);
      }

      // Create the framework activator
      FrameworkActivator.create(builder);

    } catch (Throwable th) {
      throw MESSAGES.startFailedToCreateFrameworkServices(th);
    }
  }
  @JavaScriptMethod
  public String checkFork(String fork, String repo) {

    doFillForkItems(fork, repo);

    if (fork.length() == 0) {
      return Messages.Fork_NoFork();
    }

    // check if given fork owner is in fork list
    for (String f : this.forkItems) {
      if (f.equals(fork)) {
        return "__succeeded";
      }
    }

    // if fork owner was not in list
    try {
      // check if user exists
      try {
        UserService githubUserSrv = new UserService(this.githubClient);
        githubUserSrv.getUser(fork);
      } catch (Exception ex) {
        return Messages.Fork_OwnerNotFound() + "\n" + ex.getMessage();
      }
      // check if user has public repository with given name
      try {
        RepositoryService githubRepoSrv = new RepositoryService(this.githubClient);
        List<org.eclipse.egit.github.core.Repository> repos = githubRepoSrv.getRepositories(fork);
        for (org.eclipse.egit.github.core.Repository r : repos) {
          if (r.getName().equals(repo)) return Messages.Fork_Found() + "__succeeded";
        }
      } catch (Exception ex) {
        return Messages.Fork_GetReposFailed() + "\n" + ex.getMessage();
      }
      return "__succeeded";
    } catch (Exception ex) {
      return Messages.Fork_AuthFailed() + "\n" + ex.getMessage();
    }
  }
  /** Checks if given fork owner exists */
  public FormValidation checkDepFork(@QueryParameter String value, @QueryParameter String name)
      throws IOException, ServletException {

    doFillForkItems(value, name);

    if (value.length() == 0) {
      return FormValidation.error(Messages.Fork_NoFork());
    }

    // check if given fork owner is in fork list
    /*for (String fork : this.forkItems) {
    	if (fork.equals(value)) {
    		return (msg.length()==0) ? FormValidation.ok() : FormValidation.ok(msg);
    	}
    }*/

    // if fork owner was not in list
    try {
      // check if user exists
      try {
        UserService githubUserSrv = new UserService(this.githubClient);
        githubUserSrv.getUser(value);
      } catch (Exception ex) {
        return FormValidation.error(Messages.Fork_OwnerNotFound() + "\n" + ex.getMessage());
      }
      // check if user has public repository with given name
      try {
        RepositoryService githubRepoSrv = new RepositoryService(this.githubClient);
        List<org.eclipse.egit.github.core.Repository> repos = githubRepoSrv.getRepositories(value);
        for (org.eclipse.egit.github.core.Repository repo : repos) {
          if (repo.getName().equals(name)) return FormValidation.ok(Messages.Fork_Found());
        }
      } catch (Exception ex) {
        return FormValidation.error(Messages.Fork_GetReposFailed() + "\n" + ex.getMessage());
      }
      return FormValidation.ok();
    } catch (Exception ex) {
      return FormValidation.error(Messages.Fork_AuthFailed() + "\n" + ex.getMessage());
    }
  }
  /** Fills combobox with repository names of organization */
  public ComboBoxModel doFillNameItems(@QueryParameter String fork) {
    ComboBoxModel aux = new ComboBoxModel();

    if (this.githubClient.getUser() == null) {
      setGithubConfig();
    }

    if (fork.length() == 0) {
      return aux;
    }

    try {
      RepositoryService githubRepoSrv = new RepositoryService(githubClient);
      List<org.eclipse.egit.github.core.Repository> repos = githubRepoSrv.getRepositories(fork);
      for (org.eclipse.egit.github.core.Repository repo : repos) {
        if (!aux.contains(repo.getName())) aux.add(0, repo.getName());
      }
    } catch (IOException ex) {
      // TODO: handle exception
    }
    Collections.sort(aux);
    return this.repoNameItems = aux;
  }
  /** Checks if given repository exists */
  public FormValidation checkDepName(@QueryParameter String value, @QueryParameter String fork)
      throws IOException, ServletException {

    doFillNameItems(fork);

    if (fork.length() == 0) {
      return FormValidation.error(Messages.Dependency_NoFork());
    }

    if (value.length() == 0) {
      return FormValidation.warning(Messages.Repository_NoName());
    }

    // check if given repository is in repo list
    for (String repoName : this.repoNameItems) {
      if (repoName.equals(value)) {
        return FormValidation.ok();
      }
    }
    // if repository was not in list, for example extern repository
    try {
      RepositoryService githubRepoSrv = new RepositoryService(githubClient);
      org.eclipse.egit.github.core.Repository selectedRepo =
          githubRepoSrv.getRepository(fork, value);
      if (selectedRepo != null) {
        if (selectedRepo.isPrivate()) {
          return FormValidation.ok(Messages.Dependency_PrivateFound());
        }
        return FormValidation.ok();
      }
    } catch (IOException ex) {
      // TODO: handle exception
    }

    return FormValidation.warning(
        Messages.Dependency_NotFound(value, fork)); // error(Messages.Repository_NoFound());
  }
  /**
   * 部署
   *
   * @param file
   * @return
   */
  @RequestMapping(value = "/deploy.do")
  public String deploy(@RequestParam(value = "file", required = false) MultipartFile file) {

    String fileName = file.getOriginalFilename();

    try {
      InputStream fileInputStream = file.getInputStream();

      repositoryService.createDeployment().addInputStream(fileName, fileInputStream).deploy();
    } catch (Exception e) {

    }

    return "redirect:/simple/index.do";
  }
  @JavaScriptMethod
  public String checkName(String repo, String fork) {

    doFillNameItems(fork);

    if (fork.length() == 0) {
      return Messages.Repository_NoFork();
    }

    if (repo.length() == 0) {
      return Messages.Repository_NoName();
    }

    // check if given repository is in repo list
    for (String repoName : this.repoNameItems) {
      if (repoName.equals(repo)) {
        return "";
      }
    }
    // if repository was not in list, for example extern repository
    try {
      RepositoryService githubRepoSrv = new RepositoryService(githubClient);
      org.eclipse.egit.github.core.Repository selectedRepo =
          githubRepoSrv.getRepository(fork, repo);
      if (selectedRepo != null) {
        if (selectedRepo.isPrivate()) {
          return Messages.Repository_PrivateFound() + "__succeeded";
        }
        return "__succeeded";
      }
    } catch (IOException ex) {
      // TODO: handle exception
    }

    return Messages.Repository_NotFound(repo, fork);
  }
 public PullRequest getPullRequest() {
   if (pullRequest == null && repositoryService.getRepository() != null) {
     Response response = null;
     try {
       response = bitbucketV2Client.getPullRequestById(repositoryOwner, repositoryName, id);
       if (response.getStatus() == HttpServletResponse.SC_OK) {
         pullRequest = response.readEntity(PullRequest.class);
       }
     } finally {
       if (response != null) {
         response.close();
       }
     }
   }
   return pullRequest;
 }
 public String getDiff() {
   if (diff == null && repositoryService.getRepository() != null) {
     Response response = null;
     try {
       response = bitbucketV2Client.getPullRequestDiff(repositoryOwner, repositoryName, id);
       if (response.getStatus() == HttpServletResponse.SC_OK) {
         diff = response.readEntity(String.class);
       }
     } finally {
       if (response != null) {
         response.close();
       }
     }
   }
   return diff;
 }
 public TaskList getTaskList() {
   if (taskList == null && repositoryService.getRepository() != null && id != null) {
     Response response = null;
     try {
       response =
           bitBucketUndocumentedClient.getPullRequestTasks(repositoryOwner, repositoryName, id);
       if (response.getStatus() == HttpServletResponse.SC_OK) {
         taskList = response.readEntity(TaskList.class);
       } else {
         LOGGER.error("error getting task list. response:{}", response.getStatus());
       }
     } finally {
       if (response != null) {
         response.close();
       }
     }
   }
   return taskList;
 }
  /**
   * 个人任务首页
   *
   * @return
   */
  @RequestMapping("/index.do")
  public String index(HttpServletRequest request, HttpServletResponse response, Model model) {

    User user =
        request.getSession(true).getAttribute("user") == null
            ? null
            : (User) request.getSession(true).getAttribute("user");

    List<Group> groups =
        request.getSession(true).getAttribute("groups") == null
            ? null
            : (List<Group>) request.getSession(true).getAttribute("groups");

    if (null == user) {
      return "redirect:/simple/login.do";
    } else {
      model.addAttribute("user", user);
      model.addAttribute("groups", groups);
      /** */
      List<ProcessDefinition> pdList = repositoryService.createProcessDefinitionQuery().list();

      model.addAttribute("pdList", pdList);
      /** 该用户所有可以认领的任务 */
      List<Task> groupTasks = taskService.createTaskQuery().taskCandidateUser(user.getId()).list();

      List<Task> userTasks = taskService.createTaskQuery().taskAssignee(user.getId()).list();
      model.addAttribute("userTasks", userTasks);
      model.addAttribute("groupTasks", groupTasks);
      /** 查看任务实例 */
      List<Task> taskList = taskService.createTaskQuery().list();
      model.addAttribute("taskList", taskList);
      /** 历史流程 */
      List<HistoricProcessInstance> hpiList =
          historyService.createHistoricProcessInstanceQuery().finished().list();
      model.addAttribute("hpiList", hpiList);
    }

    return "/simple/index";
  }
  /**
   * 显示图片
   *
   * @return
   */
  @RequestMapping(value = "/viewPic.do")
  public void viewPic(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam("executionId") String executionId)
      throws Exception {
    ProcessInstance processInstance =
        runtimeService.createProcessInstanceQuery().processInstanceId(executionId).singleResult();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);

    // 使用spring注入引擎请使用下面的这行代码
    Context.setProcessEngineConfiguration(processEngine.getProcessEngineConfiguration());

    InputStream imageStream =
        ProcessDiagramGenerator.generateDiagram(bpmnModel, "png", activeActivityIds);

    // 输出资源内容到相应对象
    byte[] b = new byte[1024];
    int len;
    while ((len = imageStream.read(b, 0, 1024)) != -1) {
      response.getOutputStream().write(b, 0, len);
    }
  }