use of org.kie.internal.task.api.TaskPersistenceContext in project jbpm by kiegroup.
the class BAMTaskEventListener method createTask.
/**
* Creates or updates a bam task summary instance.
*
* @param ti The source task
* @param newStatus The new state for the task.
* @param worker Perform additional operations to the bam task summary instance.
* @return The created or updated bam task summary instance.
*/
protected BAMTaskSummaryImpl createTask(TaskEvent event, Status newStatus, BAMTaskWorker worker) {
BAMTaskSummaryImpl result = null;
Task ti = event.getTask();
TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext) event.getTaskContext()).getPersistenceContext());
try {
if (ti == null) {
logger.error("The task instance does not exist.");
return result;
}
Status status = newStatus != null ? newStatus : ti.getTaskData().getStatus();
String actualOwner = "";
if (ti.getTaskData().getActualOwner() != null) {
actualOwner = ti.getTaskData().getActualOwner().getId();
}
result = new BAMTaskSummaryImpl(ti.getId(), ti.getName(), status.toString(), event.getEventDate(), actualOwner, ti.getTaskData().getProcessInstanceId());
if (worker != null)
worker.createTask(result, ti);
persistenceContext.persist(result);
return result;
} finally {
cleanup(persistenceContext);
}
}
use of org.kie.internal.task.api.TaskPersistenceContext in project jbpm by kiegroup.
the class CancelDeadlineCommand method execute.
@Override
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskDeadlinesService deadlineService = context.getTaskDeadlinesService();
TaskQueryService queryService = context.getTaskQueryService();
TaskPersistenceContext persistenceContext = context.getPersistenceContext();
InternalTask task = (InternalTask) queryService.getTaskInstanceById(taskId);
if (task == null || task.getDeadlines() == null) {
return null;
}
Iterator<? extends Deadline> it = null;
if (removeStart) {
if (task.getDeadlines().getStartDeadlines() != null) {
deadlineService.unschedule(taskId, DeadlineType.START);
it = task.getDeadlines().getStartDeadlines().iterator();
while (it.hasNext()) {
persistenceContext.removeDeadline(it.next());
it.remove();
}
}
}
if (removeEnd) {
if (task.getDeadlines().getEndDeadlines() != null) {
deadlineService.unschedule(taskId, DeadlineType.END);
it = task.getDeadlines().getEndDeadlines().iterator();
while (it.hasNext()) {
persistenceContext.removeDeadline(it.next());
it.remove();
}
}
}
return null;
}
use of org.kie.internal.task.api.TaskPersistenceContext in project jbpm by kiegroup.
the class GetTasksByVariableNameAndValueCommand method execute.
public List<TaskSummary> execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
doCallbackUserOperation(userId, context);
if (statuses == null) {
statuses = new ArrayList<Status>();
statuses.add(Status.Ready);
statuses.add(Status.InProgress);
statuses.add(Status.Reserved);
}
if (groupIds == null) {
groupIds = doUserGroupCallbackOperation(userId, null, context);
if (groupIds == null) {
groupIds = new ArrayList<String>();
}
}
TaskPersistenceContext persistenceContext = context.getPersistenceContext();
List<TaskSummary> tasks = (List<TaskSummary>) persistenceContext.queryWithParametersInTransaction("TasksByStatusByVariableNameAndValue", persistenceContext.addParametersToMap("userId", userId, "groupIds", groupIds, "variableName", variableName, "variableValue", variableValue, "status", statuses), ClassUtil.<List<TaskSummary>>castClass(List.class));
return tasks;
}
use of org.kie.internal.task.api.TaskPersistenceContext in project jbpm by kiegroup.
the class CancelTaskDeadlineCommand method execute.
@Override
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
}
logger.debug("About to cancel deadline {} on a task {}", deadlineId, task);
Deadlines deadlines = ((InternalTask) task).getDeadlines();
DeadlineType type = DeadlineType.START;
Deadline deadline = deadlines.getStartDeadlines().stream().filter(d -> deadlineId.equals(d.getId())).findFirst().orElse(null);
if (deadline == null) {
deadline = deadlines.getEndDeadlines().stream().filter(d -> deadlineId.equals(d.getId())).findFirst().orElse(null);
type = DeadlineType.END;
}
TaskPersistenceContext persistenceContext = context.getPersistenceContext();
TaskDeadlinesService deadlinesService = context.getTaskDeadlinesService();
deadlinesService.unschedule(taskId, deadline, type);
persistenceContext.removeDeadline(deadline);
return null;
}
use of org.kie.internal.task.api.TaskPersistenceContext in project jbpm by kiegroup.
the class ExecuteDeadlinesCommand method execute.
@SuppressWarnings("unchecked")
@Override
public Void execute(Context context) {
TaskContext ctx = (TaskContext) context;
UserInfo userInfo = (UserInfo) context.get(EnvironmentName.TASK_USER_INFO);
TaskPersistenceContext persistenceContext = ctx.getPersistenceContext();
try {
Task task = persistenceContext.findTask(taskId);
Deadline deadline = persistenceContext.findDeadline(deadlineId);
if (task == null || deadline == null) {
return null;
}
TaskData taskData = task.getTaskData();
if (taskData != null) {
// check if task is still in valid status
if (type.isValidStatus(taskData.getStatus())) {
Map<String, Object> variables = null;
Content content = persistenceContext.findContent(taskData.getDocumentContentId());
if (content != null) {
ContentMarshallerContext mContext = ctx.getTaskContentService().getMarshallerContext(task);
Object objectFromBytes = ContentMarshallerHelper.unmarshall(content.getContent(), mContext.getEnvironment(), mContext.getClassloader());
if (objectFromBytes instanceof Map) {
variables = (Map<String, Object>) objectFromBytes;
} else {
variables = new HashMap<String, Object>();
variables.put("content", objectFromBytes);
}
} else {
variables = Collections.emptyMap();
}
if (deadline == null || deadline.getEscalations() == null) {
return null;
}
TaskEventSupport taskEventSupport = ctx.getTaskEventSupport();
for (Escalation escalation : deadline.getEscalations()) {
// run reassignment first to allow notification to be send to new potential owners
if (!escalation.getReassignments().isEmpty()) {
taskEventSupport.fireBeforeTaskReassigned(task, ctx);
// get first and ignore the rest.
Reassignment reassignment = escalation.getReassignments().get(0);
logger.debug("Reassigning to {}", reassignment.getPotentialOwners());
((InternalTaskData) task.getTaskData()).setStatus(Status.Ready);
List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>(reassignment.getPotentialOwners());
((InternalPeopleAssignments) task.getPeopleAssignments()).setPotentialOwners(potentialOwners);
((InternalTaskData) task.getTaskData()).setActualOwner(null);
// use assignment service to directly assign actual owner if enabled
AssignmentService assignmentService = AssignmentServiceProvider.get();
if (assignmentService.isEnabled()) {
assignmentService.assignTask(task, ctx);
}
taskEventSupport.fireAfterTaskReassigned(task, ctx);
}
for (Notification notification : escalation.getNotifications()) {
if (notification.getNotificationType() == NotificationType.Email) {
taskEventSupport.fireBeforeTaskNotified(task, ctx);
logger.debug("Sending an Email");
NotificationListenerManager.get().broadcast(new NotificationEvent(notification, task, variables), userInfo);
taskEventSupport.fireAfterTaskNotified(task, ctx);
}
}
}
}
}
deadline.setEscalated(true);
persistenceContext.updateDeadline(deadline);
persistenceContext.updateTask(task);
} catch (Exception e) {
logger.error("Error when executing deadlines", e);
}
return null;
}
Aggregations