Search in sources :

Example 21 with RestException

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

the class AbstractVariablesResource method setBinaryVariable.

public void setBinaryVariable(String variableKey, MultipartFormData payload) {
    FormPart dataPart = payload.getNamedPart("data");
    FormPart objectTypePart = payload.getNamedPart("type");
    FormPart valueTypePart = payload.getNamedPart("valueType");
    if (objectTypePart != null) {
        Object object = null;
        if (dataPart.getContentType() != null && dataPart.getContentType().toLowerCase().contains(MediaType.APPLICATION_JSON)) {
            object = deserializeJsonObject(objectTypePart.getTextContent(), dataPart.getBinaryContent());
        } else {
            throw new InvalidRequestException(Status.BAD_REQUEST, "Unrecognized content type for serialized java type: " + dataPart.getContentType());
        }
        if (object != null) {
            setVariableEntity(variableKey, Variables.objectValue(object).create());
        }
    } else {
        String valueTypeName = DEFAULT_BINARY_VALUE_TYPE;
        if (valueTypePart != null) {
            if (valueTypePart.getTextContent() == null) {
                throw new InvalidRequestException(Status.BAD_REQUEST, "Form part with name 'valueType' must have a text/plain value");
            }
            valueTypeName = valueTypePart.getTextContent();
        }
        VariableValueDto valueDto = VariableValueDto.fromFormPart(valueTypeName, dataPart);
        try {
            TypedValue typedValue = valueDto.toTypedValue(engine, objectMapper);
            setVariableEntity(variableKey, typedValue);
        } catch (AuthorizationException e) {
            throw e;
        } catch (ProcessEngineException e) {
            String errorMessage = String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableKey, e.getMessage());
            throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
        }
    }
}
Also used : FormPart(org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart) VariableValueDto(org.camunda.bpm.engine.rest.dto.VariableValueDto) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 22 with RestException

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

the class CaseDefinitionResourceImpl method getCaseDefinitionCmmnXml.

@Override
public CaseDefinitionDiagramDto getCaseDefinitionCmmnXml() {
    InputStream caseModelInputStream = null;
    try {
        caseModelInputStream = engine.getRepositoryService().getCaseModel(caseDefinitionId);
        byte[] caseModel = IoUtil.readInputStream(caseModelInputStream, "caseModelCmmnXml");
        return CaseDefinitionDiagramDto.create(caseDefinitionId, new String(caseModel, "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(caseModelInputStream);
    }
}
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 23 with RestException

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

the class CaseDefinitionResourceImpl method createCaseInstance.

public CaseInstanceDto createCaseInstance(UriInfo context, CreateCaseInstanceDto parameters) {
    CaseService caseService = engine.getCaseService();
    CaseInstance instance = null;
    try {
        String businessKey = parameters.getBusinessKey();
        VariableMap variables = VariableValueDto.toMap(parameters.getVariables(), engine, objectMapper);
        instance = caseService.withCaseDefinition(caseDefinitionId).businessKey(businessKey).setVariables(variables).create();
    } catch (RestException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    } catch (NotFoundException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new InvalidRequestException(Status.NOT_FOUND, e, errorMessage);
    } catch (NotValidException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new InvalidRequestException(Status.BAD_REQUEST, e, errorMessage);
    } catch (NotAllowedException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new InvalidRequestException(Status.FORBIDDEN, e, errorMessage);
    } catch (ProcessEngineException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
    }
    CaseInstanceDto result = CaseInstanceDto.fromCaseInstance(instance);
    URI uri = context.getBaseUriBuilder().path(rootResourcePath).path(CaseInstanceRestService.PATH).path(instance.getId()).build();
    result.addReflexiveLink(uri, HttpMethod.GET, "self");
    return result;
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) NotValidException(org.camunda.bpm.engine.exception.NotValidException) NotAllowedException(org.camunda.bpm.engine.exception.NotAllowedException) VariableMap(org.camunda.bpm.engine.variable.VariableMap) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) CaseService(org.camunda.bpm.engine.CaseService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) CreateCaseInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.CreateCaseInstanceDto) CaseInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.CaseInstanceDto) URI(java.net.URI) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 24 with RestException

use of org.camunda.bpm.engine.rest.exception.RestException 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 25 with RestException

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

the class TaskResourceImpl method complete.

@Override
public void complete(CompleteTaskDto dto) {
    TaskService taskService = engine.getTaskService();
    try {
        VariableMap variables = VariableValueDto.toMap(dto.getVariables(), engine, objectMapper);
        taskService.complete(taskId, variables);
    } catch (RestException e) {
        String errorMessage = String.format("Cannot complete task %s: %s", taskId, e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        String errorMessage = String.format("Cannot complete task %s: %s", taskId, e.getMessage());
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
    }
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) TaskService(org.camunda.bpm.engine.TaskService) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) 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