Search in sources :

Example 1 with InternalTask

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

the class DefaultChecklistManager method addTask.

public ChecklistItem addTask(String userId, String[] actorIds, String[] groupIds, String name, String orderingId, long processInstanceId) {
    RuntimeEngine runtime = getRuntime();
    InternalTask task = (InternalTask) TaskModelProvider.getFactory().newTask();
    ;
    setTaskName(task, name);
    setTaskDescription(task, orderingId);
    // task.setPriority(priority);
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    taskData.setProcessInstanceId(processInstanceId);
    // taskData.setProcessSessionId(sessionId);
    taskData.setSkipable(false);
    taskData.setDeploymentId("default-singleton");
    User cuser = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) cuser).setId(userId);
    taskData.setCreatedBy(cuser);
    task.setTaskData(taskData);
    InternalPeopleAssignments peopleAssignments = (InternalPeopleAssignments) task.getPeopleAssignments();
    if (peopleAssignments == null) {
        peopleAssignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
        peopleAssignments.setPotentialOwners(new ArrayList<OrganizationalEntity>());
        peopleAssignments.setBusinessAdministrators(new ArrayList<OrganizationalEntity>());
        peopleAssignments.setExcludedOwners(new ArrayList<OrganizationalEntity>());
        peopleAssignments.setRecipients(new ArrayList<OrganizationalEntity>());
        peopleAssignments.setTaskStakeholders(new ArrayList<OrganizationalEntity>());
        task.setPeopleAssignments(peopleAssignments);
    }
    List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>();
    for (String actorId : actorIds) {
        User user = TaskModelProvider.getFactory().newUser();
        ((InternalOrganizationalEntity) user).setId(actorId);
        potentialOwners.add(user);
    }
    for (String groupId : groupIds) {
        Group group = TaskModelProvider.getFactory().newGroup();
        ((InternalOrganizationalEntity) group).setId(groupId);
        potentialOwners.add(group);
    }
    setTaskPotentialOwners(task, potentialOwners);
    List<OrganizationalEntity> businessAdministrators = peopleAssignments.getBusinessAdministrators();
    User administrator = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) administrator).setId("Administrator");
    businessAdministrators.add(administrator);
    TaskService taskService = runtime.getTaskService();
    long taskId = taskService.addTask(task, (Map<String, Object>) null);
    manager.disposeRuntimeEngine(runtime);
    return ChecklistItemFactory.createChecklistItem(taskService.getTaskById(taskId));
}
Also used : Group(org.kie.api.task.model.Group) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) ArrayList(java.util.ArrayList) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments)

Example 2 with InternalTask

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

the class CancelDeadlineCommand method execute.

@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskDeadlinesService deadlineService = context.getTaskDeadlinesService();
    TaskQueryService queryService = context.getTaskQueryService();
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    InternalTask task = (InternalTask) queryService.getTaskInstanceById(taskId);
    if (task == null || task.getDeadlines() == null) {
        return null;
    }
    Iterator<? extends Deadline> it = null;
    if (removeStart) {
        if (task.getDeadlines().getStartDeadlines() != null) {
            deadlineService.unschedule(taskId, DeadlineType.START);
            it = task.getDeadlines().getStartDeadlines().iterator();
            while (it.hasNext()) {
                persistenceContext.removeDeadline(it.next());
                it.remove();
            }
        }
    }
    if (removeEnd) {
        if (task.getDeadlines().getEndDeadlines() != null) {
            deadlineService.unschedule(taskId, DeadlineType.END);
            it = task.getDeadlines().getEndDeadlines().iterator();
            while (it.hasNext()) {
                persistenceContext.removeDeadline(it.next());
                it.remove();
            }
        }
    }
    return null;
}
Also used : TaskDeadlinesService(org.kie.internal.task.api.TaskDeadlinesService) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskQueryService(org.kie.internal.task.api.TaskQueryService) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 3 with InternalTask

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

the class CancelTaskDeadlineCommand method execute.

@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    logger.debug("About to cancel deadline {} on a task {}", deadlineId, task);
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    DeadlineType type = DeadlineType.START;
    Deadline deadline = deadlines.getStartDeadlines().stream().filter(d -> deadlineId.equals(d.getId())).findFirst().orElse(null);
    if (deadline == null) {
        deadline = deadlines.getEndDeadlines().stream().filter(d -> deadlineId.equals(d.getId())).findFirst().orElse(null);
        type = DeadlineType.END;
    }
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    TaskDeadlinesService deadlinesService = context.getTaskDeadlinesService();
    deadlinesService.unschedule(taskId, deadline, type);
    persistenceContext.removeDeadline(deadline);
    return null;
}
Also used : DeadlineType(org.kie.internal.task.api.TaskDeadlinesService.DeadlineType) Logger(org.slf4j.Logger) Task(org.kie.api.task.model.Task) LoggerFactory(org.slf4j.LoggerFactory) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) TaskDeadlinesService(org.kie.internal.task.api.TaskDeadlinesService) Context(org.kie.api.runtime.Context) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) Deadline(org.kie.internal.task.api.model.Deadline) Deadlines(org.kie.internal.task.api.model.Deadlines) DeadlineType(org.kie.internal.task.api.TaskDeadlinesService.DeadlineType) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) Deadlines(org.kie.internal.task.api.model.Deadlines) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskDeadlinesService(org.kie.internal.task.api.TaskDeadlinesService) Deadline(org.kie.internal.task.api.model.Deadline) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 4 with InternalTask

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

the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskCompleted.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskCompleted() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task.getTaskData()).setSkipable(true);
    InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Administrator");
    ba.add(user);
    assignments.setBusinessAdministrators(ba);
    List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Administrator");
    po.add(user2);
    assignments.setPotentialOwners(po);
    task.setPeopleAssignments(assignments);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    taskService.start(taskId, "Administrator");
    taskService.complete(taskId, "Administrator", null);
    // emails should not be set yet
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    countDownListener.waitTillCompleted();
    // no email should ne sent as task was completed before deadline was triggered
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    task = (InternalTask) taskService.getTaskById(taskId);
    assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Completed);
    assertThat(((InternalTask) task).getDeadlines().getStartDeadlines().size()).isEqualTo(0);
    assertThat(((InternalTask) task).getDeadlines().getEndDeadlines().size()).isEqualTo(0);
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Example 5 with InternalTask

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

the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskCompletedMultipleTasks.

@Test(timeout = 12000)
public void testDelayedEmailNotificationOnDeadlineTaskCompletedMultipleTasks() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(2, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    // create task 1
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task.getTaskData()).setSkipable(true);
    InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Administrator");
    ba.add(user);
    assignments.setBusinessAdministrators(ba);
    List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Administrator");
    po.add(user2);
    assignments.setPotentialOwners(po);
    task.setPeopleAssignments(assignments);
    // create task 2
    reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    InternalTask task2 = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task2.getTaskData()).setSkipable(true);
    task2.setPeopleAssignments(assignments);
    taskService.addTask(task, new HashMap<String, Object>());
    taskService.addTask(task2, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.SECOND, 5);
    task.getDeadlines().getStartDeadlines().get(0).setDate(cal.getTime());
    task2.getDeadlines().getStartDeadlines().get(0).setDate(cal.getTime());
    taskService.start(taskId, "Administrator");
    taskService.complete(taskId, "Administrator", null);
    // emails should not be set yet
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    countDownListener.waitTillCompleted();
    // no email should be sent as task was completed before deadline was triggered
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(1);
    task = (InternalTask) taskService.getTaskById(taskId);
    assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Completed);
    assertThat(((InternalTask) task).getDeadlines().getStartDeadlines().size()).isEqualTo(0);
    assertThat(((InternalTask) task).getDeadlines().getEndDeadlines().size()).isEqualTo(0);
    taskService.start(task2.getId(), "Administrator");
    taskService.complete(task2.getId(), "Administrator", null);
    task = (InternalTask) taskService.getTaskById(task2.getId());
    assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Completed);
    assertThat(((InternalTask) task).getDeadlines().getStartDeadlines().size()).isEqualTo(0);
    assertThat(((InternalTask) task).getDeadlines().getEndDeadlines().size()).isEqualTo(0);
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Aggregations

InternalTask (org.kie.internal.task.api.model.InternalTask)50 Task (org.kie.api.task.model.Task)29 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)21 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)18 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)17 InputStreamReader (java.io.InputStreamReader)16 Reader (java.io.Reader)16 User (org.kie.api.task.model.User)16 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)15 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)15 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)14 Date (java.util.Date)12 HashMap (java.util.HashMap)11 ContentData (org.kie.internal.task.api.model.ContentData)11 InternalContent (org.kie.internal.task.api.model.InternalContent)11 I18NText (org.kie.api.task.model.I18NText)10 InternalI18NText (org.kie.internal.task.api.model.InternalI18NText)8 TaskSummary (org.kie.api.task.model.TaskSummary)6 StringReader (java.io.StringReader)5