Exemple #1
0
        private void extractDuplicateFilteringForDeployment(MultipartFormData payload, DeploymentBuilder deploymentBuilder)
        {
            bool enableDuplicateFiltering = false;
            bool deployChangedOnly        = false;

            MultipartFormData.FormPart deploymentEnableDuplicateFiltering = payload.getNamedPart(ENABLE_DUPLICATE_FILTERING);
            if (deploymentEnableDuplicateFiltering != null)
            {
                enableDuplicateFiltering = bool.Parse(deploymentEnableDuplicateFiltering.TextContent);
            }

            MultipartFormData.FormPart deploymentDeployChangedOnly = payload.getNamedPart(DEPLOY_CHANGED_ONLY);
            if (deploymentDeployChangedOnly != null)
            {
                deployChangedOnly = bool.Parse(deploymentDeployChangedOnly.TextContent);
            }

            // deployChangedOnly overrides the enableDuplicateFiltering setting
            if (deployChangedOnly)
            {
                deploymentBuilder.enableDuplicateFiltering(true);
            }
            else if (enableDuplicateFiltering)
            {
                deploymentBuilder.enableDuplicateFiltering(false);
            }
        }
Exemple #2
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);
                }
            }
        }
Exemple #3
0
        private DeploymentBuilder extractDeploymentInformation(MultipartFormData payload)
        {
            DeploymentBuilder deploymentBuilder = ProcessEngine.RepositoryService.createDeployment();

            ISet <string> partNames = payload.PartNames;

            foreach (string name in partNames)
            {
                MultipartFormData.FormPart part = payload.getNamedPart(name);

                if (!RESERVED_KEYWORDS.Contains(name))
                {
                    string fileName = part.FileName;
                    if (!string.ReferenceEquals(fileName, null))
                    {
                        deploymentBuilder.addInputStream(part.FileName, new MemoryStream(part.BinaryContent));
                    }
                    else
                    {
                        throw new InvalidRequestException(Status.BAD_REQUEST, "No file name found in the deployment resource described by form parameter '" + fileName + "'.");
                    }
                }
            }

            MultipartFormData.FormPart deploymentName = payload.getNamedPart(DEPLOYMENT_NAME);
            if (deploymentName != null)
            {
                deploymentBuilder.name(deploymentName.TextContent);
            }

            MultipartFormData.FormPart deploymentSource = payload.getNamedPart(DEPLOYMENT_SOURCE);
            if (deploymentSource != null)
            {
                deploymentBuilder.source(deploymentSource.TextContent);
            }

            MultipartFormData.FormPart deploymentTenantId = payload.getNamedPart(TENANT_ID);
            if (deploymentTenantId != null)
            {
                deploymentBuilder.tenantId(deploymentTenantId.TextContent);
            }

            extractDuplicateFilteringForDeployment(payload, deploymentBuilder);
            return(deploymentBuilder);
        }
Exemple #4
0
        public virtual AttachmentDto addAttachment(UriInfo uriInfo, MultipartFormData payload)
        {
            ensureHistoryEnabled(Status.FORBIDDEN);
            ensureTaskExists(Status.BAD_REQUEST);

            MultipartFormData.FormPart attachmentNamePart        = payload.getNamedPart("attachment-name");
            MultipartFormData.FormPart attachmentTypePart        = payload.getNamedPart("attachment-type");
            MultipartFormData.FormPart attachmentDescriptionPart = payload.getNamedPart("attachment-description");
            MultipartFormData.FormPart contentPart = payload.getNamedPart("content");
            MultipartFormData.FormPart urlPart     = payload.getNamedPart("url");

            if (urlPart == null && contentPart == null)
            {
                throw new InvalidRequestException(Status.BAD_REQUEST, "No content or url to remote content exists to create the task attachment.");
            }

            string attachmentName        = null;
            string attachmentDescription = null;
            string attachmentType        = null;

            if (attachmentNamePart != null)
            {
                attachmentName = attachmentNamePart.TextContent;
            }
            if (attachmentDescriptionPart != null)
            {
                attachmentDescription = attachmentDescriptionPart.TextContent;
            }
            if (attachmentTypePart != null)
            {
                attachmentType = attachmentTypePart.TextContent;
            }

            Attachment attachment = null;

            try
            {
                if (contentPart != null)
                {
                    MemoryStream byteArrayInputStream = new MemoryStream(contentPart.BinaryContent);
                    attachment = engine.TaskService.createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, byteArrayInputStream);
                }
                else if (urlPart != null)
                {
                    attachment = engine.TaskService.createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, urlPart.TextContent);
                }
            }
            catch (ProcessEngineException e)
            {
                throw new InvalidRequestException(Status.BAD_REQUEST, e, "Task id is null");
            }

            URI uri = uriInfo.BaseUriBuilder.path(rootResourcePath).path(org.camunda.bpm.engine.rest.TaskRestService_Fields.PATH).path(taskId + "/attachment/" + attachment.Id).build();

            AttachmentDto attachmentDto = AttachmentDto.fromAttachment(attachment);

            // GET /
            attachmentDto.addReflexiveLink(uri, HttpMethod.GET, "self");

            return(attachmentDto);
        }