use of org.activiti.engine.ActivitiException in project Activiti by Activiti.
the class RuntimeServiceTest method testSetProcessInstanceName.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testSetProcessInstanceName() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertNotNull(processInstance);
assertNull(processInstance.getName());
// Set the name
runtimeService.setProcessInstanceName(processInstance.getId(), "New name");
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(processInstance);
assertEquals("New name", processInstance.getName());
// Set the name to null
runtimeService.setProcessInstanceName(processInstance.getId(), null);
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(processInstance);
assertNull(processInstance.getName());
// Set name for unexisting process instance, should fail
try {
runtimeService.setProcessInstanceName("unexisting", null);
fail("Exception excpected");
} catch (ActivitiObjectNotFoundException aonfe) {
assertEquals(ProcessInstance.class, aonfe.getObjectClass());
}
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(processInstance);
assertNull(processInstance.getName());
// Set name for suspended process instance, should fail
runtimeService.suspendProcessInstanceById(processInstance.getId());
try {
runtimeService.setProcessInstanceName(processInstance.getId(), null);
fail("Exception excpected");
} catch (ActivitiException ae) {
assertEquals("process instance " + processInstance.getId() + " is suspended, cannot set name", ae.getMessage());
}
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(processInstance);
assertNull(processInstance.getName());
}
use of org.activiti.engine.ActivitiException in project Activiti by Activiti.
the class ProcessDefinitionSuspensionTest method testStartProcessInstanceForSuspendedProcessDefinition.
@Deployment(resources = { "org/activiti/engine/test/db/processOne.bpmn20.xml" })
public void testStartProcessInstanceForSuspendedProcessDefinition() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
repositoryService.suspendProcessDefinitionById(processDefinition.getId());
// By id
try {
runtimeService.startProcessInstanceById(processDefinition.getId());
fail("Exception is expected but not thrown");
} catch (ActivitiException e) {
assertTextPresentIgnoreCase("cannot start process instance", e.getMessage());
}
// By Key
try {
runtimeService.startProcessInstanceByKey(processDefinition.getKey());
fail("Exception is expected but not thrown");
} catch (ActivitiException e) {
assertTextPresentIgnoreCase("cannot start process instance", e.getMessage());
}
}
use of org.activiti.engine.ActivitiException in project Activiti by Activiti.
the class ProcessDefinitionSuspensionTest method testDelayedActivateProcessDefinition.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testDelayedActivateProcessDefinition() {
Date startTime = new Date();
processEngineConfiguration.getClock().setCurrentTime(startTime);
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
repositoryService.suspendProcessDefinitionById(processDefinition.getId());
// Try to start process instance. It should fail now.
try {
runtimeService.startProcessInstanceById(processDefinition.getId());
fail();
} catch (ActivitiException e) {
assertTextPresentIgnoreCase("suspended", e.getMessage());
}
assertEquals(0, runtimeService.createProcessInstanceQuery().count());
assertEquals(0, repositoryService.createProcessDefinitionQuery().active().count());
assertEquals(1, repositoryService.createProcessDefinitionQuery().suspended().count());
// Activate in a day from now
long oneDayFromStart = startTime.getTime() + (24 * 60 * 60 * 1000);
repositoryService.activateProcessDefinitionById(processDefinition.getId(), false, new Date(oneDayFromStart));
// Move clock two days and let job executor run
long twoDaysFromStart = startTime.getTime() + (2 * 24 * 60 * 60 * 1000);
processEngineConfiguration.getClock().setCurrentTime(new Date(twoDaysFromStart));
waitForJobExecutorToProcessAllJobs(5000L, 50L);
// Starting a process instance should now succeed
runtimeService.startProcessInstanceById(processDefinition.getId());
assertEquals(1, runtimeService.createProcessInstanceQuery().count());
assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
}
use of org.activiti.engine.ActivitiException in project Activiti by Activiti.
the class ProcessDefinitionSuspensionTest method testDelayedSuspendProcessDefinitionIncludingProcessInstances.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testDelayedSuspendProcessDefinitionIncludingProcessInstances() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
Date startTime = new Date();
processEngineConfiguration.getClock().setCurrentTime(startTime);
// Start some process instances
int nrOfProcessInstances = 30;
for (int i = 0; i < nrOfProcessInstances; i++) {
runtimeService.startProcessInstanceById(processDefinition.getId());
}
assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().active().count());
assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count());
assertEquals(0, taskService.createTaskQuery().suspended().count());
assertEquals(nrOfProcessInstances, taskService.createTaskQuery().active().count());
assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
// Suspend process definition in one week from now
long oneWeekFromStartTime = startTime.getTime() + (7 * 24 * 60 * 60 * 1000);
repositoryService.suspendProcessDefinitionById(processDefinition.getId(), true, new Date(oneWeekFromStartTime));
// Verify we can start process instances
runtimeService.startProcessInstanceById(processDefinition.getId());
nrOfProcessInstances = nrOfProcessInstances + 1;
assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
// Move clock 9 days further and let job executor run
long eightDaysSinceStartTime = oneWeekFromStartTime + (2 * 24 * 60 * 60 * 1000);
processEngineConfiguration.getClock().setCurrentTime(new Date(eightDaysSinceStartTime));
waitForJobExecutorToProcessAllJobs(5000L, 50L);
// Try to start process instance. It should fail now.
try {
runtimeService.startProcessInstanceById(processDefinition.getId());
fail();
} catch (ActivitiException e) {
assertTextPresentIgnoreCase("suspended", e.getMessage());
}
assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
assertEquals(0, runtimeService.createProcessInstanceQuery().active().count());
assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().suspended().count());
assertEquals(nrOfProcessInstances, taskService.createTaskQuery().suspended().count());
assertEquals(0, taskService.createTaskQuery().active().count());
assertEquals(0, repositoryService.createProcessDefinitionQuery().active().count());
assertEquals(1, repositoryService.createProcessDefinitionQuery().suspended().count());
// Activate again
repositoryService.activateProcessDefinitionById(processDefinition.getId(), true, null);
assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().active().count());
assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count());
assertEquals(0, taskService.createTaskQuery().suspended().count());
assertEquals(nrOfProcessInstances, taskService.createTaskQuery().active().count());
assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
}
use of org.activiti.engine.ActivitiException in project Activiti by Activiti.
the class TaskNavigator method directToSpecificTaskPage.
protected void directToSpecificTaskPage(String category, String taskId, UriFragment uriFragment) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
ViewManager viewManager = ExplorerApp.get().getViewManager();
String loggedInUserId = ExplorerApp.get().getLoggedInUser().getId();
boolean pageFound = false;
if (CATEGORY_TASKS.equals(category)) {
if (loggedInUserId.equals(task.getOwner())) {
viewManager.showTasksPage(task.getId());
pageFound = true;
}
} else if (CATEGORY_INBOX.equals(category)) {
if (loggedInUserId.equals(task.getAssignee())) {
viewManager.showInboxPage(task.getId());
pageFound = true;
}
} else if (CATEGORY_QUEUED.equals(category)) {
String groupId = uriFragment.getParameter(PARAMETER_GROUP);
boolean isTaskAssignedToGroup = taskService.createTaskQuery().taskId(task.getId()).taskCandidateGroup(groupId).count() == 1;
boolean isUserMemberOfGroup = identityService.createGroupQuery().groupMember(loggedInUserId).groupId(groupId).count() == 1;
if (isTaskAssignedToGroup && isUserMemberOfGroup) {
viewManager.showQueuedPage(groupId, task.getId());
pageFound = true;
}
} else if (CATEGORY_INVOLVED.equals(category)) {
boolean isUserInvolved = taskService.createTaskQuery().taskInvolvedUser(loggedInUserId).count() == 1;
if (isUserInvolved) {
viewManager.showInvolvedPage(task.getId());
pageFound = true;
}
} else if (CATEGORY_ARCHIVED.equals(category)) {
if (task == null) {
boolean isOwner = historyService.createHistoricTaskInstanceQuery().taskId(taskId).taskOwner(loggedInUserId).finished().count() == 1;
if (isOwner) {
viewManager.showArchivedPage(taskId);
pageFound = true;
}
}
} else {
throw new ActivitiException("Couldn't find a matching category");
}
if (!pageFound) {
// If URL doesnt match anymore, we must use the task data to redirect to the right page
viewManager.showTaskPage(taskId);
}
}
Aggregations