use of org.camunda.bpm.engine.repository.CaseDefinition in project camunda-bpm-platform by camunda.
the class TaskRestServiceInteractionTest method testGetSingleTaskHal.
@Test
@SuppressWarnings("unchecked")
public void testGetSingleTaskHal() {
// setup user query mock
List<User> mockUsers = Arrays.asList(MockProvider.mockUser().id(EXAMPLE_TASK_ASSIGNEE_NAME).build(), MockProvider.mockUser().id(EXAMPLE_TASK_OWNER).build());
UserQuery sampleUserQuery = mock(UserQuery.class);
when(sampleUserQuery.userIdIn(eq(EXAMPLE_TASK_ASSIGNEE_NAME), eq(EXAMPLE_TASK_OWNER))).thenReturn(sampleUserQuery);
when(sampleUserQuery.userIdIn(eq(EXAMPLE_TASK_OWNER), eq(EXAMPLE_TASK_ASSIGNEE_NAME))).thenReturn(sampleUserQuery);
when(sampleUserQuery.listPage(eq(0), eq(2))).thenReturn(mockUsers);
when(sampleUserQuery.count()).thenReturn((long) mockUsers.size());
when(processEngine.getIdentityService().createUserQuery()).thenReturn(sampleUserQuery);
// setup group query mock
List<Group> mockGroups = Arrays.asList(MockProvider.mockGroup().id(mockCandidateGroupIdentityLink.getGroupId()).build(), MockProvider.mockGroup().id(mockCandidateGroup2IdentityLink.getGroupId()).build());
GroupQuery sampleGroupQuery = mock(GroupQuery.class);
when(sampleGroupQuery.groupIdIn(eq(EXAMPLE_GROUP_ID), eq(EXAMPLE_GROUP_ID2))).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.groupIdIn(eq(EXAMPLE_GROUP_ID2), eq(EXAMPLE_GROUP_ID))).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.listPage(eq(0), eq(2))).thenReturn(mockGroups);
when(sampleGroupQuery.count()).thenReturn((long) mockGroups.size());
when(processEngine.getIdentityService().createGroupQuery()).thenReturn(sampleGroupQuery);
// setup process definition query mock
List<ProcessDefinition> mockDefinitions = MockProvider.createMockDefinitions();
ProcessDefinitionQuery sampleProcessDefinitionQuery = mock(ProcessDefinitionQuery.class);
when(sampleProcessDefinitionQuery.listPage(0, 1)).thenReturn(mockDefinitions);
when(sampleProcessDefinitionQuery.processDefinitionIdIn(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).thenReturn(sampleProcessDefinitionQuery);
when(sampleProcessDefinitionQuery.count()).thenReturn(1l);
when(processEngine.getRepositoryService().createProcessDefinitionQuery()).thenReturn(sampleProcessDefinitionQuery);
// setup case definition query mock
List<CaseDefinition> mockCaseDefinitions = MockProvider.createMockCaseDefinitions();
CaseDefinitionQuery sampleCaseDefinitionQuery = mock(CaseDefinitionQuery.class);
when(sampleCaseDefinitionQuery.listPage(0, 1)).thenReturn(mockCaseDefinitions);
when(sampleCaseDefinitionQuery.caseDefinitionIdIn(MockProvider.EXAMPLE_CASE_DEFINITION_ID)).thenReturn(sampleCaseDefinitionQuery);
when(sampleCaseDefinitionQuery.count()).thenReturn(1l);
when(processEngine.getRepositoryService().createCaseDefinitionQuery()).thenReturn(sampleCaseDefinitionQuery);
Response response = given().header("accept", Hal.APPLICATION_HAL_JSON).pathParam("id", EXAMPLE_TASK_ID).then().expect().statusCode(Status.OK.getStatusCode()).body("id", equalTo(EXAMPLE_TASK_ID)).body("name", equalTo(MockProvider.EXAMPLE_TASK_NAME)).body("assignee", equalTo(MockProvider.EXAMPLE_TASK_ASSIGNEE_NAME)).body("created", equalTo(MockProvider.EXAMPLE_TASK_CREATE_TIME)).body("due", equalTo(MockProvider.EXAMPLE_TASK_DUE_DATE)).body("delegationState", equalTo(MockProvider.EXAMPLE_TASK_DELEGATION_STATE.toString())).body("description", equalTo(MockProvider.EXAMPLE_TASK_DESCRIPTION)).body("executionId", equalTo(MockProvider.EXAMPLE_TASK_EXECUTION_ID)).body("owner", equalTo(MockProvider.EXAMPLE_TASK_OWNER)).body("parentTaskId", equalTo(MockProvider.EXAMPLE_TASK_PARENT_TASK_ID)).body("priority", equalTo(MockProvider.EXAMPLE_TASK_PRIORITY)).body("processDefinitionId", equalTo(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).body("processInstanceId", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)).body("taskDefinitionKey", equalTo(MockProvider.EXAMPLE_TASK_DEFINITION_KEY)).body("suspended", equalTo(MockProvider.EXAMPLE_TASK_SUSPENSION_STATE)).body("caseExecutionId", equalTo(MockProvider.EXAMPLE_CASE_EXECUTION_ID)).body("caseInstanceId", equalTo(MockProvider.EXAMPLE_CASE_INSTANCE_ID)).body("caseDefinitionId", equalTo(MockProvider.EXAMPLE_CASE_DEFINITION_ID)).body("tenantId", equalTo(MockProvider.EXAMPLE_TENANT_ID)).body("_links.assignee.href", endsWith(EXAMPLE_TASK_ASSIGNEE_NAME)).body("_links.caseDefinition.href", endsWith(EXAMPLE_CASE_DEFINITION_ID)).body("_links.caseExecution.href", endsWith(EXAMPLE_CASE_EXECUTION_ID)).body("_links.caseInstance.href", endsWith(EXAMPLE_CASE_INSTANCE_ID)).body("_links.execution.href", endsWith(EXAMPLE_TASK_EXECUTION_ID)).body("_links.owner.href", endsWith(EXAMPLE_TASK_OWNER)).body("_links.parentTask.href", endsWith(EXAMPLE_TASK_PARENT_TASK_ID)).body("_links.processDefinition.href", endsWith(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).body("_links.processInstance.href", endsWith(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)).body("_links.identityLink.href", endsWith("/task/" + EXAMPLE_TASK_ID + "/identity-links")).body("_links.self.href", endsWith(EXAMPLE_TASK_ID)).when().get(SINGLE_TASK_URL);
String content = response.asString();
// validate embedded users:
List<Map<String, Object>> embeddedUsers = from(content).getList("_embedded.user");
Assert.assertEquals("There should be two users returned.", 2, embeddedUsers.size());
Map<String, Object> embeddedUser = embeddedUsers.get(0);
assertNotNull("The returned user should not be null.", embeddedUser);
assertEquals(MockProvider.EXAMPLE_TASK_ASSIGNEE_NAME, embeddedUser.get("id"));
assertEquals(MockProvider.EXAMPLE_USER_FIRST_NAME, embeddedUser.get("firstName"));
assertEquals(MockProvider.EXAMPLE_USER_LAST_NAME, embeddedUser.get("lastName"));
assertEquals(MockProvider.EXAMPLE_USER_EMAIL, embeddedUser.get("email"));
assertNull(embeddedUser.get("_embedded"));
Map<String, Object> links = (Map<String, Object>) embeddedUser.get("_links");
assertEquals(1, links.size());
assertHalLink(links, "self", UserRestService.PATH + "/" + MockProvider.EXAMPLE_TASK_ASSIGNEE_NAME);
embeddedUser = embeddedUsers.get(1);
assertNotNull("The returned user should not be null.", embeddedUser);
assertEquals(MockProvider.EXAMPLE_TASK_OWNER, embeddedUser.get("id"));
assertEquals(MockProvider.EXAMPLE_USER_FIRST_NAME, embeddedUser.get("firstName"));
assertEquals(MockProvider.EXAMPLE_USER_LAST_NAME, embeddedUser.get("lastName"));
assertEquals(MockProvider.EXAMPLE_USER_EMAIL, embeddedUser.get("email"));
assertNull(embeddedUser.get("_embedded"));
links = (Map<String, Object>) embeddedUser.get("_links");
assertEquals(1, links.size());
assertHalLink(links, "self", UserRestService.PATH + "/" + MockProvider.EXAMPLE_TASK_OWNER);
// validate embedded groups:
List<Map<String, Object>> embeddedGroups = from(content).getList("_embedded.group");
Assert.assertEquals("There should be two groups returned.", 2, embeddedGroups.size());
Map<String, Object> embeddedGroup = embeddedGroups.get(0);
assertNotNull("The returned group should not be null.", embeddedGroup);
assertEquals(MockProvider.EXAMPLE_GROUP_ID, embeddedGroup.get("id"));
assertEquals(MockProvider.EXAMPLE_GROUP_NAME, embeddedGroup.get("name"));
assertEquals(MockProvider.EXAMPLE_GROUP_TYPE, embeddedGroup.get("type"));
assertNull(embeddedGroup.get("_embedded"));
links = (Map<String, Object>) embeddedGroup.get("_links");
assertEquals(1, links.size());
assertHalLink(links, "self", GroupRestService.PATH + "/" + MockProvider.EXAMPLE_GROUP_ID);
embeddedGroup = embeddedGroups.get(1);
assertNotNull("The returned group should not be null.", embeddedGroup);
assertEquals(MockProvider.EXAMPLE_GROUP_ID2, embeddedGroup.get("id"));
assertEquals(MockProvider.EXAMPLE_GROUP_NAME, embeddedGroup.get("name"));
assertEquals(MockProvider.EXAMPLE_GROUP_TYPE, embeddedGroup.get("type"));
assertNull(embeddedGroup.get("_embedded"));
links = (Map<String, Object>) embeddedGroup.get("_links");
assertEquals(1, links.size());
assertHalLink(links, "self", GroupRestService.PATH + "/" + MockProvider.EXAMPLE_GROUP_ID2);
// validate embedded processDefinitions:
List<Map<String, Object>> embeddedDefinitions = from(content).getList("_embedded.processDefinition");
Assert.assertEquals("There should be one processDefinition returned.", 1, embeddedDefinitions.size());
Map<String, Object> embeddedProcessDefinition = embeddedDefinitions.get(0);
Assert.assertNotNull("The returned processDefinition should not be null.", embeddedProcessDefinition);
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID, embeddedProcessDefinition.get("id"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY, embeddedProcessDefinition.get("key"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_CATEGORY, embeddedProcessDefinition.get("category"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_NAME, embeddedProcessDefinition.get("name"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_DESCRIPTION, embeddedProcessDefinition.get("description"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_VERSION, embeddedProcessDefinition.get("version"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_RESOURCE_NAME, embeddedProcessDefinition.get("resource"));
Assert.assertEquals(MockProvider.EXAMPLE_DEPLOYMENT_ID, embeddedProcessDefinition.get("deploymentId"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_DIAGRAM_RESOURCE_NAME, embeddedProcessDefinition.get("diagram"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_IS_SUSPENDED, embeddedProcessDefinition.get("suspended"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_APPLICATION_CONTEXT_PATH, embeddedProcessDefinition.get("contextPath"));
links = (Map<String, Object>) embeddedProcessDefinition.get("_links");
Assert.assertEquals(3, links.size());
assertHalLink(links, "self", "/process-definition/" + MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);
assertHalLink(links, "deployment", "/deployment/" + MockProvider.EXAMPLE_DEPLOYMENT_ID);
assertHalLink(links, "resource", "/deployment/" + MockProvider.EXAMPLE_DEPLOYMENT_ID + "/resources/" + MockProvider.EXAMPLE_PROCESS_DEFINITION_RESOURCE_NAME);
// validate embedded caseDefinitions:
List<Map<String, Object>> embeddedCaseDefinitions = from(content).getList("_embedded.caseDefinition");
Assert.assertEquals("There should be one caseDefinition returned.", 1, embeddedCaseDefinitions.size());
Map<String, Object> embeddedCaseDefinition = embeddedCaseDefinitions.get(0);
Assert.assertNotNull("The returned caseDefinition should not be null.", embeddedCaseDefinition);
Assert.assertEquals(MockProvider.EXAMPLE_CASE_DEFINITION_ID, embeddedCaseDefinition.get("id"));
Assert.assertEquals(MockProvider.EXAMPLE_CASE_DEFINITION_KEY, embeddedCaseDefinition.get("key"));
Assert.assertEquals(MockProvider.EXAMPLE_CASE_DEFINITION_CATEGORY, embeddedCaseDefinition.get("category"));
Assert.assertEquals(MockProvider.EXAMPLE_CASE_DEFINITION_NAME, embeddedCaseDefinition.get("name"));
Assert.assertEquals(MockProvider.EXAMPLE_CASE_DEFINITION_VERSION, embeddedCaseDefinition.get("version"));
Assert.assertEquals(MockProvider.EXAMPLE_CASE_DEFINITION_RESOURCE_NAME, embeddedCaseDefinition.get("resource"));
Assert.assertEquals(MockProvider.EXAMPLE_DEPLOYMENT_ID, embeddedCaseDefinition.get("deploymentId"));
Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_APPLICATION_CONTEXT_PATH, embeddedCaseDefinition.get("contextPath"));
links = (Map<String, Object>) embeddedCaseDefinition.get("_links");
Assert.assertEquals(3, links.size());
assertHalLink(links, "self", "/case-definition/" + MockProvider.EXAMPLE_CASE_DEFINITION_ID);
assertHalLink(links, "deployment", "/deployment/" + MockProvider.EXAMPLE_DEPLOYMENT_ID);
assertHalLink(links, "resource", "/deployment/" + MockProvider.EXAMPLE_DEPLOYMENT_ID + "/resources/" + MockProvider.EXAMPLE_CASE_DEFINITION_RESOURCE_NAME);
// validate embedded identity links
List<Map<String, Object>> embeddedIdentityLinks = from(content).getList("_embedded.identityLink");
assertEquals("There should be three identityLink returned", 4, embeddedIdentityLinks.size());
assertEmbeddedIdentityLink(mockAssigneeIdentityLink, embeddedIdentityLinks.get(0));
assertEmbeddedIdentityLink(mockOwnerIdentityLink, embeddedIdentityLinks.get(1));
assertEmbeddedIdentityLink(mockCandidateGroupIdentityLink, embeddedIdentityLinks.get(2));
assertEmbeddedIdentityLink(mockCandidateGroup2IdentityLink, embeddedIdentityLinks.get(3));
}
use of org.camunda.bpm.engine.repository.CaseDefinition in project camunda-bpm-platform by camunda.
the class CaseDefinitionRestServiceInteractionTest method setUpRuntime.
@Before
public void setUpRuntime() {
CaseDefinition mockCaseDefinition = MockProvider.createMockCaseDefinition();
setUpRuntimeData(mockCaseDefinition);
caseServiceMock = mock(CaseService.class);
when(processEngine.getCaseService()).thenReturn(caseServiceMock);
caseInstanceBuilder = mock(CaseInstanceBuilder.class);
CaseInstance mockCaseInstance = MockProvider.createMockCaseInstance();
when(caseServiceMock.withCaseDefinition(MockProvider.EXAMPLE_CASE_DEFINITION_ID)).thenReturn(caseInstanceBuilder);
when(caseInstanceBuilder.businessKey(anyString())).thenReturn(caseInstanceBuilder);
when(caseInstanceBuilder.setVariables(Matchers.<Map<String, Object>>any())).thenReturn(caseInstanceBuilder);
when(caseInstanceBuilder.create()).thenReturn(mockCaseInstance);
}
use of org.camunda.bpm.engine.repository.CaseDefinition in project camunda-bpm-platform by camunda.
the class CaseDefinitionResourceImpl method getCaseDefinition.
@Override
public CaseDefinitionDto getCaseDefinition() {
RepositoryService repositoryService = engine.getRepositoryService();
CaseDefinition definition = null;
try {
definition = repositoryService.getCaseDefinition(caseDefinitionId);
} catch (NotFoundException e) {
throw new InvalidRequestException(Status.NOT_FOUND, e, e.getMessage());
} catch (NotValidException e) {
throw new InvalidRequestException(Status.BAD_REQUEST, e, e.getMessage());
} catch (ProcessEngineException e) {
throw new RestException(Status.INTERNAL_SERVER_ERROR, e);
}
return CaseDefinitionDto.fromCaseDefinition(definition);
}
use of org.camunda.bpm.engine.repository.CaseDefinition in project camunda-bpm-platform by camunda.
the class ProcessApplicationManager method getDeployedCaseDefinitionArtifacts.
protected List<CaseDefinition> getDeployedCaseDefinitionArtifacts(DeploymentEntity deployment) {
CommandContext commandContext = Context.getCommandContext();
// in case deployment was created by this command
List<CaseDefinition> entities = deployment.getDeployedCaseDefinitions();
if (entities == null) {
String deploymentId = deployment.getId();
CaseDefinitionManager caseDefinitionManager = commandContext.getCaseDefinitionManager();
return caseDefinitionManager.findCaseDefinitionByDeploymentId(deploymentId);
}
return entities;
}
use of org.camunda.bpm.engine.repository.CaseDefinition in project camunda-bpm-platform by camunda.
the class ProcessApplicationManager method logRegistration.
// logger ////////////////////////////////////////////////////////////////////////////
protected void logRegistration(Set<String> deploymentIds, ProcessApplicationReference reference) {
if (!LOG.isInfoEnabled()) {
// building the log message is expensive (db queries) so we avoid it if we can
return;
}
try {
StringBuilder builder = new StringBuilder();
builder.append("ProcessApplication '");
builder.append(reference.getName());
builder.append("' registered for DB deployments ");
builder.append(deploymentIds);
builder.append(". ");
List<ProcessDefinition> processDefinitions = new ArrayList<ProcessDefinition>();
List<CaseDefinition> caseDefinitions = new ArrayList<CaseDefinition>();
CommandContext commandContext = Context.getCommandContext();
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
boolean cmmnEnabled = processEngineConfiguration.isCmmnEnabled();
for (String deploymentId : deploymentIds) {
DeploymentEntity deployment = commandContext.getDbEntityManager().selectById(DeploymentEntity.class, deploymentId);
if (deployment != null) {
processDefinitions.addAll(getDeployedProcessDefinitionArtifacts(deployment));
if (cmmnEnabled) {
caseDefinitions.addAll(getDeployedCaseDefinitionArtifacts(deployment));
}
}
}
logProcessDefinitionRegistrations(builder, processDefinitions);
if (cmmnEnabled) {
logCaseDefinitionRegistrations(builder, caseDefinitions);
}
LOG.registrationSummary(builder.toString());
} catch (Throwable e) {
LOG.exceptionWhileLoggingRegistrationSummary(e);
}
}
Aggregations