use of org.wso2.carbon.humantask.rendering.api.OutputType in project ballerina by ballerina-lang.
the class IterableAnalyzer method validateIterableContext.
public void validateIterableContext(IterableContext context) {
final Operation lastOperation = context.operations.getLast();
final BType expectedType = lastOperation.expectedType;
final BType outputType = lastOperation.resultType;
if (expectedType.tag == TypeTags.VOID && outputType.tag == TypeTags.VOID) {
context.resultType = symTable.noType;
return;
}
if (expectedType.tag == TypeTags.VOID) {
// This error already logged.
return;
}
if (expectedType == symTable.errType) {
context.resultType = symTable.errType;
return;
}
if (outputType.tag == TypeTags.VOID) {
dlog.error(lastOperation.pos, DiagnosticCode.DOES_NOT_RETURN_VALUE, lastOperation.kind);
context.resultType = symTable.errType;
return;
}
// Calculate expected type, if this is an chained iterable operation.
if (outputType.tag == TypeTags.INTERMEDIATE_COLLECTION) {
BIntermediateCollectionType collectionType = (BIntermediateCollectionType) outputType;
final BTupleType tupleType = collectionType.tupleType;
if (expectedType.tag == TypeTags.ARRAY && tupleType.tupleTypes.size() == 1) {
// Convert result into an array.
context.resultType = new BArrayType(tupleType.tupleTypes.get(0));
return;
} else if (expectedType.tag == TypeTags.MAP && tupleType.tupleTypes.size() == 2 && tupleType.tupleTypes.get(0).tag == TypeTags.STRING) {
// Convert result into a map.
context.resultType = new BMapType(TypeTags.MAP, tupleType.tupleTypes.get(1), null);
return;
} else if (expectedType.tag == TypeTags.TABLE) {
// 3. Whether the returned struct is compatible with the constraint struct of the expected type(table)
if (tupleType.getTupleTypes().size() == 1 && tupleType.getTupleTypes().get(0).tag == TypeTags.STRUCT && types.isAssignable(tupleType.getTupleTypes().get(0), ((BTableType) expectedType).constraint)) {
context.resultType = symTable.tableType;
} else {
context.resultType = types.checkType(lastOperation.pos, outputType, ((BTableType) expectedType).constraint, DiagnosticCode.INCOMPATIBLE_TYPES);
}
return;
} else if (expectedType.tag == TypeTags.ANY) {
context.resultType = symTable.errType;
dlog.error(lastOperation.pos, DiagnosticCode.ITERABLE_RETURN_TYPE_MISMATCH, lastOperation.kind);
return;
} else if (expectedType.tag == TypeTags.NONE) {
context.resultType = symTable.noType;
return;
}
}
// Validate compatibility with calculated and expected type.
context.resultType = types.checkType(lastOperation.pos, outputType, expectedType, DiagnosticCode.INCOMPATIBLE_TYPES);
}
use of org.wso2.carbon.humantask.rendering.api.OutputType in project carbon-business-process by wso2.
the class HTRenderingApiImpl method getRenderingOutputElements.
/**
* Function to retrieve output rendering elements
*
* @param taskIdentifier interested task identifier
* @return set of output renderings wrapped within OutputType
* @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 xml content in the input source is invalid
* @throws IllegalOperationFault
* @throws IllegalAccessFault
* @throws IllegalStateFault
* @throws XPathExpressionException If error occurred while xpath evaluation
* @throws GetRenderingsFaultException If unable to find unique id for the wso2:output rendering element
*/
private OutputType getRenderingOutputElements(URI taskIdentifier) throws IllegalArgumentFault, IOException, SAXException, IllegalOperationFault, IllegalAccessFault, IllegalStateFault, XPathExpressionException, GetRenderingsFaultException {
QName renderingType = new QName(htRenderingNS, "output", "wso2");
String outputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType);
// create output element
OutputType renderingOutputs = null;
// check availability of output renderings
if (outputRenderings != null && outputRenderings.length() > 0) {
// parse output renderings
Element outputRenderingsElement = DOMUtils.stringToDOM(outputRenderings);
// retrieve output rendering elements
NodeList outputElementList = outputRenderingsElement.getElementsByTagNameNS(htRenderingNS, "element");
if (outputElementList != null && outputElementList.getLength() > 0) {
int outputElementNum = outputElementList.getLength();
OutputElementType[] outputElements = new OutputElementType[outputElementNum];
// TODO get task output message from the cache
// (if not in the cache) retrieve saved output using HumanTaskClientAPI
String savedOutputMsg = (String) taskOps.getOutput(taskIdentifier, null);
// Element to hold parsed saved output message
Element savedOutputElement = null;
if (savedOutputMsg != null && savedOutputMsg.length() > 0) {
savedOutputElement = DOMUtils.stringToDOM(savedOutputMsg);
}
for (int i = 0; i < outputElementNum; i++) {
Element tempElement = (Element) outputElementList.item(i);
if (tempElement.hasAttribute("id")) {
// Retrieve element data
String elementID = tempElement.getAttribute("id");
String label = tempElement.getElementsByTagNameNS(htRenderingNS, "label").item(0).getTextContent();
String xpath = tempElement.getElementsByTagNameNS(htRenderingNS, "xpath").item(0).getTextContent();
String defaultValue = tempElement.getElementsByTagNameNS(htRenderingNS, "default").item(0).getTextContent();
// set the readOnly attribute if Exists, default false
String readOnly = "false";
if (tempElement.hasAttribute("readOnly")) {
readOnly = tempElement.getAttribute("readOnly");
}
// set element data in the response message
outputElements[i] = new OutputElementType();
// set ID
outputElements[i].setId(elementID);
// set label
outputElements[i].setLabel(label);
// set xpath
outputElements[i].setXpath(xpath);
// set value
Element valueElement = (Element) tempElement.getElementsByTagNameNS(htRenderingNS, "value").item(0);
outputElements[i].setValue(createOutRenderElementValue(valueElement));
if (readOnly.equals("true")) {
outputElements[i].setReadOnly(true);
} else {
outputElements[i].setReadOnly(false);
}
if (savedOutputElement != null) {
// resolve default value
String savedOutMessageValue = evaluateXPath(xpath, savedOutputElement, outputRenderingsElement.getOwnerDocument());
if (savedOutMessageValue == null) {
outputElements[i].set_default(defaultValue);
} else {
outputElements[i].set_default(savedOutMessageValue);
}
} else {
// add default value specified in the HT rendering definition
outputElements[i].set_default(defaultValue);
}
} else {
// no unique id for the element
log.error("Unable to find unique id for the wso2:output rendering element");
throw new GetRenderingsFaultException("Unable to find unique id for the wso2:output rendering element");
}
}
renderingOutputs = new OutputType();
renderingOutputs.setElement(outputElements);
}
}
return renderingOutputs;
}
Aggregations