use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.util.HumanTaskBuilderImpl in project carbon-business-process by wso2.
the class HumanTaskDAOConnectionImpl method createTask.
public TaskDAO createTask(TaskCreationContext creationContext) throws HumanTaskException {
HumanTaskBuilderImpl taskBuilder = new HumanTaskBuilderImpl();
if (log.isDebugEnabled()) {
log.debug("Creating task instance for task " + creationContext.getTaskConfiguration().getName());
}
MessageDAO inputMessage = createMessage(creationContext);
inputMessage.setMessageType(MessageDAO.MessageType.INPUT);
taskBuilder.addTaskCreationContext(creationContext).addInputMessage(inputMessage);
TaskDAO task = taskBuilder.build();
entityManager.persist(task);
try {
creationContext.injectExpressionEvaluationContext(task);
JPATaskUtil.processGenericHumanRoles(task, creationContext.getTaskConfiguration(), creationContext.getPeopleQueryEvaluator(), creationContext.getEvalContext());
JPATaskUtil.processPresentationElements(task, creationContext.getTaskConfiguration(), creationContext);
if (task.getType().equals(TaskType.TASK)) {
CommonTaskUtil.nominate(task, creationContext.getPeopleQueryEvaluator());
} else if (task.getType().equals(TaskType.NOTIFICATION)) {
task.setStatus(TaskStatus.READY);
notificationScheduler = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getNotificationScheduler();
notificationScheduler.checkForNotificationTasks(creationContext.getTaskConfiguration(), creationContext, task);
}
task.setPriority(CommonTaskUtil.calculateTaskPriority(creationContext.getTaskConfiguration(), creationContext.getEvalContext()));
CommonTaskUtil.setTaskToMessage(task);
if (TaskType.TASK.equals(task.getType())) {
CommonTaskUtil.processDeadlines(task, (TaskConfiguration) creationContext.getTaskConfiguration(), creationContext.getEvalContext());
CommonTaskUtil.scheduleDeadlines(task);
}
// Setting HumanTask context override attributes
CommonTaskUtil.setTaskOverrideContextAttributes(task, creationContext.getMessageHeaderParts());
HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getEventProcessor().processEvent(CommonTaskUtil.createNewTaskEvent(task));
} catch (HumanTaskRuntimeException ex) {
String errorMsg = "Error occurred after task creation for Task ID: " + task.getId() + ". Cause: " + ex.getMessage();
log.error(errorMsg);
task.setStatus(TaskStatus.ERROR);
throw ex;
}
return task;
}
Aggregations