Пример #1
0
  ProcessDeployment execute(
      DeploymentRepository deploymentRepository, ProcessRepository processRepository)
      throws PieceworkException {
    if (LOG.isDebugEnabled()) LOG.debug("Executing publication command " + this.toString());

    // Verify that this deployment belongs to this process
    ProcessDeploymentVersion selectedDeploymentVersion =
        ProcessUtility.deploymentVersion(process, deploymentId);
    if (selectedDeploymentVersion == null) throw new NotFoundError();

    // Grab the actual deployment object back from the repository
    ProcessDeployment original = deploymentRepository.findOne(deploymentId);
    if (original == null) throw new NotFoundError();

    if (!original.isDeployed())
      throw new ForbiddenError(Constants.ExceptionCodes.process_not_deployed);

    // Update the deployment to indicate that it is published
    PassthroughSanitizer passthroughSanitizer = new PassthroughSanitizer();
    ProcessDeployment updatedDeployment =
        new ProcessDeployment.Builder(
                original, process.getProcessDefinitionKey(), passthroughSanitizer, true)
            .publish()
            .build();

    // Make sure we persist that fact
    ProcessDeployment persistedDeployment = deploymentRepository.save(updatedDeployment);

    // And update the process definition to indicate that this is the officially published
    // deployment for the process
    Process updatedProcess =
        new Process.Builder(process, passthroughSanitizer)
            .deploy(selectedDeploymentVersion, persistedDeployment)
            .build();
    // Persist that too
    processRepository.save(updatedProcess);

    return persistedDeployment;
  }