Search in sources :

Example 36 with ActivitiObjectNotFoundException

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;
}
Also used : Job(org.activiti.engine.runtime.Job) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with ActivitiObjectNotFoundException

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;
}
Also used : TablePage(org.activiti.engine.management.TablePage) DataResponse(org.activiti.rest.common.api.DataResponse) TablePageQuery(org.activiti.engine.management.TablePageQuery) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 38 with ActivitiObjectNotFoundException

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);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) InputStream(java.io.InputStream) Deployment(org.activiti.engine.repository.Deployment) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 39 with ActivitiObjectNotFoundException

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);
    }
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) ActivitiException(org.activiti.engine.ActivitiException) Execution(org.activiti.engine.runtime.Execution) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 40 with ActivitiObjectNotFoundException

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);
    }
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)88 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 ActivitiException (org.activiti.engine.ActivitiException)26 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)26 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)17 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)15 Task (org.activiti.engine.task.Task)12 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)8 User (org.activiti.engine.identity.User)8 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)8 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 IOException (java.io.IOException)7 ObjectOutputStream (java.io.ObjectOutputStream)7 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)7 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)6 RestVariableScope (org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 Comment (org.activiti.engine.task.Comment)5 DeploymentEntity (org.activiti.engine.impl.persistence.entity.DeploymentEntity)4