Search in sources :

Example 11 with Operation

use of org.wso2.carbon.device.mgt.common.operation.mgt.Operation in project ballerina by ballerina-lang.

the class SignatureHelpUtil method getSignatureInfoModel.

/**
 * Get the required signature information filled model.
 *
 * @param bInvokableSymbol                  Invokable symbol
 * @param signatureContext                  Signature operation context
 * @return {@link SignatureInfoModel}       SignatureInfoModel containing signature information
 */
private static SignatureInfoModel getSignatureInfoModel(BInvokableSymbol bInvokableSymbol, TextDocumentServiceContext signatureContext) {
    Map<String, String> paramDescMap = new HashMap<>();
    SignatureInfoModel signatureInfoModel = new SignatureInfoModel();
    List<ParameterInfoModel> paramModels = new ArrayList<>();
    String functionName = signatureContext.get(SignatureKeys.CALLABLE_ITEM_NAME);
    CompilerContext compilerContext = signatureContext.get(DocumentServiceKeys.COMPILER_CONTEXT_KEY);
    BLangPackage bLangPackage = signatureContext.get(DocumentServiceKeys.LS_PACKAGE_CACHE_KEY).findPackage(compilerContext, bInvokableSymbol.pkgID);
    BLangFunction blangFunction = bLangPackage.getFunctions().stream().filter(bLangFunction -> bLangFunction.getName().getValue().equals(functionName)).findFirst().orElse(null);
    if (!blangFunction.getDocumentationAttachments().isEmpty()) {
        // Get the first documentation attachment
        BLangDocumentation bLangDocumentation = blangFunction.getDocumentationAttachments().get(0);
        signatureInfoModel.setSignatureDescription(bLangDocumentation.documentationText.trim());
        bLangDocumentation.attributes.forEach(attribute -> {
            if (attribute.docTag.equals(DocTag.PARAM)) {
                paramDescMap.put(attribute.documentationField.getValue(), attribute.documentationText.trim());
            }
        });
    } else {
        // TODO: Should be deprecated in due course
        // Iterate over the attachments list and extract the attachment Description Map
        blangFunction.getAnnotationAttachments().forEach(annotationAttachment -> {
            BLangExpression expr = annotationAttachment.expr;
            if (expr instanceof BLangRecordLiteral) {
                List<BLangRecordLiteral.BLangRecordKeyValue> recordKeyValues = ((BLangRecordLiteral) expr).keyValuePairs;
                for (BLangRecordLiteral.BLangRecordKeyValue recordKeyValue : recordKeyValues) {
                    BLangExpression key = recordKeyValue.key.expr;
                    BLangExpression value = recordKeyValue.getValue();
                    if (key instanceof BLangSimpleVarRef && ((BLangSimpleVarRef) key).getVariableName().getValue().equals("value") && value instanceof BLangLiteral) {
                        String annotationValue = ((BLangLiteral) value).getValue().toString();
                        if (annotationAttachment.getAnnotationName().getValue().equals("Param")) {
                            String paramName = annotationValue.substring(0, annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD));
                            String annotationDesc = annotationValue.substring(annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD) + 1).trim();
                            paramDescMap.put(paramName, annotationDesc);
                        } else if (annotationAttachment.getAnnotationName().getValue().equals("Description")) {
                            signatureInfoModel.setSignatureDescription(annotationValue);
                        }
                    }
                }
            }
        });
    }
    bInvokableSymbol.getParameters().forEach(bVarSymbol -> {
        ParameterInfoModel parameterInfoModel = new ParameterInfoModel();
        parameterInfoModel.setParamType(bVarSymbol.getType().toString());
        parameterInfoModel.setParamValue(bVarSymbol.getName().getValue());
        parameterInfoModel.setDescription(paramDescMap.get(bVarSymbol.getName().getValue()));
        paramModels.add(parameterInfoModel);
    });
    signatureInfoModel.setParameterInfoModels(paramModels);
    return signatureInfoModel;
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) HashMap(java.util.HashMap) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) ArrayList(java.util.ArrayList) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 12 with Operation

use of org.wso2.carbon.device.mgt.common.operation.mgt.Operation in project ballerina by ballerina-lang.

the class SignatureHelpUtil method getSignatureInformation.

/**
 * Get the signature information for the given Ballerina function.
 *
 * @param bInvokableSymbol BLang Invokable symbol
 * @param signatureContext Signature operation context
 * @return {@link SignatureInformation}     Signature information for the function
 */
private static SignatureInformation getSignatureInformation(BInvokableSymbol bInvokableSymbol, TextDocumentServiceContext signatureContext) {
    List<ParameterInformation> parameterInformationList = new ArrayList<>();
    SignatureInformation signatureInformation = new SignatureInformation();
    SignatureInfoModel signatureInfoModel = getSignatureInfoModel(bInvokableSymbol, signatureContext);
    String functionName = bInvokableSymbol.getName().getValue();
    // Join the function parameters to generate the function's signature
    String paramsJoined = signatureInfoModel.getParameterInfoModels().stream().map(parameterInfoModel -> {
        // For each of the parameters, create a parameter info instance
        ParameterInformation parameterInformation = new ParameterInformation(parameterInfoModel.paramValue, parameterInfoModel.description);
        parameterInformationList.add(parameterInformation);
        return parameterInfoModel.toString();
    }).collect(Collectors.joining(", "));
    signatureInformation.setLabel(functionName + "(" + paramsJoined + ")");
    signatureInformation.setParameters(parameterInformationList);
    signatureInformation.setDocumentation(signatureInfoModel.signatureDescription);
    return signatureInformation;
}
Also used : Arrays(java.util.Arrays) HashMap(java.util.HashMap) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) Stack(java.util.Stack) ArrayList(java.util.ArrayList) DocTag(org.ballerinalang.model.elements.DocTag) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo) Map(java.util.Map) Position(org.eclipse.lsp4j.Position) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) DocumentServiceKeys(org.ballerinalang.langserver.DocumentServiceKeys) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) TextDocumentServiceContext(org.ballerinalang.langserver.TextDocumentServiceContext) ParameterInformation(org.eclipse.lsp4j.ParameterInformation) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) SignatureInformation(org.eclipse.lsp4j.SignatureInformation) Collectors(java.util.stream.Collectors) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Objects(java.util.Objects) List(java.util.List) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) UtilSymbolKeys(org.ballerinalang.langserver.common.UtilSymbolKeys) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) SignatureInformation(org.eclipse.lsp4j.SignatureInformation) ArrayList(java.util.ArrayList) ParameterInformation(org.eclipse.lsp4j.ParameterInformation)

Example 13 with Operation

use of org.wso2.carbon.device.mgt.common.operation.mgt.Operation in project wso2-dss-connectors by wso2-attic.

the class MongoDBDataSource method decodeQuery.

private Object[] decodeQuery(String query) throws DataServiceFault {
    int i1 = query.indexOf('.');
    if (i1 == -1) {
        throw new DataServiceFault("The MongoDB Collection not specified in the query '" + query + "'");
    }
    String collection = query.substring(0, i1).trim();
    int i2 = query.indexOf('(', i1);
    if (i2 == -1 || i2 - i1 <= 1) {
        throw new DataServiceFault("Invalid MongoDB operation in the query '" + query + "'");
    }
    String operation = query.substring(i1 + 1, i2).trim();
    int i3 = query.lastIndexOf(')');
    if (i3 == -1) {
        throw new DataServiceFault("Invalid MongoDB operation in the query '" + query + "'");
    }
    String opQuery = null;
    if (i3 - i2 > 1) {
        opQuery = query.substring(i2 + 1, i3).trim();
    }
    MongoOperation mongoOp = this.convertToMongoOp(operation);
    if (mongoOp == MongoOperation.UPDATE) {
        List<Object> result = new ArrayList<Object>();
        result.add(collection);
        result.add(mongoOp);
        result.addAll(parseInsertQuery(opQuery));
        return result.toArray();
    } else {
        return new Object[] { collection, mongoOp, this.checkAndCleanOpQuery(opQuery) };
    }
}
Also used : MongoOperation(org.wso2.dss.connectors.mongodb.MongoDBDSConstants.MongoOperation) DataServiceFault(org.wso2.carbon.dataservices.core.DataServiceFault) ArrayList(java.util.ArrayList) DBObject(com.mongodb.DBObject)

Example 14 with Operation

use of org.wso2.carbon.device.mgt.common.operation.mgt.Operation in project carbon-business-process by wso2.

the class AxisServiceUtils method createAxisService.

/**
 * Build the underlying Axis Service from Service QName and Port Name of interest using given WSDL
 * for BPEL document.
 * In the current implementation we are extracting service name from the soap:address' location property.
 * But specified port may not contain soap:adress instead it may contains http:address. We need to handle that
 * situation.
 *
 * @param axisConfiguration AxisConfiguration to which we should publish the service
 * @param processProxy      BPELProcessProxy
 * @return Axis Service build using WSDL, Service and Port
 * @throws org.apache.axis2.AxisFault on error
 */
public static AxisService createAxisService(AxisConfiguration axisConfiguration, BPELProcessProxy processProxy) throws AxisFault {
    QName serviceName = processProxy.getServiceName();
    String portName = processProxy.getPort();
    Definition wsdlDefinition = processProxy.getWsdlDefinition();
    ProcessConf processConfiguration = processProxy.getProcessConfiguration();
    if (log.isDebugEnabled()) {
        log.debug("Creating AxisService: Service=" + serviceName + " port=" + portName + " WSDL=" + wsdlDefinition.getDocumentBaseURI() + " BPEL=" + processConfiguration.getBpelDocument());
    }
    WSDL11ToAxisServiceBuilder serviceBuilder = createAxisServiceBuilder(processProxy);
    /**
     * Need to figure out a way to handle service name extractoin. According to my perspective extracting
     * the service name from the EPR is not a good decision. But we need to handle JMS case properly.
     * I am keeping JMS handling untouched until we figureout best solution.
     */
    /* String axisServiceName = extractServiceName(processConf, wsdlServiceName, portName);*/
    AxisService axisService = populateAxisService(processProxy, axisConfiguration, serviceBuilder);
    Iterator operations = axisService.getOperations();
    BPELMessageReceiver messageRec = new BPELMessageReceiver();
    /**
     * Set the corresponding BPELService to message receivers
     */
    messageRec.setProcessProxy(processProxy);
    while (operations.hasNext()) {
        AxisOperation operation = (AxisOperation) operations.next();
        // Setting WSDLAwareMessage Receiver even if operation has a message receiver specified.
        // This is to fix the issue when build service configuration using services.xml(Always RPCMessageReceiver
        // is set to operations).
        operation.setMessageReceiver(messageRec);
        axisConfiguration.getPhasesInfo().setOperationPhases(operation);
    }
    /**
     * TODO: JMS Destination handling.
     */
    return axisService;
}
Also used : AxisOperation(org.apache.axis2.description.AxisOperation) QName(javax.xml.namespace.QName) ProcessConf(org.apache.ode.bpel.iapi.ProcessConf) AxisService(org.apache.axis2.description.AxisService) Definition(javax.wsdl.Definition) Iterator(java.util.Iterator) WSDL11ToAxisServiceBuilder(org.apache.axis2.description.WSDL11ToAxisServiceBuilder) BPELMessageReceiver(org.wso2.carbon.bpel.core.ode.integration.axis2.receivers.BPELMessageReceiver)

Example 15 with Operation

use of org.wso2.carbon.device.mgt.common.operation.mgt.Operation in project carbon-business-process by wso2.

the class SOAPUtils method buildSoapDetail.

private static OMElement buildSoapDetail(final BPELMessageContext bpelMessageContext, final MessageExchange odeMessageContext) throws AxisFault {
    Element message = odeMessageContext.getResponse().getMessage();
    QName faultName = odeMessageContext.getFault();
    Operation operation = odeMessageContext.getOperation();
    SOAPFactory soapFactory = bpelMessageContext.getSoapFactoryForCurrentMessageFlow();
    if (faultName.getNamespaceURI() == null) {
        return toFaultDetail(message, soapFactory);
    }
    Fault f = operation.getFault(faultName.getLocalPart());
    if (f == null) {
        return toFaultDetail(message, soapFactory);
    }
    // For faults, there will be exactly one part.
    Part p = (Part) f.getMessage().getParts().values().iterator().next();
    if (p == null) {
        return toFaultDetail(message, soapFactory);
    }
    Element partEl = DOMUtils.findChildByName(message, new QName(null, p.getName()));
    if (partEl == null) {
        return toFaultDetail(message, soapFactory);
    }
    Element detail = DOMUtils.findChildByName(partEl, p.getElementName());
    if (detail == null) {
        return toFaultDetail(message, soapFactory);
    }
    return OMUtils.toOM(detail, soapFactory);
}
Also used : QName(javax.xml.namespace.QName) Part(javax.wsdl.Part) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) SOAPFault(org.apache.axiom.soap.SOAPFault) Fault(javax.wsdl.Fault) AxisFault(org.apache.axis2.AxisFault) BPELFault(org.wso2.carbon.bpel.core.ode.integration.BPELFault) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

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