Java Code Examples for org.camunda.bpm.engine.RepositoryService#createDeployment()

The following examples show how to use org.camunda.bpm.engine.RepositoryService#createDeployment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeploymentResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected DeploymentWithDefinitions tryToRedeploy(RedeploymentDto redeployment) {
  RepositoryService repositoryService = getProcessEngine().getRepositoryService();

  DeploymentBuilder builder = repositoryService.createDeployment();
  builder.nameFromDeployment(deploymentId);

  String tenantId = getDeployment().getTenantId();
  if (tenantId != null) {
    builder.tenantId(tenantId);
  }

  if (redeployment != null) {
    builder = addRedeploymentResources(builder, redeployment);
  } else {
    builder.addDeploymentResources(deploymentId);
  }

  return builder.deployWithResult();
}
 
Example 2
Source File: ProcessDefinitionDeployerImpl.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
@Override
public void deployProcessDefinitions(String bundleSymbolicName, List<URL> pathList) {
	try {
		LOGGER.log(Level.FINE,
				"Found process in bundle " + bundleSymbolicName
						+ " with paths: " + pathList);

		if (engine == null) {
			throw new IllegalStateException(
					"Unable to find a ProcessEngine service");
		}

		RepositoryService service = engine.getRepositoryService();
		DeploymentBuilder builder = service.createDeployment();
		builder.name(bundleSymbolicName);
		for (URL url : pathList) {
			InputStream is = url.openStream();
			if (is == null) {
				throw new IOException("Error opening url: " + url);
			}
			try {
				builder.addInputStream(getPath(url), is);
			} finally {
				is.close();
			}
		}
		builder.enableDuplicateFiltering(true);
		builder.deploy();
	} catch (Exception e) {
		LOGGER.log(Level.SEVERE, "Unable to deploy bundle", e);
	}
}
 
Example 3
Source File: DeployProcessArchiveStep.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void performOperationStep(DeploymentOperation operationContext) {

  final PlatformServiceContainer serviceContainer = operationContext.getServiceContainer();
  final AbstractProcessApplication processApplication = operationContext.getAttachment(Attachments.PROCESS_APPLICATION);
  final ClassLoader processApplicationClassloader = processApplication.getProcessApplicationClassloader();

  ProcessEngine processEngine = getProcessEngine(serviceContainer, processApplication.getDefaultDeployToEngineName());

  // start building deployment map
  Map<String, byte[]> deploymentMap = new HashMap<String, byte[]>();

  // add all processes listed in the processes.xml
  List<String> listedProcessResources = processArchive.getProcessResourceNames();
  for (String processResource : listedProcessResources) {
    InputStream resourceAsStream = null;
    try {
      resourceAsStream = processApplicationClassloader.getResourceAsStream(processResource);
      byte[] bytes = IoUtil.readInputStream(resourceAsStream, processResource);
      deploymentMap.put(processResource, bytes);
    } finally {
      IoUtil.closeSilently(resourceAsStream);
    }
  }

  // scan for additional process definitions if not turned off
  if(PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_SCAN_FOR_PROCESS_DEFINITIONS, true)) {
    String paResourceRoot = processArchive.getProperties().get(ProcessArchiveXml.PROP_RESOURCE_ROOT_PATH);
    String[] additionalResourceSuffixes = StringUtil.split(processArchive.getProperties().get(ProcessArchiveXml.PROP_ADDITIONAL_RESOURCE_SUFFIXES), ProcessArchiveXml.PROP_ADDITIONAL_RESOURCE_SUFFIXES_SEPARATOR);
    deploymentMap.putAll(findResources(processApplicationClassloader, paResourceRoot, additionalResourceSuffixes));
  }

  // perform process engine deployment
  RepositoryService repositoryService = processEngine.getRepositoryService();
  ProcessApplicationDeploymentBuilder deploymentBuilder = repositoryService.createDeployment(processApplication.getReference());

  // set the name for the deployment
  String deploymentName = processArchive.getName();
  if(deploymentName == null || deploymentName.isEmpty()) {
    deploymentName = processApplication.getName();
  }
  deploymentBuilder.name(deploymentName);

  // set the tenant id for the deployment
  String tenantId = processArchive.getTenantId();
  if(tenantId != null && !tenantId.isEmpty()) {
    deploymentBuilder.tenantId(tenantId);
  }

  // enable duplicate filtering
  deploymentBuilder.enableDuplicateFiltering(PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_DEPLOY_CHANGED_ONLY, false));

  if (PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_RESUME_PREVIOUS_VERSIONS, true)) {
    enableResumingOfPreviousVersions(deploymentBuilder);
  }

  // add all resources obtained through the processes.xml and through scanning
  for (Entry<String, byte[]> deploymentResource : deploymentMap.entrySet()) {
    deploymentBuilder.addInputStream(deploymentResource.getKey(), new ByteArrayInputStream(deploymentResource.getValue()));
  }

  // allow the process application to add additional resources to the deployment
  processApplication.createDeployment(processArchive.getName(), deploymentBuilder);

  Collection<String> deploymentResourceNames = deploymentBuilder.getResourceNames();
  if(!deploymentResourceNames.isEmpty()) {

    LOG.deploymentSummary(deploymentResourceNames, deploymentName);

    // perform the process engine deployment
    deployment = deploymentBuilder.deploy();

    // add attachment
    Map<String, DeployedProcessArchive> processArchiveDeploymentMap = operationContext.getAttachment(Attachments.PROCESS_ARCHIVE_DEPLOYMENT_MAP);
    if(processArchiveDeploymentMap == null) {
      processArchiveDeploymentMap = new HashMap<String, DeployedProcessArchive>();
      operationContext.addAttachment(Attachments.PROCESS_ARCHIVE_DEPLOYMENT_MAP, processArchiveDeploymentMap);
    }
    processArchiveDeploymentMap.put(processArchive.getName(), new DeployedProcessArchive(deployment));

  }
  else {
    LOG.notCreatingPaDeployment(processApplication.getName());
  }
}