use of org.kie.internal.task.api.model.InternalOrganizationalEntity 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.internal.task.api.model.InternalOrganizationalEntity in project jbpm by kiegroup.
the class UserGroupCallbackTaskCommand method addGroupFromCallbackOperation.
protected void addGroupFromCallbackOperation(String groupId, TaskContext context) {
Group group = context.getPersistenceContext().findGroup(groupId);
boolean groupExists = group != null;
if (!StringUtils.isEmpty(groupId) && !groupExists) {
group = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) group).setId(groupId);
persistIfNotExists(group, context);
}
}
use of org.kie.internal.task.api.model.InternalOrganizationalEntity in project jbpm by kiegroup.
the class UserGroupCallbackTaskCommand method addUserFromCallbackOperation.
protected User addUserFromCallbackOperation(String userId, TaskContext context) {
User user = context.getPersistenceContext().findUser(userId);
boolean userExists = user != null;
if (!StringUtils.isEmpty(userId) && !userExists) {
user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId(userId);
persistIfNotExists(user, context);
}
return user;
}
use of org.kie.internal.task.api.model.InternalOrganizationalEntity in project jbpm by kiegroup.
the class AddGroupCommand method execute.
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
Group group = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) group).setId(groupId);
context.getTaskIdentityService().addGroup(group);
return null;
}
use of org.kie.internal.task.api.model.InternalOrganizationalEntity in project jbpm by kiegroup.
the class LifeCycleBaseTest method testNominateToGroup.
@Test
public void testNominateToGroup() {
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { businessAdministrators = [ new User('Darth Vader'), new User('Bobba Fet') ] } ),";
str += "name = 'This is my task name'})";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
List<OrganizationalEntity> potentialGroups = new ArrayList<OrganizationalEntity>();
Group group = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) group).setId("Knights Templer");
potentialGroups.add(group);
taskService.nominate(taskId, "Darth Vader", potentialGroups);
// shouldn't affect the assignments
Task task1 = taskService.getTaskById(taskId);
assertTrue(task1.getPeopleAssignments().getPotentialOwners().contains(group));
assertEquals(task1.getTaskData().getStatus(), Status.Ready);
}
Aggregations