use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class AbstractHTWorkItemHandler method createTaskBasedOnWorkItemParams.
protected Task createTaskBasedOnWorkItemParams(KieSession session, WorkItem workItem) {
InternalTask task = (InternalTask) TaskModelProvider.getFactory().newTask();
String taskName = (String) workItem.getParameter("NodeName");
CaseData caseFile = null;
String locale = (String) workItem.getParameter("Locale");
if (locale == null) {
locale = "en-UK";
}
if (taskName != null) {
List<I18NText> names = new ArrayList<I18NText>();
I18NText text = TaskModelProvider.getFactory().newI18NText();
((InternalI18NText) text).setLanguage(locale);
((InternalI18NText) text).setText(taskName);
names.add(text);
task.setNames(names);
}
task.setName(taskName);
// this should be replaced by FormName filled by designer
// TaskName shouldn't be trimmed if we are planning to use that for the task lists
String formName = (String) workItem.getParameter("TaskName");
if (formName != null) {
task.setFormName(formName);
}
String comment = (String) workItem.getParameter("Comment");
if (comment == null) {
comment = "";
}
String description = (String) workItem.getParameter("Description");
if (description == null) {
description = comment;
}
List<I18NText> descriptions = new ArrayList<I18NText>();
I18NText descText = TaskModelProvider.getFactory().newI18NText();
((InternalI18NText) descText).setLanguage(locale);
((InternalI18NText) descText).setText(description);
descriptions.add(descText);
task.setDescriptions(descriptions);
task.setDescription(description);
List<I18NText> subjects = new ArrayList<I18NText>();
I18NText subjectText = TaskModelProvider.getFactory().newI18NText();
((InternalI18NText) subjectText).setLanguage(locale);
((InternalI18NText) subjectText).setText(comment);
subjects.add(subjectText);
task.setSubjects(subjects);
task.setSubject(comment);
String priorityString = (String) workItem.getParameter("Priority");
int priority = 0;
if (priorityString != null) {
try {
priority = new Integer(priorityString);
} catch (NumberFormatException e) {
// do nothing
}
}
task.setPriority(priority);
InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
taskData.setWorkItemId(workItem.getId());
taskData.setProcessInstanceId(workItem.getProcessInstanceId());
if (session != null) {
if (session.getProcessInstance(workItem.getProcessInstanceId()) != null) {
taskData.setProcessId(session.getProcessInstance(workItem.getProcessInstanceId()).getProcess().getId());
String deploymentId = ((WorkItemImpl) workItem).getDeploymentId();
taskData.setDeploymentId(deploymentId);
}
if (session instanceof KieSession) {
taskData.setProcessSessionId(((KieSession) session).getIdentifier());
}
@SuppressWarnings("unchecked") Collection<CaseData> caseFiles = (Collection<CaseData>) session.getObjects(new ClassObjectFilter(CaseData.class));
if (caseFiles != null && caseFiles.size() == 1) {
caseFile = caseFiles.iterator().next();
}
}
taskData.setSkipable(!"false".equals(workItem.getParameter("Skippable")));
// Sub Task Data
Long parentId = (Long) workItem.getParameter("ParentId");
if (parentId != null) {
taskData.setParentId(parentId);
}
String createdBy = (String) workItem.getParameter("CreatedBy");
if (createdBy != null && createdBy.trim().length() > 0) {
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId(createdBy);
taskData.setCreatedBy(user);
}
String dueDateString = (String) workItem.getParameter("DueDate");
Date date = null;
if (dueDateString != null && !dueDateString.isEmpty()) {
if (DateTimeUtils.isPeriod(dueDateString)) {
Long longDateValue = DateTimeUtils.parseDateAsDuration(dueDateString.substring(1));
date = new Date(System.currentTimeMillis() + longDateValue);
} else {
date = new Date(DateTimeUtils.parseDateTime(dueDateString));
}
}
if (date != null) {
taskData.setExpirationTime(date);
}
PeopleAssignmentHelper peopleAssignmentHelper = new PeopleAssignmentHelper(caseFile);
peopleAssignmentHelper.handlePeopleAssignments(workItem, task, taskData);
PeopleAssignments peopleAssignments = task.getPeopleAssignments();
List<OrganizationalEntity> businessAdministrators = peopleAssignments.getBusinessAdministrators();
taskData.initialize();
task.setTaskData(taskData);
task.setDeadlines(HumanTaskHandlerHelper.setDeadlines(workItem, businessAdministrators, session.getEnvironment()));
return task;
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class LocalTaskAuditWithDeadlineTest method testDelayedReassignmentOnDeadline.
@Test(timeout = 10000)
public void testDelayedReassignmentOnDeadline() throws Exception {
CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, true, false);
addCountDownListner(countDownListener);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("now", new Date());
Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithReassignment));
Task task = (InternalTask) TaskFactory.evalTask(reader, vars);
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
taskService.claim(taskId, "Tony Stark");
task = taskService.getTaskById(taskId);
List<OrganizationalEntity> potentialOwners = (List<OrganizationalEntity>) task.getPeopleAssignments().getPotentialOwners();
List<String> ids = new ArrayList<String>(potentialOwners.size());
for (OrganizationalEntity entity : potentialOwners) {
ids.add(entity.getId());
}
assertTrue(ids.contains("Tony Stark"));
assertTrue(ids.contains("Luke Cage"));
List<AuditTask> tasks = taskAuditService.getAllAuditTasks(new QueryFilter());
assertEquals(1, tasks.size());
AuditTask auditTask = tasks.get(0);
assertEquals(Status.Reserved.toString(), auditTask.getStatus());
assertEquals("Tony Stark", auditTask.getActualOwner());
// should have re-assigned by now
countDownListener.waitTillCompleted();
task = taskService.getTaskById(taskId);
assertNull(task.getTaskData().getActualOwner());
assertEquals(Status.Ready, task.getTaskData().getStatus());
potentialOwners = (List<OrganizationalEntity>) task.getPeopleAssignments().getPotentialOwners();
ids = new ArrayList<String>(potentialOwners.size());
for (OrganizationalEntity entity : potentialOwners) {
ids.add(entity.getId());
}
assertTrue(ids.contains("Bobba Fet"));
assertTrue(ids.contains("Jabba Hutt"));
tasks = taskAuditService.getAllAuditTasks(new QueryFilter());
assertEquals(1, tasks.size());
auditTask = tasks.get(0);
assertEquals(Status.Ready.toString(), auditTask.getStatus());
assertEquals("", auditTask.getActualOwner());
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class JPATaskLifeCycleEventListener method assignmentsUpadted.
protected void assignmentsUpadted(TaskEvent event, AssignmentType type, List<OrganizationalEntity> entities, String messageSufix) {
if (entities == null || entities.isEmpty()) {
return;
}
String userId = event.getTaskContext().getUserId();
Task task = event.getTask();
TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext) event.getTaskContext()).getPersistenceContext());
StringBuilder message = new StringBuilder();
switch(type) {
case POT_OWNER:
message.append("Potential owners [");
break;
case EXCL_OWNER:
message.append("Excluded owners [");
break;
case ADMIN:
message.append("Business administrators [");
break;
default:
break;
}
String entitiesAsString = entities.stream().map(oe -> oe.getId()).collect(Collectors.joining(","));
message.append(entitiesAsString);
message.append(messageSufix);
persistenceContext.persist(new TaskEventImpl(task.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.UPDATED, task.getTaskData().getProcessInstanceId(), task.getTaskData().getWorkItemId(), userId, message.toString()));
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testTransitionBetweenStagesInCaseWithActiveElements.
@Test
public void testTransitionBetweenStagesInCaseWithActiveElements() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl(USER));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, caseFile);
assertNotNull(caseId);
try {
Collection<CaseStageInstance> stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
CaseStageInstance stageInstance = stage.iterator().next();
assertEquals("Stage One", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
Collection<NodeInstanceDesc> activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
caseService.triggerAdHocFragment(caseId, "Task 1", data);
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
stageInstance = stage.iterator().next();
assertEquals("Stage One", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertEquals("Task 1", activeNodes.iterator().next().getName());
caseService.addDataToCaseFile(caseId, "customData", "nextStagePlease");
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
assertEquals("Stage Two", stage.iterator().next().getName());
assertEquals(StageStatus.Active, stage.iterator().next().getStatus());
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
stageInstance = stage.iterator().next();
assertEquals("Stage Two", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
caseService.triggerAdHocFragment(caseId, "Task 2", data);
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
stageInstance = stage.iterator().next();
assertEquals("Stage Two", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertEquals("Task 2", activeNodes.iterator().next().getName());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testUserTasksInCase.
@Test
public void testUserTasksInCase() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl(USER));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
String caseId2 = null;
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(0, tasks.size());
Map<String, Object> taskInput = new HashMap<>();
taskInput.put("ActorId", "john");
taskInput.put("Comment", "Need to provide data");
caseService.triggerAdHocFragment(caseId, "Missing data", taskInput);
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertEquals("Missing data", task.getName());
assertEquals("Need to provide data", task.getSubject());
caseId2 = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
assertNotNull(caseId2);
assertEquals("CASE-0000000002", caseId2);
caseService.triggerAdHocFragment(caseId2, "Missing data", taskInput);
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId2, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertEquals("Missing data", task.getName());
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertEquals("Missing data", task.getName());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
if (caseId2 != null) {
caseService.cancelCase(caseId2);
}
}
}
Aggregations