use of org.jbpm.services.task.events.TaskEventSupport in project jbpm by kiegroup.
the class ExecuteReminderCommand method executedeadLine.
private Void executedeadLine(TaskContext ctx, TaskPersistenceContext persistenceContext, Task task, DeadlineSummary deadlineSummary, TaskData taskData) {
Deadline deadline = persistenceContext.findDeadline(deadlineSummary.getDeadlineId());
if (task == null || deadline == null) {
return null;
}
if (taskData != null) {
UserInfo userInfo = (UserInfo) ctx.get(EnvironmentName.TASK_USER_INFO);
// check if task is still in valid status
if (DeadlineType.START.isValidStatus(taskData.getStatus()) || DeadlineType.END.isValidStatus(taskData.getStatus())) {
Map<String, Object> variables = getVariables(ctx, persistenceContext, task, taskData);
if (deadline == null || deadline.getEscalations() == null) {
return null;
}
TaskEventSupport taskEventSupport = ctx.getTaskEventSupport();
taskEventSupport.fireBeforeTaskNotified(task, ctx);
for (Escalation escalation : deadline.getEscalations()) {
for (Notification notification : escalation.getNotifications()) {
if (notification.getNotificationType() == NotificationType.Email) {
logger.debug("Sending an Email");
NotificationListenerManager.get().broadcast(new NotificationEvent(notification, task, variables), userInfo);
}
}
}
taskEventSupport.fireAfterTaskNotified(task, ctx);
}
}
return null;
}
use of org.jbpm.services.task.events.TaskEventSupport in project jbpm by kiegroup.
the class AddPeopleAssignmentsCommand method execute.
@Override
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskEventSupport taskEventSupport = context.getTaskEventSupport();
Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
// security check
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
}
List<OrganizationalEntity> entityList = Arrays.asList(entities);
AssignmentType assignmentType = null;
switch(type) {
case POT_OWNER:
if (removeExisting) {
task.getPeopleAssignments().getPotentialOwners().clear();
}
task.getPeopleAssignments().getPotentialOwners().addAll(entityList);
assignmentType = AssignmentType.POT_OWNER;
break;
case EXCL_OWNER:
if (removeExisting) {
((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners().clear();
}
((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners().addAll(entityList);
assignmentType = AssignmentType.EXCL_OWNER;
break;
case ADMIN:
if (removeExisting) {
task.getPeopleAssignments().getBusinessAdministrators().clear();
}
task.getPeopleAssignments().getBusinessAdministrators().addAll(entityList);
assignmentType = AssignmentType.ADMIN;
break;
default:
break;
}
taskEventSupport.fireBeforeTaskAssignmentsAddedEvent(task, context, assignmentType, entityList);
doCallbackOperationForPeopleAssignments(((InternalPeopleAssignments) task.getPeopleAssignments()), context);
taskEventSupport.fireAfterTaskAssignmentsAddedEvent(task, context, assignmentType, entityList);
return null;
}
use of org.jbpm.services.task.events.TaskEventSupport in project jbpm by kiegroup.
the class AddTaskInputsCommand 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 inputContentId = task.getTaskData().getDocumentContentId();
Content outputContent = persistenceContext.findContent(inputContentId);
Map<String, Object> initialContent = new HashMap<String, Object>();
Map<String, Object> mergedContent = values;
if (outputContent == null) {
ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
ContentData outputContentData = ContentMarshallerHelper.marshal(task, values, 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(outputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
// set initial content with data from storage before being altered by this values
initialContent.putAll((Map<String, Object>) unmarshalledObject);
((Map<String, Object>) unmarshalledObject).putAll(values);
mergedContent = ((Map<String, Object>) unmarshalledObject);
}
ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, mcontext.getEnvironment());
((InternalContent) outputContent).setContent(outputContentData.getContent());
persistenceContext.persistContent(outputContent);
}
taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, initialContent);
((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
taskEventSupport.fireAfterTaskInputVariablesChanged(task, context, mergedContent);
return null;
}
use of org.jbpm.services.task.events.TaskEventSupport in project jbpm by kiegroup.
the class RemovePeopleAssignmentsCommand method execute.
@Override
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskEventSupport taskEventSupport = context.getTaskEventSupport();
Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
// security check
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
}
List<OrganizationalEntity> entityList = Arrays.asList(entities);
AssignmentType assignmentType = null;
taskEventSupport.fireBeforeTaskUpdated(task, context);
switch(type) {
case POT_OWNER:
assignmentType = AssignmentType.POT_OWNER;
taskEventSupport.fireBeforeTaskAssignmentsRemovedEvent(task, context, assignmentType, entityList);
task.getPeopleAssignments().getPotentialOwners().removeAll(entityList);
break;
case EXCL_OWNER:
assignmentType = AssignmentType.EXCL_OWNER;
taskEventSupport.fireBeforeTaskAssignmentsRemovedEvent(task, context, assignmentType, entityList);
((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners().removeAll(entityList);
break;
case ADMIN:
assignmentType = AssignmentType.ADMIN;
taskEventSupport.fireBeforeTaskAssignmentsRemovedEvent(task, context, assignmentType, entityList);
task.getPeopleAssignments().getBusinessAdministrators().removeAll(entityList);
break;
default:
break;
}
taskEventSupport.fireAfterTaskAssignmentsRemovedEvent(task, context, assignmentType, entityList);
return null;
}
Aggregations