Exemplo n.º 1
0
        public virtual void setBinaryVariable(string variableKey, MultipartFormData payload)
        {
            MultipartFormData.FormPart dataPart       = payload.getNamedPart("data");
            MultipartFormData.FormPart objectTypePart = payload.getNamedPart("type");
            MultipartFormData.FormPart valueTypePart  = payload.getNamedPart("valueType");

            if (objectTypePart != null)
            {
                object @object = null;

                if (!string.ReferenceEquals(dataPart.ContentType, null) && dataPart.ContentType.ToLower().Contains(MediaType.APPLICATION_JSON))
                {
                    @object = deserializeJsonObject(objectTypePart.TextContent, dataPart.BinaryContent);
                }
                else
                {
                    throw new InvalidRequestException(Response.Status.BAD_REQUEST, "Unrecognized content type for serialized java type: " + dataPart.ContentType);
                }

                if (@object != null)
                {
                    setVariableEntity(variableKey, Variables.objectValue(@object).create());
                }
            }
            else
            {
                string valueTypeName = DEFAULT_BINARY_VALUE_TYPE;
                if (valueTypePart != null)
                {
                    if (string.ReferenceEquals(valueTypePart.TextContent, null))
                    {
                        throw new InvalidRequestException(Response.Status.BAD_REQUEST, "Form part with name 'valueType' must have a text/plain value");
                    }

                    valueTypeName = valueTypePart.TextContent;
                }

                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 {0} variable {1}: {2}", ResourceTypeName, variableKey, e.Message);
                    throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e, errorMessage);
                }
            }
        }