use of org.camunda.bpm.engine.rest.exception.RestException in project camunda-bpm-platform by camunda.
the class JobResourceImpl method executeJob.
@Override
public void executeJob() {
try {
ManagementService managementService = engine.getManagementService();
managementService.executeJob(this.jobId);
} catch (AuthorizationException e) {
throw e;
} catch (ProcessEngineException e) {
throw new InvalidRequestException(Status.NOT_FOUND, e.getMessage());
} catch (RuntimeException r) {
throw new RestException(Status.INTERNAL_SERVER_ERROR, r.getMessage());
}
}
use of org.camunda.bpm.engine.rest.exception.RestException in project camunda-bpm-platform by camunda.
the class VariableValueDto method toTypedValue.
public TypedValue toTypedValue(ProcessEngine processEngine, ObjectMapper objectMapper) {
ValueTypeResolver valueTypeResolver = processEngine.getProcessEngineConfiguration().getValueTypeResolver();
if (type == null) {
if (valueInfo != null && valueInfo.get(ValueType.VALUE_INFO_TRANSIENT) instanceof Boolean) {
return Variables.untypedValue(value, (Boolean) valueInfo.get(ValueType.VALUE_INFO_TRANSIENT));
}
return Variables.untypedValue(value);
}
ValueType valueType = valueTypeResolver.typeForName(fromRestApiTypeName(type));
if (valueType == null) {
throw new RestException(Status.BAD_REQUEST, String.format("Unsupported value type '%s'", type));
} else {
if (valueType instanceof PrimitiveValueType) {
PrimitiveValueType primitiveValueType = (PrimitiveValueType) valueType;
Class<?> javaType = primitiveValueType.getJavaType();
Object mappedValue = null;
try {
if (value != null) {
if (javaType.isAssignableFrom(value.getClass())) {
mappedValue = value;
} else {
// use jackson to map the value to the requested java type
mappedValue = objectMapper.readValue("\"" + value + "\"", javaType);
}
}
return valueType.createValue(mappedValue, valueInfo);
} catch (Exception e) {
throw new InvalidRequestException(Status.BAD_REQUEST, e, String.format("Cannot convert value '%s' of type '%s' to java type %s", value, type, javaType.getName()));
}
} else if (valueType instanceof SerializableValueType) {
if (value != null && !(value instanceof String)) {
throw new InvalidRequestException(Status.BAD_REQUEST, "Must provide 'null' or String value for value of SerializableValue type '" + type + "'.");
}
return ((SerializableValueType) valueType).createValueFromSerialized((String) value, valueInfo);
} else if (valueType instanceof FileValueType) {
if (value instanceof String) {
value = Base64.decodeBase64((String) value);
}
return valueType.createValue(value, valueInfo);
} else {
return valueType.createValue(value, valueInfo);
}
}
}
use of org.camunda.bpm.engine.rest.exception.RestException in project camunda-bpm-platform by camunda.
the class VariableValueDto method fromFormPart.
public static VariableValueDto fromFormPart(String type, FormPart binaryDataFormPart) {
VariableValueDto dto = new VariableValueDto();
dto.type = type;
dto.value = binaryDataFormPart.getBinaryContent();
if (ValueType.FILE.getName().equals(fromRestApiTypeName(type))) {
String contentType = binaryDataFormPart.getContentType();
if (contentType == null) {
contentType = MediaType.APPLICATION_OCTET_STREAM;
}
dto.valueInfo = new HashMap<String, Object>();
dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_NAME, binaryDataFormPart.getFileName());
MimeType mimeType = null;
try {
mimeType = new MimeType(contentType);
} catch (MimeTypeParseException e) {
throw new RestException(Status.BAD_REQUEST, "Invalid mime type given");
}
dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_MIME_TYPE, mimeType.getBaseType());
String encoding = mimeType.getParameter("encoding");
if (encoding != null) {
dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_ENCODING, encoding);
}
String transientString = mimeType.getParameter("transient");
boolean isTransient = Boolean.parseBoolean(transientString);
if (isTransient) {
dto.valueInfo.put(AbstractValueTypeImpl.VALUE_INFO_TRANSIENT, isTransient);
}
}
return dto;
}
use of org.camunda.bpm.engine.rest.exception.RestException in project camunda-bpm-platform by camunda.
the class AbstractVariablesResource method putVariable.
@Override
public void putVariable(String variableName, VariableValueDto variable) {
try {
TypedValue typedValue = variable.toTypedValue(engine, objectMapper);
setVariableEntity(variableName, typedValue);
} catch (RestException e) {
throw new InvalidRequestException(e.getStatus(), e, String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableName, e.getMessage()));
} catch (BadUserRequestException e) {
throw new RestException(Status.BAD_REQUEST, e, String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableName, e.getMessage()));
} catch (AuthorizationException e) {
throw e;
} catch (ProcessEngineException e) {
throw new RestException(Status.INTERNAL_SERVER_ERROR, e, String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableName, e.getMessage()));
}
}
use of org.camunda.bpm.engine.rest.exception.RestException 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);
}
}
Aggregations