Search in sources :

Example 41 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class ProcessDefinitionResourceImpl method getActivityStatistics.

@Override
public List<StatisticsResultDto> getActivityStatistics(Boolean includeFailedJobs, Boolean includeIncidents, String includeIncidentsForType) {
    if (includeIncidents != null && includeIncidentsForType != null) {
        throw new InvalidRequestException(Status.BAD_REQUEST, "Only one of the query parameter includeIncidents or includeIncidentsForType can be set.");
    }
    ManagementService mgmtService = engine.getManagementService();
    ActivityStatisticsQuery query = mgmtService.createActivityStatisticsQuery(processDefinitionId);
    if (includeFailedJobs != null && includeFailedJobs) {
        query.includeFailedJobs();
    }
    if (includeIncidents != null && includeIncidents) {
        query.includeIncidents();
    } else if (includeIncidentsForType != null) {
        query.includeIncidentsForType(includeIncidentsForType);
    }
    List<ActivityStatistics> queryResults = query.list();
    List<StatisticsResultDto> results = new ArrayList<StatisticsResultDto>();
    for (ActivityStatistics queryResult : queryResults) {
        StatisticsResultDto dto = ActivityStatisticsResultDto.fromActivityStatistics(queryResult);
        results.add(dto);
    }
    return results;
}
Also used : ActivityStatistics(org.camunda.bpm.engine.management.ActivityStatistics) ManagementService(org.camunda.bpm.engine.ManagementService) ArrayList(java.util.ArrayList) ActivityStatisticsResultDto(org.camunda.bpm.engine.rest.dto.repository.ActivityStatisticsResultDto) StatisticsResultDto(org.camunda.bpm.engine.rest.dto.StatisticsResultDto) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ActivityStatisticsQuery(org.camunda.bpm.engine.management.ActivityStatisticsQuery)

Example 42 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class DecisionDefinitionResourceImpl method getDecisionDefinitionDmnXml.

@Override
public DecisionDefinitionDiagramDto getDecisionDefinitionDmnXml() {
    InputStream decisionModelInputStream = null;
    try {
        decisionModelInputStream = engine.getRepositoryService().getDecisionModel(decisionDefinitionId);
        byte[] decisionModel = IoUtil.readInputStream(decisionModelInputStream, "decisionModelDmnXml");
        return DecisionDefinitionDiagramDto.create(decisionDefinitionId, new String(decisionModel, "UTF-8"));
    } catch (NotFoundException e) {
        throw new InvalidRequestException(Status.NOT_FOUND, e, e.getMessage());
    } catch (NotValidException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e, e.getMessage());
    } catch (ProcessEngineException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e);
    } catch (UnsupportedEncodingException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e);
    } finally {
        IoUtil.closeSilently(decisionModelInputStream);
    }
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) InputStream(java.io.InputStream) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 43 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class ExecutionResourceImpl method getExecution.

@Override
public ExecutionDto getExecution() {
    RuntimeService runtimeService = engine.getRuntimeService();
    Execution execution = runtimeService.createExecutionQuery().executionId(executionId).singleResult();
    if (execution == null) {
        throw new InvalidRequestException(Status.NOT_FOUND, "Execution with id " + executionId + " does not exist");
    }
    return ExecutionDto.fromExecution(execution);
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) RuntimeService(org.camunda.bpm.engine.RuntimeService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 44 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class TaskResourceImpl method resolve.

@Override
public void resolve(CompleteTaskDto dto) {
    TaskService taskService = engine.getTaskService();
    try {
        VariableMap variables = VariableValueDto.toMap(dto.getVariables(), engine, objectMapper);
        taskService.resolveTask(taskId, variables);
    } catch (RestException e) {
        String errorMessage = String.format("Cannot resolve task %s: %s", taskId, e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    }
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) TaskService(org.camunda.bpm.engine.TaskService) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 45 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class TaskResourceImpl method getRenderedForm.

public Response getRenderedForm() {
    FormService formService = engine.getFormService();
    Object renderedTaskForm = formService.getRenderedTaskForm(taskId);
    if (renderedTaskForm != null) {
        String content = renderedTaskForm.toString();
        InputStream stream = new ByteArrayInputStream(content.getBytes(EncodingUtil.DEFAULT_ENCODING));
        return Response.ok(stream).type(MediaType.APPLICATION_XHTML_XML).build();
    }
    throw new InvalidRequestException(Status.NOT_FOUND, "No matching rendered form for task with the id " + taskId + " found.");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FormService(org.camunda.bpm.engine.FormService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Aggregations

InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)116 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)30 RestException (org.camunda.bpm.engine.rest.exception.RestException)25 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)20 NotValidException (org.camunda.bpm.engine.exception.NotValidException)12 ArrayList (java.util.ArrayList)11 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)11 ManagementService (org.camunda.bpm.engine.ManagementService)11 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)11 VariableQueryParameterDto (org.camunda.bpm.engine.rest.dto.VariableQueryParameterDto)10 HistoryService (org.camunda.bpm.engine.HistoryService)9 RuntimeService (org.camunda.bpm.engine.RuntimeService)9 InputStream (java.io.InputStream)8 RepositoryService (org.camunda.bpm.engine.RepositoryService)8 Batch (org.camunda.bpm.engine.batch.Batch)8 URI (java.net.URI)6 VariableMap (org.camunda.bpm.engine.variable.VariableMap)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 FormService (org.camunda.bpm.engine.FormService)5 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)5