Search in sources :

Example 41 with InternalTask

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

the class PeopleAssignmentHelperTest method testgetNullSafePeopleAssignments.

@Test
public void testgetNullSafePeopleAssignments() {
    Task task = TaskModelProvider.getFactory().newTask();
    InternalPeopleAssignments peopleAssignment = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    assertNotNull(peopleAssignment);
    peopleAssignment = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    assertNotNull(peopleAssignment);
    ((InternalTask) task).setPeopleAssignments(null);
    peopleAssignment = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    assertNotNull(peopleAssignment);
    assertEquals(0, peopleAssignment.getPotentialOwners().size());
    assertEquals(0, peopleAssignment.getBusinessAdministrators().size());
    assertEquals(0, peopleAssignment.getExcludedOwners().size());
    assertEquals(0, peopleAssignment.getRecipients().size());
    assertEquals(0, peopleAssignment.getTaskStakeholders().size());
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) InternalTask(org.kie.internal.task.api.model.InternalTask) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 42 with InternalTask

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

the class PeopleAssignmentHelperTest method testHandlePeopleAssignments.

@Test
public void testHandlePeopleAssignments() {
    InternalTask task = (InternalTask) TaskModelProvider.getFactory().newTask();
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    InternalPeopleAssignments peopleAssignment = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    assertNotNull(peopleAssignment);
    assertEquals(0, peopleAssignment.getPotentialOwners().size());
    assertEquals(0, peopleAssignment.getBusinessAdministrators().size());
    assertEquals(0, peopleAssignment.getTaskStakeholders().size());
    String actorId = "espiegelberg";
    String taskStakeholderId = "drmary";
    String businessAdministratorId = "drbug";
    String businessAdministratorGroupId = "Super users";
    String excludedOwnerId = "john";
    String recipientId = "mary";
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter(PeopleAssignmentHelper.ACTOR_ID, actorId);
    workItem.setParameter(PeopleAssignmentHelper.TASKSTAKEHOLDER_ID, taskStakeholderId);
    workItem.setParameter(PeopleAssignmentHelper.BUSINESSADMINISTRATOR_ID, businessAdministratorId);
    workItem.setParameter(PeopleAssignmentHelper.BUSINESSADMINISTRATOR_GROUP_ID, businessAdministratorGroupId);
    workItem.setParameter(PeopleAssignmentHelper.EXCLUDED_OWNER_ID, excludedOwnerId);
    workItem.setParameter(PeopleAssignmentHelper.RECIPIENT_ID, recipientId);
    peopleAssignmentHelper.handlePeopleAssignments(workItem, task, taskData);
    List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners();
    assertEquals(1, potentialOwners.size());
    assertEquals(actorId, potentialOwners.get(0).getId());
    List<OrganizationalEntity> businessAdministrators = task.getPeopleAssignments().getBusinessAdministrators();
    assertEquals(4, businessAdministrators.size());
    assertEquals("Administrator", businessAdministrators.get(0).getId());
    // Admin group
    assertEquals("Administrators", businessAdministrators.get(1).getId());
    assertEquals(businessAdministratorId, businessAdministrators.get(2).getId());
    assertEquals(businessAdministratorGroupId, businessAdministrators.get(3).getId());
    List<OrganizationalEntity> taskStakehoders = ((InternalPeopleAssignments) task.getPeopleAssignments()).getTaskStakeholders();
    assertEquals(1, taskStakehoders.size());
    assertEquals(taskStakeholderId, taskStakehoders.get(0).getId());
    List<OrganizationalEntity> excludedOwners = ((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners();
    assertEquals(1, excludedOwners.size());
    assertEquals(excludedOwnerId, excludedOwners.get(0).getId());
    List<OrganizationalEntity> recipients = ((InternalPeopleAssignments) task.getPeopleAssignments()).getRecipients();
    assertEquals(1, recipients.size());
    assertEquals(recipientId, recipients.get(0).getId());
}
Also used : InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItem(org.drools.core.process.instance.WorkItem) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 43 with InternalTask

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

the class TaskAdminServiceImpl method removeTasks.

public int removeTasks(List<TaskSummary> tasks) {
    int removedTasks = 0;
    for (TaskSummary sum : tasks) {
        long taskId = sum.getId();
        // Only remove archived tasks
        Task task = persistenceContext.findTask(taskId);
        if (task != null) {
            Content content = persistenceContext.findContent(task.getTaskData().getDocumentContentId());
            Content outputContent = persistenceContext.findContent(task.getTaskData().getOutputContentId());
            if (((InternalTask) task).isArchived()) {
                persistenceContext.remove(task);
                if (content != null) {
                    persistenceContext.remove(content);
                }
                if (outputContent != null) {
                    persistenceContext.remove(outputContent);
                }
                removedTasks++;
            } else {
                logger.warn(" The Task cannot be removed if it wasn't archived first !!");
            }
        }
    }
    return removedTasks;
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTask(org.kie.internal.task.api.model.InternalTask) Content(org.kie.api.task.model.Content) TaskSummary(org.kie.api.task.model.TaskSummary)

Example 44 with InternalTask

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

the class TaskDeadlinesServiceImpl method unschedule.

public void unschedule(long taskId, DeadlineType type) {
    Task task = persistenceContext.findTask(taskId);
    String deploymentId = task.getTaskData().getDeploymentId();
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    TimerService timerService = TimerServiceRegistry.getInstance().get(deploymentId + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
    if (timerService != null && timerService instanceof GlobalTimerService) {
        if (type == DeadlineType.START) {
            List<Deadline> startDeadlines = deadlines.getStartDeadlines();
            List<DeadlineSummary> resultList = (List<DeadlineSummary>) persistenceContext.queryWithParametersInTransaction("UnescalatedStartDeadlinesByTaskId", persistenceContext.addParametersToMap("taskId", taskId), ClassUtil.<List<DeadlineSummary>>castClass(List.class));
            for (DeadlineSummary summary : resultList) {
                TaskDeadlineJob deadlineJob = new TaskDeadlineJob(summary.getTaskId(), summary.getDeadlineId(), DeadlineType.START, deploymentId, task.getTaskData().getProcessInstanceId());
                logger.debug("unscheduling timer job for deadline {} {} and task {}  using timer service {}", deadlineJob.getId(), summary.getDeadlineId(), taskId, timerService);
                JobHandle jobHandle = jobHandles.remove(deadlineJob.getId());
                if (jobHandle == null) {
                    jobHandle = ((GlobalTimerService) timerService).buildJobHandleForContext(new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId));
                }
                timerService.removeJob(jobHandle);
                // mark the deadlines so they won't be rescheduled again
                for (Deadline deadline : startDeadlines) {
                    if (deadline.getId() == summary.getDeadlineId()) {
                        deadline.setEscalated(true);
                    }
                }
            }
        } else if (type == DeadlineType.END) {
            List<Deadline> endDeadlines = deadlines.getStartDeadlines();
            List<DeadlineSummary> resultList = (List<DeadlineSummary>) persistenceContext.queryWithParametersInTransaction("UnescalatedEndDeadlinesByTaskId", persistenceContext.addParametersToMap("taskId", taskId), ClassUtil.<List<DeadlineSummary>>castClass(List.class));
            for (DeadlineSummary summary : resultList) {
                TaskDeadlineJob deadlineJob = new TaskDeadlineJob(summary.getTaskId(), summary.getDeadlineId(), DeadlineType.END, deploymentId, task.getTaskData().getProcessInstanceId());
                logger.debug("unscheduling timer job for deadline {} and task {}  using timer service {}", deadlineJob.getId(), taskId, timerService);
                JobHandle jobHandle = jobHandles.remove(deadlineJob.getId());
                if (jobHandle == null) {
                    jobHandle = ((GlobalTimerService) timerService).buildJobHandleForContext(new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId));
                }
                timerService.removeJob(jobHandle);
                // mark the deadlines so they won't be rescheduled again
                for (Deadline deadline : endDeadlines) {
                    if (deadline.getId() == summary.getDeadlineId()) {
                        deadline.setEscalated(true);
                    }
                }
            }
        }
    } else {
        List<ScheduledFuture<ScheduledTaskDeadline>> knownFutures = null;
        if (type == DeadlineType.START) {
            knownFutures = startScheduledTaskDeadlines.get(taskId);
        } else if (type == DeadlineType.END) {
            knownFutures = endScheduledTaskDeadlines.get(taskId);
        }
        if (knownFutures == null) {
            return;
        }
        Iterator<ScheduledFuture<ScheduledTaskDeadline>> it = knownFutures.iterator();
        while (it.hasNext()) {
            ScheduledFuture<ScheduledTaskDeadline> scheduled = it.next();
            try {
                if (!scheduled.isDone() && !scheduled.isCancelled()) {
                    scheduled.cancel(true);
                }
            } catch (Exception e) {
                logger.error("Error while cancelling scheduled deadline task for Task with id {} -> {}", taskId, e);
            }
        }
    }
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTask(org.kie.internal.task.api.model.InternalTask) DeadlineSummary(org.kie.internal.task.api.model.DeadlineSummary) Deadline(org.kie.internal.task.api.model.Deadline) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) ScheduledFuture(java.util.concurrent.ScheduledFuture) JobHandle(org.drools.core.time.JobHandle) Deadlines(org.kie.internal.task.api.model.Deadlines) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService)

Example 45 with InternalTask

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

the class JaxbTask method getTask.

/**
 * This is a convienence method that retrieves a TaskImpl instance. It's used
 * internally in the {@link AddTaskCommand#execute(org.kie.internal.command.Context)} method
 * because that command requires a persistable task representation.
 * </p>
 * Users who are looking for information from the task should <i>not</i> use this method:
 * all of the task information is already available via the normal methods
 * defined by the {@link Task} or {@link InternalTask} interfaces, both of which this class
 * implements: for example: {@link JaxbTask#getId()}, {@link JaxbTask#getTaskData()}
 * or {@link JaxbTask#getPeopleAssignments()}.
 * @return a TaskImpl instance
 */
public Task getTask() {
    InternalTask taskImpl = (InternalTask) TaskModelProvider.getFactory().newTask();
    if (this.getId() != null) {
        taskImpl.setId(this.getId());
    }
    if (this.priority != null) {
        taskImpl.setPriority(this.getPriority());
    }
    JaxbPeopleAssignments jaxbPeopleAssignments = this.peopleAssignments;
    InternalPeopleAssignments peopleAssignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    if (jaxbPeopleAssignments.getTaskInitiator() != null) {
        User user = createUser(this.getPeopleAssignments().getTaskInitiator().getId());
        peopleAssignments.setTaskInitiator(user);
    }
    List<OrganizationalEntity> potentialOwners = copyOrganizationalEntityList(jaxbPeopleAssignments.getPotentialOwners());
    peopleAssignments.setPotentialOwners(potentialOwners);
    List<OrganizationalEntity> businessAdmins = copyOrganizationalEntityList(jaxbPeopleAssignments.getBusinessAdministrators());
    peopleAssignments.setBusinessAdministrators(businessAdmins);
    List<OrganizationalEntity> exclOwners = copyOrganizationalEntityList(jaxbPeopleAssignments.getExcludedOwners());
    peopleAssignments.setExcludedOwners(exclOwners);
    List<OrganizationalEntity> taskStake = copyOrganizationalEntityList(jaxbPeopleAssignments.getTaskStakeholders());
    peopleAssignments.setTaskStakeholders(taskStake);
    List<OrganizationalEntity> recipients = copyOrganizationalEntityList(jaxbPeopleAssignments.getRecipients());
    peopleAssignments.setRecipients(recipients);
    taskImpl.setPeopleAssignments(peopleAssignments);
    taskImpl.setSubTaskStrategy(this.getSubTaskStrategy());
    {
        List<I18NText> names = new ArrayList<I18NText>();
        for (I18NText n : this.getNames()) {
            I18NText text = TaskModelProvider.getFactory().newI18NText();
            ((InternalI18NText) text).setId(n.getId());
            ((InternalI18NText) text).setLanguage(n.getLanguage());
            ((InternalI18NText) text).setText(n.getText());
            names.add(text);
        }
        taskImpl.setNames(names);
    }
    if (this.getName() != null) {
        taskImpl.setName(this.getName());
    } else if (!this.getNames().isEmpty()) {
        taskImpl.setName(this.getNames().get(0).getText());
    }
    {
        List<I18NText> subjects = new ArrayList<I18NText>();
        for (I18NText s : this.getSubjects()) {
            I18NText text = TaskModelProvider.getFactory().newI18NText();
            ((InternalI18NText) text).setId(s.getId());
            ((InternalI18NText) text).setLanguage(s.getLanguage());
            ((InternalI18NText) text).setText(s.getText());
            subjects.add(text);
        }
        taskImpl.setSubjects(subjects);
    }
    if (this.getSubject() != null) {
        taskImpl.setSubject(this.getSubject());
    } else if (!this.getSubjects().isEmpty()) {
        taskImpl.setSubject(this.getSubjects().get(0).getText());
    }
    {
        List<I18NText> descriptions = new ArrayList<I18NText>();
        for (I18NText d : this.getDescriptions()) {
            I18NText text = TaskModelProvider.getFactory().newI18NText();
            ((InternalI18NText) text).setId(d.getId());
            ((InternalI18NText) text).setLanguage(d.getLanguage());
            ((InternalI18NText) text).setText(d.getText());
            descriptions.add(text);
        }
        taskImpl.setDescriptions(descriptions);
    }
    if (this.getDescription() != null) {
        taskImpl.setDescription(this.getDescription());
    } else if (!this.getDescriptions().isEmpty()) {
        taskImpl.setDescription(this.getDescriptions().get(0).getText());
    }
    taskImpl.setTaskType(this.getTaskType());
    taskImpl.setFormName(this.getFormName());
    // task data
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    JaxbTaskData jaxbTaskData = (JaxbTaskData) this.getTaskData();
    taskData.setStatus(jaxbTaskData.getStatus());
    taskData.setPreviousStatus(jaxbTaskData.getPreviousStatus());
    taskData.setActualOwner(createUser(jaxbTaskData.getActualOwnerId()));
    taskData.setCreatedBy(createUser(jaxbTaskData.getCreatedById()));
    taskData.setCreatedOn(jaxbTaskData.getCreatedOn());
    taskData.setActivationTime(jaxbTaskData.getActivationTime());
    taskData.setExpirationTime(jaxbTaskData.getExpirationTime());
    taskData.setSkipable(jaxbTaskData.isSkipable());
    taskData.setWorkItemId(jaxbTaskData.getWorkItemId());
    taskData.setProcessInstanceId(jaxbTaskData.getProcessInstanceId());
    taskData.setDocumentContentId(jaxbTaskData.getDocumentContentId());
    taskData.setDocumentAccessType(jaxbTaskData.getDocumentAccessType());
    taskData.setDocumentType(jaxbTaskData.getDocumentType());
    taskData.setOutputAccessType(jaxbTaskData.getOutputAccessType());
    taskData.setOutputType(jaxbTaskData.getOutputType());
    taskData.setOutputContentId(jaxbTaskData.getOutputContentId());
    taskData.setFaultName(jaxbTaskData.getFaultName());
    taskData.setFaultAccessType(jaxbTaskData.getFaultAccessType());
    taskData.setFaultType(jaxbTaskData.getFaultType());
    taskData.setFaultContentId(jaxbTaskData.getFaultContentId());
    taskData.setParentId(jaxbTaskData.getParentId());
    taskData.setProcessId(jaxbTaskData.getProcessId());
    taskData.setProcessSessionId(jaxbTaskData.getProcessSessionId());
    List<Comment> jaxbComments = jaxbTaskData.getComments();
    if (jaxbComments != null) {
        List<Comment> comments = new ArrayList<Comment>(jaxbComments.size());
        for (Comment jaxbComment : jaxbComments) {
            InternalComment comment = (InternalComment) TaskModelProvider.getFactory().newComment();
            if (jaxbComment.getId() != null) {
                comment.setId(jaxbComment.getId());
            }
            comment.setAddedAt(jaxbComment.getAddedAt());
            comment.setAddedBy(createUser(((JaxbComment) jaxbComment).getAddedById()));
            comment.setText(jaxbComment.getText());
            comments.add(comment);
        }
        taskData.setComments(comments);
    }
    List<Attachment> jaxbAttachments = jaxbTaskData.getAttachments();
    if (jaxbAttachments != null) {
        List<Attachment> attachments = new ArrayList<Attachment>(jaxbAttachments.size());
        for (Attachment jaxbAttach : jaxbAttachments) {
            InternalAttachment attach = (InternalAttachment) TaskModelProvider.getFactory().newAttachment();
            if (jaxbAttach.getId() != null) {
                attach.setId(jaxbAttach.getId());
            }
            attach.setName(jaxbAttach.getName());
            attach.setContentType(jaxbAttach.getContentType());
            attach.setAttachedAt(jaxbAttach.getAttachedAt());
            attach.setAttachedBy(createUser(((JaxbAttachment) jaxbAttach).getAttachedById()));
            attach.setSize(jaxbAttach.getSize());
            attach.setAttachmentContentId(jaxbAttach.getAttachmentContentId());
            attachments.add(attach);
        }
        taskData.setAttachments(attachments);
    }
    taskData.setDeploymentId(jaxbTaskData.getDeploymentId());
    ((InternalTask) taskImpl).setTaskData(taskData);
    return taskImpl;
}
Also used : InternalComment(org.kie.internal.task.api.model.InternalComment) Comment(org.kie.api.task.model.Comment) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalComment(org.kie.internal.task.api.model.InternalComment) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) ArrayList(java.util.ArrayList) Attachment(org.kie.api.task.model.Attachment) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ArrayList(java.util.ArrayList) List(java.util.List)

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