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;
}
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 + "'");
}
}
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));
}
}
Aggregations