use of org.jbpm.services.task.events.TaskEventSupport 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;
}
use of org.jbpm.services.task.events.TaskEventSupport in project jbpm by kiegroup.
the class ExecuteReminderCommand method execute.
@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);
TaskData taskData = task.getTaskData();
List<DeadlineSummary> resultList = null;
resultList = getAlldeadlines(persistenceContext, taskData);
TaskEventSupport taskEventSupport = ctx.getTaskEventSupport();
if (resultList == null || resultList.size() == 0) {
if (taskData.getActualOwner() == null)
return null;
if (taskData != null) {
// check if task is still in valid status
if (DeadlineType.START.isValidStatus(taskData.getStatus()) || DeadlineType.END.isValidStatus(taskData.getStatus())) {
taskEventSupport.fireBeforeTaskNotified(task, ctx);
logger.debug("Sending an Email");
Map<String, Object> variables = getVariables(ctx, persistenceContext, task, taskData);
Notification notification = buildDefaultNotification(taskData, task);
NotificationListenerManager.get().broadcast(new NotificationEvent(notification, task, variables), userInfo);
taskEventSupport.fireAfterTaskNotified(task, ctx);
}
}
} else {
for (DeadlineSummary deadlineSummary : resultList) {
executedeadLine(ctx, persistenceContext, task, deadlineSummary, taskData);
}
}
} catch (Exception e) {
logger.error("Error when executing deadlines", e);
}
return null;
}
use of org.jbpm.services.task.events.TaskEventSupport in project jbpm by kiegroup.
the class RemoveTaskDataCommand 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)) {
throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
}
long contentId = task.getTaskData().getDocumentContentId();
if (!input) {
contentId = task.getTaskData().getOutputContentId();
}
Content outputContent = persistenceContext.findContent(contentId);
Map<String, Object> initialContent = new HashMap<>();
Map<String, Object> mergedContent = new HashMap<>();
if (outputContent != null) {
ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
mergedContent.putAll(((Map<String, Object>) unmarshalledObject));
// set initial content for the sake of listeners
initialContent.putAll(mergedContent);
variableNames.forEach(name -> mergedContent.remove(name));
}
ContentData outputContentData = ContentMarshallerHelper.marshal(task, mergedContent, mcontext.getEnvironment());
((InternalContent) outputContent).setContent(outputContentData.getContent());
persistenceContext.persistContent(outputContent);
}
if (input) {
taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, initialContent);
((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
taskEventSupport.fireAfterTaskInputVariablesChanged(task, context, mergedContent);
} else {
taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, context, initialContent);
((InternalTaskData) task.getTaskData()).setTaskOutputVariables(mergedContent);
taskEventSupport.fireAfterTaskOutputVariablesChanged(task, context, mergedContent);
}
return null;
}
use of org.jbpm.services.task.events.TaskEventSupport 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.events.TaskEventSupport in project jbpm by kiegroup.
the class HumanTaskConfigurator method getTaskService.
@SuppressWarnings("unchecked")
public TaskService getTaskService() {
if (service == null) {
TaskEventSupport taskEventSupport = new TaskEventSupport();
this.commandExecutor = new TaskCommandExecutorImpl(this.environment, taskEventSupport);
if (userGroupCallback == null) {
userGroupCallback = new MvelUserGroupCallbackImpl(true);
}
environment.set(EnvironmentName.TASK_USER_GROUP_CALLBACK, userGroupCallback);
if (userInfo == null) {
userInfo = new DefaultUserInfo(true);
}
environment.set(EnvironmentName.TASK_USER_INFO, userInfo);
addDefaultInterceptor();
addTransactionLockInterceptor();
addOptimisticLockInterceptor();
addErrorHandlingInterceptor();
for (PriorityInterceptor pInterceptor : interceptors) {
this.commandExecutor.addInterceptor(pInterceptor.getInterceptor());
}
service = new CommandBasedTaskService(this.commandExecutor, taskEventSupport, this.environment);
// register listeners
for (TaskLifeCycleEventListener listener : listeners) {
((EventService<TaskLifeCycleEventListener>) service).registerTaskEventListener(listener);
}
if (AssignmentServiceProvider.get().isEnabled()) {
((EventService<TaskLifeCycleEventListener>) service).registerTaskEventListener(new AssignmentTaskEventListener());
}
// initialize deadline service with command executor for processing
if (TaskDeadlinesServiceImpl.getInstance() == null) {
TaskDeadlinesServiceImpl.initialize(commandExecutor);
}
}
return service;
}
Aggregations