Search in sources :

Example 56 with Attachment

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();
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)

Example 57 with Attachment

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();
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Example 58 with Attachment

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;
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler)

Example 59 with Attachment

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;
}
Also used : TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)

Example 60 with 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;
}
Also used : HumanTaskClientAPIServiceClient(org.wso2.carbon.humantask.ui.clients.HumanTaskClientAPIServiceClient) FileItemData(org.wso2.carbon.utils.FileItemData) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

HashMap (java.util.HashMap)11 AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)11 TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)10 DataHandler (javax.activation.DataHandler)9 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)9 ArrayList (java.util.ArrayList)8 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)8 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)8 File (java.io.File)7 Response (javax.ws.rs.core.Response)7 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)7 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)7 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)6 AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)6 BaseTaskService (org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)5 IOException (java.io.IOException)4 List (java.util.List)4 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)4 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)4 Attachment (org.wso2.carbon.attachment.mgt.api.attachment.Attachment)4