use of org.jbpm.services.task.commands.TaskContext in project jbpm by kiegroup.
the class ScheduleTaskDeadlineCommand method execute.
@Override
public Long execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
TaskPersistenceContext persistenceContext = context.getPersistenceContext();
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
}
logger.debug("About to schedule {} on a task {}", deadline, task);
Deadlines deadlines = ((InternalTask) task).getDeadlines();
if (type.equals(DeadlineType.START)) {
deadlines.getStartDeadlines().add(deadline);
} else {
deadlines.getEndDeadlines().add(deadline);
}
doCallbackOperationForTaskDeadlines(deadlines, context);
persistenceContext.persistDeadline(deadline);
persistenceContext.updateTask(task);
logger.debug("Task updated and deadline stored with id {}", deadline.getId());
TaskDeadlinesService deadlinesService = context.getTaskDeadlinesService();
long fireAfterDuration = DateTimeUtils.parseDuration(timeExpression);
deadline.setDate(new Date(System.currentTimeMillis() + fireAfterDuration));
logger.debug("Deadline expiration time set to {} and duration {}", deadline.getDate(), fireAfterDuration);
deadlinesService.schedule(taskId, deadline.getId(), fireAfterDuration, type);
logger.debug("Deadline on task {} successfully scheduled to fire at {}", task, deadline.getDate());
return deadline.getId();
}
use of org.jbpm.services.task.commands.TaskContext in project jbpm by kiegroup.
the class UpdateTaskCommand method execute.
@SuppressWarnings("unchecked")
@Override
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskEventSupport taskEventSupport = context.getTaskEventSupport();
TaskPersistenceContext persistenceContext = context.getPersistenceContext();
Task task = persistenceContext.findTask(taskId);
// security check
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context) && !isOwner(userId, task.getPeopleAssignments().getPotentialOwners(), task.getTaskData().getActualOwner(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin or potential owner of task " + taskId);
}
taskEventSupport.fireBeforeTaskUpdated(task, context);
// process task meta data
if (userTask.getFormName() != null) {
((InternalTask) task).setFormName(userTask.getFormName());
}
if (userTask.getName() != null) {
((InternalTask) task).setName(userTask.getName());
}
if (userTask.getDescription() != null) {
((InternalTask) task).setDescription(userTask.getDescription());
}
if (userTask.getPriority() != null) {
((InternalTask) task).setPriority(userTask.getPriority());
}
if (userTask.getDueDate() != null) {
((InternalTaskData) task.getTaskData()).setExpirationTime(userTask.getDueDate());
}
// process task inputs
long inputContentId = task.getTaskData().getDocumentContentId();
Content inputContent = persistenceContext.findContent(inputContentId);
Map<String, Object> mergedContent = inputs;
if (inputs != null) {
if (inputContent == null) {
ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
ContentData outputContentData = ContentMarshallerHelper.marshal(task, inputs, mcontext.getEnvironment());
Content content = TaskModelProvider.getFactory().newContent();
((InternalContent) content).setContent(outputContentData.getContent());
persistenceContext.persistContent(content);
((InternalTaskData) task.getTaskData()).setOutput(content.getId(), outputContentData);
} else {
ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(inputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
((Map<String, Object>) unmarshalledObject).putAll(inputs);
mergedContent = ((Map<String, Object>) unmarshalledObject);
}
ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, mcontext.getEnvironment());
((InternalContent) inputContent).setContent(outputContentData.getContent());
persistenceContext.persistContent(inputContent);
}
((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
}
if (outputs != null) {
// process task outputs
context.getTaskContentService().addOutputContent(taskId, outputs);
}
persistenceContext.updateTask(task);
// finally trigger event support after the updates
taskEventSupport.fireAfterTaskUpdated(task, context);
return null;
}
use of org.jbpm.services.task.commands.TaskContext in project jbpm by kiegroup.
the class AbstractTaskAuditQueryCommand method execute.
@Override
public List<R> execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskAuditQueryCriteriaUtil queryCriteriaUtil = new TaskAuditQueryCriteriaUtil(context.getPersistenceContext());
List<Q> implResult = queryCriteriaUtil.doCriteriaQuery(getQueryWhere(), getQueryType());
return QueryCriteriaUtil.convertListToInterfaceList(implResult, getResultType());
}
use of org.jbpm.services.task.commands.TaskContext in project jbpm by kiegroup.
the class BAMTaskSummaryQueryCommand method execute.
@Override
public List<BAMTaskSummaryImpl> execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskAuditQueryCriteriaUtil queryCriteriaUtil = new TaskAuditQueryCriteriaUtil(context.getPersistenceContext());
return queryCriteriaUtil.doCriteriaQuery(getQueryWhere(), BAMTaskSummaryImpl.class);
}
use of org.jbpm.services.task.commands.TaskContext in project jbpm by kiegroup.
the class GetTasksByVariableNameCommand 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("TasksByStatusByVariableName", persistenceContext.addParametersToMap("userId", userId, "groupIds", groupIds, "variableName", variableName, "status", statuses), ClassUtil.<List<TaskSummary>>castClass(List.class));
return tasks;
}
Aggregations