Search in sources :

Example 6 with RestException

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

the class ExternalTaskResourceImpl method complete.

@Override
public void complete(CompleteExternalTaskDto dto) {
    ExternalTaskService externalTaskService = engine.getExternalTaskService();
    VariableMap variables = VariableValueDto.toMap(dto.getVariables(), engine, objectMapper);
    VariableMap localVariables = VariableValueDto.toMap(dto.getLocalVariables(), engine, objectMapper);
    try {
        externalTaskService.complete(externalTaskId, dto.getWorkerId(), variables, localVariables);
    } catch (NotFoundException e) {
        throw new RestException(Status.NOT_FOUND, e, "External task with id " + externalTaskId + " does not exist");
    } catch (BadUserRequestException e) {
        throw new RestException(Status.BAD_REQUEST, e, e.getMessage());
    }
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) ExternalTaskService(org.camunda.bpm.engine.ExternalTaskService) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException)

Example 7 with RestException

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

the class CaseDefinitionResourceImpl method getCaseDefinition.

@Override
public CaseDefinitionDto getCaseDefinition() {
    RepositoryService repositoryService = engine.getRepositoryService();
    CaseDefinition definition = null;
    try {
        definition = repositoryService.getCaseDefinition(caseDefinitionId);
    } 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);
    }
    return CaseDefinitionDto.fromCaseDefinition(definition);
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) CaseDefinition(org.camunda.bpm.engine.repository.CaseDefinition) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 8 with RestException

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

the class DecisionRequirementsDefinitionResourceImpl method getDecisionRequirementsDefinition.

@Override
public DecisionRequirementsDefinitionDto getDecisionRequirementsDefinition() {
    RepositoryService repositoryService = engine.getRepositoryService();
    DecisionRequirementsDefinition definition = null;
    try {
        definition = repositoryService.getDecisionRequirementsDefinition(decisionRequirementsDefinitionId);
    } 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);
    }
    return DecisionRequirementsDefinitionDto.fromDecisionRequirementsDefinition(definition);
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) DecisionRequirementsDefinition(org.camunda.bpm.engine.repository.DecisionRequirementsDefinition) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 9 with RestException

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

the class DecisionRequirementsDefinitionResourceImpl method getDecisionRequirementsDefinitionDmnXml.

@Override
public DecisionRequirementsDefinitionXmlDto getDecisionRequirementsDefinitionDmnXml() {
    InputStream decisionRequirementsModelInputStream = null;
    try {
        decisionRequirementsModelInputStream = engine.getRepositoryService().getDecisionRequirementsModel(decisionRequirementsDefinitionId);
        byte[] decisionRequirementsModel = IoUtil.readInputStream(decisionRequirementsModelInputStream, "decisionRequirementsModelDmnXml");
        return DecisionRequirementsDefinitionXmlDto.create(decisionRequirementsDefinitionId, new String(decisionRequirementsModel, "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(decisionRequirementsModelInputStream);
    }
}
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 10 with RestException

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

the class ProcessDefinitionResourceImpl method submitForm.

@Override
public ProcessInstanceDto submitForm(UriInfo context, StartProcessInstanceDto parameters) {
    FormService formService = engine.getFormService();
    ProcessInstance instance = null;
    try {
        Map<String, Object> variables = VariableValueDto.toMap(parameters.getVariables(), engine, objectMapper);
        String businessKey = parameters.getBusinessKey();
        if (businessKey != null) {
            instance = formService.submitStartForm(processDefinitionId, businessKey, variables);
        } else {
            instance = formService.submitStartForm(processDefinitionId, variables);
        }
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
    } catch (RestException e) {
        String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    }
    ProcessInstanceDto result = ProcessInstanceDto.fromProcessInstance(instance);
    URI uri = context.getBaseUriBuilder().path(rootResourcePath).path(ProcessInstanceRestService.PATH).path(instance.getId()).build();
    result.addReflexiveLink(uri, HttpMethod.GET, "self");
    return result;
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestartProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.RestartProcessInstanceDto) ProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto) StartProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.StartProcessInstanceDto) FormService(org.camunda.bpm.engine.FormService) RestException(org.camunda.bpm.engine.rest.exception.RestException) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) URI(java.net.URI) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Aggregations

RestException (org.camunda.bpm.engine.rest.exception.RestException)33 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)25 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)21 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)14 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)10 NotValidException (org.camunda.bpm.engine.exception.NotValidException)8 VariableMap (org.camunda.bpm.engine.variable.VariableMap)8 InputStream (java.io.InputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 URI (java.net.URI)3 FormService (org.camunda.bpm.engine.FormService)3 RepositoryService (org.camunda.bpm.engine.RepositoryService)3 MimeTypeParseException (javax.activation.MimeTypeParseException)2 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)2 ManagementService (org.camunda.bpm.engine.ManagementService)2 RuntimeService (org.camunda.bpm.engine.RuntimeService)2 TaskService (org.camunda.bpm.engine.TaskService)2 ProcessInstanceDto (org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto)2 RestartProcessInstanceDto (org.camunda.bpm.engine.rest.dto.runtime.RestartProcessInstanceDto)2 StartProcessInstanceDto (org.camunda.bpm.engine.rest.dto.runtime.StartProcessInstanceDto)2