Search in sources :

Example 61 with InvalidRequestException

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

the class AbstractVariablesResource method modifyVariables.

@Override
public void modifyVariables(PatchVariablesDto patch) {
    VariableMap variableModifications = null;
    try {
        variableModifications = VariableValueDto.toMap(patch.getModifications(), engine, objectMapper);
    } catch (RestException e) {
        String errorMessage = String.format("Cannot modify variables for %s: %s", getResourceTypeName(), e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    }
    List<String> variableDeletions = patch.getDeletions();
    try {
        updateVariableEntities(variableModifications, variableDeletions);
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        String errorMessage = String.format("Cannot modify variables for %s %s: %s", getResourceTypeName(), resourceId, 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) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 62 with InvalidRequestException

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

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

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

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

the class ProcessDefinitionResourceImpl method getRenderedForm.

public Response getRenderedForm() {
    FormService formService = engine.getFormService();
    Object startForm = formService.getRenderedStartForm(processDefinitionId);
    if (startForm != null) {
        String content = startForm.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 start form for process definition with the id " + processDefinitionId + " 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