protected InstanceView<ProcessInstance> getInstanceViewFor(ProcessInstance pi) { if (((WorkflowProcess)pi.getProcess()).isDynamic()) { return new CaseInstanceView(pi); } return new ProcessInstanceView(pi); }
@Override public void copyFromSource() { if (this.id != null) { return; } this.compositeId = System.getProperty("org.kie.server.id", "") + "_" + source.getId(); this.containerId = ((WorkflowProcessInstance)source).getDeploymentId(); this.correlationKey = ((WorkflowProcessInstanceImpl)source).getCorrelationKey(); this.date = new Date(); this.id = source.getId(); this.initiator = (String) ((WorkflowProcessInstanceImpl)source).getVariable("initiator"); this.parentId = source.getParentProcessInstanceId(); this.processId = source.getProcessId(); this.processInstanceDescription = ((WorkflowProcessInstanceImpl)source).getDescription(); this.processName = source.getProcessName(); this.processVersion = source.getProcess().getVersion(); this.state = source.getState(); this.variables = ((WorkflowProcessInstanceImpl)source).getVariables(); }
/** * Fill the process instance .kruntime and .process fields with the appropriate values. * @param processInstance * @param streamContext */ private void connectProcessInstanceToRuntimeAndProcess(ProcessInstance processInstance, Object streamContext) { ProcessInstanceImpl processInstanceImpl = (ProcessInstanceImpl) processInstance; InternalKnowledgeRuntime kruntime = processInstanceImpl.getKnowledgeRuntime(); // Attach the kruntime if not present if ( kruntime == null ) { kruntime = retrieveKnowledgeRuntime( streamContext ); processInstanceImpl.setKnowledgeRuntime( kruntime ); } // Attach the process if not present if ( processInstance.getProcess() == null ) { String processId = processInstance.getProcessId(); if (processId != null) { Process process = kruntime.getKieBase().getProcess( processId ); if (process != null) { processInstanceImpl.setProcess( process ); } } } }
public ProcessEvent(org.kie.api.event.process.ProcessEvent event) { this.processId = event.getProcessInstance().getProcessId(); this.version = event.getProcessInstance().getProcess().getVersion(); this.processInstanceId = event.getProcessInstance().getId(); this.state = event.getProcessInstance().getState(); this.processName = event.getProcessInstance().getProcessName(); }
public void afterProcessStarted(ProcessStartedEvent event) { logger.debug("after process"); Map<String, Object> metaData = event.getProcessInstance().getProcess().getMetaData(); for (Map.Entry<String, Object> entry: metaData.entrySet()) { logger.debug(entry.getKey() + " " + entry.getValue()); } String customTag = (String) metaData.get("customTagProcess"); if (customTag != null) { list4.add(customTag); } } });
public SimulationEvent simulate(Object activity, SimulationContext context) { NodeInstance nodeInstance = (NodeInstance) activity; long startTime = context.getClock().getCurrentTime(); ProcessInstance pi = nodeInstance.getProcessInstance(); Node node = nodeInstance.getNode(); String bpmn2NodeId = (String) node.getMetaData().get("UniqueId"); String processName = pi.getProcessName(); String processVer = pi.getProcess().getVersion(); if (processVer == null) { processVer = ""; } // set end time for processinstance end time context.setMaxEndTime(context.getClock().getCurrentTime()); return new EndSimulationEvent(pi.getProcessId(), context.getProcessInstanceId(), startTime, context.getClock().getCurrentTime(), context.getStartTime(), bpmn2NodeId, node.getName(), processName, processVer); }
if (context.getProcessInstance() != null && context.getProcessInstance().getProcess() != null) {
public SimulationEvent simulate(Object activity, SimulationContext context) { NodeInstance nodeInstance = (NodeInstance) activity; long startTime = context.getClock().getCurrentTime(); ProcessInstance pi = nodeInstance.getProcessInstance(); Node node = nodeInstance.getNode(); String bpmn2NodeId = (String) node.getMetaData().get("UniqueId"); String processName = pi.getProcessName(); String processVer = pi.getProcess().getVersion(); if (processVer == null) { processVer = ""; } // set end time for processinstance end time context.setMaxEndTime(context.getClock().getCurrentTime()); return new EndSimulationEvent(pi.getProcessId(), context.getProcessInstanceId(), startTime, context.getClock().getCurrentTime(), context.getStartTime(), bpmn2NodeId, node.getName(), processName, processVer); }
public void writeProcessInstances(MarshallerWriteContext context) throws IOException { ProtobufMessages.ProcessData.Builder _pdata = (ProtobufMessages.ProcessData.Builder) context.parameterObject; List<org.kie.api.runtime.process.ProcessInstance> processInstances = new ArrayList<org.kie.api.runtime.process.ProcessInstance>( context.wm.getProcessInstances() ); Collections.sort( processInstances, new Comparator<org.kie.api.runtime.process.ProcessInstance>() { public int compare(org.kie.api.runtime.process.ProcessInstance o1, org.kie.api.runtime.process.ProcessInstance o2) { return (int) (o1.getId() - o2.getId()); } } ); for ( org.kie.api.runtime.process.ProcessInstance processInstance : processInstances ) { String processType = processInstance.getProcess().getType(); JBPMMessages.ProcessInstance _instance = (JBPMMessages.ProcessInstance) ProcessMarshallerRegistry.INSTANCE.getMarshaller( processType ) .writeProcessInstance( context, processInstance ); _pdata.addExtension( JBPMMessages.processInstance, _instance ); } }
public void execute(ProcessContext context) throws Exception { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("JavaScript"); engine.put("kcontext", context); // insert globals into context Globals globals = context.getKieRuntime().getGlobals(); if (globals != null && globals.getGlobalKeys() != null) { for (String gKey : globals.getGlobalKeys()) { engine.put(gKey, globals.get(gKey)); } } if (context.getProcessInstance() != null && context.getProcessInstance().getProcess() != null) { // insert process variables VariableScopeInstance variableScope = (VariableScopeInstance) ((WorkflowProcessInstance)context.getProcessInstance()) .getContextInstance(VariableScope.VARIABLE_SCOPE); Map<String, Object> variables = variableScope.getVariables(); if (variables != null ) { for (Entry<String, Object> variable : variables.entrySet()) { engine.put(variable.getKey(), variable.getValue()); } } } engine.eval(expr); }
if (context.getProcessInstance() != null && context.getProcessInstance().getProcess() != null) {
public void afterVariableChanged(ProcessVariableChangedEvent event) { logger.debug("after variable"); VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.impl.ProcessImpl) event.getProcessInstance().getProcess()) .resolveContext(VariableScope.VARIABLE_SCOPE, event.getVariableId()); if (variableScope == null) { return; } Map<String, Object> metaData = variableScope.findVariable(event.getVariableId()).getMetaData(); for (Map.Entry<String, Object> entry: metaData.entrySet()) { logger.debug(entry.getKey() + " " + entry.getValue()); } String customTag = (String) metaData.get("customTagVar"); if (customTag != null) { list3.add(customTag); } } public void afterProcessStarted(ProcessStartedEvent event) {
@Test public void testAssociation() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-Association.bpmn2"); ksession = createKnowledgeSession(kbase); ProcessInstance processInstance = ksession.startProcess("Evaluation"); List<Association> associations = (List<Association>) processInstance.getProcess().getMetaData().get(ProcessHandler.ASSOCIATIONS); assertNotNull(associations); assertTrue(associations.size() == 1); Association assoc = associations.get(0); assertEquals("_1234", assoc.getId()); assertEquals("_1", assoc.getSourceRef()); assertEquals("_2", assoc.getTargetRef()); }
@Test public void testDataStore() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-DataStore.bpmn2"); ksession = createKnowledgeSession(kbase); ProcessInstance processInstance = ksession.startProcess("Evaluation"); Definitions def = (Definitions) processInstance.getProcess() .getMetaData().get("Definitions"); assertNotNull(def.getDataStores()); assertTrue(def.getDataStores().size() == 1); DataStore dataStore = def.getDataStores().get(0); assertEquals("employee", dataStore.getId()); assertEquals("employeeStore", dataStore.getName()); assertEquals(String.class.getCanonicalName(), ((ObjectDataType) dataStore.getType()).getClassName()); }
if (session != null) { if (session.getProcessInstance(workItem.getProcessInstanceId()) != null) { taskData.setProcessId(session.getProcessInstance(workItem.getProcessInstanceId()).getProcess().getId()); String deploymentId = ((WorkItemImpl) workItem).getDeploymentId(); taskData.setDeploymentId(deploymentId);
public org.drools.definition.process.Process getProcess() { return new ProcessAdapter(delegate.getProcess()); }
public void afterProcessStarted(ProcessStartedEvent event) { logger.debug("after process"); Map<String, Object> metaData = event.getProcessInstance().getProcess().getMetaData(); for (Map.Entry<String, Object> entry: metaData.entrySet()) { logger.debug(entry.getKey() + " " + entry.getValue()); } String customTag = (String) metaData.get("customTagProcess"); if (customTag != null) { list4.add(customTag); } } });
public void afterVariableChanged(ProcessVariableChangedEvent event) { logger.debug("after variable"); VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.impl.ProcessImpl) event.getProcessInstance().getProcess()) .resolveContext(VariableScope.VARIABLE_SCOPE, event.getVariableId()); if (variableScope == null) { return; } Map<String, Object> metaData = variableScope.findVariable(event.getVariableId()).getMetaData(); for (Map.Entry<String, Object> entry: metaData.entrySet()) { logger.debug(entry.getKey() + " " + entry.getValue()); } String customTag = (String) metaData.get("customTagVar"); if (customTag != null) { list3.add(customTag); } } public void afterProcessStarted(ProcessStartedEvent event) {
@Test public void testAssociation() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-Association.bpmn2"); ksession = createKnowledgeSession(kbase); ProcessInstance processInstance = ksession.startProcess("Evaluation"); List<Association> associations = (List<Association>) processInstance.getProcess().getMetaData().get(ProcessHandler.ASSOCIATIONS); assertNotNull(associations); assertTrue(associations.size() == 1); Association assoc = associations.get(0); assertEquals("_1234", assoc.getId()); assertEquals("_1", assoc.getSourceRef()); assertEquals("_2", assoc.getTargetRef()); }
@Test public void testDataStore() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-DataStore.bpmn2"); ksession = createKnowledgeSession(kbase); ProcessInstance processInstance = ksession.startProcess("Evaluation"); Definitions def = (Definitions) processInstance.getProcess() .getMetaData().get("Definitions"); assertNotNull(def.getDataStores()); assertTrue(def.getDataStores().size() == 1); DataStore dataStore = def.getDataStores().get(0); assertEquals("employee", dataStore.getId()); assertEquals("employeeStore", dataStore.getName()); assertEquals(String.class.getCanonicalName(), ((ObjectDataType) dataStore.getType()).getClassName()); }