use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.
the class AbstractProtobufProcessInstanceMarshaller method readNodeInstance.
public NodeInstance readNodeInstance(MarshallerReaderContext context, NodeInstanceContainer nodeInstanceContainer, WorkflowProcessInstance processInstance) throws IOException {
JBPMMessages.ProcessInstance.NodeInstance _node = (JBPMMessages.ProcessInstance.NodeInstance) context.parameterObject;
NodeInstanceImpl nodeInstance = readNodeInstanceContent(_node, context, processInstance);
nodeInstance.setNodeId(_node.getNodeId());
nodeInstance.setId(_node.getId());
nodeInstance.setNodeInstanceContainer(nodeInstanceContainer);
nodeInstance.setProcessInstance((org.jbpm.workflow.instance.WorkflowProcessInstance) processInstance);
nodeInstance.setLevel(_node.getLevel() == 0 ? 1 : _node.getLevel());
nodeInstance.internalSetSlaCompliance(_node.getSlaCompliance());
if (_node.getSlaDueDate() > 0) {
nodeInstance.internalSetSlaDueDate(new Date(_node.getSlaDueDate()));
}
nodeInstance.internalSetSlaTimerId(_node.getSlaTimerId());
switch(_node.getContent().getType()) {
case COMPOSITE_CONTEXT_NODE:
case DYNAMIC_NODE:
if (_node.getContent().getComposite().getVariableCount() > 0) {
Context variableScope = ((org.jbpm.process.core.Process) ((org.jbpm.process.instance.ProcessInstance) processInstance).getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) nodeInstance).getContextInstance(variableScope);
for (JBPMMessages.Variable _variable : _node.getContent().getComposite().getVariableList()) {
try {
Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
variableScopeInstance.internalSetVariable(_variable.getName(), _value);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
}
}
}
if (_node.getContent().getComposite().getIterationLevelsCount() > 0) {
for (JBPMMessages.IterationLevel _level : _node.getContent().getComposite().getIterationLevelsList()) {
((CompositeContextNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
}
}
for (JBPMMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getComposite().getNodeInstanceList()) {
context.parameterObject = _instance;
readNodeInstance(context, (CompositeContextNodeInstance) nodeInstance, processInstance);
}
for (JBPMMessages.ProcessInstance.ExclusiveGroupInstance _excl : _node.getContent().getComposite().getExclusiveGroupList()) {
ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
((CompositeContextNodeInstance) nodeInstance).addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
for (Long nodeInstanceId : _excl.getGroupNodeInstanceIdList()) {
NodeInstance groupNodeInstance = ((org.jbpm.workflow.instance.NodeInstanceContainer) processInstance).getNodeInstance(nodeInstanceId, true);
if (groupNodeInstance == null) {
throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
}
exclusiveGroupInstance.addNodeInstance(groupNodeInstance);
}
}
break;
case FOR_EACH_NODE:
for (JBPMMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getForEach().getNodeInstanceList()) {
context.parameterObject = _instance;
readNodeInstance(context, (ForEachNodeInstance) nodeInstance, processInstance);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ForEachNodeInstance) nodeInstance).getContextInstance(VariableScope.VARIABLE_SCOPE);
for (JBPMMessages.Variable _variable : _node.getContent().getForEach().getVariableList()) {
try {
Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
variableScopeInstance.internalSetVariable(_variable.getName(), _value);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
}
}
if (_node.getContent().getForEach().getIterationLevelsCount() > 0) {
for (JBPMMessages.IterationLevel _level : _node.getContent().getForEach().getIterationLevelsList()) {
((ForEachNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
}
}
}
break;
case EVENT_SUBPROCESS_NODE:
for (JBPMMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getComposite().getNodeInstanceList()) {
context.parameterObject = _instance;
readNodeInstance(context, (EventSubProcessNodeInstance) nodeInstance, processInstance);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((EventSubProcessNodeInstance) nodeInstance).getContextInstance(VariableScope.VARIABLE_SCOPE);
for (JBPMMessages.Variable _variable : _node.getContent().getComposite().getVariableList()) {
try {
Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
variableScopeInstance.internalSetVariable(_variable.getName(), _value);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
}
}
}
break;
default:
}
return nodeInstance;
}
use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.
the class MigrateProcessInstanceCommand method updateNodeInstances.
private 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();
}
((NodeInstanceImpl) nodeInstance).setNodeId(newNodeId);
if (nodeInstance instanceof NodeInstanceContainer) {
updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping);
}
}
}
use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.
the class DefaultAuditEventBuilderImpl method buildEvent.
@Override
public AuditEvent buildEvent(ProcessNodeTriggeredEvent pnte, Object log) {
NodeInstanceImpl nodeInstance = (NodeInstanceImpl) pnte.getNodeInstance();
NodeInstanceLog logEvent = null;
if (log != null) {
logEvent = (NodeInstanceLog) log;
if (nodeInstance instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) nodeInstance).getWorkItem() != null) {
logEvent.setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId());
}
if (nodeInstance instanceof SubProcessNodeInstance) {
logEvent.setReferenceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
}
return logEvent;
}
return null;
}
use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.
the class DefaultAuditEventBuilderImpl method buildEvent.
@Override
public AuditEvent buildEvent(ProcessNodeTriggeredEvent pnte) {
ProcessInstanceImpl pi = (ProcessInstanceImpl) pnte.getProcessInstance();
NodeInstanceImpl nodeInstance = (NodeInstanceImpl) pnte.getNodeInstance();
Node node = nodeInstance.getNode();
String nodeId = null;
String nodeType = null;
String nodeContainerId = null;
if (node != null) {
nodeId = (String) node.getMetaData().get("UniqueId");
nodeType = node.getClass().getSimpleName();
nodeContainerId = getNodeContainerId(node.getNodeContainer());
} else {
nodeId = Long.toString(nodeInstance.getNodeId());
nodeType = (String) nodeInstance.getMetaData("NodeType");
}
NodeInstanceLog log = new NodeInstanceLog(NodeInstanceLog.TYPE_ENTER, pi.getId(), pi.getProcessId(), Long.toString(nodeInstance.getId()), nodeId, nodeInstance.getNodeName());
if (nodeInstance instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) nodeInstance).getWorkItem() != null) {
log.setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId());
}
if (nodeInstance instanceof SubProcessNodeInstance) {
log.setReferenceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
}
String connection = (String) nodeInstance.getMetaData().get("IncomingConnection");
log.setConnection(connection);
log.setExternalId("" + ((KieSession) pnte.getKieRuntime()).getIdentifier());
log.setNodeType(nodeType);
log.setNodeContainerId(nodeContainerId);
log.setDate(pnte.getEventDate());
log.setSlaCompliance(nodeInstance.getSlaCompliance());
log.setSlaDueDate(nodeInstance.getSlaDueDate());
return log;
}
use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.
the class DefaultAuditEventBuilderImpl method buildEvent.
@Override
public AuditEvent buildEvent(ProcessNodeLeftEvent pnle, Object log) {
ProcessInstanceImpl pi = (ProcessInstanceImpl) pnle.getProcessInstance();
NodeInstanceImpl nodeInstance = (NodeInstanceImpl) pnle.getNodeInstance();
Node node = nodeInstance.getNode();
String nodeId = null;
String nodeType = null;
String nodeContainerId = null;
if (node != null) {
nodeId = (String) node.getMetaData().get("UniqueId");
nodeType = node.getClass().getSimpleName();
nodeContainerId = getNodeContainerId(node.getNodeContainer());
} else {
nodeId = Long.toString(nodeInstance.getNodeId());
nodeType = (String) nodeInstance.getMetaData("NodeType");
}
NodeInstanceLog logEvent = null;
if (log != null) {
logEvent = (NodeInstanceLog) log;
} else {
logEvent = new NodeInstanceLog(NodeInstanceLog.TYPE_EXIT, pi.getId(), pi.getProcessId(), Long.toString(nodeInstance.getId()), nodeId, nodeInstance.getNodeName());
}
if (nodeInstance instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) nodeInstance).getWorkItem() != null) {
logEvent.setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId());
}
if (nodeInstance instanceof SubProcessNodeInstance) {
logEvent.setReferenceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
}
String connection = (String) nodeInstance.getMetaData().get("OutgoingConnection");
logEvent.setConnection(connection);
logEvent.setExternalId("" + ((KieSession) pnle.getKieRuntime()).getIdentifier());
logEvent.setNodeType(nodeType);
logEvent.setNodeContainerId(nodeContainerId);
logEvent.setDate(pnle.getEventDate());
logEvent.setSlaCompliance(nodeInstance.getSlaCompliance());
logEvent.setSlaDueDate(nodeInstance.getSlaDueDate());
return logEvent;
}
Aggregations