Search in sources :

Example 16 with RestException

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());
    }
}
Also used : ManagementService(org.camunda.bpm.engine.ManagementService) 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 17 with RestException

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);
        }
    }
}
Also used : SerializableValueType(org.camunda.bpm.engine.variable.type.SerializableValueType) SerializableValueType(org.camunda.bpm.engine.variable.type.SerializableValueType) FileValueType(org.camunda.bpm.engine.variable.type.FileValueType) ValueType(org.camunda.bpm.engine.variable.type.ValueType) PrimitiveValueType(org.camunda.bpm.engine.variable.type.PrimitiveValueType) PrimitiveValueType(org.camunda.bpm.engine.variable.type.PrimitiveValueType) RestException(org.camunda.bpm.engine.rest.exception.RestException) ValueTypeResolver(org.camunda.bpm.engine.variable.type.ValueTypeResolver) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) FileValueType(org.camunda.bpm.engine.variable.type.FileValueType) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) MimeTypeParseException(javax.activation.MimeTypeParseException) RestException(org.camunda.bpm.engine.rest.exception.RestException)

Example 18 with RestException

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;
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) RestException(org.camunda.bpm.engine.rest.exception.RestException) MimeType(javax.activation.MimeType)

Example 19 with RestException

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()));
    }
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 20 with RestException

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

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