use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class HumanResourcesHiringTest method testHiringProcess.
@SuppressWarnings("unchecked")
private void testHiringProcess(RuntimeManager manager, Context<?> context) {
RuntimeEngine runtime = manager.getRuntimeEngine(context);
KieSession ksession = runtime.getKieSession();
TaskService taskService = runtime.getTaskService();
assertNotNull(runtime);
assertNotNull(ksession);
ksession.getWorkItemManager().registerWorkItemHandler("EmailService", new WorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
manager.completeWorkItem(workItem.getId(), null);
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
});
ksession.getWorkItemManager().registerWorkItemHandler("TwitterService", new WorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
manager.completeWorkItem(workItem.getId(), null);
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
});
ProcessInstance processInstance = ksession.startProcess("hiring");
Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
Collection<NodeInstanceDesc> completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(1, completedNodes.size());
List<TaskSummary> tasks = ((InternalTaskService) taskService).getTasksAssignedByGroup("HR");
TaskSummary HRInterview = tasks.get(0);
taskService.claim(HRInterview.getId(), "katy");
taskService.start(HRInterview.getId(), "katy");
Map<String, Object> hrOutput = new HashMap<String, Object>();
hrOutput.put("out_name", "salaboy");
hrOutput.put("out_age", 29);
hrOutput.put("out_mail", "salaboy@gmail.com");
hrOutput.put("out_score", 8);
taskService.complete(HRInterview.getId(), "katy", hrOutput);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(2, completedNodes.size());
assertNotNull(processInstance);
assertNotNull(tasks);
assertEquals(1, tasks.size());
tasks = ((InternalTaskService) taskService).getTasksAssignedByGroup("IT");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary techInterview = tasks.get(0);
Task techInterviewTask = taskService.getTaskById(techInterview.getId());
Content contentById = taskService.getContentById(techInterviewTask.getTaskData().getDocumentContentId());
assertNotNull(contentById);
Map<String, Object> taskContent = (Map<String, Object>) ContentMarshallerHelper.unmarshall(contentById.getContent(), null);
assertEquals(7, taskContent.size());
assertEquals("salaboy@gmail.com", taskContent.get("in_mail"));
assertEquals(29, taskContent.get("in_age"));
assertEquals("salaboy", taskContent.get("in_name"));
taskService.claim(techInterview.getId(), "salaboy");
taskService.start(techInterview.getId(), "salaboy");
Map<String, Object> techOutput = new HashMap<String, Object>();
techOutput.put("out_skills", "java, jbpm, drools");
techOutput.put("out_twitter", "@salaboy");
techOutput.put("out_score", 8);
taskService.complete(techInterview.getId(), "salaboy", techOutput);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(3, completedNodes.size());
tasks = ((InternalTaskService) taskService).getTasksAssignedByGroup("Accounting");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary createProposal = tasks.get(0);
Task createProposalTask = taskService.getTaskById(createProposal.getId());
contentById = taskService.getContentById(createProposalTask.getTaskData().getDocumentContentId());
assertNotNull(contentById);
taskContent = (Map<String, Object>) ContentMarshallerHelper.unmarshall(contentById.getContent(), null);
assertEquals(6, taskContent.size());
assertEquals(8, taskContent.get("in_tech_score"));
assertEquals(8, taskContent.get("in_hr_score"));
taskService.claim(createProposal.getId(), "john");
taskService.start(createProposal.getId(), "john");
Map<String, Object> proposalOutput = new HashMap<String, Object>();
proposalOutput.put("out_offering", 10000);
taskService.complete(createProposal.getId(), "john", proposalOutput);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(5, completedNodes.size());
tasks = ((InternalTaskService) taskService).getTasksAssignedByGroup("HR");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary signContract = tasks.get(0);
Task signContractTask = taskService.getTaskById(signContract.getId());
contentById = taskService.getContentById(signContractTask.getTaskData().getDocumentContentId());
assertNotNull(contentById);
taskContent = (Map<String, Object>) ContentMarshallerHelper.unmarshall(contentById.getContent(), null);
assertEquals(6, taskContent.size());
assertEquals(10000, taskContent.get("in_offering"));
assertEquals("salaboy", taskContent.get("in_name"));
taskService.claim(signContract.getId(), "katy");
taskService.start(signContract.getId(), "katy");
Map<String, Object> signOutput = new HashMap<String, Object>();
signOutput.put("out_signed", true);
taskService.complete(signContract.getId(), "katy", signOutput);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(8, completedNodes.size());
int removeAllTasks = ((InternalTaskService) taskService).removeAllTasks();
logger.debug(">>> Removed Tasks > {}", removeAllTasks);
}
use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class AddAttachmentCommand method execute.
public Long execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
Attachment attachmentImpl = attachment;
if (attachmentImpl == null) {
attachmentImpl = jaxbAttachment;
}
Content contentImpl = content;
if (contentImpl == null) {
contentImpl = jaxbContent;
}
if (rawContent != null && contentImpl == null) {
Task task = context.getPersistenceContext().findTask(taskId);
contentImpl = TaskModelProvider.getFactory().newContent();
ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task.getTaskData().getDeploymentId());
((InternalContent) contentImpl).setContent(ContentMarshallerHelper.marshallContent(task, rawContent, ctx.getEnvironment()));
((InternalAttachment) attachmentImpl).setSize(contentImpl.getContent().length);
}
doCallbackOperationForAttachment(attachmentImpl, context);
return context.getTaskAttachmentService().addAttachment(taskId, attachmentImpl, contentImpl);
}
use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class GetTaskContentCommand method execute.
@SuppressWarnings("unchecked")
public Map<String, Object> execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
Task taskById = context.getTaskQueryService().getTaskInstanceById(taskId);
if (taskById == null) {
throw new IllegalStateException("Unable to find task with id " + taskId);
}
TaskContentService contentService = context.getTaskContentService();
Content contentById = contentService.getContentById(taskById.getTaskData().getDocumentContentId());
ContentMarshallerContext mContext = contentService.getMarshallerContext(taskById);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(contentById.getContent(), mContext.getEnvironment(), mContext.getClassloader());
if (!(unmarshalledObject instanceof Map)) {
logger.debug(" The Task Content is not of type Map, it was: {} so packaging it into new map under Content key ", unmarshalledObject.getClass());
Map<String, Object> content = new HashMap<String, Object>();
content.put("Content", unmarshalledObject);
return content;
}
Map<String, Object> content = (Map<String, Object>) unmarshalledObject;
return content;
}
use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class LifeCycleBaseTest method testNewTaskWithMapContent.
@Test
public void testNewTaskWithMapContent() {
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ],businessAdministrators = [ new User('Administrator') ], }),";
str += "name = 'This is my task name' })";
Map<String, Object> variablesMap = new HashMap<String, Object>();
variablesMap.put("key1", "value1");
variablesMap.put("key2", null);
variablesMap.put("key3", "value3");
ContentData data = ContentMarshallerHelper.marshal(null, variablesMap, null);
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, data);
long taskId = task.getId();
// Task should be assigned to the single potential owner and state set to Reserved
Task task1 = taskService.getTaskById(taskId);
assertEquals(AccessType.Inline, ((InternalTaskData) task1.getTaskData()).getDocumentAccessType());
assertEquals("java.util.HashMap", task1.getTaskData().getDocumentType());
long contentId = task1.getTaskData().getDocumentContentId();
assertTrue(contentId != -1);
// content
Content content = taskService.getContentById(contentId);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
if (!(unmarshalledObject instanceof Map)) {
fail("The variables should be a Map");
}
Map<String, Object> unmarshalledvars = (Map<String, Object>) unmarshalledObject;
JaxbContent jaxbContent = xmlRoundTripContent(content);
assertNotNull("Jaxb Content map not filled", jaxbContent.getContentMap());
assertEquals("value1", unmarshalledvars.get("key1"));
assertNull(unmarshalledvars.get("key2"));
assertEquals("value3", unmarshalledvars.get("key3"));
}
use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class LifeCycleBaseTest method testCompleteWithContent.
@Test
public void testCompleteWithContent() {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ],businessAdministrators = [ new User('Administrator') ], }),";
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();
// Go straight from Ready to Inprogress
taskService.start(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
// ContentData data = ContentMarshallerHelper.marshal("content", null);
Map<String, Object> params = new HashMap<String, Object>();
params.put("content", "content");
taskService.complete(taskId, "Darth Vader", params);
List<Content> allContent = taskService.getAllContentByTaskId(taskId);
assertNotNull(allContent);
assertEquals(3, allContent.size());
// only input(0) and output(1) is present
assertNotNull(allContent.get(0));
assertNotNull(allContent.get(1));
assertNull(allContent.get(2));
Task task2 = taskService.getTaskById(taskId);
assertEquals(AccessType.Inline, ((InternalTaskData) task2.getTaskData()).getOutputAccessType());
assertEquals("java.util.HashMap", task2.getTaskData().getOutputType());
long contentId = task2.getTaskData().getOutputContentId();
assertTrue(contentId != -1);
Content content = taskService.getContentById(contentId);
Map<String, Object> unmarshalledObject = (Map<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), null);
assertEquals("content", unmarshalledObject.get("content"));
// update content
params.put("content", "updated content");
taskService.setOutput(taskId, "Darth Vader", params);
task = taskService.getTaskById(taskId);
contentId = task.getTaskData().getOutputContentId();
content = taskService.getContentById(contentId);
String updated = new String(content.getContent());
unmarshalledObject = (Map<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), null);
assertEquals("updated content", unmarshalledObject.get("content"));
taskService.deleteOutput(taskId, "Darth Vader");
content = taskService.getContentById(contentId);
assertNull(content);
}
Aggregations