use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class HistoricDetailCollectionResourceTest method testQueryDetail.
/**
* Test querying historic detail.
* GET history/historic-detail
*/
@Deployment
public void testQueryDetail() throws Exception {
HashMap<String, Object> processVariables = new HashMap<String, Object>();
processVariables.put("stringVar", "Azerty");
processVariables.put("intVar", 67890);
processVariables.put("booleanVar", false);
processVariables.put("byteVar", "test".getBytes());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.complete(task.getId());
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.setVariableLocal(task.getId(), "taskVariable", "test");
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_DETAIL);
assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance.getId(), 5, "stringVar", "Azerty");
assertResultsPresentInDataResponse(url + "?taskId=" + task.getId(), 1, "taskVariable", "test");
assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance2.getId(), 4, "intVar", 67890);
assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance2.getId() + "&selectOnlyVariableUpdates=true", 4, "booleanVar", false);
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url + "?processInstanceId=" + processInstance2.getId()), HttpStatus.SC_OK);
// Check status and size
JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
closeResponse(response);
boolean byteVarFound = false;
Iterator<JsonNode> it = dataNode.iterator();
while (it.hasNext()) {
JsonNode variableNode = it.next().get("variable");
String name = variableNode.get("name").textValue();
if ("byteVar".equals(name)) {
byteVarFound = true;
String valueUrl = variableNode.get("valueUrl").textValue();
response = executeRequest(new HttpGet(valueUrl), HttpStatus.SC_OK);
byte[] varInput = IOUtils.toByteArray(response.getEntity().getContent());
closeResponse(response);
assertEquals("test", new String(varInput));
break;
}
}
assertTrue(byteVarFound);
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class JpaRestTest method testGetJpaVariableViaHistoricProcessCollection.
@Deployment(resources = { "org/activiti/rest/api/jpa/jpa-process.bpmn20.xml" })
public void testGetJpaVariableViaHistoricProcessCollection() throws Exception {
// Get JPA managed entity through the repository
Message message = messageRepository.findOne(1L);
assertNotNull(message);
assertEquals("Hello World", message.getText());
// add the entity to the process variables and start the process
Map<String, Object> processVariables = new HashMap<String, Object>();
processVariables.put("message", message);
ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("jpa-process", processVariables);
assertNotNull(processInstance);
Task task = processEngine.getTaskService().createTaskQuery().singleResult();
assertEquals("Activiti is awesome!", task.getName());
// Request all variables (no scope provides) which include global and local
HttpResponse response = executeHttpRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCES) + "?processInstanceId=" + processInstance.getId() + "&includeProcessVariables=true"), HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
// check for message variable of type serializable
assertNotNull(responseNode);
JsonNode variablesArrayNode = responseNode.get("data").get(0).get("variables");
assertEquals(1, variablesArrayNode.size());
JsonNode variableNode = variablesArrayNode.get(0);
assertEquals("message", variableNode.get("name").asText());
assertEquals("serializable", variableNode.get("type").asText());
assertNotNull(variableNode.get("valueUrl"));
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class TaskIdentityLinkFamilyResource method getIdentityLinksForFamily.
@RequestMapping(value = "/runtime/tasks/{taskId}/identitylinks/{family}", method = RequestMethod.GET, produces = "application/json")
public List<RestIdentityLink> getIdentityLinksForFamily(@PathVariable("taskId") String taskId, @PathVariable("family") String family, HttpServletRequest request) {
Task task = getTaskFromRequest(taskId);
if (family == null || (!RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS.equals(family) && !RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS.equals(family))) {
throw new ActivitiIllegalArgumentException("Identity link family should be 'users' or 'groups'.");
}
boolean isUser = family.equals(RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS);
List<RestIdentityLink> results = new ArrayList<RestIdentityLink>();
List<IdentityLink> allLinks = taskService.getIdentityLinksForTask(task.getId());
for (IdentityLink link : allLinks) {
boolean match = false;
if (isUser) {
match = link.getUserId() != null;
} else {
match = link.getGroupId() != null;
}
if (match) {
results.add(restResponseFactory.createRestIdentityLink(link));
}
}
return results;
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class TaskResource method deleteTask.
@RequestMapping(value = "/runtime/tasks/{taskId}", method = RequestMethod.DELETE)
public void deleteTask(@PathVariable String taskId, @RequestParam(value = "cascadeHistory", required = false) Boolean cascadeHistory, @RequestParam(value = "deleteReason", required = false) String deleteReason, HttpServletResponse response) {
Task taskToDelete = getTaskFromRequest(taskId);
if (taskToDelete.getExecutionId() != null) {
// Can't delete a task that is part of a process instance
throw new ActivitiForbiddenException("Cannot delete a task that is part of a process-instance.");
}
if (cascadeHistory != null) {
// Ignore delete-reason since the task-history (where the reason is recorded) will be deleted anyway
taskService.deleteTask(taskToDelete.getId(), cascadeHistory);
} else {
// Delete with delete-reason
taskService.deleteTask(taskToDelete.getId(), deleteReason);
}
response.setStatus(HttpStatus.NO_CONTENT.value());
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class TaskVariableCollectionResource method getVariables.
@RequestMapping(value = "/runtime/tasks/{taskId}/variables", method = RequestMethod.GET, produces = "application/json")
public List<RestVariable> getVariables(@PathVariable String taskId, @RequestParam(value = "scope", required = false) String scope, HttpServletRequest request) {
List<RestVariable> result = new ArrayList<RestVariable>();
Map<String, RestVariable> variableMap = new HashMap<String, RestVariable>();
// Check if it's a valid task to get the variables for
Task task = getTaskFromRequest(taskId);
RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
if (variableScope == null) {
// Use both local and global variables
addLocalVariables(task, variableMap);
addGlobalVariables(task, variableMap);
} else if (variableScope == RestVariableScope.GLOBAL) {
addGlobalVariables(task, variableMap);
} else if (variableScope == RestVariableScope.LOCAL) {
addLocalVariables(task, variableMap);
}
// Get unique variables from map
result.addAll(variableMap.values());
return result;
}
Aggregations