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