use of org.activiti.engine.history.HistoricTaskInstanceQuery in project Activiti by Activiti.
the class HistoryServiceTest method testHistoricTaskInstanceQueryByDeploymentIdIn.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricTaskInstanceQueryByDeploymentIdIn() {
org.activiti.engine.repository.Deployment deployment = repositoryService.createDeploymentQuery().singleResult();
HashSet<String> processInstanceIds = new HashSet<String>();
for (int i = 0; i < 4; i++) {
processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess", i + "").getId());
}
processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess2", "1").getId());
List<String> deploymentIds = new ArrayList<String>();
deploymentIds.add(deployment.getId());
HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().deploymentIdIn(deploymentIds);
assertThat(taskInstanceQuery.count()).isEqualTo(5);
List<HistoricTaskInstance> taskInstances = taskInstanceQuery.list();
assertThat(taskInstances).isNotNull();
assertThat(taskInstances).hasSize(5);
deploymentIds.add("invalid");
taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().deploymentIdIn(deploymentIds);
assertThat(taskInstanceQuery.count()).isEqualTo(5);
deploymentIds = new ArrayList<String>();
deploymentIds.add("invalid");
taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().deploymentIdIn(deploymentIds);
assertThat(taskInstanceQuery.count()).isEqualTo(0);
}
use of org.activiti.engine.history.HistoricTaskInstanceQuery in project Activiti by Activiti.
the class HistoryServiceTest method testHistoricTaskInstanceOrQueryByDeploymentId.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricTaskInstanceOrQueryByDeploymentId() {
org.activiti.engine.repository.Deployment deployment = repositoryService.createDeploymentQuery().singleResult();
HashSet<String> processInstanceIds = new HashSet<String>();
for (int i = 0; i < 4; i++) {
processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess", i + "").getId());
}
processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess2", "1").getId());
HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().or().deploymentId(deployment.getId()).endOr();
assertThat(taskInstanceQuery.count()).isEqualTo(5);
List<HistoricTaskInstance> taskInstances = taskInstanceQuery.list();
assertThat(taskInstances).isNotNull();
assertThat(taskInstances).hasSize(5);
taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().or().deploymentId("invalid").endOr();
assertThat(taskInstanceQuery.count()).isEqualTo(0);
taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().or().taskDefinitionKey("theTask").deploymentId("invalid").endOr();
assertThat(taskInstanceQuery.count()).isEqualTo(5);
taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().taskDefinitionKey("theTask").or().deploymentId("invalid").endOr();
assertThat(taskInstanceQuery.count()).isEqualTo(0);
taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().or().taskDefinitionKey("theTask").deploymentId("invalid").endOr().or().processDefinitionKey("oneTaskProcess").processDefinitionId("invalid").endOr();
assertThat(taskInstanceQuery.count()).isEqualTo(4);
taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().or().taskDefinitionKey("theTask").deploymentId("invalid").endOr().or().processDefinitionKey("oneTaskProcess2").processDefinitionId("invalid").endOr();
assertThat(taskInstanceQuery.count()).isEqualTo(1);
taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().or().taskDefinitionKey("theTask").deploymentId("invalid").endOr().or().processDefinitionKey("oneTaskProcess").processDefinitionId("invalid").endOr().processInstanceBusinessKey("1");
assertThat(taskInstanceQuery.count()).isEqualTo(1);
taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().or().taskDefinitionKey("theTask").deploymentId("invalid").endOr().or().processDefinitionKey("oneTaskProcess2").processDefinitionId("invalid").endOr().processInstanceBusinessKey("1");
assertThat(taskInstanceQuery.count()).isEqualTo(1);
taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().or().taskDefinitionKey("theTask").deploymentId("invalid").endOr().or().processDefinitionKey("oneTaskProcess2").processDefinitionId("invalid").endOr().processInstanceBusinessKey("2");
assertThat(taskInstanceQuery.count()).isEqualTo(0);
}
use of org.activiti.engine.history.HistoricTaskInstanceQuery in project Activiti by Activiti.
the class HistoricTaskAndVariablesQueryTest method testOrQueryMultipleVariableValues.
@Deployment
public void testOrQueryMultipleVariableValues() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
Map<String, Object> startMap = new HashMap<String, Object>();
startMap.put("processVar", true);
startMap.put("anotherProcessVar", 123);
runtimeService.startProcessInstanceByKey("oneTaskProcess", startMap);
startMap.put("anotherProcessVar", 999);
runtimeService.startProcessInstanceByKey("oneTaskProcess", startMap);
HistoricTaskInstanceQuery query0 = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().or();
for (int i = 0; i < 20; i++) {
query0 = query0.processVariableValueEquals("anotherProcessVar", i);
}
query0 = query0.endOr();
assertThat(query0.singleResult()).isNull();
HistoricTaskInstanceQuery query1 = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().or().processVariableValueEquals("anotherProcessVar", 123);
for (int i = 0; i < 20; i++) {
query1 = query1.processVariableValueEquals("anotherProcessVar", i);
}
query1 = query1.endOr();
HistoricTaskInstance task = query1.singleResult();
assertThat(task.getProcessVariables()).hasSize(2);
assertThat(task.getProcessVariables().get("processVar")).isEqualTo(true);
assertThat(task.getProcessVariables().get("anotherProcessVar")).isEqualTo(123);
}
}
use of org.activiti.engine.history.HistoricTaskInstanceQuery in project alfresco-remote-api by Alfresco.
the class TasksImpl method getValidHistoricTask.
/**
* Get a valid {@link HistoricTaskInstance} based on the given task id. Checks if current logged
* in user is assignee/owner/involved with the task. In case true was passed for "validIfClaimable",
* the task is also valid if the current logged in user is a candidate for claiming the task.
*
* @throws EntityNotFoundException when the task was not found
* @throws PermissionDeniedException when the current logged in user isn't allowed to access task.
*/
protected HistoricTaskInstance getValidHistoricTask(String taskId) {
HistoricTaskInstanceQuery query = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery().taskId(taskId);
if (authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
// Admin is allowed to read all tasks in the current tenant
if (tenantService.isEnabled()) {
query.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
}
} else {
// If non-admin user, involvement in the task is required (either owner, assignee or externally involved).
query.taskInvolvedUser(AuthenticationUtil.getRunAsUser());
}
HistoricTaskInstance taskInstance = query.singleResult();
if (taskInstance == null) {
// Either the task doesn't exist or the user is not involved directly. We can differentiate by
// checking if the task exists without applying the additional filtering
taskInstance = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
if (taskInstance == null) {
// Full error message will be "Task with id: 'id' was not found"
throw new EntityNotFoundException(taskId);
} else {
boolean isTaskClaimable = false;
if (taskInstance.getEndTime() == null) {
// Task is not yet finished, so potentially claimable. If user is part of a "candidateGroup", the task is accessible to the
// user regardless of not being involved/owner/assignee
isTaskClaimable = activitiProcessEngine.getTaskService().createTaskQuery().taskCandidateGroupIn(new ArrayList<String>(authorityService.getAuthoritiesForUser(AuthenticationUtil.getRunAsUser()))).taskId(taskId).count() == 1;
}
if (isTaskClaimable == false) {
throw new PermissionDeniedException();
}
}
}
return taskInstance;
}
use of org.activiti.engine.history.HistoricTaskInstanceQuery in project alfresco-remote-api by Alfresco.
the class WorkflowRestImpl method validateIfUserAllowedToWorkWithProcess.
/**
* Validates if the logged in user is allowed to get information about a specific process instance.
* If the user is not allowed an exception is thrown.
*
* @param processId identifier of the process instance
*/
protected List<HistoricVariableInstance> validateIfUserAllowedToWorkWithProcess(String processId) {
List<HistoricVariableInstance> variableInstances = activitiProcessEngine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(processId).list();
Map<String, Object> variableMap = new HashMap<String, Object>();
if (variableInstances != null && variableInstances.size() > 0) {
for (HistoricVariableInstance variableInstance : variableInstances) {
variableMap.put(variableInstance.getVariableName(), variableInstance.getValue());
}
} else {
throw new EntityNotFoundException(processId);
}
if (tenantService.isEnabled()) {
String tenantDomain = (String) variableMap.get(ActivitiConstants.VAR_TENANT_DOMAIN);
if (TenantUtil.getCurrentDomain().equals(tenantDomain) == false) {
throw new PermissionDeniedException("Process is running in another tenant");
}
}
// MNT-17918 - required for initiator variable already updated as NodeRef type
Object initiator = variableMap.get(WorkflowConstants.PROP_INITIATOR);
String nodeId = ((initiator instanceof ActivitiScriptNode) ? ((ActivitiScriptNode) initiator).getNodeRef().getId() : ((NodeRef) initiator).getId());
if (initiator != null && AuthenticationUtil.getRunAsUser().equals(nodeId)) {
// user is allowed
return variableInstances;
}
String username = AuthenticationUtil.getRunAsUser();
if (authorityService.isAdminAuthority(username)) {
// Admin is allowed to read all processes in the current tenant
return variableInstances;
} else {
// MNT-12382 check for membership in the assigned group
ActivitiScriptNode group = (ActivitiScriptNode) variableMap.get("bpm_groupAssignee");
if (group != null) {
// check that the process is unclaimed
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processId).singleResult();
if ((task != null) && (task.getAssignee() == null) && isUserInGroup(username, group.getNodeRef())) {
return variableInstances;
}
}
// If non-admin user, involvement in the task is required (either owner, assignee or externally involved).
HistoricTaskInstanceQuery query = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery().processInstanceId(processId).taskInvolvedUser(AuthenticationUtil.getRunAsUser());
List<HistoricTaskInstance> taskList = query.list();
if (org.apache.commons.collections.CollectionUtils.isEmpty(taskList)) {
throw new PermissionDeniedException("user is not allowed to access information about process " + processId);
}
}
return variableInstances;
}
Aggregations