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