use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.
the class CaseCommentNotificationTest method testCommentsNotificationWithTemplate.
@Test
public void testCommentsNotificationWithTemplate() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
TestNotificationPublisher publisher = new TestNotificationPublisher(false);
CommentNotificationEventListener listener = CommentNotificationEventListenerFactory.get("test");
listener.addPublisher(publisher);
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Collection<CommentInstance> caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(0, caseComments.size());
caseService.addCaseComment(FIRST_CASE_ID, "poul", "just a tiny comment refering to @owner");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(1, caseComments.size());
CommentInstance comment = caseComments.iterator().next();
assertComment(comment, "poul", "just a tiny comment refering to @owner");
String expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-0000000001) comment to [[UserImpl:'john']] with template mentioned-in-comment";
List<String> published = publisher.get();
assertThat(published).hasSize(1);
assertThat(published.get(0)).isEqualTo(expectedNotification);
caseService.updateCaseComment(FIRST_CASE_ID, comment.getId(), comment.getAuthor(), "Updated " + comment.getComment());
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(1, caseComments.size());
comment = caseComments.iterator().next();
assertComment(comment, "poul", "Updated just a tiny comment refering to @owner");
expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-0000000001) comment to [[UserImpl:'john']] with template mentioned-in-comment";
published = publisher.get();
assertThat(published).hasSize(1);
assertThat(published.get(0)).isEqualTo(expectedNotification);
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.
the class TaskFluent method addPotentialUser.
public TaskFluent addPotentialUser(String userId) {
if (assignments.getPotentialOwners().isEmpty()) {
List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>();
assignments.setPotentialOwners(potentialOwners);
}
assignments.getPotentialOwners().add(new UserImpl(userId));
return this;
}
use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testTransitionBetweenStagesInCaseWithActiveElements.
@Test
public void testTransitionBetweenStagesInCaseWithActiveElements() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl(USER));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, caseFile);
assertNotNull(caseId);
try {
Collection<CaseStageInstance> stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
CaseStageInstance stageInstance = stage.iterator().next();
assertEquals("Stage One", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
Collection<NodeInstanceDesc> activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
caseService.triggerAdHocFragment(caseId, "Task 1", data);
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
stageInstance = stage.iterator().next();
assertEquals("Stage One", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertEquals("Task 1", activeNodes.iterator().next().getName());
caseService.addDataToCaseFile(caseId, "customData", "nextStagePlease");
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
assertEquals("Stage Two", stage.iterator().next().getName());
assertEquals(StageStatus.Active, stage.iterator().next().getStatus());
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
stageInstance = stage.iterator().next();
assertEquals("Stage Two", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
caseService.triggerAdHocFragment(caseId, "Task 2", data);
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
stageInstance = stage.iterator().next();
assertEquals("Stage Two", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertEquals("Task 2", activeNodes.iterator().next().getName());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testUserTasksInCase.
@Test
public void testUserTasksInCase() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl(USER));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
String caseId2 = null;
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(0, tasks.size());
Map<String, Object> taskInput = new HashMap<>();
taskInput.put("ActorId", "john");
taskInput.put("Comment", "Need to provide data");
caseService.triggerAdHocFragment(caseId, "Missing data", taskInput);
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertEquals("Missing data", task.getName());
assertEquals("Need to provide data", task.getSubject());
caseId2 = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
assertNotNull(caseId2);
assertEquals("CASE-0000000002", caseId2);
caseService.triggerAdHocFragment(caseId2, "Missing data", taskInput);
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId2, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertEquals("Missing data", task.getName());
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertEquals("Missing data", task.getName());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
if (caseId2 != null) {
caseService.cancelCase(caseId2);
}
}
}
use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testUserTasksInCaseWithSubprocess.
@Test
public void testUserTasksInCaseWithSubprocess() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl(USER));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(0, tasks.size());
Map<String, Object> taskInput = new HashMap<>();
taskInput.put("ActorId", "john");
caseService.triggerAdHocFragment(caseId, "Missing data", taskInput);
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertEquals("Missing data", task.getName());
caseService.addDynamicSubprocess(caseId, "UserTask", null);
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(2, tasks.size());
task = tasks.get(0);
assertEquals("Hello", task.getName());
task = tasks.get(1);
assertEquals("Missing data", task.getName());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations