Search in sources :

Example 1 with FormPart

use of org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart in project camunda-bpm-platform by camunda.

the class DeploymentRestServiceImpl method extractDuplicateFilteringForDeployment.

private void extractDuplicateFilteringForDeployment(MultipartFormData payload, DeploymentBuilder deploymentBuilder) {
    boolean enableDuplicateFiltering = false;
    boolean deployChangedOnly = false;
    FormPart deploymentEnableDuplicateFiltering = payload.getNamedPart(ENABLE_DUPLICATE_FILTERING);
    if (deploymentEnableDuplicateFiltering != null) {
        enableDuplicateFiltering = Boolean.parseBoolean(deploymentEnableDuplicateFiltering.getTextContent());
    }
    FormPart deploymentDeployChangedOnly = payload.getNamedPart(DEPLOY_CHANGED_ONLY);
    if (deploymentDeployChangedOnly != null) {
        deployChangedOnly = Boolean.parseBoolean(deploymentDeployChangedOnly.getTextContent());
    }
    // deployChangedOnly overrides the enableDuplicateFiltering setting
    if (deployChangedOnly) {
        deploymentBuilder.enableDuplicateFiltering(true);
    } else if (enableDuplicateFiltering) {
        deploymentBuilder.enableDuplicateFiltering(false);
    }
}
Also used : FormPart(org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart)

Example 2 with FormPart

use of org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart in project camunda-bpm-platform by camunda.

the class MultipartPayloadProvider method parseRequest.

protected void parseRequest(MultipartFormData multipartFormData, FileUpload fileUpload, RestMultipartRequestContext requestContext) {
    try {
        FileItemIterator itemIterator = fileUpload.getItemIterator(requestContext);
        while (itemIterator.hasNext()) {
            FileItemStream stream = itemIterator.next();
            multipartFormData.addPart(new FormPart(stream));
        }
    } catch (Exception e) {
        throw new RestException(Status.BAD_REQUEST, e, "multipart/form-data cannot be processed");
    }
}
Also used : FormPart(org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart) FileItemStream(org.apache.commons.fileupload.FileItemStream) RestException(org.camunda.bpm.engine.rest.exception.RestException) FileItemIterator(org.apache.commons.fileupload.FileItemIterator) IOException(java.io.IOException) RestException(org.camunda.bpm.engine.rest.exception.RestException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 3 with FormPart

use of org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart 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);
        }
    }
}
Also used : FormPart(org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart) VariableValueDto(org.camunda.bpm.engine.rest.dto.VariableValueDto) 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) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 4 with FormPart

use of org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart in project camunda-bpm-platform by camunda.

the class TaskAttachmentResourceImpl method addAttachment.

@Override
public AttachmentDto addAttachment(UriInfo uriInfo, MultipartFormData payload) {
    ensureHistoryEnabled(Status.FORBIDDEN);
    ensureTaskExists(Status.BAD_REQUEST);
    FormPart attachmentNamePart = payload.getNamedPart("attachment-name");
    FormPart attachmentTypePart = payload.getNamedPart("attachment-type");
    FormPart attachmentDescriptionPart = payload.getNamedPart("attachment-description");
    FormPart contentPart = payload.getNamedPart("content");
    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.getTextContent();
    }
    if (attachmentDescriptionPart != null) {
        attachmentDescription = attachmentDescriptionPart.getTextContent();
    }
    if (attachmentTypePart != null) {
        attachmentType = attachmentTypePart.getTextContent();
    }
    Attachment attachment = null;
    try {
        if (contentPart != null) {
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(contentPart.getBinaryContent());
            attachment = engine.getTaskService().createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, byteArrayInputStream);
        } else if (urlPart != null) {
            attachment = engine.getTaskService().createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, urlPart.getTextContent());
        }
    } catch (ProcessEngineException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e, "Task id is null");
    }
    URI uri = uriInfo.getBaseUriBuilder().path(rootResourcePath).path(TaskRestService.PATH).path(taskId + "/attachment/" + attachment.getId()).build();
    AttachmentDto attachmentDto = AttachmentDto.fromAttachment(attachment);
    // GET /
    attachmentDto.addReflexiveLink(uri, HttpMethod.GET, "self");
    return attachmentDto;
}
Also used : AttachmentDto(org.camunda.bpm.engine.rest.dto.task.AttachmentDto) FormPart(org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart) ByteArrayInputStream(java.io.ByteArrayInputStream) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Attachment(org.camunda.bpm.engine.task.Attachment) URI(java.net.URI) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 5 with FormPart

use of org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart in project camunda-bpm-platform by camunda.

the class DeploymentRestServiceImpl method extractDeploymentInformation.

private DeploymentBuilder extractDeploymentInformation(MultipartFormData payload) {
    DeploymentBuilder deploymentBuilder = getProcessEngine().getRepositoryService().createDeployment();
    Set<String> partNames = payload.getPartNames();
    for (String name : partNames) {
        FormPart part = payload.getNamedPart(name);
        if (!RESERVED_KEYWORDS.contains(name)) {
            deploymentBuilder.addInputStream(part.getFileName(), new ByteArrayInputStream(part.getBinaryContent()));
        }
    }
    FormPart deploymentName = payload.getNamedPart(DEPLOYMENT_NAME);
    if (deploymentName != null) {
        deploymentBuilder.name(deploymentName.getTextContent());
    }
    FormPart deploymentSource = payload.getNamedPart(DEPLOYMENT_SOURCE);
    if (deploymentSource != null) {
        deploymentBuilder.source(deploymentSource.getTextContent());
    }
    FormPart deploymentTenantId = payload.getNamedPart(TENANT_ID);
    if (deploymentTenantId != null) {
        deploymentBuilder.tenantId(deploymentTenantId.getTextContent());
    }
    extractDuplicateFilteringForDeployment(payload, deploymentBuilder);
    return deploymentBuilder;
}
Also used : FormPart(org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

FormPart (org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart)5 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)2 RestException (org.camunda.bpm.engine.rest.exception.RestException)2 IOException (java.io.IOException)1 URI (java.net.URI)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 FileItemIterator (org.apache.commons.fileupload.FileItemIterator)1 FileItemStream (org.apache.commons.fileupload.FileItemStream)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 VariableValueDto (org.camunda.bpm.engine.rest.dto.VariableValueDto)1 AttachmentDto (org.camunda.bpm.engine.rest.dto.task.AttachmentDto)1 Attachment (org.camunda.bpm.engine.task.Attachment)1 TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)1