Search in sources :

Example 66 with InvalidRequestException

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

the class ProcessDefinitionResourceImpl method getProcessDefinitionBpmn20Xml.

@Override
public ProcessDefinitionDiagramDto getProcessDefinitionBpmn20Xml() {
    InputStream processModelIn = null;
    try {
        processModelIn = engine.getRepositoryService().getProcessModel(processDefinitionId);
        byte[] processModel = IoUtil.readInputStream(processModelIn, "processModelBpmn20Xml");
        return ProcessDefinitionDiagramDto.create(processDefinitionId, new String(processModel, "UTF-8"));
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e, "No matching definition with id " + processDefinitionId);
    } catch (UnsupportedEncodingException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e);
    } finally {
        IoUtil.closeSilently(processModelIn);
    }
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RestException(org.camunda.bpm.engine.rest.exception.RestException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 67 with InvalidRequestException

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

the class ProcessInstanceResourceImpl method getProcessInstance.

@Override
public ProcessInstanceDto getProcessInstance() {
    RuntimeService runtimeService = engine.getRuntimeService();
    ProcessInstance instance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    if (instance == null) {
        throw new InvalidRequestException(Status.NOT_FOUND, "Process instance with id " + processInstanceId + " does not exist");
    }
    ProcessInstanceDto result = ProcessInstanceDto.fromProcessInstance(instance);
    return result;
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) ProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 68 with InvalidRequestException

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

the class ProcessInstanceResourceImpl method getActivityInstanceTree.

@Override
public ActivityInstanceDto getActivityInstanceTree() {
    RuntimeService runtimeService = engine.getRuntimeService();
    ActivityInstance activityInstance = null;
    try {
        activityInstance = runtimeService.getActivityInstance(processInstanceId);
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        throw new InvalidRequestException(Status.INTERNAL_SERVER_ERROR, e, e.getMessage());
    }
    if (activityInstance == null) {
        throw new InvalidRequestException(Status.NOT_FOUND, "Process instance with id " + processInstanceId + " does not exist");
    }
    ActivityInstanceDto result = ActivityInstanceDto.fromActivityInstance(activityInstance);
    return result;
}
Also used : ActivityInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.ActivityInstanceDto) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) RuntimeService(org.camunda.bpm.engine.RuntimeService) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 69 with InvalidRequestException

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

the class TaskCommentResourceImpl method getComment.

public CommentDto getComment(String commentId) {
    ensureHistoryEnabled(Status.NOT_FOUND);
    Comment comment = engine.getTaskService().getTaskComment(taskId, commentId);
    if (comment == null) {
        throw new InvalidRequestException(Status.NOT_FOUND, "Task comment with id " + commentId + " does not exist for task id '" + taskId + "'.");
    }
    return CommentDto.fromComment(comment);
}
Also used : Comment(org.camunda.bpm.engine.task.Comment) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 70 with InvalidRequestException

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

the class TaskCommentResourceImpl method createComment.

public CommentDto createComment(UriInfo uriInfo, CommentDto commentDto) {
    ensureHistoryEnabled(Status.FORBIDDEN);
    ensureTaskExists(Status.BAD_REQUEST);
    Comment comment;
    try {
        comment = engine.getTaskService().createComment(taskId, null, commentDto.getMessage());
    } catch (ProcessEngineException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e, "Not enough parameters submitted");
    }
    URI uri = uriInfo.getBaseUriBuilder().path(rootResourcePath).path(TaskRestService.PATH).path(taskId + "/comment/" + comment.getId()).build();
    CommentDto resultDto = CommentDto.fromComment(comment);
    // GET /
    resultDto.addReflexiveLink(uri, HttpMethod.GET, "self");
    return resultDto;
}
Also used : Comment(org.camunda.bpm.engine.task.Comment) CommentDto(org.camunda.bpm.engine.rest.dto.task.CommentDto) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) URI(java.net.URI) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

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