use of org.jbpm.process.core.context.swimlane.SwimlaneContext in project jbpm by kiegroup.
the class XmlBPMNProcessDumper method visitLanes.
private void visitLanes(WorkflowProcess process, StringBuilder xmlDump) {
// lanes
Collection<Swimlane> swimlanes = ((SwimlaneContext) ((org.jbpm.workflow.core.WorkflowProcess) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE)).getSwimlanes();
if (!swimlanes.isEmpty()) {
xmlDump.append(" <laneSet>" + EOL);
for (Swimlane swimlane : swimlanes) {
xmlDump.append(" <lane name=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(swimlane.getName()) + "\" >" + EOL);
visitLane(process, swimlane.getName(), xmlDump);
xmlDump.append(" </lane>" + EOL);
}
xmlDump.append(" </laneSet>" + EOL);
}
}
use of org.jbpm.process.core.context.swimlane.SwimlaneContext in project jbpm by kiegroup.
the class AbstractProtobufProcessInstanceMarshaller method readProcessInstance.
// Input methods
public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
InternalKnowledgeBase ruleBase = context.kBase;
InternalWorkingMemory wm = context.wm;
JBPMMessages.ProcessInstance _instance = (org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance) context.parameterObject;
if (_instance == null) {
// try to parse from the stream
ExtensionRegistry registry = PersisterHelper.buildRegistry(context, null);
Header _header;
try {
_header = PersisterHelper.readFromStreamWithHeaderPreloaded(context, registry);
} catch (ClassNotFoundException e) {
// Java 5 does not accept [new IOException(String, Throwable)]
IOException ioe = new IOException("Error deserializing process instance.");
ioe.initCause(e);
throw ioe;
}
_instance = JBPMMessages.ProcessInstance.parseFrom(_header.getPayload(), registry);
}
WorkflowProcessInstanceImpl processInstance = createProcessInstance();
processInstance.setId(_instance.getId());
String processId = _instance.getProcessId();
processInstance.setProcessId(processId);
String processXml = _instance.getProcessXml();
Process process = null;
if (processXml != null && processXml.trim().length() > 0) {
processInstance.setProcessXml(processXml);
process = processInstance.getProcess();
} else {
process = ruleBase.getProcess(processId);
if (process == null) {
throw new RuntimeException("Could not find process " + processId + " when restoring process instance " + processInstance.getId());
}
processInstance.setProcess(process);
}
processInstance.setDescription(_instance.getDescription());
processInstance.setState(_instance.getState());
processInstance.setParentProcessInstanceId(_instance.getParentProcessInstanceId());
processInstance.setSignalCompletion(_instance.getSignalCompletion());
processInstance.setDeploymentId(_instance.getDeploymentId());
processInstance.setCorrelationKey(_instance.getCorrelationKey());
processInstance.internalSetSlaCompliance(_instance.getSlaCompliance());
if (_instance.getSlaDueDate() > 0) {
processInstance.internalSetSlaDueDate(new Date(_instance.getSlaDueDate()));
}
processInstance.internalSetSlaTimerId(_instance.getSlaTimerId());
long nodeInstanceCounter = _instance.getNodeInstanceCounter();
processInstance.setKnowledgeRuntime(wm.getKnowledgeRuntime());
processInstance.internalSetNodeInstanceCounter(nodeInstanceCounter);
for (String completedNodeId : _instance.getCompletedNodeIdsList()) {
processInstance.addCompletedNodeId(completedNodeId);
}
if (_instance.getSwimlaneContextCount() > 0) {
Context swimlaneContext = ((org.jbpm.process.core.Process) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance(swimlaneContext);
for (JBPMMessages.ProcessInstance.SwimlaneContextInstance _swimlane : _instance.getSwimlaneContextList()) {
swimlaneContextInstance.setActorId(_swimlane.getSwimlane(), _swimlane.getActorId());
}
}
for (JBPMMessages.ProcessInstance.NodeInstance _node : _instance.getNodeInstanceList()) {
context.parameterObject = _node;
readNodeInstance(context, processInstance, processInstance);
}
for (JBPMMessages.ProcessInstance.ExclusiveGroupInstance _excl : _instance.getExclusiveGroupList()) {
ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
processInstance.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
for (Long nodeInstanceId : _excl.getGroupNodeInstanceIdList()) {
NodeInstance nodeInstance = ((org.jbpm.workflow.instance.NodeInstanceContainer) processInstance).getNodeInstance(nodeInstanceId, true);
if (nodeInstance == null) {
throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
}
exclusiveGroupInstance.addNodeInstance(nodeInstance);
}
}
if (_instance.getVariableCount() > 0) {
Context variableScope = ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(variableScope);
for (JBPMMessages.Variable _variable : _instance.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 (_instance.getIterationLevelsCount() > 0) {
for (JBPMMessages.IterationLevel _level : _instance.getIterationLevelsList()) {
processInstance.getIterationLevels().put(_level.getId(), _level.getLevel());
}
}
processInstance.reconnect();
return processInstance;
}
use of org.jbpm.process.core.context.swimlane.SwimlaneContext in project jbpm by kiegroup.
the class SwimlaneHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
WorkflowProcessImpl process = (WorkflowProcessImpl) parser.getParent();
final String name = attrs.getValue("name");
emptyAttributeCheck(localName, "name", name, parser);
SwimlaneContext swimlaneContext = (SwimlaneContext) process.getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
if (swimlaneContext != null) {
Swimlane swimlane = new Swimlane();
swimlane.setName(name);
swimlaneContext.addSwimlane(swimlane);
} else {
throw new SAXParseException("Could not find default swimlane context.", parser.getLocator());
}
return null;
}
use of org.jbpm.process.core.context.swimlane.SwimlaneContext in project jbpm by kiegroup.
the class XmlWorkflowProcessDumper method visitHeader.
protected void visitHeader(WorkflowProcess process, StringBuilder xmlDump, boolean includeMeta) {
xmlDump.append(" <header>" + EOL);
visitImports(((org.jbpm.process.core.Process) process).getImports(), xmlDump);
visitGlobals(((org.jbpm.process.core.Process) process).getGlobals(), xmlDump);
visitFunctionImports(((org.jbpm.process.core.Process) process).getFunctionImports(), xmlDump);
VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
if (variableScope != null) {
visitVariables(variableScope.getVariables(), xmlDump);
}
SwimlaneContext swimlaneContext = (SwimlaneContext) ((org.jbpm.process.core.Process) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
if (swimlaneContext != null) {
visitSwimlanes(swimlaneContext.getSwimlanes(), xmlDump);
}
ExceptionScope exceptionScope = (ExceptionScope) ((org.jbpm.process.core.Process) process).getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
if (exceptionScope != null) {
visitExceptionHandlers(exceptionScope.getExceptionHandlers(), xmlDump);
}
xmlDump.append(" </header>" + EOL + EOL);
}
use of org.jbpm.process.core.context.swimlane.SwimlaneContext in project jbpm by kiegroup.
the class AbstractProcessInstanceMarshaller method readProcessInstance.
// Input methods
public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
ObjectInputStream stream = context.stream;
InternalKnowledgeBase kBase = context.kBase;
InternalWorkingMemory wm = context.wm;
WorkflowProcessInstanceImpl processInstance = createProcessInstance();
processInstance.setId(stream.readLong());
String processId = stream.readUTF();
processInstance.setProcessId(processId);
Process process = kBase.getProcess(processId);
if (kBase != null) {
processInstance.setProcess(process);
}
processInstance.setState(stream.readInt());
long nodeInstanceCounter = stream.readLong();
processInstance.setKnowledgeRuntime(wm.getKnowledgeRuntime());
int nbSwimlanes = stream.readInt();
if (nbSwimlanes > 0) {
Context swimlaneContext = ((org.jbpm.process.core.Process) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance(swimlaneContext);
for (int i = 0; i < nbSwimlanes; i++) {
String name = stream.readUTF();
String value = stream.readUTF();
swimlaneContextInstance.setActorId(name, value);
}
}
while (stream.readShort() == PersisterEnums.NODE_INSTANCE) {
readNodeInstance(context, processInstance, processInstance);
}
int exclusiveGroupInstances = stream.readInt();
for (int i = 0; i < exclusiveGroupInstances; i++) {
ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
processInstance.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
int nodeInstances = stream.readInt();
for (int j = 0; j < nodeInstances; j++) {
long nodeInstanceId = stream.readLong();
NodeInstance nodeInstance = processInstance.getNodeInstance(nodeInstanceId);
if (nodeInstance == null) {
throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
}
exclusiveGroupInstance.addNodeInstance(nodeInstance);
}
}
// Process Variables
// - Number of Variables = keys.size()
// For Each Variable
// - Variable Key
// - Marshalling Strategy Index
// - Marshalled Object
int nbVariables = stream.readInt();
if (nbVariables > 0) {
Context variableScope = ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(variableScope);
for (int i = 0; i < nbVariables; i++) {
String name = stream.readUTF();
try {
ObjectMarshallingStrategy strategy = null;
int index = stream.readInt();
// This is the old way of de/serializing strategy objects
if (index >= 0) {
strategy = context.resolverStrategyFactory.getStrategy(index);
} else // This is the new way
if (index == -2) {
String strategyClassName = context.stream.readUTF();
if (!StringUtils.isEmpty(strategyClassName)) {
strategy = context.resolverStrategyFactory.getStrategyObject(strategyClassName);
if (strategy == null) {
throw new IllegalStateException("No strategy of type " + strategyClassName + " available.");
}
}
}
// If either way retrieves a strategy, use it
Object value = null;
if (strategy != null) {
value = strategy.read(stream);
}
variableScopeInstance.internalSetVariable(name, value);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not reload variable " + name);
}
}
}
processInstance.internalSetNodeInstanceCounter(nodeInstanceCounter);
if (wm != null) {
processInstance.reconnect();
}
return processInstance;
}
Aggregations