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));
}
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;
}
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;
}
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);
}
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);
}
Aggregations