Search in sources :

Example 16 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.

the class PeopleActivity method invoke.

public String invoke(ExtensionContext extensionContext) throws FaultException {
    BPELMessageContext taskMessageContext = new BPELMessageContext(hiWSDL);
    UUID messageID = null;
    int tenantId = B4PServiceComponent.getBPELServer().getMultiTenantProcessStore().getTenantId(processId);
    String tenantDomain = null;
    try {
        tenantDomain = B4PContentHolder.getInstance().getRealmService().getTenantManager().getDomain(tenantId);
    } catch (UserStoreException e) {
        log.error(" Cannot find the tenant domain " + e.toString());
    }
    if (tenantDomain == null) {
        tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    }
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
    try {
        // Setting the attachment id attachmentIDList
        List<Long> attachmentIDList = extractAttachmentIDsToBeSentToHumanTask(extensionContext, taskMessageContext);
        taskMessageContext.setOperationName(getOperationName());
        SOAPHelper soapHelper = new SOAPHelper(getBinding(), getSoapFactory(), isRPC);
        MessageContext messageContext = new MessageContext();
        /*
            Adding attachment ID list as a method input to createSoapRequest makes no sense.
            Have to fix. Here we can't embed attachments in MessageContext, as we have only a
            list of attachment ids.
            */
        soapHelper.createSoapRequest(messageContext, (Element) extensionContext.readVariable(inputVarName), getOperation(extensionContext), attachmentIDList);
        // Coordination Context and skipable attribute is only valid for a Task.
        if (InteractionType.TASK.equals(activityType)) {
            // Note: If registration service is not enabled, we don't need to send coor-context.
            if (CoordinationConfiguration.getInstance().isHumantaskCoordinationEnabled() && CoordinationConfiguration.getInstance().isRegistrationServiceEnabled()) {
                messageID = UUID.randomUUID();
                soapHelper.addCoordinationContext(messageContext, messageID.toString(), getRegistrationServiceURL());
            }
            // Adding HumanTask Context overriding attributes.
            soapHelper.addOverridingHumanTaskAttributes(messageContext, isSkipable);
        }
        taskMessageContext.setInMessageContext(messageContext);
        taskMessageContext.setPort(getServicePort());
        taskMessageContext.setService(getServiceName());
        taskMessageContext.setRPCStyleOperation(isRPC);
        taskMessageContext.setTwoWay(isTwoWay);
        taskMessageContext.setSoapFactoryForCurrentMessageFlow(getSoapFactory());
        taskMessageContext.setWsdlBindingForCurrentMessageFlow(getBinding());
        taskMessageContext.setUep(getUnifiedEndpoint());
        taskMessageContext.setCaller(processId.getLocalPart());
        AxisServiceUtils.invokeService(taskMessageContext, getConfigurationContext());
    } catch (AxisFault axisFault) {
        log.error(axisFault, axisFault);
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Error occurred while invoking service " + serviceName, axisFault);
    } catch (B4PCoordinationException coordinationFault) {
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Error occurred while generating Registration Service URL" + serviceName, coordinationFault);
    }
    if (taskMessageContext.getFaultMessageContext() != null || taskMessageContext.getOutMessageContext().isFault()) {
        MessageContext faultContext = taskMessageContext.getFaultMessageContext() != null ? taskMessageContext.getFaultMessageContext() : taskMessageContext.getOutMessageContext();
        log.warn("SOAP Fault: " + faultContext.getEnvelope().toString());
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, faultContext.getEnvelope().toString());
    }
    String taskID = SOAPHelper.parseResponseFeedback(taskMessageContext.getOutMessageContext().getEnvelope().getBody());
    // Ignore Notifications, since we are ignore coordination context for notification.
    if (CoordinationConfiguration.getInstance().isHumantaskCoordinationEnabled() && InteractionType.TASK.equals(activityType)) {
        Long instanceID = extensionContext.getProcessId();
        if (CoordinationConfiguration.getInstance().isRegistrationServiceEnabled()) {
            try {
                // Already coordinated with Registration service.
                updateCoordinationData(messageID.toString(), Long.toString(instanceID), taskID);
            } catch (Exception e) {
                log.error("Error occurred while updating humantask coordination data.", e);
            }
        } else {
            // Handler URL by manually.
            try {
                messageID = UUID.randomUUID();
                String protocolHandlerURL = generateTaskProtocolHandlerURL(taskMessageContext);
                if (log.isDebugEnabled()) {
                    log.debug("Generated Protocol Handler URL : " + protocolHandlerURL);
                }
                createCoordinationData(messageID.toString(), protocolHandlerURL, Long.toString(instanceID), taskID);
            } catch (Exception e) {
                log.error("Error occurred while creating humantask coordination data for coordinated task.", e);
            }
        }
    }
    return taskID;
}
Also used : AxisFault(org.apache.axis2.AxisFault) BPELMessageContext(org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext) WSDL11Endpoint(org.apache.ode.bpel.epr.WSDL11Endpoint) UnifiedEndpoint(org.wso2.carbon.unifiedendpoint.core.UnifiedEndpoint) FaultException(org.apache.ode.bpel.common.FaultException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) B4PCoordinationException(org.wso2.carbon.bpel.b4p.coordination.B4PCoordinationException) SocketException(java.net.SocketException) SOAPHelper(org.wso2.carbon.bpel.b4p.utils.SOAPHelper) FaultException(org.apache.ode.bpel.common.FaultException) B4PCoordinationException(org.wso2.carbon.bpel.b4p.coordination.B4PCoordinationException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) BPELMessageContext(org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext) MessageContext(org.apache.axis2.context.MessageContext) UUID(java.util.UUID)

Example 17 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.

the class WorkflowTaskService method createSimpleAttachment.

protected AttachmentResponse createSimpleAttachment(AttachmentRequest attachmentRequest, Task task) {
    if (attachmentRequest.getName() == null) {
        throw new ActivitiIllegalArgumentException("Attachment name is required.");
    }
    TaskService taskService = BPMNOSGIService.getTaskService();
    Attachment createdAttachment = taskService.createAttachment(attachmentRequest.getType(), task.getId(), task.getProcessInstanceId(), attachmentRequest.getName(), attachmentRequest.getDescription(), attachmentRequest.getExternalUrl());
    return new RestResponseFactory().createAttachmentResponse(createdAttachment, uriInfo.getBaseUri().toString());
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Example 18 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.

the class WorkflowTaskService method getAttachments.

@GET
@Path("/{taskId}/attachments")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getAttachments(@PathParam("taskId") String taskId) {
    List<AttachmentResponse> result = new ArrayList<AttachmentResponse>();
    HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
    TaskService taskService = BPMNOSGIService.getTaskService();
    RestResponseFactory restResponseFactory = new RestResponseFactory();
    String baseUri = uriInfo.getBaseUri().toString();
    for (Attachment attachment : taskService.getProcessInstanceAttachments(task.getProcessInstanceId())) {
        result.add(restResponseFactory.createAttachmentResponse(attachment, baseUri));
    }
    AttachmentResponseCollection attachmentResponseCollection = new AttachmentResponseCollection();
    attachmentResponseCollection.setAttachmentResponseList(result);
    return Response.ok().entity(attachmentResponseCollection).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 19 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.

the class AttachmentServiceComponent method registerAttachmentDownloadServlet.

/**
 * Register the Servlet used to download attachments
 */
private void registerAttachmentDownloadServlet() {
    HttpServlet attachmentDownloadServlet = new AttachmentDownloadServlet();
    Dictionary redirectorParams = new Hashtable(1);
    redirectorParams.put("url-pattern", "/attachment-mgt/download");
    // redirectorParams.put("url-pattern", "/t/carbon.super" + AttachmentMgtConfigurationConstants.ATTACHMENT_DOWNLOAD_SERVELET_URL_PATTERN);
    bundleContext.registerService(Servlet.class.getName(), attachmentDownloadServlet, redirectorParams);
    if (log.isDebugEnabled()) {
        log.debug("Attachment Download Servlet registered.");
    }
}
Also used : Dictionary(java.util.Dictionary) HttpServlet(javax.servlet.http.HttpServlet) Hashtable(java.util.Hashtable) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) AttachmentDownloadServlet(org.wso2.carbon.attachment.mgt.servlet.AttachmentDownloadServlet) AttachmentDownloadServlet(org.wso2.carbon.attachment.mgt.servlet.AttachmentDownloadServlet)

Example 20 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.

the class AttachmentMgtDAOBasicOperationsTest method createAttachment.

/**
 * Creates an attachment stub bean which is consumable by the Back-End server interface
 * {@link org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtServiceSkeletonInterface}
 *
 * @return an attachment stub bean which is consumable by the Back-End server interface
 */
private TAttachment createAttachment() {
    dummyAttachment = new TAttachment();
    dummyAttachment.setName("DummyName");
    dummyAttachment.setContentType("DummyContentType");
    dummyAttachment.setCreatedBy("DummyUser");
    DataHandler handler = new DataHandler(new FileDataSource(new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "dbConfig.xml")));
    dummyAttachment.setContent(handler);
    return dummyAttachment;
}
Also used : TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment) FileDataSource(javax.activation.FileDataSource) DataHandler(javax.activation.DataHandler) File(java.io.File)

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