use of org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl in project kogito-runtimes by kiegroup.
the class HumanTaskNodeInstance method createWorkItem.
@Override
protected InternalKogitoWorkItem createWorkItem(WorkItemNode workItemNode) {
HumanTaskWorkItemImpl workItem = (HumanTaskWorkItemImpl) super.createWorkItem(workItemNode);
String actorId = assignWorkItem(workItem);
if (actorId != null) {
workItem.setParameter(ACTOR_ID, actorId);
}
workItem.setTaskName((String) workItem.getParameter(TASK_NAME));
workItem.setTaskDescription((String) workItem.getParameter(DESCRIPTION));
workItem.setTaskPriority((String) workItem.getParameter(PRIORITY));
workItem.setReferenceName((String) workItem.getParameter(NODE_NAME));
Work work = workItemNode.getWork();
scheduleDeadlines(work.getNotStartedDeadlines(), notStartedDeadlines);
scheduleDeadlines(work.getNotCompletedDeadlines(), notCompletedDeadlines);
scheduleDeadlines(work.getNotStartedReassignments(), notStartedReassignments);
scheduleDeadlines(work.getNotCompletedReassigments(), notCompletedReassignments);
return workItem;
}
use of org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl in project kogito-runtimes by kiegroup.
the class ProtobufProcessInstanceReader method buildWorkItemNodeInstance.
private NodeInstanceImpl buildWorkItemNodeInstance(WorkItemNodeInstanceContent content) {
try {
WorkItemNodeInstance nodeInstance = instanceWorkItem(content);
if (nodeInstance instanceof HumanTaskNodeInstance) {
HumanTaskNodeInstance humanTaskNodeInstance = (HumanTaskNodeInstance) nodeInstance;
HumanTaskWorkItemImpl workItem = (HumanTaskWorkItemImpl) nodeInstance.getWorkItem();
Any workItemDataMessage = content.getWorkItemData();
if (workItemDataMessage.is(HumanTaskWorkItemData.class)) {
HumanTaskWorkItemData workItemData = workItemDataMessage.unpack(HumanTaskWorkItemData.class);
humanTaskNodeInstance.getNotCompletedDeadlineTimers().putAll(buildDeadlines(workItemData.getCompletedDeadlinesMap()));
humanTaskNodeInstance.getNotCompletedReassigments().putAll(buildReassignments(workItemData.getCompletedReassigmentsMap()));
humanTaskNodeInstance.getNotStartedDeadlineTimers().putAll(buildDeadlines(workItemData.getStartDeadlinesMap()));
humanTaskNodeInstance.getNotStartedReassignments().putAll(buildReassignments(workItemData.getStartReassigmentsMap()));
if (workItemData.hasTaskName()) {
workItem.setTaskName(workItemData.getTaskName());
}
if (workItemData.hasTaskDescription()) {
workItem.setTaskDescription(workItemData.getTaskDescription());
}
if (workItemData.hasTaskPriority()) {
workItem.setTaskPriority(workItemData.getTaskPriority());
}
if (workItemData.hasTaskReferenceName()) {
workItem.setReferenceName(workItemData.getTaskReferenceName());
}
if (workItemData.hasActualOwner()) {
workItem.setActualOwner(workItemData.getActualOwner());
}
workItem.getAdminUsers().addAll(workItemData.getAdminUsersList());
workItem.getAdminGroups().addAll(workItemData.getAdminGroupsList());
workItem.getPotentialUsers().addAll(workItemData.getPotUsersList());
workItem.getPotentialGroups().addAll(workItemData.getPotGroupsList());
workItem.getExcludedUsers().addAll(workItemData.getExcludedUsersList());
workItem.getComments().putAll(workItemData.getCommentsList().stream().map(this::buildComment).collect(Collectors.toMap(Comment::getId, Function.identity())));
workItem.getAttachments().putAll(workItemData.getAttachmentsList().stream().map(this::buildAttachment).collect(Collectors.toMap(Attachment::getId, Function.identity())));
}
}
nodeInstance.internalSetWorkItemId(content.getWorkItemId());
KogitoWorkItemImpl workItem = (KogitoWorkItemImpl) nodeInstance.getWorkItem();
workItem.setId(content.getWorkItemId());
workItem.setProcessInstanceId(ruleFlowProcessInstance.getStringId());
workItem.setName(content.getName());
workItem.setState(content.getState());
workItem.setDeploymentId(ruleFlowProcessInstance.getDeploymentId());
workItem.setProcessInstance(ruleFlowProcessInstance);
workItem.setPhaseId(content.getPhaseId());
workItem.setPhaseStatus(content.getPhaseStatus());
workItem.setStartDate(new Date(content.getStartDate()));
if (content.getCompleteDate() > 0) {
workItem.setCompleteDate(new Date(content.getCompleteDate()));
}
if (content.getTimerInstanceIdCount() > 0) {
nodeInstance.internalSetTimerInstances(new ArrayList<>(content.getTimerInstanceIdList()));
}
nodeInstance.internalSetProcessInstanceId(content.getErrorHandlingProcessInstanceId());
varReader.buildVariables(content.getVariableList()).forEach(var -> nodeInstance.getWorkItem().getParameters().put(var.getName(), var.getValue()));
varReader.buildVariables(content.getResultList()).forEach(var -> nodeInstance.getWorkItem().getResults().put(var.getName(), var.getValue()));
return nodeInstance;
} catch (InvalidProtocolBufferException ex) {
throw new ProcessInstanceMarshallerException("cannot unpack node instance", ex);
}
}
use of org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl in project kogito-runtimes by kiegroup.
the class ProtobufProcessInstanceReader method instanceWorkItem.
private WorkItemNodeInstance instanceWorkItem(WorkItemNodeInstanceContent content) {
if (content.hasWorkItemData()) {
Any workItemDataMessage = content.getWorkItemData();
if (workItemDataMessage.is(HumanTaskWorkItemData.class)) {
HumanTaskNodeInstance nodeInstance = new HumanTaskNodeInstance();
HumanTaskWorkItemImpl workItem = new HumanTaskWorkItemImpl();
nodeInstance.internalSetWorkItem(workItem);
return nodeInstance;
} else {
throw new ProcessInstanceMarshallerException("Don't know which type of work item is");
}
} else {
WorkItemNodeInstance nodeInstance = new WorkItemNodeInstance();
KogitoWorkItemImpl workItem = new KogitoWorkItemImpl();
nodeInstance.internalSetWorkItem(workItem);
return nodeInstance;
}
}
use of org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl in project kogito-runtimes by kiegroup.
the class ProcessHumanTaskTest method testSwimlane.
@Test
public void testSwimlane() {
Reader source = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.humantask\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <swimlanes>\n" + " <swimlane name=\"actor1\" />\n" + " </swimlanes>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <humanTask id=\"2\" name=\"HumanTask\" swimlane=\"actor1\" >\n" + " <work name=\"Human Task\" >\n" + " <parameter name=\"ActorId\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>John Doe</value>\n" + " </parameter>\n" + " <parameter name=\"TaskName\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>Do something</value>\n" + " </parameter>\n" + " <parameter name=\"Priority\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"Comment\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " </work>\n" + " <mapping type=\"out\" from=\"ActorId\" to=\"ActorId\" />" + " </humanTask>\n" + " <humanTask id=\"3\" name=\"HumanTask\" swimlane=\"actor1\" >\n" + " <work name=\"Human Task\" >\n" + " <parameter name=\"ActorId\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"TaskName\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>Do something else</value>\n" + " </parameter>\n" + " <parameter name=\"Priority\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " <parameter name=\"Comment\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </parameter>\n" + " </work>\n" + " <mapping type=\"out\" from=\"ActorId\" to=\"ActorId\" />" + " </humanTask>\n" + " <end id=\"4\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " <connection from=\"3\" to=\"4\" />\n" + " </connections>\n" + "\n" + "</process>");
builder.add(new ReaderResource(source), ResourceType.DRF);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
TestWorkItemHandler handler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler);
KogitoProcessInstance processInstance = kruntime.startProcess("org.drools.humantask");
assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
KogitoWorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
assertEquals("Do something", workItem.getParameter("TaskName"));
assertEquals("John Doe", workItem.getParameter("ActorId"));
Map<String, Object> results = new HashMap<String, Object>();
((HumanTaskWorkItemImpl) workItem).setActualOwner("Jane Doe");
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), results);
workItem = handler.getWorkItem();
assertNotNull(workItem);
assertEquals("Do something else", workItem.getParameter("TaskName"));
assertEquals("Jane Doe", workItem.getParameter("SwimlaneActorId"));
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
assertEquals(KogitoProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl in project kogito-runtimes by kiegroup.
the class PredictionAwareHumanTaskLifeCycle method transitionTo.
@Override
public Map<String, Object> transitionTo(KogitoWorkItem workItem, KogitoWorkItemManager manager, Transition<Map<String, Object>> transition) {
LifeCyclePhase targetPhase = phaseById(transition.phase());
if (targetPhase == null) {
logger.debug("Target life cycle phase '{}' does not exist in {}", transition.phase(), this.getClass().getSimpleName());
throw new InvalidLifeCyclePhaseException(transition.phase());
}
HumanTaskWorkItemImpl humanTaskWorkItem = (HumanTaskWorkItemImpl) workItem;
if (targetPhase.id().equals(Active.ID)) {
PredictionOutcome outcome = predictionService.predict(workItem, workItem.getParameters());
logger.debug("Prediction service returned confidence level {} for work item {}", outcome.getConfidenceLevel(), humanTaskWorkItem.getStringId());
if (outcome.isCertain()) {
humanTaskWorkItem.getResults().putAll(outcome.getData());
logger.debug("Prediction service is certain (confidence level {}) on the outputs, completing work item {}", outcome.getConfidenceLevel(), humanTaskWorkItem.getStringId());
((InternalKogitoWorkItemManager) manager).internalCompleteWorkItem(humanTaskWorkItem);
return outcome.getData();
} else if (outcome.isPresent()) {
logger.debug("Prediction service is NOT certain (confidence level {}) on the outputs, setting recommended outputs on work item {}", outcome.getConfidenceLevel(), humanTaskWorkItem.getStringId());
humanTaskWorkItem.getResults().putAll(outcome.getData());
}
}
// prediction service does work only on activating tasks
Map<String, Object> data = super.transitionTo(workItem, manager, transition);
if (targetPhase.id().equals(Complete.ID)) {
// upon actual transition train the data if it's completion phase
predictionService.train(humanTaskWorkItem, workItem.getParameters(), data);
}
return data;
}
Aggregations