use of org.wso2.carbon.humantask.rendering.api.SetTaskOutputFaultException in project carbon-business-process by wso2.
the class HTRenderingApiImpl method setTaskOutput.
public SetTaskOutputResponse setTaskOutput(URI taskIdentifier, SetOutputValuesType values) throws SetTaskOutputFaultException {
// Retrieve task information
TaskDAO htTaskDAO;
try {
htTaskDAO = getTaskDAO(taskIdentifier);
} catch (Exception e) {
log.error("Error occurred while retrieving task data", e);
throw new SetTaskOutputFaultException(e);
}
QName taskName = QName.valueOf(htTaskDAO.getName());
// Check hash map for output message template
Element outputMsgTemplate = outputTemplates.get(taskName);
if (outputMsgTemplate == null) {
try {
// generate output message template
int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
HumanTaskBaseConfiguration htConf = HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(tenantID).getTaskConfiguration(taskName);
TaskConfiguration taskConf = (TaskConfiguration) htConf;
// retrieve response binding
Service callbackService = (Service) taskConf.getResponseWSDL().getServices().get(taskConf.getCallbackServiceName());
Port callbackPort = (Port) callbackService.getPorts().get(taskConf.getCallbackPortName());
String callbackBinding = callbackPort.getBinding().getQName().getLocalPart();
outputMsgTemplate = createSoapTemplate(taskConf.getResponseWSDL().getDocumentBaseURI(), taskConf.getResponsePortType().getLocalPart(), taskConf.getResponseOperation(), callbackBinding);
} catch (Exception e) {
log.error("Error occurred while output message template generation", e);
throw new SetTaskOutputFaultException("Unable to generate output message", e);
}
// add to the template HashMap
if (outputMsgTemplate != null) {
outputTemplates.put(taskName, outputMsgTemplate);
} else {
log.error("Unable to create output message template");
throw new SetTaskOutputFaultException("Unable to generate output message");
}
}
// update template with new values
try {
// TODO improve this section with caching
QName renderingType = new QName(htRenderingNS, "output", "wso2");
String outputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType);
SetOutputvalueType[] valueSet = values.getValue();
if (outputRenderings != null && valueSet.length > 0) {
Element outputRenderingsElement = DOMUtils.stringToDOM(outputRenderings);
// update elements in the template to create output xml
for (int i = 0; i < valueSet.length; i++) {
Element outElement = getOutputElementById(valueSet[i].getId(), outputRenderingsElement);
if (outElement != null) {
outputMsgTemplate = updateXmlByXpath(outputMsgTemplate, outElement.getElementsByTagNameNS(htRenderingNS, "xpath").item(0).getTextContent(), valueSet[i].getString(), outputRenderingsElement.getOwnerDocument());
}
}
} else {
log.error("Retrieving output renderings failed");
throw new SetTaskOutputFaultException("Retrieving output renderings failed");
}
// TODO what is this NCName?
taskOps.setOutput(taskIdentifier, new NCName("message"), DOMUtils.domToString(outputMsgTemplate));
} catch (IllegalArgumentFault illegalArgumentFault) {
// Error occurred while retrieving HT renderings and set output message
throw new SetTaskOutputFaultException(illegalArgumentFault);
} catch (SAXException e) {
log.error("Error occured while parsing output renderings", e);
throw new SetTaskOutputFaultException("Response message generation failed");
} catch (XPathExpressionException e) {
// Error occured while updating elements in the template to create output xml
log.error("XPath evaluation failed", e);
throw new SetTaskOutputFaultException("Internal Error Occurred");
} catch (Exception e) {
// Error occurred while updating template with new values
log.error("Error occurred while updating template with new values", e);
throw new SetTaskOutputFaultException("Internal Error Occurred");
}
SetTaskOutputResponse response = new SetTaskOutputResponse();
response.setSuccess(true);
return response;
}
Aggregations