Search in sources :

Example 6 with Escalation

use of org.kie.internal.task.api.model.Escalation in project jbpm by kiegroup.

the class HumanTaskHandlerHelper method parseDeadlineString.

protected static List<Deadline> parseDeadlineString(String deadlineInfo, List<OrganizationalEntity> businessAdministrators, Environment environment) {
    if (deadlineInfo == null || deadlineInfo.length() == 0) {
        return new ArrayList<Deadline>();
    }
    List<Deadline> deadlines = new ArrayList<Deadline>();
    String[] allComponents = deadlineInfo.split(COMPONENT_SEPARATOR);
    BusinessCalendar businessCalendar = null;
    if (environment != null && environment.get("jbpm.business.calendar") != null) {
        businessCalendar = (BusinessCalendar) environment.get("jbpm.business.calendar");
    }
    for (String component : allComponents) {
        String[] mainComponents = component.split(ELEMENT_SEPARATOR);
        if (mainComponents != null && mainComponents.length == 2) {
            String actionComponent = mainComponents[0].substring(1, mainComponents[0].length() - 1);
            String expireComponents = mainComponents[1].substring(1, mainComponents[1].length() - 1);
            String[] expireElements = expireComponents.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
            Deadline taskDeadline = null;
            for (String expiresAt : expireElements) {
                logger.debug("Expires at is {}", expiresAt);
                taskDeadline = TaskModelProvider.getFactory().newDeadline();
                if (businessCalendar != null) {
                    taskDeadline.setDate(businessCalendar.calculateBusinessTimeAsDate(expiresAt));
                } else {
                    taskDeadline.setDate(new Date(System.currentTimeMillis() + TimeUtils.parseTimeString(expiresAt)));
                }
                logger.debug("Calculated date of execution is {} and current date {}", taskDeadline.getDate(), new Date());
                List<Escalation> escalations = new ArrayList<Escalation>();
                Escalation escalation = TaskModelProvider.getFactory().newEscalation();
                escalations.add(escalation);
                escalation.setName("Default escalation");
                taskDeadline.setEscalations(escalations);
                escalation.setReassignments(parseReassignment(actionComponent));
                escalation.setNotifications(parseNotifications(actionComponent, businessAdministrators));
                deadlines.add(taskDeadline);
            }
        } else {
            logger.warn("Incorrect syntax of deadline property {}", deadlineInfo);
        }
    }
    return deadlines;
}
Also used : Deadline(org.kie.internal.task.api.model.Deadline) Escalation(org.kie.internal.task.api.model.Escalation) ArrayList(java.util.ArrayList) BusinessCalendar(org.jbpm.process.core.timer.BusinessCalendar) Date(java.util.Date)

Example 7 with Escalation

use of org.kie.internal.task.api.model.Escalation in project jbpm by kiegroup.

the class UserTaskAdminServiceImpl method reassign.

protected Long reassign(String deploymentId, long taskId, String timeExpression, DeadlineType type, OrganizationalEntity... orgEntities) throws TaskNotFoundException {
    UserTaskInstanceDesc task = runtimeDataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    if (timeExpression == null || timeExpression.isEmpty()) {
        throw new IllegalArgumentException("Invalid time expression");
    }
    if (orgEntities == null || orgEntities.length <= 0) {
        throw new IllegalArgumentException("Invalid org entity");
    }
    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 reassignment for task " + taskId);
    List<Reassignment> reassignments = new ArrayList<Reassignment>();
    Reassignment reassignment = TaskModelProvider.getFactory().newReassignment();
    reassignment.setPotentialOwners(new ArrayList<>(Arrays.asList(orgEntities)));
    reassignments.add(reassignment);
    escalation.setReassignments(reassignments);
    return userTaskService.execute(task.getDeploymentId(), ProcessInstanceIdContext.get(task.getProcessInstanceId()), new ScheduleTaskDeadlineCommand(identityProvider.getName(), taskId, type, taskDeadline, timeExpression));
}
Also used : Escalation(org.kie.internal.task.api.model.Escalation) Deadline(org.kie.internal.task.api.model.Deadline) ArrayList(java.util.ArrayList) ScheduleTaskDeadlineCommand(org.jbpm.kie.services.impl.admin.commands.ScheduleTaskDeadlineCommand) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) Reassignment(org.kie.internal.task.api.model.Reassignment)

Aggregations

Escalation (org.kie.internal.task.api.model.Escalation)7 Deadline (org.kie.internal.task.api.model.Deadline)6 ArrayList (java.util.ArrayList)5 Notification (org.kie.internal.task.api.model.Notification)4 Reassignment (org.kie.internal.task.api.model.Reassignment)3 ScheduleTaskDeadlineCommand (org.jbpm.kie.services.impl.admin.commands.ScheduleTaskDeadlineCommand)2 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)2 TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)2 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)2 UserInfo (org.kie.internal.task.api.UserInfo)2 EmailNotification (org.kie.internal.task.api.model.EmailNotification)2 NotificationEvent (org.kie.internal.task.api.model.NotificationEvent)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BusinessCalendar (org.jbpm.process.core.timer.BusinessCalendar)1 TaskNotification (org.jbpm.services.api.admin.TaskNotification)1 TaskReassignment (org.jbpm.services.api.admin.TaskReassignment)1 AssignmentService (org.jbpm.services.task.assignment.AssignmentService)1 EscalationImpl (org.jbpm.services.task.impl.model.EscalationImpl)1