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);
}
}
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);
}
}
}
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);
}
}
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;
}
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.");
}
Aggregations