use of org.wso2.carbon.humantask.core.store.TaskConfiguration in project carbon-business-process by wso2.
the class HumanTaskBuilderImpl method build.
/**
* Builds the Task from the given input.
*
* @return : The created task object.
*/
public TaskDAO build() {
validateParams();
TaskDAO task;
HumanTaskBaseConfiguration taskConfiguration = creationContext.getTaskConfiguration();
int tenantId = creationContext.getTenantId();
if (creationContext.getTaskConfiguration().isTask()) {
task = new Task(taskConfiguration.getName(), TaskType.TASK, tenantId);
} else {
task = new Task(taskConfiguration.getName(), TaskType.NOTIFICATION, tenantId);
}
task.setInputMessage(this.inputMessage);
task.setSkipable(false);
task.setEscalated(false);
task.setStatus(TaskStatus.CREATED);
task.setActivationTime(new Date());
task.setTaskVersion(taskConfiguration.getVersion());
task.setTaskPackageName(taskConfiguration.getPackageName());
task.setDefinitionName(taskConfiguration.getDefinitionName());
if (creationContext.getTaskConfiguration().isTask()) {
// Setting the attachments to the task
try {
task.setAttachments(TransformerUtils.generateAttachmentDAOListFromIDs(task, creationContext.getAttachmentIDs()));
} catch (HumanTaskException e) {
log.error(e.getLocalizedMessage(), e);
}
}
// Setting the attachments to the task
try {
task.setAttachments(TransformerUtils.generateAttachmentDAOListFromIDs(task, creationContext.getAttachmentIDs()));
} catch (HumanTaskException e) {
log.error(e.getLocalizedMessage(), e);
}
return task;
}
use of org.wso2.carbon.humantask.core.store.TaskConfiguration 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;
}
use of org.wso2.carbon.humantask.core.store.TaskConfiguration in project carbon-business-process by wso2.
the class JPATaskUtil method processGenericHumanRoles.
public static void processGenericHumanRoles(TaskDAO task, HumanTaskBaseConfiguration taskConfiguration, PeopleQueryEvaluator peopleQueryEvaluator, EvaluationContext evaluationContext) throws HumanTaskException {
if (taskConfiguration.isTask()) {
// Task
TTask tTask = ((TaskConfiguration) taskConfiguration).getTask();
// TODO move the reading of configuration file in to the TaskConfiguration class
// Reading Excluded users
TGenericHumanRoleAssignment[] tExcludedOwners = tTask.getPeopleAssignments().getExcludedOwnersArray();
if (tExcludedOwners != null && tExcludedOwners.length > 0) {
assignHumanRoles(task, peopleQueryEvaluator, tExcludedOwners[0], GenericHumanRoleDAO.GenericHumanRoleType.EXCLUDED_OWNERS, evaluationContext);
}
// Reading potential owners
TPotentialOwnerAssignment[] tPotentialOwners = tTask.getPeopleAssignments().getPotentialOwnersArray();
if (tPotentialOwners != null && tPotentialOwners.length > 0) {
TPotentialOwnerAssignment tPotentialOwner = tPotentialOwners[0];
OrganizationalEntityProvider provider = OrganizationalEntityProviderFactory.getOrganizationalEntityProvider(tPotentialOwner.getFrom());
List<OrganizationalEntityDAO> orgEntities = provider.getOrganizationalEntities(peopleQueryEvaluator, tPotentialOwner.getFrom(), evaluationContext);
if (tExcludedOwners != null && tExcludedOwners.length > 0) {
GenericHumanRoleDAO excludedOwners = task.getGenericHumanRole(GenericHumanRoleDAO.GenericHumanRoleType.EXCLUDED_OWNERS);
for (OrganizationalEntityDAO excludedEntity : excludedOwners.getOrgEntities()) {
for (OrganizationalEntityDAO ownerEntity : orgEntities) {
if (excludedEntity.getOrgEntityType() == ownerEntity.getOrgEntityType() && excludedEntity.getName().equals(ownerEntity.getName())) {
orgEntities.remove(ownerEntity);
break;
}
}
}
}
GenericHumanRole potentialOwnersGHRole = new GenericHumanRole();
potentialOwnersGHRole.setType(GenericHumanRole.GenericHumanRoleType.POTENTIAL_OWNERS);
potentialOwnersGHRole.setOrgEntities(orgEntities);
potentialOwnersGHRole.setTask(task);
for (OrganizationalEntityDAO oe : orgEntities) {
oe.addGenericHumanRole(potentialOwnersGHRole);
}
task.addHumanRole(potentialOwnersGHRole);
}
// Reading Stake holders
TGenericHumanRoleAssignment[] tStakeHolders = tTask.getPeopleAssignments().getTaskStakeholdersArray();
if (tStakeHolders != null && tStakeHolders.length > 0) {
assignHumanRoles(task, peopleQueryEvaluator, tStakeHolders[0], GenericHumanRoleDAO.GenericHumanRoleType.STAKEHOLDERS, evaluationContext);
}
// Reading Business administrators
TGenericHumanRoleAssignment[] tBusinessAdministrators = tTask.getPeopleAssignments().getBusinessAdministratorsArray();
if (tBusinessAdministrators != null && tBusinessAdministrators.length > 0) {
assignHumanRoles(task, peopleQueryEvaluator, tBusinessAdministrators[0], GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS, evaluationContext);
}
} else {
// Notification
TNotification tNotification = ((NotificationConfiguration) taskConfiguration).getNotificationDefinition();
// Reading Notification recipients
TGenericHumanRoleAssignment[] tRecipients = tNotification.getPeopleAssignments().getRecipientsArray();
if (tRecipients != null && tRecipients.length > 0) {
assignHumanRoles(task, peopleQueryEvaluator, tRecipients[0], GenericHumanRoleDAO.GenericHumanRoleType.NOTIFICATION_RECIPIENTS, evaluationContext);
}
}
}
use of org.wso2.carbon.humantask.core.store.TaskConfiguration in project carbon-business-process by wso2.
the class Complete method execute.
/**
* The method to execute the business logic for the specific command.
*/
public void execute() {
authorise();
TaskDAO task = getTask();
checkPreConditions();
checkState();
task.complete(createMessage());
TaskConfiguration taskConf = (TaskConfiguration) HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(task.getTenantId()).getTaskConfiguration(QName.valueOf(task.getName()));
try {
taskConf.getCallBackService().invoke(XMLUtils.toOM(taskOutput), task.getId());
} catch (Exception e) {
throw new HumanTaskRuntimeException("Error occurred while invoking callback service", e);
}
processTaskEvent();
checkPostConditions();
}
use of org.wso2.carbon.humantask.core.store.TaskConfiguration in project carbon-business-process by wso2.
the class HumanTaskStore method validateTaskConfig.
/**
* Performance a test deployment of the task in order to avoid deployment issues due to invalid task packages
* @param humanTaskDU
* @return
* @throws HumanTaskDeploymentException
*/
public void validateTaskConfig(HumanTaskDeploymentUnit humanTaskDU) throws HumanTaskDeploymentException, AxisFault {
boolean validateTask = HumanTaskServiceComponent.getHumanTaskServer().getServerConfig().getEnableTaskValidationBeforeDeployment();
if (validateTask) {
TTask[] tasks = humanTaskDU.getTasks();
if (tasks != null) {
for (TTask task : tasks) {
QName taskQName = new QName(humanTaskDU.getNamespace(), task.getName());
TaskConfiguration taskConf = new TaskConfiguration(task, humanTaskDU.getTaskServiceInfo(taskQName), humanTaskDU.getHumanInteractionsDefinition(), humanTaskDU.getWSDLs(), humanTaskDU.getNamespace(), humanTaskDU.getName(), getTenantAxisConfig(), humanTaskDU.getPackageName(), humanTaskDU.getVersion(), humanTaskDU.getHumanTaskDefinitionFile());
if (taskConf.isErroneous()) {
throw new HumanTaskDeploymentException(taskConf.getDeploymentError());
}
validateServiceCreationForTaskConfig(taskConf);
}
}
TNotification[] notifications = humanTaskDU.getNotifications();
if (notifications != null) {
for (TNotification notification : notifications) {
QName notificationQName = new QName(humanTaskDU.getNamespace(), notification.getName());
NotificationConfiguration notificationConf = new NotificationConfiguration(notification, humanTaskDU.getNotificationServiceInfo(notificationQName), humanTaskDU.getHumanInteractionsDefinition(), humanTaskDU.getWSDLs(), humanTaskDU.getNamespace(), humanTaskDU.getName(), getTenantAxisConfig(), humanTaskDU.getPackageName(), humanTaskDU.getVersion(), humanTaskDU.getHumanTaskDefinitionFile());
if (notificationConf.isErroneous()) {
throw new HumanTaskDeploymentException(notificationConf.getDeploymentError());
}
validateServiceCreationForTaskConfig(notificationConf);
}
}
for (TNotification inlineNotification : humanTaskDU.getInlineNotifications()) {
QName notificationQName = new QName(humanTaskDU.getNamespace(), inlineNotification.getName());
NotificationConfiguration notificationConf = new NotificationConfiguration(inlineNotification, humanTaskDU.getNotificationServiceInfo(notificationQName), humanTaskDU.getHumanInteractionsDefinition(), humanTaskDU.getWSDLs(), humanTaskDU.getNamespace(), humanTaskDU.getName(), getTenantAxisConfig(), humanTaskDU.getPackageName(), humanTaskDU.getVersion(), humanTaskDU.getHumanTaskDefinitionFile());
notificationConf.setPackageStatus(humanTaskDU.getTaskPackageStatus());
if (notificationConf.isErroneous()) {
throw new HumanTaskDeploymentException(notificationConf.getDeploymentError());
}
validateServiceCreationForTaskConfig(notificationConf);
}
}
return;
}
Aggregations