use of org.kie.internal.task.api.model.Escalation in project jbpm by kiegroup.
the class UserTaskAdminServiceImpl method notify.
protected Long notify(String deploymentId, long taskId, String timeExpression, DeadlineType type, Notification notification) throws TaskNotFoundException {
UserTaskInstanceDesc task = runtimeDataService.getTaskById(taskId);
validateTask(deploymentId, taskId, task);
List<Escalation> escalations = new ArrayList<Escalation>();
Deadline taskDeadline = TaskModelProvider.getFactory().newDeadline();
taskDeadline.setEscalations(escalations);
Escalation escalation = TaskModelProvider.getFactory().newEscalation();
escalations.add(escalation);
escalation.setName("Admin notification for task " + taskId);
List<Notification> notifications = new ArrayList<Notification>();
notifications.add(notification);
escalation.setNotifications(notifications);
return userTaskService.execute(task.getDeploymentId(), ProcessInstanceIdContext.get(task.getProcessInstanceId()), new ScheduleTaskDeadlineCommand(identityProvider.getName(), taskId, type, taskDeadline, timeExpression));
}
use of org.kie.internal.task.api.model.Escalation 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.kie.internal.task.api.model.Escalation in project jbpm by kiegroup.
the class CollectionUtils method readEscalationList.
public static List<Escalation> readEscalationList(ObjectInput in) throws IOException, ClassNotFoundException {
int size = in.readInt();
List<Escalation> list = new ArrayList<Escalation>(size);
for (int i = 0; i < size; i++) {
Escalation item = new EscalationImpl();
item.readExternal(in);
list.add(item);
}
return list;
}
use of org.kie.internal.task.api.model.Escalation in project jbpm by kiegroup.
the class UserGroupCallbackTaskCommand method doCallbackOperationForTaskDeadlines.
protected void doCallbackOperationForTaskDeadlines(Deadlines deadlines, TaskContext context) {
if (deadlines != null) {
if (deadlines.getStartDeadlines() != null) {
List<? extends Deadline> startDeadlines = deadlines.getStartDeadlines();
for (Deadline startDeadline : startDeadlines) {
List<? extends Escalation> escalations = startDeadline.getEscalations();
if (escalations != null) {
for (Escalation escalation : escalations) {
List<? extends Notification> notifications = escalation.getNotifications();
List<? extends Reassignment> ressignments = escalation.getReassignments();
if (notifications != null) {
for (Notification notification : notifications) {
List<? extends OrganizationalEntity> recipients = notification.getRecipients();
if (recipients != null) {
for (OrganizationalEntity recipient : recipients) {
if (recipient instanceof User) {
doCallbackUserOperation(recipient.getId(), context);
}
if (recipient instanceof Group) {
doCallbackGroupOperation(recipient.getId(), context);
}
}
}
List<? extends OrganizationalEntity> administrators = notification.getBusinessAdministrators();
if (administrators != null) {
for (OrganizationalEntity administrator : administrators) {
if (administrator instanceof User) {
doCallbackUserOperation(administrator.getId(), context);
}
if (administrator instanceof Group) {
doCallbackGroupOperation(administrator.getId(), context);
}
}
}
}
}
if (ressignments != null) {
for (Reassignment reassignment : ressignments) {
List<? extends OrganizationalEntity> potentialOwners = reassignment.getPotentialOwners();
if (potentialOwners != null) {
for (OrganizationalEntity potentialOwner : potentialOwners) {
if (potentialOwner instanceof User) {
doCallbackUserOperation(potentialOwner.getId(), context);
}
if (potentialOwner instanceof Group) {
doCallbackGroupOperation(potentialOwner.getId(), context);
}
}
}
}
}
}
}
}
}
if (deadlines.getEndDeadlines() != null) {
List<? extends Deadline> endDeadlines = deadlines.getEndDeadlines();
for (Deadline endDeadline : endDeadlines) {
List<? extends Escalation> escalations = endDeadline.getEscalations();
if (escalations != null) {
for (Escalation escalation : escalations) {
List<? extends Notification> notifications = escalation.getNotifications();
List<? extends Reassignment> ressignments = escalation.getReassignments();
if (notifications != null) {
for (Notification notification : notifications) {
List<? extends OrganizationalEntity> recipients = notification.getRecipients();
if (recipients != null) {
for (OrganizationalEntity recipient : recipients) {
if (recipient instanceof User) {
doCallbackUserOperation(recipient.getId(), context);
}
if (recipient instanceof Group) {
doCallbackGroupOperation(recipient.getId(), context);
}
}
}
List<? extends OrganizationalEntity> administrators = notification.getBusinessAdministrators();
if (administrators != null) {
for (OrganizationalEntity administrator : administrators) {
if (administrator instanceof User) {
doCallbackUserOperation(administrator.getId(), context);
}
if (administrator instanceof Group) {
doCallbackGroupOperation(administrator.getId(), context);
}
}
}
}
}
if (ressignments != null) {
for (Reassignment reassignment : ressignments) {
List<? extends OrganizationalEntity> potentialOwners = reassignment.getPotentialOwners();
if (potentialOwners != null) {
for (OrganizationalEntity potentialOwner : potentialOwners) {
if (potentialOwner instanceof User) {
doCallbackUserOperation(potentialOwner.getId(), context);
}
if (potentialOwner instanceof Group) {
doCallbackGroupOperation(potentialOwner.getId(), context);
}
}
}
}
}
}
}
}
}
}
}
use of org.kie.internal.task.api.model.Escalation 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;
}
Aggregations