package org.camunda.demo.spielwiese.spielwiese2; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import org.camunda.bpm.application.PostDeploy; import org.camunda.bpm.application.PreUndeploy; import org.camunda.bpm.application.ProcessApplication; import org.camunda.bpm.application.ProcessApplicationDeploymentInfo; import org.camunda.bpm.application.ProcessApplicationInfo; import org.camunda.bpm.application.ProcessApplicationRegistration; import org.camunda.bpm.application.impl.ServletProcessApplication; import org.camunda.bpm.engine.ProcessEngine; import org.camunda.bpm.engine.repository.ProcessDefinition; @ProcessApplication public class CamundaBpmProcessApplication extends ServletProcessApplication { private static final Logger log = Logger.getLogger(CamundaBpmProcessApplication.class.getName()); protected List processApplicationRegistrations = new ArrayList(); @PostDeploy public void registerProcessApplication(ProcessEngine processEngine, ProcessApplicationInfo processApplicationInfo) { // First: Get the information which deployments are registered for the current process application List deploymentInfos = processApplicationInfo.getDeploymentInfo(); for (ProcessApplicationDeploymentInfo processApplicationDeploymentInfo : deploymentInfos) { // Second: Get all processes contained in the current deployments List allProcessesForDeployment = // processEngine.getRepositoryService().createProcessDefinitionQuery() // .deploymentId(processApplicationDeploymentInfo.getDeploymentId()) // .list(); for (ProcessDefinition registeredProcessDefinition : allProcessesForDeployment) { // Third: Not get all version of every process List allVersionsOfThisProcessKey = // processEngine.getRepositoryService().createProcessDefinitionQuery() // .processDefinitionKey(registeredProcessDefinition.getKey()) // .list(); for (ProcessDefinition pd : allVersionsOfThisProcessKey) { // Fourth: register the deployment if not already done (for the current one it is already done) if (processEngine.getManagementService().getProcessApplicationForDeployment(pd.getDeploymentId()) == null) { log.info("Manually register process " + pd.getId() + " within deployment " + pd.getDeploymentId()); processApplicationRegistrations.add( processEngine.getManagementService().registerProcessApplication(pd.getDeploymentId(), getReference())); } } } } } @PreUndeploy public void unregisterProcessApplicaiton(ProcessEngine processEngine) { for (ProcessApplicationRegistration registration : processApplicationRegistrations) { log.info("Manually unregister process " + registration.getDeploymentId()); processEngine.getManagementService().unregisterProcessApplication(registration.getDeploymentId(), true); } } }