use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.
the class WorkflowTaskService method updateBinaryTaskVariable.
@PUT
@Path("/{taskId}/variables/{variableName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response updateBinaryTaskVariable(@PathParam("taskId") String taskId, @PathParam("variableName") String variableName, MultipartBody multipartBody) {
Task task = getTaskFromRequest(taskId);
RestVariable result = null;
try {
result = setBinaryVariable(multipartBody, task, false, uriInfo);
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("Error Reading variable attachment", e);
}
if (result != null) {
if (!result.getName().equals(variableName)) {
throw new ActivitiIllegalArgumentException("Variable name in the body should be equal to the name used in the requested URL.");
}
}
return Response.ok().entity(result).build();
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.
the class WorkflowTaskService method getAttachment.
@GET
@Path("/{taskId}/attachments/{attachmentId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getAttachment(@PathParam("taskId") String taskId, @PathParam("attachmentId") String attachmentId) {
HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
TaskService taskService = BPMNOSGIService.getTaskService();
Attachment attachment = taskService.getAttachment(attachmentId);
if (attachment == null) {
throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have an attachment with id '" + attachmentId + "'.", Comment.class);
}
return Response.ok().entity(new RestResponseFactory().createAttachmentResponse(attachment, uriInfo.getBaseUri().toString())).build();
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.
the class BPELMessageReceiver method persistAttachments.
/**
* Upload each attachment from attachment-map and returns a list of attachment ids.
*
* @param attachmentsMap
* @return list of attachment ids
*/
private List<String> persistAttachments(Attachments attachmentsMap) {
List<String> attachmentIdList = new ArrayList<String>();
// for each attachment upload it
for (String id : attachmentsMap.getAllContentIDs()) {
DataHandler attachmentContent = attachmentsMap.getDataHandler(id);
try {
String attachmentID = BPELServerHolder.getInstance().getAttachmentService().getAttachmentService().add(createAttachmentDTO(attachmentContent));
attachmentIdList.add(attachmentID);
log.info("Attachment added. ID : " + attachmentID);
} catch (AttachmentMgtException e) {
log.error(e.getLocalizedMessage(), e);
}
}
return attachmentIdList;
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.
the class BPELMessageReceiver method createAttachmentDTO.
private TAttachment createAttachmentDTO(DataHandler attachmentHandler) {
TAttachment attachment = new TAttachment();
String attachmentName = attachmentHandler.getName();
attachment.setName(attachmentName);
log.warn("Couldn't determine the name of BPEL client. So the owner of the attachment:" + attachmentName + " " + "will be the default bpel client" + org.wso2.carbon.bpel.core.BPELConstants.DAFAULT_BPEL_CLIENT);
attachment.setCreatedBy(org.wso2.carbon.bpel.core.BPELConstants.DAFAULT_BPEL_CLIENT);
attachment.setContentType(attachmentHandler.getContentType());
// As well there are some other parameters to be set.
attachment.setContent(attachmentHandler);
return attachment;
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.
the class AttachmentUploadExecutor method execute.
@Override
public boolean execute(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter out = response.getWriter();
String webContext = (String) request.getAttribute(CarbonConstants.WEB_CONTEXT);
String serverURL = (String) request.getAttribute(CarbonConstants.SERVER_URL);
String cookie = (String) request.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
Map<String, ArrayList<String>> formFieldsMap = getFormFieldsMap();
String taskID = null;
String redirect = null;
try {
if (formFieldsMap.get("taskID") != null) {
taskID = formFieldsMap.get("taskID").get(0);
}
if (formFieldsMap.get("redirect") != null) {
redirect = formFieldsMap.get("redirect").get(0);
}
ArrayList<FileItemData> fileItemsMap = getFileItemsMap().get("fileToUpload");
FileItemData fileToBeUpload = fileItemsMap.get(0);
AttachmentUploadClient attachmentUploadClient = new AttachmentUploadClient(configurationContext, serverURL, cookie);
HumanTaskClientAPIServiceClient taskOperationClient = new HumanTaskClientAPIServiceClient(cookie, serverURL, configurationContext);
response.setContentType("text/html; charset=utf-8");
String attachmentID = attachmentUploadClient.addUploadedFileItem(fileToBeUpload);
String attachmentName = fileToBeUpload.getDataHandler().getName();
String contentType = fileToBeUpload.getDataHandler().getContentType();
boolean isAdded = taskOperationClient.addAttachment(taskID, attachmentName, contentType, attachmentID);
String msg = "Your attachment has been uploaded successfully.";
if (!isAdded) {
throw new Exception("Attachment was added successfully with id:" + attachmentID + ". But the task " + "with id: " + taskID + " was not associated with it correctly.");
} else {
if (redirect != null && redirect.contains("humantask/basic_task_view.jsp")) {
// redirection is going to the carbon mgt console
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request, response, getContextRoot(request) + "/" + webContext + "/" + redirect);
} else if (redirect != null) {
// redirection exists, not to carbon mgt console
out.write(msg);
response.sendRedirect(redirect);
} else {
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request);
}
return true;
}
} catch (Exception ex) {
String errMsg = "File upload failed. Reason :" + ex.getLocalizedMessage();
log.error(errMsg, ex);
if (redirect != null) {
CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request, response, getContextRoot(request) + "/" + webContext + "/" + redirect);
} else {
CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request);
}
}
return false;
}
Aggregations