use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class EscalateToAdminSLAViolationListener method afterSLAViolated.
@Override
public void afterSLAViolated(SLAViolatedEvent event) {
CaseFileInstance caseFile = getCaseFile((KieSession) event.getKieRuntime());
if (caseFile != null) {
String caseId = ((WorkflowProcessInstanceImpl) event.getProcessInstance()).getCorrelationKey();
if (caseFile.getCaseId().equals(caseId)) {
try {
Collection<OrganizationalEntity> adminAssignments = ((CaseAssignment) caseFile).getAssignments("admin");
String users = adminAssignments.stream().filter(oe -> oe instanceof User).map(oe -> oe.getId()).collect(Collectors.joining(","));
String groups = adminAssignments.stream().filter(oe -> oe instanceof Group).map(oe -> oe.getId()).collect(Collectors.joining(","));
String taskName = "SLA violation for case " + caseId;
String taskDescription = "Service Level Agreement has been violated for case " + caseId;
if (event.getNodeInstance() != null) {
taskName += "Task (" + event.getNodeInstance().getNodeName() + ") SLA violation for case " + caseId;
taskDescription += " on task " + event.getNodeInstance().getNodeName();
}
logger.debug("Case instance {} has SLA violation, escalating to administrator", caseId);
CaseService caseService = (CaseService) ServiceRegistry.get().service(ServiceRegistry.CASE_SERVICE);
TaskSpecification taskSpec = caseService.newHumanTaskSpec(taskName, taskDescription, users, groups, null);
caseService.addDynamicTask(caseId, taskSpec);
} catch (IllegalArgumentException e) {
logger.debug("There is no admin role defined in case instance {}, unable to escalate SLA violation", caseId);
}
}
}
}
use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class StateBasedNodeInstance method internalTrigger.
public void internalTrigger(NodeInstance from, String type) {
super.internalTrigger(from, type);
// if node instance was cancelled, abort
if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
return;
}
// activate timers
Map<Timer, DroolsAction> timers = getEventBasedNode().getTimers();
if (timers != null) {
addTimerListener();
timerInstances = new ArrayList<Long>(timers.size());
TimerManager timerManager = ((InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getTimerManager();
for (Timer timer : timers.keySet()) {
TimerInstance timerInstance = createTimerInstance(timer);
timerManager.registerTimer(timerInstance, (ProcessInstance) getProcessInstance());
timerInstances.add(timerInstance.getId());
}
}
if (getEventBasedNode().getBoundaryEvents() != null) {
for (String name : getEventBasedNode().getBoundaryEvents()) {
boolean isActive = ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda()).isRuleActiveInRuleFlowGroup("DROOLS_SYSTEM", name, getProcessInstance().getId());
if (isActive) {
getProcessInstance().getKnowledgeRuntime().signalEvent(name, null);
} else {
addActivationListener();
}
}
}
((WorkflowProcessInstanceImpl) getProcessInstance()).addActivatingNodeId((String) getNode().getMetaData().get("UniqueId"));
}
use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class WorkflowProcessInstanceUpgrader method updateNodeInstances.
private static void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, Long> nodeMapping) {
for (NodeInstance nodeInstance : nodeInstanceContainer.getNodeInstances()) {
String oldNodeId = ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getUniqueId();
Long newNodeId = nodeMapping.get(oldNodeId);
if (newNodeId == null) {
newNodeId = nodeInstance.getNodeId();
}
// clean up iteration levels for removed (old) nodes
Map<String, Integer> iterLevels = ((WorkflowProcessInstanceImpl) nodeInstance.getProcessInstance()).getIterationLevels();
String uniqueId = (String) ((NodeImpl) nodeInstance.getNode()).getMetaData("UniqueId");
iterLevels.remove(uniqueId);
// and now set to new node id
((NodeInstanceImpl) nodeInstance).setNodeId(newNodeId);
if (nodeInstance instanceof NodeInstanceContainer) {
updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping);
}
}
}
use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class JbpmBpmn2TestCase method assertNodeExists.
public void assertNodeExists(ProcessInstance process, String... nodeNames) {
WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
List<String> names = new ArrayList<String>();
for (String nodeName : nodeNames) {
names.add(nodeName);
}
for (Node node : instance.getNodeContainer().getNodes()) {
if (names.contains(node.getName())) {
names.remove(node.getName());
}
}
if (!names.isEmpty()) {
String s = names.get(0);
for (int i = 1; i < names.size(); i++) {
s += ", " + names.get(i);
}
fail("Node(s) do not exist: " + s);
}
}
use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class JbpmBpmn2TestCase method assertNumOfIncommingConnections.
public void assertNumOfIncommingConnections(ProcessInstance process, String nodeName, int num) {
assertNodeExists(process, nodeName);
WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
for (Node node : instance.getNodeContainer().getNodes()) {
if (node.getName().equals(nodeName)) {
if (node.getIncomingConnections().size() != num) {
fail("Expected incomming connections: " + num + " - found " + node.getIncomingConnections().size());
} else {
break;
}
}
}
}
Aggregations