Search in sources :

Example 1 with InputType

use of org.wso2.carbon.humantask.rendering.api.InputType in project carbon-business-process by wso2.

the class HTRenderingApiImpl method getRenderingInputElements.

/**
 * @param taskIdentifier : interested task identifier
 * @return set of input renderings wrapped within InputType
 * @throws IllegalArgumentFault : error occured while retrieving renderings from task definition
 * @throws IOException          If an error occurred while reading from the input source
 * @throws SAXException         If the content in the input source is invalid
 */
private InputType getRenderingInputElements(URI taskIdentifier) throws IllegalArgumentFault, IOException, SAXException, IllegalOperationFault, IllegalAccessFault, IllegalStateFault, XPathExpressionException {
    // TODO Chaching : check cache against task id for input renderings
    QName renderingType = new QName(htRenderingNS, "input", "wso2");
    String inputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType);
    // Create input element
    InputType renderingInputs = null;
    // check availability of input renderings
    if (inputRenderings != null && inputRenderings.length() > 0) {
        // parse input renderings
        Element inputRenderingsElement = DOMUtils.stringToDOM(inputRenderings);
        // retrieve input elements
        NodeList inputElementList = inputRenderingsElement.getElementsByTagNameNS(htRenderingNS, "element");
        Element taskInputMsgElement = DOMUtils.stringToDOM((String) taskOps.getInput(taskIdentifier, null));
        if (inputElementList != null && inputElementList.getLength() > 0) {
            // hold number of input element
            int inputElementNum = inputElementList.getLength();
            InputElementType[] inputElements = new InputElementType[inputElementNum];
            for (int i = 0; i < inputElementNum; i++) {
                Element tempElement = (Element) inputElementList.item(i);
                String label = tempElement.getElementsByTagNameNS(htRenderingNS, "label").item(0).getTextContent();
                String value = tempElement.getElementsByTagNameNS(htRenderingNS, "value").item(0).getTextContent();
                // if the value starts with '/' then considered as an xpath and evaluate over received Input Message
                if (value.startsWith("/") && taskInputMsgElement != null) {
                    // value represents xpath. evaluate against the input message
                    String xpathValue = evaluateXPath(value, taskInputMsgElement, inputRenderingsElement.getOwnerDocument());
                    if (xpathValue != null) {
                        value = xpathValue;
                    }
                }
                inputElements[i] = new InputElementType();
                inputElements[i].setLabel(label);
                inputElements[i].setValue(value);
            }
            renderingInputs = new InputType();
            renderingInputs.setElement(inputElements);
        // TODO cache renderingInputs against task instance id
        }
    }
    return renderingInputs;
}
Also used : InputElementType(org.wso2.carbon.humantask.rendering.api.InputElementType) InputType(org.wso2.carbon.humantask.rendering.api.InputType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList)

Example 2 with InputType

use of org.wso2.carbon.humantask.rendering.api.InputType in project siddhi by wso2.

the class ConvertFunctionExecutor method init.

@Override
public void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext) {
    if (attributeExpressionExecutors.length != 2) {
        throw new SiddhiAppValidationException("convert() must have at 2 parameters, attribute and to be " + "converted type");
    }
    inputType = attributeExpressionExecutors[0].getReturnType();
    if (inputType == Attribute.Type.OBJECT) {
        throw new SiddhiAppValidationException("1st parameter of convert() cannot be 'object' as " + "it's not supported, it has to be either of (STRING, " + "INT, LONG, FLOAT, DOUBLE, BOOL), but found " + attributeExpressionExecutors[0].getReturnType());
    }
    if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("2nd parameter of convert() must be 'string' have constant " + "value either of (STRING, INT, LONG, FLOAT, DOUBLE, " + "BOOL), but found " + attributeExpressionExecutors[0].getReturnType());
    }
    if (!(attributeExpressionExecutors[1] instanceof ConstantExpressionExecutor)) {
        throw new SiddhiAppValidationException("2nd parameter of convert() must have constant value either " + "of (STRING, INT, LONG, FLOAT, DOUBLE, BOOL), but found " + "a variable expression");
    }
    String type = (String) attributeExpressionExecutors[1].execute(null);
    if (Attribute.Type.STRING.toString().equalsIgnoreCase(type)) {
        returnType = Attribute.Type.STRING;
    } else if (Attribute.Type.BOOL.toString().equalsIgnoreCase(type)) {
        returnType = Attribute.Type.BOOL;
    } else if (Attribute.Type.DOUBLE.toString().equalsIgnoreCase(type)) {
        returnType = Attribute.Type.DOUBLE;
    } else if (Attribute.Type.FLOAT.toString().equalsIgnoreCase(type)) {
        returnType = Attribute.Type.FLOAT;
    } else if (Attribute.Type.INT.toString().equalsIgnoreCase(type)) {
        returnType = Attribute.Type.INT;
    } else if (Attribute.Type.LONG.toString().equalsIgnoreCase(type)) {
        returnType = Attribute.Type.LONG;
    } else {
        throw new SiddhiAppValidationException("2nd parameter of convert() must have value either of " + "(STRING, INT, LONG, FLOAT, DOUBLE, BOOL), but found '" + type + "'");
    }
}
Also used : SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor)

Example 3 with InputType

use of org.wso2.carbon.humantask.rendering.api.InputType in project ballerina by ballerina-lang.

the class IterableCodeDesugar method generateStreamingIteratorBlock.

private void generateStreamingIteratorBlock(IterableContext ctx, BLangFunction funcNode, LinkedList<Operation> streamOperations) {
    final Operation firstOperation = ctx.getFirstOperation();
    final DiagnosticPos pos = firstOperation.pos;
    // Generate streaming based function Body.
    if (isReturningIteratorFunction(ctx)) {
        if (ctx.resultType.tag != TypeTags.TABLE) {
            // This should be the select operation. No need of a count variable.
            createCounterVarDefStmt(funcNode, ctx);
        }
        createResultVarDefStmt(funcNode, ctx);
        ctx.iteratorResultVariables = createIteratorResultVariables(ctx, streamOperations.getLast().retVar, funcNode);
    } else {
        ctx.iteratorResultVariables = Collections.emptyList();
    }
    // Create variables required.
    final List<BLangVariable> foreachVariables = createForeachVariables(ctx, ctx.getFirstOperation().argVar, funcNode);
    // Define all undefined variables.
    defineRequiredVariables(ctx, streamOperations, foreachVariables, funcNode);
    // Generate foreach iteration.
    final BLangForeach foreachStmt = ASTBuilderUtil.createForeach(pos, funcNode.body, ASTBuilderUtil.createVariableRef(pos, ctx.collectionVar.symbol), ASTBuilderUtil.createVariableRefList(pos, foreachVariables), ctx.foreachTypes);
    if (foreachVariables.size() > 1) {
        // Create tuple, for lambda invocation.
        final BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(pos, foreachStmt.body);
        assignmentStmt.declaredWithVar = true;
        assignmentStmt.varRefs.add(ASTBuilderUtil.createVariableRef(pos, ctx.getFirstOperation().argVar.symbol));
        final BLangBracedOrTupleExpr tupleExpr = (BLangBracedOrTupleExpr) TreeBuilder.createBracedOrTupleExpression();
        for (BLangVariable foreachVariable : foreachVariables) {
            tupleExpr.expressions.add(ASTBuilderUtil.createVariableRef(pos, foreachVariable.symbol));
        }
        tupleExpr.isBracedExpr = foreachVariables.size() == 1;
        tupleExpr.type = new BTupleType(getTupleTypeList(ctx.getFirstOperation().inputType));
        assignmentStmt.expr = tupleExpr;
    }
    // Generate Operations related
    ctx.operations.forEach(operation -> generateOperationCode(foreachStmt.body, operation));
    // Generate aggregator and result
    if (isReturningIteratorFunction(ctx)) {
        if (ctx.iteratorResultVariables.size() > 1) {
            // Destructure return Values.
            final BLangTupleDestructure tupleAssign = (BLangTupleDestructure) TreeBuilder.createTupleDestructureStatementNode();
            tupleAssign.pos = pos;
            tupleAssign.declaredWithVar = true;
            foreachStmt.body.addStatement(tupleAssign);
            tupleAssign.expr = ASTBuilderUtil.createVariableRef(pos, ctx.getLastOperation().retVar.symbol);
            tupleAssign.varRefs.addAll(ASTBuilderUtil.createVariableRefList(pos, ctx.iteratorResultVariables));
        }
        generateAggregator(foreachStmt.body, ctx);
        generateFinalResult(funcNode.body, ctx);
    }
    final BLangReturn returnStmt = ASTBuilderUtil.createReturnStmt(firstOperation.pos, funcNode.body);
    if (isReturningIteratorFunction(ctx)) {
        returnStmt.addExpression(ASTBuilderUtil.createVariableRef(pos, ctx.resultVar.symbol));
    }
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) BTupleType(org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType) Operation(org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation) BLangTupleDestructure(org.wso2.ballerinalang.compiler.tree.statements.BLangTupleDestructure) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangBracedOrTupleExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBracedOrTupleExpr)

Aggregations

QName (javax.xml.namespace.QName)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1 Operation (org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation)1 BTupleType (org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1 BLangBracedOrTupleExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangBracedOrTupleExpr)1 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)1 BLangForeach (org.wso2.ballerinalang.compiler.tree.statements.BLangForeach)1 BLangReturn (org.wso2.ballerinalang.compiler.tree.statements.BLangReturn)1 BLangTupleDestructure (org.wso2.ballerinalang.compiler.tree.statements.BLangTupleDestructure)1 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)1 InputElementType (org.wso2.carbon.humantask.rendering.api.InputElementType)1 InputType (org.wso2.carbon.humantask.rendering.api.InputType)1 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)1 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)1