use of org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext in project carbon-business-process by wso2.
the class JPATaskUtil method assignHumanRoles.
private static void assignHumanRoles(TaskDAO task, PeopleQueryEvaluator peopleQueryEvaluator, TGenericHumanRoleAssignment roleAssignment, GenericHumanRole.GenericHumanRoleType type, EvaluationContext evaluationContext) throws HumanTaskException {
OrganizationalEntityProvider provider = OrganizationalEntityProviderFactory.getOrganizationalEntityProvider(roleAssignment.getFrom());
List<OrganizationalEntityDAO> orgEntities = provider.getOrganizationalEntities(peopleQueryEvaluator, roleAssignment.getFrom(), evaluationContext);
GenericHumanRole humanRole = new GenericHumanRole();
humanRole.setType(type);
humanRole.setOrgEntities(orgEntities);
humanRole.setTask(task);
for (OrganizationalEntityDAO oe : orgEntities) {
oe.addGenericHumanRole(humanRole);
}
task.addHumanRole(humanRole);
}
use of org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext 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.engine.runtime.api.EvaluationContext in project carbon-business-process by wso2.
the class XPathExpressionRuntime method evaluateAsPart.
/**
* Evaluate the expression returns an OMElement
*
* @param exp Expresion
* @param partName Name of the part
* @param evalCtx EvaluationContext
* @return Part as an Node
*/
@Override
public Node evaluateAsPart(String exp, String partName, EvaluationContext evalCtx) {
Document document = DOMUtils.newDocument();
Node node = document.createElement(partName);
List<Node> nodeList = evaluate(exp, evalCtx);
if (nodeList.size() == 0) {
String errMsg = "0 nodes selected for the expression: " + exp;
log.error(errMsg);
throw new HumanTaskRuntimeException(errMsg);
} else if (nodeList.size() > 1) {
String errMsg = "More than one nodes are selected for the expression: " + exp;
log.error(errMsg);
throw new HumanTaskRuntimeException(errMsg);
}
Node partNode = nodeList.get(0);
replaceElement((Element) node, (Element) partNode);
return node;
}
use of org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext in project carbon-business-process by wso2.
the class CommonTaskUtil method processDeadlines.
/**
* Process the deadlines for the given task.
*
* @param task : The task object.
* @param taskConf : The task configuration for this task.
* @param evalContext : The task's eval context.
*/
public static void processDeadlines(TaskDAO task, TaskConfiguration taskConf, EvaluationContext evalContext) {
// TODO is it possible to process deadlines once per a task definition and set the duration per a task instance?
TDeadlines deadlines = taskConf.getDeadlines();
if (deadlines != null) {
TDeadline[] startDeadlines = deadlines.getStartDeadlineArray();
TDeadline[] completionDeadlines = deadlines.getCompletionDeadlineArray();
for (TDeadline deadline : startDeadlines) {
DeadlineDAO startDeadline = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getDaoConnectionFactory().getConnection().createDeadline();
startDeadline.setStatus(TaskStatus.IN_PROGRESS);
startDeadline.setName((deadline.getName() == null ? "startDeadline" : deadline.getName()));
startDeadline.setTask(task);
startDeadline.setDeadlineDate(calculateDeadline(task, deadline, taskConf, evalContext).getTime());
task.addDeadline(startDeadline);
}
for (TDeadline deadline : completionDeadlines) {
Deadline completionDeadline = new Deadline();
completionDeadline.setStatus(TaskStatus.COMPLETED);
completionDeadline.setName((deadline.getName() == null ? "completionDeadline" : deadline.getName()));
completionDeadline.setTask(task);
completionDeadline.setDeadlineDate(calculateDeadline(task, deadline, taskConf, evalContext).getTime());
task.addDeadline(completionDeadline);
}
}
}
use of org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext in project carbon-business-process by wso2.
the class CommonTaskUtil method calculateTaskPriority.
/**
* Calculates the task priority.
*
* @param taskConfig : The task's configuration
* @param evalCtx : The evaluation context.
* @return : The task priority
*/
public static int calculateTaskPriority(HumanTaskBaseConfiguration taskConfig, EvaluationContext evalCtx) {
TPriorityExpr priorityDef = taskConfig.getPriorityExpression();
int taskPriorityInt = HumanTaskConstants.DEFAULT_TASK_PRIORITY;
if (priorityDef != null) {
String expLang = priorityDef.getExpressionLanguage() == null ? taskConfig.getExpressionLanguage() : priorityDef.getExpressionLanguage();
ExpressionLanguageRuntime expLangRuntime = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getExpressionLanguageRuntime(expLang);
Number priority = expLangRuntime.evaluateAsNumber(priorityDef.newCursor().getTextValue().trim(), evalCtx);
if (priority.intValue() > 10 || priority.intValue() < 0) {
log.warn(String.format("Ignoring the task priority value :[%d] The task priority has to be with 0 and 10. Setting to default:[%d].", priority.intValue(), HumanTaskConstants.DEFAULT_TASK_PRIORITY));
} else {
taskPriorityInt = priority.intValue();
}
}
return taskPriorityInt;
}
Aggregations