Java源码示例:org.camunda.bpm.engine.repository.Deployment
示例1
@Override
protected Object doExecute() throws Exception {
if (processDefinitionId != null) {
printProcessInfo(processDefinitionId);
} else {
//search for the last deployment
List<Deployment> deployments = engine.getRepositoryService().createDeploymentQuery().orderByDeploymenTime().desc().listPage(0,
1);
Deployment lastDeployment = deployments.get(0);
System.out.println("Process instance for the last deployment: " + lastDeployment.getId());
//iterate over the process definitions
for (ProcessDefinition process : engine.getRepositoryService().createProcessDefinitionQuery().deploymentId(lastDeployment.getId())
.list()) {
System.out.println("\nInstances for the process definition: " + process.getId());
printProcessInfo(process.getId());
}
}
return null;
}
示例2
public void testDeleteProcessDefinitiontWithoutCascadingShouldKeepCreateUserOperationLog() {
// given
Deployment deployment = repositoryService
.createDeployment()
.name(DEPLOYMENT_NAME)
.addModelInstance(RESOURCE_NAME, createProcessWithServiceTask(PROCESS_KEY))
.deploy();
ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery()
.deploymentId(deployment.getId())
.singleResult();
UserOperationLogQuery query = historyService
.createUserOperationLogQuery()
.operationType(UserOperationLogEntry.OPERATION_TYPE_CREATE);
assertEquals(1, query.count());
// when
repositoryService.deleteProcessDefinition(procDef.getId());
// then
assertEquals(1, query.count());
}
示例3
@Test
public void testDeploymentWithoutTenantId() {
Deployment mockDeployment = MockProvider.createMockDeployment(null);
mockedQuery = setUpMockDeploymentQuery(Collections.singletonList(mockDeployment));
Response response = given()
.queryParam("withoutTenantId", true)
.then().expect()
.statusCode(Status.OK.getStatusCode())
.when()
.get(DEPLOYMENT_QUERY_URL);
verify(mockedQuery).withoutTenantId();
verify(mockedQuery).list();
String content = response.asString();
List<String> definitions = from(content).getList("");
assertThat(definitions).hasSize(1);
String returnedTenantId1 = from(content).getString("[0].tenantId");
assertThat(returnedTenantId1).isEqualTo(null);
}
示例4
@Test
@org.camunda.bpm.engine.test.Deployment(resources={"org/camunda/bpm/engine/test/api/repository/failingProcessCreateOneIncident.bpmn20.xml"})
public void testQueryByIncidentMessage() {
assertThat(repositoryService.createProcessDefinitionQuery()
.processDefinitionKey("failingProcess")
.count()).isEqualTo(1);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("failingProcess");
testRule.waitForJobExecutorToProcessAllJobs();
List<Incident> incidentList = runtimeService.createIncidentQuery().list();
assertThat(incidentList.size()).isEqualTo(1);
Incident incident = runtimeService.createIncidentQuery().processInstanceId(processInstance.getId()).singleResult();
ProcessDefinitionQuery query = repositoryService
.createProcessDefinitionQuery()
.incidentMessage(incident.getIncidentMessage());
verifyQueryResults(query, 1);
}
示例5
public void testTxListenersInvokeAsync() {
BpmnModelInstance process = Bpmn.createExecutableProcess("testProcess")
.startEvent()
.camundaAsyncBefore()
.camundaAsyncAfter()
.endEvent()
.done();
Deployment deployment = repositoryService.createDeployment()
.addModelInstance("testProcess.bpmn", process)
.deploy();
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess");
waitForJobExecutorToProcessAllJobs(6000);
assertProcessEnded(pi.getId());
repositoryService.deleteDeployment(deployment.getId(), true);
}
示例6
protected void initializeCallableElement(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context) {
Deployment deployment = context.getDeployment();
String deploymentId = null;
if (deployment != null) {
deploymentId = deployment.getId();
}
BaseCallableElement callableElement = createCallableElement();
callableElement.setDeploymentId(deploymentId);
// set callableElement on behavior
CallingTaskActivityBehavior behavior = (CallingTaskActivityBehavior) activity.getActivityBehavior();
behavior.setCallableElement(callableElement);
// definition key
initializeDefinitionKey(element, activity, context, callableElement);
// binding
initializeBinding(element, activity, context, callableElement);
// version
initializeVersion(element, activity, context, callableElement);
// tenant-id
initializeTenantId(element, activity, context, callableElement);
}
示例7
@Test
public void testUnregisterProcessApplicationOnDeploymentDeletion() {
// given a deployment with a process application registration
Deployment deployment = testRule.deploy(repositoryService
.createDeployment()
.addModelInstance("process.bpmn",
Bpmn.createExecutableProcess("foo").done()));
// and a process application registration
managementService.registerProcessApplication(deployment.getId(),
processApplication.getReference());
// when deleting the deploymen
repositoryService.deleteDeployment(deployment.getId(), true);
// then the registration is removed
assertNull(managementService.getProcessApplicationForDeployment(deployment.getId()));
}
示例8
@Test
public void testCreateJobDefinitionWithParseListenerAndAsyncInXml() {
//given the asyncBefore is set in the xml
String modelFileName = "jobAsyncBeforeCreationWithinParseListener.bpmn20.xml";
InputStream in = JobDefinitionCreationWithParseListenerTest.class.getResourceAsStream(modelFileName);
DeploymentBuilder builder = engineRule.getRepositoryService().createDeployment().addInputStream(modelFileName, in);
//when the asyncBefore is set in the parse listener
Deployment deployment = builder.deploy();
engineRule.manageDeployment(deployment);
//then there exists only one job definition
JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
JobDefinition jobDef = query.singleResult();
assertNotNull(jobDef);
assertEquals(jobDef.getProcessDefinitionKey(), "oneTaskProcess");
assertEquals(jobDef.getActivityId(), "servicetask1");
}
示例9
@Test
public void testRedeploySetDeploymentSourceProperty() {
// given
BpmnModelInstance model = createProcessWithServiceTask(PROCESS_KEY);
Deployment deployment1 = testRule.deploy(repositoryService
.createDeployment()
.name(DEPLOYMENT_NAME)
.source("my-deployment-source")
.addModelInstance(RESOURCE_NAME, model));
assertEquals("my-deployment-source", deployment1.getSource());
// when
Deployment deployment2 = testRule.deploy(repositoryService
.createDeployment()
.name(DEPLOYMENT_NAME)
.addDeploymentResources(deployment1.getId())
.source("my-another-deployment-source"));
// then
assertNotNull(deployment2);
assertEquals("my-another-deployment-source", deployment2.getSource());
}
示例10
public void testDeleteDeploymentCascadingShouldKeepCreateUserOperationLog() {
// given
Deployment deployment = repositoryService
.createDeployment()
.name(DEPLOYMENT_NAME)
.addModelInstance(RESOURCE_NAME, createProcessWithServiceTask(PROCESS_KEY))
.deploy();
UserOperationLogQuery query = historyService
.createUserOperationLogQuery()
.operationType(UserOperationLogEntry.OPERATION_TYPE_CREATE);
assertEquals(1, query.count());
// when
repositoryService.deleteDeployment(deployment.getId(), true);
// then
assertEquals(1, query.count());
}
示例11
@Test
public void registrationFoundFromPreviousDefinition() {
// given
ProcessApplicationReference reference = processApplication.getReference();
Deployment deployment1 = repositoryService
.createDeployment(reference)
.name(DEPLOYMENT_NAME)
.addClasspathResource(resource1)
.deploy();
// when
Deployment deployment2 = repositoryService
.createDeployment()
.name(DEPLOYMENT_NAME)
.addDeploymentResources(deployment1.getId())
.deploy();
String definitionId = getLatestDefinitionIdByKey(definitionKey1);
// then
assertEquals(reference, getProcessApplicationForDefinition(definitionId));
// and the reference is not cached
assertNull(getProcessApplicationForDeployment(deployment2.getId()));
}
示例12
@Test
public void testDeleteNonExistingAndCreateNewJobDefinitionWithParseListener() {
//given
String modelFileName = "jobCreationWithinParseListener.bpmn20.xml";
InputStream in = JobDefinitionCreationWithParseListenerTest.class.getResourceAsStream(modelFileName);
DeploymentBuilder builder = engineRule.getRepositoryService().createDeployment().addInputStream(modelFileName, in);
//when the asyncBefore is set to false and the asyncAfter to true in the parse listener
Deployment deployment = builder.deploy();
engineRule.manageDeployment(deployment);
//then there exists one job definition
JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
JobDefinition jobDef = query.singleResult();
assertNotNull(jobDef);
assertEquals(jobDef.getProcessDefinitionKey(), "oneTaskProcess");
assertEquals(jobDef.getActivityId(), "servicetask1");
assertEquals(jobDef.getJobConfiguration(), MessageJobDeclaration.ASYNC_AFTER);
}
示例13
@Test
public void redeployForDifferentAuthenticatedTenantsDisabledTenantCheck() {
Deployment deploymentOne = repositoryService.createDeployment()
.addModelInstance("emptyProcess.bpmn", emptyProcess)
.addModelInstance("startEndProcess.bpmn", startEndProcess)
.tenantId(TENANT_ONE)
.deploy();
identityService.setAuthentication("user", null, null);
processEngineConfiguration.setTenantCheckEnabled(false);
repositoryService.createDeployment()
.addDeploymentResources(deploymentOne.getId())
.tenantId(TENANT_TWO)
.deploy();
DeploymentQuery query = repositoryService.createDeploymentQuery();
assertThat(query.count(), is(2L));
assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));
assertThat(query.tenantIdIn(TENANT_TWO).count(), is(1L));
}
示例14
public void cleanDatabase(ProcessEngine engine) {
// delete all deployments
RepositoryService repositoryService = engine.getRepositoryService();
List<Deployment> deployments = repositoryService
.createDeploymentQuery()
.list();
for (Deployment deployment : deployments) {
repositoryService.deleteDeployment(deployment.getId(), true);
}
// drop DB
((ProcessEngineImpl)engine).getProcessEngineConfiguration()
.getCommandExecutorTxRequired()
.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
commandContext.getDbSqlSession().dbSchemaDrop();
return null;
}
});
engine.close();
}
示例15
public void testDeployWithTenantIds() {
registerProcessEngine();
TestApplicationWithTenantId processApplication = new TestApplicationWithTenantId();
processApplication.deploy();
List<Deployment> deployments = repositoryService
.createDeploymentQuery()
.orderByTenantId()
.asc()
.list();
assertEquals(2, deployments.size());
assertEquals("tenant1", deployments.get(0).getTenantId());
assertEquals("tenant2", deployments.get(1).getTenantId());
processApplication.undeploy();
}
示例16
@Test
public void redeployForTheSameAuthenticatedTenant() {
Deployment deploymentOne = repositoryService.createDeployment()
.addModelInstance("emptyProcess.bpmn", emptyProcess)
.addModelInstance("startEndProcess.bpmn", startEndProcess)
.tenantId(TENANT_ONE)
.deploy();
identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));
repositoryService.createDeployment()
.addDeploymentResources(deploymentOne.getId())
.tenantId(TENANT_ONE)
.deploy();
DeploymentQuery query = repositoryService.createDeploymentQuery();
assertThat(query.count(), is(2L));
assertThat(query.tenantIdIn(TENANT_ONE).count(), is(2L));
}
示例17
public void testClearAuthorizationOnDeleteDeployment() {
// given
createGrantAuthorization(DEPLOYMENT, ANY, userId, CREATE);
Deployment deployment = repositoryService
.createDeployment()
.addClasspathResource(FIRST_RESOURCE)
.deploy();
String deploymentId = deployment.getId();
AuthorizationQuery query = authorizationService
.createAuthorizationQuery()
.userIdIn(userId)
.resourceId(deploymentId);
Authorization authorization = query.singleResult();
assertNotNull(authorization);
// when
repositoryService.deleteDeployment(deploymentId);
authorization = query.singleResult();
assertNull(authorization);
deleteDeployment(deploymentId);
}
示例18
@Test
public void deleteJobsWhileUndeployment() {
Deployment deploymentForTenantOne = testRule.deployForTenant(TENANT_ONE, PROCESS);
Deployment deploymentForTenantTwo = testRule.deployForTenant(TENANT_TWO, PROCESS);
JobQuery query = managementService.createJobQuery();
assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));
assertThat(query.tenantIdIn(TENANT_TWO).count(), is(1L));
repositoryService.deleteDeployment(deploymentForTenantOne.getId(), true);
assertThat(query.tenantIdIn(TENANT_ONE).count(), is(0L));
assertThat(query.tenantIdIn(TENANT_TWO).count(), is(1L));
repositoryService.deleteDeployment(deploymentForTenantTwo.getId(), true);
assertThat(query.tenantIdIn(TENANT_ONE).count(), is(0L));
assertThat(query.tenantIdIn(TENANT_TWO).count(), is(0L));
}
示例19
@Test
@org.camunda.bpm.engine.test.Deployment(resources={"org/camunda/bpm/engine/test/api/repository/failingProcessCreateOneIncident.bpmn20.xml"})
public void testQueryByNoVersionTag() {
// 4 definitions without and 1 definition with version tag are deployed
assertThat(repositoryService.createProcessDefinitionQuery()
.withoutVersionTag()
.count()).isEqualTo(4);
}
示例20
@org.camunda.bpm.engine.test.Deployment
public void testScriptEvaluationException() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("Process_1").singleResult();
try {
runtimeService.startProcessInstanceByKey("Process_1");
} catch (ScriptEvaluationException e) {
assertTextPresent("Unable to evaluate script while executing activity 'Failing' in the process definition with id '" + processDefinition.getId() + "'", e.getMessage());
}
}
示例21
protected void deployProcess(String scriptFormat, String scriptText) {
BpmnModelInstance process = createProcess(scriptFormat, scriptText);
Deployment deployment = repositoryService.createDeployment()
.addModelInstance("testProcess.bpmn", process)
.addString("testScript.txt", scriptText)
.deploy();
deploymentId = deployment.getId();
}
示例22
@org.camunda.bpm.engine.test.Deployment
public void testGroovyScriptExecution() {
try {
processEngineConfiguration.setAutoStoreScriptVariables(true);
int[] inputArray = new int[] {1, 2, 3, 4, 5};
ProcessInstance pi = runtimeService.startProcessInstanceByKey("scriptExecution", CollectionUtil.singletonMap("inputArray", inputArray));
Integer result = (Integer) runtimeService.getVariable(pi.getId(), "sum");
assertEquals(15, result.intValue());
} finally {
processEngineConfiguration.setAutoStoreScriptVariables(false);
}
}
示例23
@Before
public void init() {
StartProcessOnAnotherEngineDelegate.engine = engine2BootstrapRule.getProcessEngine();
NestedProcessStartDelegate.engine = engineRule1.getProcessEngine();
// given
Deployment deployment1 = engineRule1.getRepositoryService()
.createDeployment()
.addModelInstance("foo.bpmn", PROCESS_MODEL)
.deploy();
Deployment deployment2 = engineRule1.getRepositoryService()
.createDeployment()
.addModelInstance("boo.bpmn", PROCESS_MODEL_2)
.deploy();
engineRule1.manageDeployment(deployment1);
engineRule1.manageDeployment(deployment2);
Deployment deployment3 = engineRule2.getProcessEngine().getRepositoryService()
.createDeployment()
.addModelInstance("joo.bpmn", ONE_TASK_PROCESS_MODEL)
.deploy();
engineRule2.manageDeployment(deployment3);
}
示例24
public AuthorizationEntity[] newDeployment(Deployment deployment) {
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
IdentityService identityService = processEngineConfiguration.getIdentityService();
Authentication currentAuthentication = identityService.getCurrentAuthentication();
if (currentAuthentication != null && currentAuthentication.getUserId() != null) {
String userId = currentAuthentication.getUserId();
String deploymentId = deployment.getId();
AuthorizationEntity authorization = createGrantAuthorization(userId, null, DEPLOYMENT, deploymentId, READ, DELETE);
return new AuthorizationEntity[]{ authorization };
}
return null;
}
示例25
@Test
public void testCreateBothAsyncJobDefinitionWithParseListener() {
//given
String modelFileName = "jobCreationWithinParseListener.bpmn20.xml";
InputStream in = JobDefinitionCreationWithParseListenerTest.class.getResourceAsStream(modelFileName);
DeploymentBuilder builder = engineRule.getRepositoryService().createDeployment().addInputStream(modelFileName, in);
//when the asyncBefore and asyncAfter is set to true in the parse listener
Deployment deployment = builder.deploy();
engineRule.manageDeployment(deployment);
//then there exists two job definitions
JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
List<JobDefinition> definitions = query.orderByJobConfiguration().asc().list();
assertEquals(definitions.size(), 2);
//asyncAfter
JobDefinition asyncAfterAfter = definitions.get(0);
assertEquals(asyncAfterAfter.getProcessDefinitionKey(), "oneTaskProcess");
assertEquals(asyncAfterAfter.getActivityId(), "servicetask1");
assertEquals(asyncAfterAfter.getJobConfiguration(), MessageJobDeclaration.ASYNC_AFTER);
//asyncBefore
JobDefinition asyncAfterBefore = definitions.get(1);
assertEquals(asyncAfterBefore.getProcessDefinitionKey(), "oneTaskProcess");
assertEquals(asyncAfterBefore.getActivityId(), "servicetask1");
assertEquals(asyncAfterBefore.getJobConfiguration(), MessageJobDeclaration.ASYNC_BEFORE);
}
示例26
protected TaskDefinition createTaskDefinition(CmmnElement element, CmmnHandlerContext context) {
Deployment deployment = context.getDeployment();
String deploymentId = deployment.getId();
// at the moment a default task form handler is only supported,
// custom task form handler are not supported.
DefaultTaskFormHandler taskFormHandler = new DefaultTaskFormHandler();
taskFormHandler.setDeploymentId(deploymentId);
// create new taskDefinition
TaskDefinition taskDefinition = new TaskDefinition(taskFormHandler);
// the plan item id will be handled as taskDefinitionKey
String taskDefinitionKey = element.getId();
taskDefinition.setKey(taskDefinitionKey);
// name
initializeTaskDefinitionName(element, taskDefinition, context);
// dueDate
initializeTaskDefinitionDueDate(element, taskDefinition, context);
// followUp
initializeTaskDefinitionFollowUpDate(element, taskDefinition, context);
// priority
initializeTaskDefinitionPriority(element, taskDefinition, context);
// assignee
initializeTaskDefinitionAssignee(element, taskDefinition, context);
// candidateUsers
initializeTaskDefinitionCandidateUsers(element, taskDefinition, context);
// candidateGroups
initializeTaskDefinitionCandidateGroups(element, taskDefinition, context);
// formKey
initializeTaskDefinitionFormKey(element, taskDefinition, context);
// description
initializeTaskDescription(element, taskDefinition, context);
return taskDefinition;
}
示例27
@Test
public void testCreateBothJobDefinitionWithParseListenerAndAsynBothInXml() {
//given the asyncBefore AND asyncAfter is set in the xml
String modelFileName = "jobAsyncBothCreationWithinParseListener.bpmn20.xml";
InputStream in = JobDefinitionCreationWithParseListenerTest.class.getResourceAsStream(modelFileName);
DeploymentBuilder builder = engineRule.getRepositoryService().createDeployment().addInputStream(modelFileName, in);
//when the asyncBefore and asyncAfter is set to true in the parse listener
Deployment deployment = builder.deploy();
engineRule.manageDeployment(deployment);
//then there exists two job definitions
JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
List<JobDefinition> definitions = query.orderByJobConfiguration().asc().list();
assertEquals(definitions.size(), 2);
//asyncAfter
JobDefinition asyncAfterAfter = definitions.get(0);
assertEquals(asyncAfterAfter.getProcessDefinitionKey(), "oneTaskProcess");
assertEquals(asyncAfterAfter.getActivityId(), "servicetask1");
assertEquals(asyncAfterAfter.getJobConfiguration(), MessageJobDeclaration.ASYNC_AFTER);
//asyncBefore
JobDefinition asyncAfterBefore = definitions.get(1);
assertEquals(asyncAfterBefore.getProcessDefinitionKey(), "oneTaskProcess");
assertEquals(asyncAfterBefore.getActivityId(), "servicetask1");
assertEquals(asyncAfterBefore.getJobConfiguration(), MessageJobDeclaration.ASYNC_BEFORE);
}
示例28
@After
public void after() {
for (Deployment deployment : repositoryService.createDeploymentQuery().list()) {
repositoryService.deleteDeployment(deployment.getId(), true);
}
processEngine.close();
processEngine = null;
processInitiatingPojo = null;
repositoryService = null;
}
示例29
@Override
public List<Deployment> executeList(CommandContext commandContext, Page page) {
checkQueryOk();
return commandContext
.getDeploymentManager()
.findDeploymentsByQueryCriteria(this, page);
}
示例30
@Test
@org.camunda.bpm.engine.test.Deployment(resources={"org/camunda/bpm/engine/test/api/repository/failingProcessCreateOneIncident.bpmn20.xml"})
public void testQueryByVersionTagLike() {
assertThat(repositoryService.createProcessDefinitionQuery()
.versionTagLike("ver\\_tag\\_%")
.count()).isEqualTo(1);
}