use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class JobExceptionStacktraceResource method getJobStacktrace.
@RequestMapping(value = "/management/jobs/{jobId}/exception-stacktrace", method = RequestMethod.GET)
public String getJobStacktrace(@PathVariable String jobId, HttpServletResponse response) {
Job job = getJobFromResponse(jobId);
String stackTrace = managementService.getJobExceptionStacktrace(job.getId());
if (stackTrace == null) {
throw new ActivitiObjectNotFoundException("Job with id '" + job.getId() + "' doesn't have an exception stacktrace.", String.class);
}
response.setContentType("text/plain");
return stackTrace;
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class TableDataResource method getTableData.
@RequestMapping(value = "/management/tables/{tableName}/data", method = RequestMethod.GET, produces = "application/json")
public DataResponse getTableData(@PathVariable String tableName, @RequestParam Map<String, String> allRequestParams) {
// Check if table exists before continuing
if (managementService.getTableMetaData(tableName) == null) {
throw new ActivitiObjectNotFoundException("Could not find a table with name '" + tableName + "'.", String.class);
}
String orderAsc = allRequestParams.get("orderAscendingColumn");
String orderDesc = allRequestParams.get("orderDescendingColumn");
if (orderAsc != null && orderDesc != null) {
throw new ActivitiIllegalArgumentException("Only one of 'orderAscendingColumn' or 'orderDescendingColumn' can be supplied.");
}
Integer start = null;
if (allRequestParams.containsKey("start")) {
start = Integer.valueOf(allRequestParams.get("start"));
}
if (start == null) {
start = 0;
}
Integer size = null;
if (allRequestParams.containsKey("size")) {
size = Integer.valueOf(allRequestParams.get("size"));
}
if (size == null) {
size = DEFAULT_RESULT_SIZE;
}
DataResponse response = new DataResponse();
TablePageQuery tablePageQuery = managementService.createTablePageQuery().tableName(tableName);
if (orderAsc != null) {
tablePageQuery.orderAsc(orderAsc);
response.setOrder("asc");
response.setSort(orderAsc);
}
if (orderDesc != null) {
tablePageQuery.orderDesc(orderDesc);
response.setOrder("desc");
response.setSort(orderDesc);
}
TablePage listPage = tablePageQuery.listPage(start, size);
response.setSize(((Long) listPage.getSize()).intValue());
response.setStart(((Long) listPage.getFirstResult()).intValue());
response.setTotal(listPage.getTotal());
response.setData(listPage.getRows());
return response;
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class BaseDeploymentResourceDataResource method getDeploymentResourceData.
protected byte[] getDeploymentResourceData(String deploymentId, String resourceId, HttpServletResponse response) {
if (deploymentId == null) {
throw new ActivitiIllegalArgumentException("No deployment id provided");
}
if (resourceId == null) {
throw new ActivitiIllegalArgumentException("No resource id provided");
}
// Check if deployment exists
Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
if (deployment == null) {
throw new ActivitiObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.", Deployment.class);
}
List<String> resourceList = repositoryService.getDeploymentResourceNames(deploymentId);
if (resourceList.contains(resourceId)) {
final InputStream resourceStream = repositoryService.getResourceAsStream(deploymentId, resourceId);
String contentType = contentTypeResolver.resolveContentType(resourceId);
response.setContentType(contentType);
try {
return IOUtils.toByteArray(resourceStream);
} catch (Exception e) {
throw new ActivitiException("Error converting resource stream", e);
}
} else {
// Resource not found in deployment
throw new ActivitiObjectNotFoundException("Could not find a resource with id '" + resourceId + "' in deployment '" + deploymentId + "'.", String.class);
}
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class ExecutionVariableDataResource method getVariableData.
@RequestMapping(value = "/runtime/executions/{executionId}/variables/{variableName}/data", method = RequestMethod.GET)
@ResponseBody
public byte[] getVariableData(@PathVariable("executionId") String executionId, @PathVariable("variableName") String variableName, @RequestParam(value = "scope", required = false) String scope, HttpServletRequest request, HttpServletResponse response) {
try {
byte[] result = null;
Execution execution = getExecutionFromRequest(executionId);
RestVariable variable = getVariableFromRequest(execution, variableName, scope, true);
if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
result = (byte[]) variable.getValue();
response.setContentType("application/octet-stream");
} else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
outputStream.writeObject(variable.getValue());
outputStream.close();
result = buffer.toByteArray();
response.setContentType("application/x-java-serialized-object");
} else {
throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
}
return result;
} catch (IOException ioe) {
throw new ActivitiException("Error getting variable " + variableName, ioe);
}
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class ProcessInstanceCollectionResource method createProcessInstance.
@RequestMapping(value = "/runtime/process-instances", method = RequestMethod.POST, produces = "application/json")
public ProcessInstanceResponse createProcessInstance(@RequestBody ProcessInstanceCreateRequest request, HttpServletRequest httpRequest, HttpServletResponse response) {
if (request.getProcessDefinitionId() == null && request.getProcessDefinitionKey() == null && request.getMessage() == null) {
throw new ActivitiIllegalArgumentException("Either processDefinitionId, processDefinitionKey or message is required.");
}
int paramsSet = ((request.getProcessDefinitionId() != null) ? 1 : 0) + ((request.getProcessDefinitionKey() != null) ? 1 : 0) + ((request.getMessage() != null) ? 1 : 0);
if (paramsSet > 1) {
throw new ActivitiIllegalArgumentException("Only one of processDefinitionId, processDefinitionKey or message should be set.");
}
if (request.isCustomTenantSet()) {
// Tenant-id can only be used with either key or message
if (request.getProcessDefinitionId() != null) {
throw new ActivitiIllegalArgumentException("TenantId can only be used with either processDefinitionKey or message.");
}
}
Map<String, Object> startVariables = null;
if (request.getVariables() != null) {
startVariables = new HashMap<String, Object>();
for (RestVariable variable : request.getVariables()) {
if (variable.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required.");
}
startVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
}
}
// Actually start the instance based on key or id
try {
ProcessInstance instance = null;
if (request.getProcessDefinitionId() != null) {
instance = runtimeService.startProcessInstanceById(request.getProcessDefinitionId(), request.getBusinessKey(), startVariables);
} else if (request.getProcessDefinitionKey() != null) {
if (request.isCustomTenantSet()) {
instance = runtimeService.startProcessInstanceByKeyAndTenantId(request.getProcessDefinitionKey(), request.getBusinessKey(), startVariables, request.getTenantId());
} else {
instance = runtimeService.startProcessInstanceByKey(request.getProcessDefinitionKey(), request.getBusinessKey(), startVariables);
}
} else {
if (request.isCustomTenantSet()) {
instance = runtimeService.startProcessInstanceByMessageAndTenantId(request.getMessage(), request.getBusinessKey(), startVariables, request.getTenantId());
} else {
instance = runtimeService.startProcessInstanceByMessage(request.getMessage(), request.getBusinessKey(), startVariables);
}
}
response.setStatus(HttpStatus.CREATED.value());
//Added by Ryan Johnston
if (request.getReturnVariables()) {
Map<String, Object> runtimeVariableMap = null;
List<HistoricVariableInstance> historicVariableList = null;
if (instance.isEnded()) {
historicVariableList = historyService.createHistoricVariableInstanceQuery().processInstanceId(instance.getId()).list();
} else {
runtimeVariableMap = runtimeService.getVariables(instance.getId());
}
return restResponseFactory.createProcessInstanceResponse(instance, true, runtimeVariableMap, historicVariableList);
} else {
return restResponseFactory.createProcessInstanceResponse(instance);
}
//End Added by Ryan Johnston
//Removed by Ryan Johnston (obsolete given the above).
//return factory.createProcessInstanceResponse(this, instance);
} catch (ActivitiObjectNotFoundException aonfe) {
throw new ActivitiIllegalArgumentException(aonfe.getMessage(), aonfe);
}
}
Aggregations