Search in sources :

Example 26 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.Operation in project carbon-business-process by wso2.

the class HumanTaskPackageManagementSkeleton method listTasksInPackage.

/**
 * Lists the tasks in the given package name.
 *
 * @param packageName : The name of the package to list task definitions.
 * @return : The Task_type0 array containing the task definition information.
 */
public Task_type0[] listTasksInPackage(String packageName) throws PackageManagementException {
    if (StringUtils.isEmpty(packageName)) {
        throw new IllegalArgumentException("The provided package name is empty!");
    }
    try {
        List<SimpleTaskDefinitionInfo> taskDefsInPackage = getTenantTaskStore().getTaskConfigurationInfoListForPackage(packageName);
        Task_type0[] taskDefArray = new Task_type0[taskDefsInPackage.size()];
        int i = 0;
        for (SimpleTaskDefinitionInfo taskDefinitionInfo : taskDefsInPackage) {
            taskDefArray[i] = createTaskTypeObject(taskDefinitionInfo);
            i++;
        }
        return taskDefArray;
    } catch (Exception ex) {
        String errMsg = "listTasksInPackage operation failed";
        log.error(errMsg, ex);
        throw new PackageManagementException(errMsg, ex);
    }
}
Also used : SimpleTaskDefinitionInfo(org.wso2.carbon.humantask.core.deployment.SimpleTaskDefinitionInfo) PackageManagementException(org.wso2.carbon.humantask.skeleton.mgt.services.PackageManagementException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PackageManagementException(org.wso2.carbon.humantask.skeleton.mgt.services.PackageManagementException)

Example 27 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.Operation in project carbon-business-process by wso2.

the class CallBackServiceImpl method sendProtocolMessage.

private void sendProtocolMessage(long taskID, String headerValue, String value) throws AxisFault {
    final MessageContext mctx = new MessageContext();
    ServiceInvocationContext invocationContext = new ServiceInvocationContext();
    invocationContext.setInMessageContext(mctx);
    invocationContext.setUep(uep);
    invocationContext.setService(serviceName);
    invocationContext.setPort(portName);
    invocationContext.setCaller(taskName.getLocalPart());
    invocationContext.setWsdlBindingForCurrentMessageFlow(binding);
    invocationContext.setOperationName(operation);
    if (mctx.getEnvelope() == null) {
        mctx.setEnvelope(getSoapFactory().createSOAPEnvelope());
    }
    if (mctx.getEnvelope().getBody() == null) {
        getSoapFactory().createSOAPBody(mctx.getEnvelope());
    }
    if (mctx.getEnvelope().getHeader() == null) {
        getSoapFactory().createSOAPHeader(mctx.getEnvelope());
    }
    // Creating Dummy Element
    // Extracting MessageName
    List bindingOperations = binding.getBindingOperations();
    String messageName = "";
    OMNamespace serviceNS = null;
    BindingOperation oper;
    for (int i = 0; i < bindingOperations.size(); i++) {
        oper = (BindingOperation) bindingOperations.get(i);
        if (operation.equals(oper.getName())) {
            Message message = oper.getOperation().getInput().getMessage();
            messageName = message.getQName().getLocalPart();
            for (Object ob : message.getParts().keySet()) {
                // Here we don't support RPC messages.
                Part part = (Part) message.getParts().get(ob);
                serviceNS = OMAbstractFactory.getSOAP11Factory().createOMNamespace(part.getElementName().getNamespaceURI(), part.getElementName().getPrefix());
                break;
            }
            break;
        }
    }
    OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(messageName, serviceNS);
    mctx.getEnvelope().getBody().addChild(payload);
    OMNamespace htpNS = OMAbstractFactory.getSOAP11Factory().createOMNamespace(HumanTaskConstants.HT_PROTOCOL_NAMESPACE, HumanTaskConstants.HT_PROTOCOL_DEFAULT_PREFIX);
    SOAPHeaderBlock protocolHeader = mctx.getEnvelope().getHeader().addHeaderBlock(headerValue, htpNS);
    protocolHeader.setText(value);
    protocolHeader.addAttribute(HumanTaskConstants.B4P_CORRELATION_HEADER_ATTRIBUTE, Long.toString(taskID), htpNS);
    OMNamespace b4pNS = OMAbstractFactory.getSOAP11Factory().createOMNamespace(HumanTaskConstants.B4P_NAMESPACE, "b4p");
    SOAPHeaderBlock header = mctx.getEnvelope().getHeader().addHeaderBlock(HumanTaskConstants.B4P_CORRELATION_HEADER, b4pNS);
    header.addAttribute(HumanTaskConstants.B4P_CORRELATION_HEADER_ATTRIBUTE, Long.toString(taskID), b4pNS);
    AxisServiceUtils.invokeService(invocationContext, HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(tenantId).getConfigContext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) List(java.util.List) OMElement(org.apache.axiom.om.OMElement) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) MessageContext(org.apache.axis2.context.MessageContext) ServiceInvocationContext(org.wso2.carbon.humantask.core.integration.utils.ServiceInvocationContext) UnifiedEndpoint(org.wso2.carbon.unifiedendpoint.core.UnifiedEndpoint)

Example 28 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.Operation in project carbon-business-process by wso2.

the class CallBackServiceImpl method invoke.

@Override
public void invoke(OMElement payload, long taskId) throws AxisFault {
    final MessageContext mctx = new MessageContext();
    ServiceInvocationContext invocationContext = new ServiceInvocationContext();
    invocationContext.setInMessageContext(mctx);
    invocationContext.setUep(uep);
    invocationContext.setService(serviceName);
    invocationContext.setPort(portName);
    invocationContext.setCaller(taskName.getLocalPart());
    invocationContext.setWsdlBindingForCurrentMessageFlow(binding);
    invocationContext.setOperationName(operation);
    if (mctx.getEnvelope() == null) {
        mctx.setEnvelope(getSoapFactory().createSOAPEnvelope());
    }
    if (mctx.getEnvelope().getBody() == null) {
        getSoapFactory().createSOAPBody(mctx.getEnvelope());
    }
    if (mctx.getEnvelope().getHeader() == null) {
        getSoapFactory().createSOAPHeader(mctx.getEnvelope());
    }
    mctx.getEnvelope().getBody().addChild(payload);
    OMNamespace ns = OMAbstractFactory.getSOAP11Factory().createOMNamespace(HumanTaskConstants.B4P_NAMESPACE, "b4p");
    SOAPHeaderBlock header = mctx.getEnvelope().getHeader().addHeaderBlock(HumanTaskConstants.B4P_CORRELATION_HEADER, ns);
    header.addAttribute(HumanTaskConstants.B4P_CORRELATION_HEADER_ATTRIBUTE, Long.toString(taskId), ns);
    AxisServiceUtils.invokeService(invocationContext, HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(tenantId).getConfigContext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) MessageContext(org.apache.axis2.context.MessageContext) ServiceInvocationContext(org.wso2.carbon.humantask.core.integration.utils.ServiceInvocationContext)

Example 29 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.Operation in project carbon-business-process by wso2.

the class AttachmentMgtDAOFactoryImpl method removeAttachment.

@Override
public boolean removeAttachment(final String id) throws AttachmentMgtException {
    try {
        boolean isRemoved = false;
        isRemoved = jobExecutor.execTransaction(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                Query query = entityManager.createQuery("DELETE FROM org.wso2.carbon.attachment.mgt.core.dao.impl" + ".jpa.openjpa.entity.AttachmentDAOImpl x WHERE x.id = " + ":attachmentID");
                query.setParameter("attachmentID", Long.parseLong(id));
                int noOfRowsUpdated = query.executeUpdate();
                // entityManager.remove(getAttachmentInfo(id));
                if (noOfRowsUpdated == 1) {
                    return true;
                } else {
                    return false;
                }
            }
        });
        return isRemoved;
    } catch (Exception e) {
        String errorMsg = "org.wso2.carbon.attachment.mgt.core.dao.impl.hibernate.AttachmentMgtDAOFactoryImpl.removeAttachment operation failed. " + "Reason: " + e.getLocalizedMessage();
        log.error(errorMsg, e);
        throw new AttachmentMgtException(errorMsg, e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) Query(javax.persistence.Query) Callable(java.util.concurrent.Callable) AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)

Example 30 with Operation

use of org.wso2.carbon.apimgt.api.doc.model.Operation in project carbon-business-process by wso2.

the class AttachmentMgtDAOFactoryImpl method getAttachmentInfoFromURL.

@Override
public AttachmentDAO getAttachmentInfoFromURL(final String attachmentURI) throws AttachmentMgtException {
    try {
        AttachmentDAO resultantDAO = jobExecutor.execTransaction(new Callable<AttachmentDAO>() {

            @Override
            public AttachmentDAO call() throws Exception {
                Query query = entityManager.createQuery("SELECT x FROM org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.entity.AttachmentDAOImpl AS x WHERE x.url = :attachmentURI");
                query.setParameter("attachmentURI", attachmentURI);
                List<AttachmentDAO> daoList = query.getResultList();
                if (daoList.isEmpty()) {
                    throw new AttachmentMgtException("Attachment not found for the uri:" + attachmentURI);
                } else if (daoList.size() != 1) {
                    String errorMsg = "There exist more than one attachment for the attachment URI:" + attachmentURI + ". org" + ".wso2.carbon.attachment.mgt.util.URLGeneratorUtil.generateURL method has generated " + "similar uris for different attachments. This has caused a major inconsistency for " + "attachment management.";
                    log.fatal(errorMsg);
                    throw new AttachmentMgtException(errorMsg);
                } else {
                    return daoList.get(0);
                }
            }
        });
        return resultantDAO;
    } catch (Exception e) {
        String errorMsg = "org.wso2.carbon.attachment.mgt.core.dao.impl.hibernate.AttachmentMgtDAOFactoryImpl.getAttachmentInfoFromURL operation failed. " + "Reason: " + e.getLocalizedMessage();
        log.error(errorMsg, e);
        throw new AttachmentMgtException(errorMsg, e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) AttachmentDAO(org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO) Query(javax.persistence.Query) List(java.util.List) AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)79 HashMap (java.util.HashMap)55 ArrayList (java.util.ArrayList)43 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)42 Test (org.testng.annotations.Test)34 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)29 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)29 Map (java.util.Map)28 IOException (java.io.IOException)23 API (org.wso2.carbon.apimgt.api.model.API)22 List (java.util.List)20 JSONObject (org.json.simple.JSONObject)20 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)20 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)19 LinkedHashMap (java.util.LinkedHashMap)18 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)18 OperationPolicyData (org.wso2.carbon.apimgt.api.model.OperationPolicyData)18 APIInfo (org.wso2.carbon.apimgt.api.model.APIInfo)17 Connection (java.sql.Connection)16 PreparedStatement (java.sql.PreparedStatement)16